diff options
| author | 2024-02-22 23:04:28 -0500 | |
|---|---|---|
| committer | 2024-02-22 23:04:28 -0500 | |
| commit | 9dc624f5dc7a12fd4070c5e596c4c1bafa1bbe41 (patch) | |
| tree | c15e26376a558448e001973717df45ce601aeddd | |
| parent | Merge pull request #13117 from liamwhite/ovln (diff) | |
| parent | yuzu: Fix shortcut error message (diff) | |
| download | yuzu-9dc624f5dc7a12fd4070c5e596c4c1bafa1bbe41.tar.gz yuzu-9dc624f5dc7a12fd4070c5e596c4c1bafa1bbe41.tar.xz yuzu-9dc624f5dc7a12fd4070c5e596c4c1bafa1bbe41.zip | |
Merge pull request #13121 from german77/clean-shortcut
yuzu: Fix shortcut error message
| -rw-r--r-- | src/yuzu/main.cpp | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index b2ae3db52..5c2a5bfe6 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -3010,9 +3010,6 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi | |||
| 3010 | 3010 | ||
| 3011 | void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path, | 3011 | void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path, |
| 3012 | GameListShortcutTarget target) { | 3012 | GameListShortcutTarget target) { |
| 3013 | std::string game_title; | ||
| 3014 | QString qt_game_title; | ||
| 3015 | std::filesystem::path out_icon_path; | ||
| 3016 | // Get path to yuzu executable | 3013 | // Get path to yuzu executable |
| 3017 | const QStringList args = QApplication::arguments(); | 3014 | const QStringList args = QApplication::arguments(); |
| 3018 | std::filesystem::path yuzu_command = args[0].toStdString(); | 3015 | std::filesystem::path yuzu_command = args[0].toStdString(); |
| @@ -3029,48 +3026,51 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga | |||
| 3029 | shortcut_path = | 3026 | shortcut_path = |
| 3030 | QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); | 3027 | QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); |
| 3031 | } | 3028 | } |
| 3032 | // Icon path and title | 3029 | |
| 3033 | if (std::filesystem::exists(shortcut_path)) { | 3030 | if (!std::filesystem::exists(shortcut_path)) { |
| 3034 | // Get title from game file | 3031 | GMainWindow::CreateShortcutMessagesGUI( |
| 3035 | const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), | 3032 | this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, |
| 3036 | system->GetContentProvider()}; | 3033 | QString::fromStdString(shortcut_path.generic_string())); |
| 3037 | const auto control = pm.GetControlMetadata(); | 3034 | LOG_ERROR(Frontend, "Invalid shortcut target {}", shortcut_path.generic_string()); |
| 3038 | const auto loader = | 3035 | return; |
| 3039 | Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::OpenMode::Read)); | 3036 | } |
| 3040 | game_title = fmt::format("{:016X}", program_id); | 3037 | |
| 3041 | if (control.first != nullptr) { | 3038 | // Get title from game file |
| 3042 | game_title = control.first->GetApplicationName(); | 3039 | const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), |
| 3043 | } else { | 3040 | system->GetContentProvider()}; |
| 3044 | loader->ReadTitle(game_title); | 3041 | const auto control = pm.GetControlMetadata(); |
| 3045 | } | 3042 | const auto loader = |
| 3046 | // Delete illegal characters from title | 3043 | Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::OpenMode::Read)); |
| 3047 | const std::string illegal_chars = "<>:\"/\\|?*."; | 3044 | std::string game_title = fmt::format("{:016X}", program_id); |
| 3048 | for (auto it = game_title.rbegin(); it != game_title.rend(); ++it) { | 3045 | if (control.first != nullptr) { |
| 3049 | if (illegal_chars.find(*it) != std::string::npos) { | 3046 | game_title = control.first->GetApplicationName(); |
| 3050 | game_title.erase(it.base() - 1); | 3047 | } else { |
| 3051 | } | 3048 | loader->ReadTitle(game_title); |
| 3052 | } | 3049 | } |
| 3053 | qt_game_title = QString::fromStdString(game_title); | 3050 | // Delete illegal characters from title |
| 3054 | // Get icon from game file | 3051 | const std::string illegal_chars = "<>:\"/\\|?*."; |
| 3055 | std::vector<u8> icon_image_file{}; | 3052 | for (auto it = game_title.rbegin(); it != game_title.rend(); ++it) { |
| 3056 | if (control.second != nullptr) { | 3053 | if (illegal_chars.find(*it) != std::string::npos) { |
| 3057 | icon_image_file = control.second->ReadAllBytes(); | 3054 | game_title.erase(it.base() - 1); |
| 3058 | } else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) { | ||
| 3059 | LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); | ||
| 3060 | } | 3055 | } |
| 3061 | QImage icon_data = | 3056 | } |
| 3062 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); | 3057 | const QString qt_game_title = QString::fromStdString(game_title); |
| 3063 | if (GMainWindow::MakeShortcutIcoPath(program_id, game_title, out_icon_path)) { | 3058 | // Get icon from game file |
| 3064 | if (!SaveIconToFile(out_icon_path, icon_data)) { | 3059 | std::vector<u8> icon_image_file{}; |
| 3065 | LOG_ERROR(Frontend, "Could not write icon to file"); | 3060 | if (control.second != nullptr) { |
| 3066 | } | 3061 | icon_image_file = control.second->ReadAllBytes(); |
| 3062 | } else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) { | ||
| 3063 | LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); | ||
| 3064 | } | ||
| 3065 | QImage icon_data = | ||
| 3066 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); | ||
| 3067 | std::filesystem::path out_icon_path; | ||
| 3068 | if (GMainWindow::MakeShortcutIcoPath(program_id, game_title, out_icon_path)) { | ||
| 3069 | if (!SaveIconToFile(out_icon_path, icon_data)) { | ||
| 3070 | LOG_ERROR(Frontend, "Could not write icon to file"); | ||
| 3067 | } | 3071 | } |
| 3068 | } else { | ||
| 3069 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, | ||
| 3070 | qt_game_title); | ||
| 3071 | LOG_ERROR(Frontend, "Invalid shortcut target"); | ||
| 3072 | return; | ||
| 3073 | } | 3072 | } |
| 3073 | |||
| 3074 | #if defined(__linux__) | 3074 | #if defined(__linux__) |
| 3075 | // Special case for AppImages | 3075 | // Special case for AppImages |
| 3076 | // Warn once if we are making a shortcut to a volatile AppImage | 3076 | // Warn once if we are making a shortcut to a volatile AppImage |