summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Franco M2023-11-05 00:39:43 +0000
committerGravatar Franco M2023-11-05 00:39:43 +0000
commit4b8b223db2ed0f79ce81083128fe8085786877cc (patch)
treefa46aa45c56e43761c2bf15b6d902b0806268280 /src
parentMerge branch 'master' into new-shortcut (diff)
downloadyuzu-4b8b223db2ed0f79ce81083128fe8085786877cc.tar.gz
yuzu-4b8b223db2ed0f79ce81083128fe8085786877cc.tar.xz
yuzu-4b8b223db2ed0f79ce81083128fe8085786877cc.zip
modified: src/yuzu/main.cpp
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp73
1 files changed, 7 insertions, 66 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index c8efd1917..6b6feb1e6 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -8,6 +8,7 @@
8#include <iostream> 8#include <iostream>
9#include <memory> 9#include <memory>
10#include <thread> 10#include <thread>
11#include <format>
11#include "core/loader/nca.h" 12#include "core/loader/nca.h"
12#include "core/tools/renderdoc.h" 13#include "core/tools/renderdoc.h"
13#ifdef __APPLE__ 14#ifdef __APPLE__
@@ -2856,6 +2857,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2856 LOG_ERROR(Frontend, "Failed to create shortcut"); 2857 LOG_ERROR(Frontend, "Failed to create shortcut");
2857 return false; 2858 return false;
2858 } 2859 }
2860 // TODO: Migrate fmt::print to std::print in futures STD C++ 23.
2859 fmt::print(shortcut_stream, "[Desktop Entry]\n"); 2861 fmt::print(shortcut_stream, "[Desktop Entry]\n");
2860 fmt::print(shortcut_stream, "Type=Application\n"); 2862 fmt::print(shortcut_stream, "Type=Application\n");
2861 fmt::print(shortcut_stream, "Version=1.0\n"); 2863 fmt::print(shortcut_stream, "Version=1.0\n");
@@ -2983,7 +2985,6 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi
2983#elif defined(__linux__) || defined(__FreeBSD__) 2985#elif defined(__linux__) || defined(__FreeBSD__)
2984 out_icon_path = Common::FS::GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256"; 2986 out_icon_path = Common::FS::GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256";
2985#endif 2987#endif
2986
2987 // Create icons directory if it doesn't exist 2988 // Create icons directory if it doesn't exist
2988 if (!Common::FS::CreateDirs(out_icon_path)) { 2989 if (!Common::FS::CreateDirs(out_icon_path)) {
2989 QMessageBox::critical( 2990 QMessageBox::critical(
@@ -2996,8 +2997,8 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi
2996 } 2997 }
2997 2998
2998 // Create icon file path 2999 // Create icon file path
2999 out_icon_path /= (program_id == 0 ? fmt::format("yuzu-{}.{}", game_file_name, ico_extension) 3000 out_icon_path /= (program_id == 0 ? std::format("yuzu-{}.{}", game_file_name, ico_extension)
3000 : fmt::format("yuzu-{:016X}.{}", program_id, ico_extension)); 3001 : std::format("yuzu-{:016X}.{}", program_id, ico_extension));
3001 return true; 3002 return true;
3002} 3003}
3003 3004
@@ -3030,7 +3031,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3030 const auto control = pm.GetControlMetadata(); 3031 const auto control = pm.GetControlMetadata();
3031 const auto loader = 3032 const auto loader =
3032 Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); 3033 Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read));
3033 game_title = fmt::format("{:016X}", program_id); 3034 game_title = std::format("{:016X}", program_id);
3034 if (control.first != nullptr) { 3035 if (control.first != nullptr) {
3035 game_title = control.first->GetApplicationName(); 3036 game_title = control.first->GetApplicationName();
3036 } else { 3037 } else {
@@ -3079,12 +3080,12 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
3079 } 3080 }
3080#endif // __linux__ 3081#endif // __linux__
3081 // Create shortcut 3082 // Create shortcut
3082 std::string arguments = fmt::format("-g \"{:s}\"", game_path); 3083 std::string arguments = std::format("-g \"{:s}\"", game_path);
3083 if (GMainWindow::CreateShortcutMessagesGUI( 3084 if (GMainWindow::CreateShortcutMessagesGUI(
3084 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, qt_game_title)) { 3085 this, GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, qt_game_title)) {
3085 arguments = "-f " + arguments; 3086 arguments = "-f " + arguments;
3086 } 3087 }
3087 const std::string comment = fmt::format("Start {:s} with the yuzu Emulator", game_title); 3088 const std::string comment = std::format("Start {:s} with the yuzu Emulator", game_title);
3088 const std::string categories = "Game;Emulator;Qt;"; 3089 const std::string categories = "Game;Emulator;Qt;";
3089 const std::string keywords = "Switch;Nintendo;"; 3090 const std::string keywords = "Switch;Nintendo;";
3090 3091
@@ -4090,66 +4091,6 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file
4090 } 4091 }
4091} 4092}
4092 4093
4093bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::string& title,
4094 const std::string& comment, const std::string& icon_path,
4095 const std::string& command, const std::string& arguments,
4096 const std::string& categories, const std::string& keywords) {
4097#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
4098 // This desktop file template was writing referencing
4099 // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
4100 std::string shortcut_contents{};
4101 shortcut_contents.append("[Desktop Entry]\n");
4102 shortcut_contents.append("Type=Application\n");
4103 shortcut_contents.append("Version=1.0\n");
4104 shortcut_contents.append(fmt::format("Name={:s}\n", title));
4105 shortcut_contents.append(fmt::format("Comment={:s}\n", comment));
4106 shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path));
4107 shortcut_contents.append(fmt::format("TryExec={:s}\n", command));
4108 shortcut_contents.append(fmt::format("Exec={:s} {:s}\n", command, arguments));
4109 shortcut_contents.append(fmt::format("Categories={:s}\n", categories));
4110 shortcut_contents.append(fmt::format("Keywords={:s}\n", keywords));
4111
4112 std::ofstream shortcut_stream(shortcut_path);
4113 if (!shortcut_stream.is_open()) {
4114 LOG_WARNING(Common, "Failed to create file {:s}", shortcut_path);
4115 return false;
4116 }
4117 shortcut_stream << shortcut_contents;
4118 shortcut_stream.close();
4119
4120 return true;
4121#elif defined(WIN32)
4122 IShellLinkW* shell_link;
4123 auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
4124 (void**)&shell_link);
4125 if (FAILED(hres)) {
4126 return false;
4127 }
4128 shell_link->SetPath(
4129 Common::UTF8ToUTF16W(command).data()); // Path to the object we are referring to
4130 shell_link->SetArguments(Common::UTF8ToUTF16W(arguments).data());
4131 shell_link->SetDescription(Common::UTF8ToUTF16W(comment).data());
4132 shell_link->SetIconLocation(Common::UTF8ToUTF16W(icon_path).data(), 0);
4133
4134 IPersistFile* persist_file;
4135 hres = shell_link->QueryInterface(IID_IPersistFile, (void**)&persist_file);
4136 if (FAILED(hres)) {
4137 return false;
4138 }
4139
4140 hres = persist_file->Save(Common::UTF8ToUTF16W(shortcut_path).data(), TRUE);
4141 if (FAILED(hres)) {
4142 return false;
4143 }
4144
4145 persist_file->Release();
4146 shell_link->Release();
4147
4148 return true;
4149#endif
4150 return false;
4151}
4152
4153void GMainWindow::OnLoadAmiibo() { 4094void GMainWindow::OnLoadAmiibo() {
4154 if (emu_thread == nullptr || !emu_thread->IsRunning()) { 4095 if (emu_thread == nullptr || !emu_thread->IsRunning()) {
4155 return; 4096 return;