summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar boludoz2023-10-16 16:01:46 -0300
committerGravatar boludoz2023-10-16 16:01:46 -0300
commit89d3e81be8b923711a548b0973276353392449a6 (patch)
tree7f0920c33d73e5087e93f3a3bde27db5b8cba933 /src
parentMerge branch 'new-shortcut' of https://github.com/boludoz/yuzu into new-shortcut (diff)
downloadyuzu-89d3e81be8b923711a548b0973276353392449a6.tar.gz
yuzu-89d3e81be8b923711a548b0973276353392449a6.tar.xz
yuzu-89d3e81be8b923711a548b0973276353392449a6.zip
Sugestions and fixes.
Diffstat (limited to 'src')
-rw-r--r--src/common/fs/path_util.cpp4
-rw-r--r--src/yuzu/main.cpp104
-rw-r--r--src/yuzu/main.h2
3 files changed, 56 insertions, 54 deletions
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index bcd64156e..60c5e477e 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -268,9 +268,9 @@ fs::path GetAppDataRoamingDirectory() {
268 PWSTR appdata_roaming_path = nullptr; 268 PWSTR appdata_roaming_path = nullptr;
269 269
270 if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appdata_roaming_path))) { 270 if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appdata_roaming_path))) {
271 std::wstring wideAppdataRoamingPath(appdata_roaming_path); 271 std::wstring wide_appdata_roaming_path(appdata_roaming_path);
272 CoTaskMemFree(appdata_roaming_path); 272 CoTaskMemFree(appdata_roaming_path);
273 return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)}; 273 return fs::path{Common::UTF16ToUTF8(wide_appdata_roaming_path)};
274 } else { 274 } else {
275 LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory"); 275 LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory");
276 } 276 }
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 36f9551a1..feb455763 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -2859,11 +2859,15 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2859 return false; 2859 return false;
2860 } 2860 }
2861 2861
2862 // Append .desktop or .lnk extension 2862 if (!std::filesystem::is_regular_file(command)) {
2863 LOG_ERROR(Frontend, "Command is not a regular file");
2864 return false;
2865 }
2866
2863 std::filesystem::path shortcut_path_full = shortcut_path / filename; 2867 std::filesystem::path shortcut_path_full = shortcut_path / filename;
2864 2868
2865#if defined(__linux__) || defined(__FreeBSD__) // Linux and FreeBSD 2869#if defined(__linux__) || defined(__FreeBSD__) // Linux and FreeBSD
2866 // This desktop file template was writing referencing 2870 // Reference for the desktop file template:
2867 // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html 2871 // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
2868 try { 2872 try {
2869 2873
@@ -2911,17 +2915,17 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2911 fmt::print(shortcut_stream, "Keywords={}\n", keywords); 2915 fmt::print(shortcut_stream, "Keywords={}\n", keywords);
2912 } 2916 }
2913 2917
2918 // Flush and close file
2919 shortcut_stream.flush();
2914 shortcut_stream.close(); 2920 shortcut_stream.close();
2915 return true; 2921 return true;
2916
2917 } else { 2922 } else {
2918 LOG_ERROR(Frontend, "Failed to create shortcut"); 2923 LOG_ERROR(Frontend, "Failed to create shortcut");
2919 } 2924 }
2920
2921 shortcut_stream.close();
2922 } catch (const std::exception& e) { 2925 } catch (const std::exception& e) {
2923 LOG_ERROR(Frontend, "Failed to create shortcut: {}", e.what()); 2926 LOG_ERROR(Frontend, "Failed to create shortcut: {}", e.what());
2924 } 2927 }
2928 shortcut_stream.close();
2925 return false; 2929 return false;
2926#elif defined(_WIN32) // Windows 2930#elif defined(_WIN32) // Windows
2927 HRESULT hr = CoInitialize(NULL); 2931 HRESULT hr = CoInitialize(NULL);
@@ -2944,19 +2948,15 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2944 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 2948 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2945 IID_IShellLinkW, (void**)&ps1); 2949 IID_IShellLinkW, (void**)&ps1);
2946 2950
2947 std::wstring wshortcut_path_full = Common::UTF8ToUTF16W(shortcut_path_full.string()); 2951 std::wstring wshortcut_path_full =
2952 Common::UTF8ToUTF16W((shortcut_path_full).string() + ".lnk");
2948 std::wstring wicon_path = Common::UTF8ToUTF16W(icon_path.string()); 2953 std::wstring wicon_path = Common::UTF8ToUTF16W(icon_path.string());
2949 std::wstring wcommand = Common::UTF8ToUTF16W(command.string()); 2954 std::wstring wcommand = Common::UTF8ToUTF16W(command.string());
2950 std::wstring warguments = Common::UTF8ToUTF16W(arguments); 2955 std::wstring warguments = Common::UTF8ToUTF16W(arguments);
2951 std::wstring wcomment = Common::UTF8ToUTF16W(comment); 2956 std::wstring wcomment = Common::UTF8ToUTF16W(comment);
2952 2957
2953 if (SUCCEEDED(hres)) { 2958 if (SUCCEEDED(hres)) {
2954 if (std::filesystem::is_regular_file(command)) { 2959 hres = ps1->SetPath(wcommand.data());
2955 hres = ps1->SetPath(wcommand.data());
2956 } else {
2957 LOG_ERROR(Frontend, "Command is not a regular file");
2958 return false;
2959 }
2960 2960
2961 if (SUCCEEDED(hres) && !arguments.empty()) { 2961 if (SUCCEEDED(hres) && !arguments.empty()) {
2962 hres = ps1->SetArguments(warguments.data()); 2962 hres = ps1->SetArguments(warguments.data());
@@ -2975,8 +2975,6 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2975 } 2975 }
2976 2976
2977 if (SUCCEEDED(hres) && persist_file != nullptr) { 2977 if (SUCCEEDED(hres) && persist_file != nullptr) {
2978 // Append .lnk extension and save shortcut
2979 shortcut_path_full += ".lnk";
2980 hres = persist_file->Save(wshortcut_path_full.data(), TRUE); 2978 hres = persist_file->Save(wshortcut_path_full.data(), TRUE);
2981 if (SUCCEEDED(hres)) { 2979 if (SUCCEEDED(hres)) {
2982 return true; 2980 return true;
@@ -2995,9 +2993,10 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2995} 2993}
2996 2994
2997// Messages in pre-defined message boxes for less code spaghetti 2995// Messages in pre-defined message boxes for less code spaghetti
2998bool GMainWindow::CreateShortcutMessagesGUI(QWidget* parent, const int& imsg, 2996bool GMainWindow::CreateShortcutMessagesGUI(QWidget* parent, int imsg, const QString& game_title) {
2999 const std::string title) {
3000 QMessageBox::StandardButtons buttons; 2997 QMessageBox::StandardButtons buttons;
2998 std::string_view game_title_sv = game_title.toStdString();
2999
3001 int result = 0; 3000 int result = 0;
3002 3001
3003 switch (imsg) { 3002 switch (imsg) {
@@ -3013,18 +3012,18 @@ bool GMainWindow::CreateShortcutMessagesGUI(QWidget* parent, const int& imsg,
3013 return (result == QMessageBox::No) ? false : true; 3012 return (result == QMessageBox::No) ? false : true;
3014 3013
3015 case GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS: 3014 case GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS:
3016 QMessageBox::information( 3015 QMessageBox::information(parent, tr("Create Shortcut"),
3017 parent, tr("Create Shortcut"), 3016 tr("Successfully created a shortcut to %1").arg(game_title));
3018 tr("Successfully created a shortcut to %1").arg(QString::fromStdString(title))); 3017 LOG_INFO(Frontend, "Successfully created a shortcut to {}", game_title_sv);
3019 LOG_INFO(Frontend, "Successfully created a shortcut to {}", title);
3020 return true; 3018 return true;
3021 3019
3022 case GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING: 3020 case GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING:
3023 result = QMessageBox::warning( 3021 buttons = QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel;
3024 this, tr("Create Shortcut"), 3022 result =
3025 tr("This will create a shortcut to the current AppImage. This may " 3023 QMessageBox::warning(this, tr("Create Shortcut"),
3026 "not work well if you update. Continue?"), 3024 tr("This will create a shortcut to the current AppImage. This may "
3027 QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel); 3025 "not work well if you update. Continue?"),
3026 buttons);
3028 return (result == QMessageBox::StandardButton::Cancel) ? true : false; 3027 return (result == QMessageBox::StandardButton::Cancel) ? true : false;
3029 case GMainWindow::CREATE_SHORTCUT_MSGBOX_ADMIN: 3028 case GMainWindow::CREATE_SHORTCUT_MSGBOX_ADMIN:
3030 buttons = QMessageBox::Ok; 3029 buttons = QMessageBox::Ok;
@@ -3035,10 +3034,9 @@ bool GMainWindow::CreateShortcutMessagesGUI(QWidget* parent, const int& imsg,
3035 return true; 3034 return true;
3036 default: 3035 default:
3037 buttons = QMessageBox::Ok; 3036 buttons = QMessageBox::Ok;
3038 QMessageBox::critical( 3037 QMessageBox::critical(parent, tr("Create Shortcut"),
3039 parent, tr("Create Shortcut"), 3038 tr("Failed to create a shortcut to %1").arg(game_title), buttons);
3040 tr("Failed to create a shortcut to %1").arg(QString::fromStdString(title)), buttons); 3039 LOG_ERROR(Frontend, "Failed to create a shortcut to {}", game_title_sv);
3041 LOG_ERROR(Frontend, "Failed to create a shortcut to {}", title);
3042 return true; 3040 return true;
3043 } 3041 }
3044 3042
@@ -3077,6 +3075,10 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi
3077void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path, 3075void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
3078 GameListShortcutTarget target) { 3076 GameListShortcutTarget target) {
3079 3077
3078 std::string game_title;
3079 QString qt_game_title;
3080 std::filesystem::path out_icon_path;
3081
3080 // Get path to yuzu executable 3082 // Get path to yuzu executable
3081 const QStringList args = QApplication::arguments(); 3083 const QStringList args = QApplication::arguments();
3082 std::filesystem::path yuzu_command = args[0].toStdString(); 3084 std::filesystem::path yuzu_command = args[0].toStdString();
@@ -3092,20 +3094,11 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3092 shortcut_path = 3094 shortcut_path =
3093 QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString(); 3095 QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString();
3094 } else if (target == GameListShortcutTarget::Applications) { 3096 } else if (target == GameListShortcutTarget::Applications) {
3095#if defined(_WIN32)
3096 if (!IsUserAnAdmin()) {
3097 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ADMIN,
3098 "");
3099 return;
3100 }
3101#endif // _WIN32
3102 shortcut_path = 3097 shortcut_path =
3103 QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); 3098 QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString();
3104 } 3099 }
3105 3100
3106 // Icon path and title 3101 // Icon path and title
3107 std::string title;
3108 std::filesystem::path out_icon_path;
3109 if (std::filesystem::exists(shortcut_path)) { 3102 if (std::filesystem::exists(shortcut_path)) {
3110 // Get title from game file 3103 // Get title from game file
3111 const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), 3104 const FileSys::PatchManager pm{program_id, system->GetFileSystemController(),
@@ -3114,14 +3107,16 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3114 const auto loader = 3107 const auto loader =
3115 Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); 3108 Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read));
3116 3109
3117 title = fmt::format("{:016X}", program_id); 3110 game_title = fmt::format("{:016X}", program_id);
3118 3111
3119 if (control.first != nullptr) { 3112 if (control.first != nullptr) {
3120 title = control.first->GetApplicationName(); 3113 game_title = control.first->GetApplicationName();
3121 } else { 3114 } else {
3122 loader->ReadTitle(title); 3115 loader->ReadTitle(game_title);
3123 } 3116 }
3124 3117
3118 qt_game_title = QString::fromStdString(game_title);
3119
3125 // Get icon from game file 3120 // Get icon from game file
3126 std::vector<u8> icon_image_file{}; 3121 std::vector<u8> icon_image_file{};
3127 if (control.second != nullptr) { 3122 if (control.second != nullptr) {
@@ -3133,7 +3128,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3133 QImage icon_data = 3128 QImage icon_data =
3134 QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); 3129 QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
3135 3130
3136 if (GMainWindow::MakeShortcutIcoPath(program_id, title, out_icon_path)) { 3131 if (GMainWindow::MakeShortcutIcoPath(program_id, game_title, out_icon_path)) {
3137 if (!SaveIconToFile(out_icon_path, icon_data)) { 3132 if (!SaveIconToFile(out_icon_path, icon_data)) {
3138 LOG_ERROR(Frontend, "Could not write icon to file"); 3133 LOG_ERROR(Frontend, "Could not write icon to file");
3139 } 3134 }
@@ -3141,20 +3136,26 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3141 3136
3142 } else { 3137 } else {
3143 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, 3138 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR,
3144 title); 3139 qt_game_title);
3145 LOG_ERROR(Frontend, "Invalid shortcut target"); 3140 LOG_ERROR(Frontend, "Invalid shortcut target");
3146 return; 3141 return;
3147 } 3142 }
3148 3143
3149// Special case for AppImages 3144#if defined(_WIN32)
3150#if defined(__linux__) 3145 if (!IsUserAnAdmin() && target == GameListShortcutTarget::Applications) {
3146 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ADMIN,
3147 qt_game_title);
3148 return;
3149 }
3150#elif defined(__linux__)
3151 // Special case for AppImages
3151 // Warn once if we are making a shortcut to a volatile AppImage 3152 // Warn once if we are making a shortcut to a volatile AppImage
3152 const std::string appimage_ending = 3153 const std::string appimage_ending =
3153 std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage"); 3154 std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage");
3154 if (yuzu_command.string().ends_with(appimage_ending) && 3155 if (yuzu_command.string().ends_with(appimage_ending) &&
3155 !UISettings::values.shortcut_already_warned) { 3156 !UISettings::values.shortcut_already_warned) {
3156 if (GMainWindow::CreateShortcutMessagesGUI( 3157 if (GMainWindow::CreateShortcutMessagesGUI(
3157 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING, title)) { 3158 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING, qt_game_title)) {
3158 return; 3159 return;
3159 } 3160 }
3160 UISettings::values.shortcut_already_warned = true; 3161 UISettings::values.shortcut_already_warned = true;
@@ -3164,22 +3165,23 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3164 // Create shortcut 3165 // Create shortcut
3165 std::string arguments = fmt::format("-g \"{:s}\"", game_path); 3166 std::string arguments = fmt::format("-g \"{:s}\"", game_path);
3166 if (GMainWindow::CreateShortcutMessagesGUI( 3167 if (GMainWindow::CreateShortcutMessagesGUI(
3167 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, title)) { 3168 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, qt_game_title)) {
3168 arguments = "-f " + arguments; 3169 arguments = "-f " + arguments;
3169 } 3170 }
3170 const std::string comment = 3171 const std::string comment =
3171 tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString(); 3172 tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(game_title)).toStdString();
3172 const std::string categories = "Game;Emulator;Qt;"; 3173 const std::string categories = "Game;Emulator;Qt;";
3173 const std::string keywords = "Switch;Nintendo;"; 3174 const std::string keywords = "Switch;Nintendo;";
3174 3175
3175 if (GMainWindow::CreateShortcutLink(shortcut_path, comment, out_icon_path, yuzu_command, 3176 if (GMainWindow::CreateShortcutLink(shortcut_path, comment, out_icon_path, yuzu_command,
3176 arguments, categories, keywords, title)) { 3177 arguments, categories, keywords, game_title)) {
3177 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS, 3178 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS,
3178 title); 3179 qt_game_title);
3179 return; 3180 return;
3180 } 3181 }
3181 3182
3182 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, title); 3183 GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR,
3184 qt_game_title);
3183} 3185}
3184 3186
3185void GMainWindow::OnGameListOpenDirectory(const QString& directory) { 3187void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index d3a1bf5b9..41902cc8d 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -442,7 +442,7 @@ private:
442 bool ConfirmShutdownGame(); 442 bool ConfirmShutdownGame();
443 443
444 QString GetTasStateDescription() const; 444 QString GetTasStateDescription() const;
445 bool CreateShortcutMessagesGUI(QWidget* parent, const int& imsg, const std::string title); 445 bool CreateShortcutMessagesGUI(QWidget* parent, int imsg, const QString& game_title);
446 bool MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name, 446 bool MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name,
447 std::filesystem::path& out_icon_path); 447 std::filesystem::path& out_icon_path);
448 bool CreateShortcutLink(const std::filesystem::path& shortcut_path, const std::string& comment, 448 bool CreateShortcutLink(const std::filesystem::path& shortcut_path, const std::string& comment,