summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/game_list.cpp14
-rw-r--r--src/yuzu/game_list.h7
-rw-r--r--src/yuzu/main.cpp167
-rw-r--r--src/yuzu/main.h7
-rw-r--r--src/yuzu/uisettings.h1
5 files changed, 196 insertions, 0 deletions
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp
index 5c33c1b0f..22aa19c56 100644
--- a/src/yuzu/game_list.cpp
+++ b/src/yuzu/game_list.cpp
@@ -554,6 +554,12 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri
554 QAction* dump_romfs_sdmc = dump_romfs_menu->addAction(tr("Dump RomFS to SDMC")); 554 QAction* dump_romfs_sdmc = dump_romfs_menu->addAction(tr("Dump RomFS to SDMC"));
555 QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard")); 555 QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard"));
556 QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry")); 556 QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry"));
557#ifndef WIN32
558 QMenu* shortcut_menu = context_menu.addMenu(tr("Create Shortcut"));
559 QAction* create_desktop_shortcut = shortcut_menu->addAction(tr("Add to Desktop"));
560 QAction* create_applications_menu_shortcut =
561 shortcut_menu->addAction(tr("Add to Applications Menu"));
562#endif
557 context_menu.addSeparator(); 563 context_menu.addSeparator();
558 QAction* properties = context_menu.addAction(tr("Properties")); 564 QAction* properties = context_menu.addAction(tr("Properties"));
559 565
@@ -619,6 +625,14 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri
619 connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() { 625 connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() {
620 emit NavigateToGamedbEntryRequested(program_id, compatibility_list); 626 emit NavigateToGamedbEntryRequested(program_id, compatibility_list);
621 }); 627 });
628#ifndef WIN32
629 connect(create_desktop_shortcut, &QAction::triggered, [this, program_id, path]() {
630 emit CreateShortcut(program_id, path, GameListShortcutTarget::Desktop);
631 });
632 connect(create_applications_menu_shortcut, &QAction::triggered, [this, program_id, path]() {
633 emit CreateShortcut(program_id, path, GameListShortcutTarget::Applications);
634 });
635#endif
622 connect(properties, &QAction::triggered, 636 connect(properties, &QAction::triggered,
623 [this, path]() { emit OpenPerGameGeneralRequested(path); }); 637 [this, path]() { emit OpenPerGameGeneralRequested(path); });
624}; 638};
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h
index cdf085019..f7ff93ed9 100644
--- a/src/yuzu/game_list.h
+++ b/src/yuzu/game_list.h
@@ -52,6 +52,11 @@ enum class DumpRomFSTarget {
52 SDMC, 52 SDMC,
53}; 53};
54 54
55enum class GameListShortcutTarget {
56 Desktop,
57 Applications,
58};
59
55enum class InstalledEntryType { 60enum class InstalledEntryType {
56 Game, 61 Game,
57 Update, 62 Update,
@@ -108,6 +113,8 @@ signals:
108 const std::string& game_path); 113 const std::string& game_path);
109 void DumpRomFSRequested(u64 program_id, const std::string& game_path, DumpRomFSTarget target); 114 void DumpRomFSRequested(u64 program_id, const std::string& game_path, DumpRomFSTarget target);
110 void CopyTIDRequested(u64 program_id); 115 void CopyTIDRequested(u64 program_id);
116 void CreateShortcut(u64 program_id, const std::string& game_path,
117 GameListShortcutTarget target);
111 void NavigateToGamedbEntryRequested(u64 program_id, 118 void NavigateToGamedbEntryRequested(u64 program_id,
112 const CompatibilityList& compatibility_list); 119 const CompatibilityList& compatibility_list);
113 void OpenPerGameGeneralRequested(const std::string& file); 120 void OpenPerGameGeneralRequested(const std::string& file);
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 6c204416f..7ae30abde 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -4,6 +4,8 @@
4#include <cinttypes> 4#include <cinttypes>
5#include <clocale> 5#include <clocale>
6#include <cmath> 6#include <cmath>
7#include <fstream>
8#include <iostream>
7#include <memory> 9#include <memory>
8#include <thread> 10#include <thread>
9#ifdef __APPLE__ 11#ifdef __APPLE__
@@ -1249,6 +1251,7 @@ void GMainWindow::ConnectWidgetEvents() {
1249 connect(game_list, &GameList::CopyTIDRequested, this, &GMainWindow::OnGameListCopyTID); 1251 connect(game_list, &GameList::CopyTIDRequested, this, &GMainWindow::OnGameListCopyTID);
1250 connect(game_list, &GameList::NavigateToGamedbEntryRequested, this, 1252 connect(game_list, &GameList::NavigateToGamedbEntryRequested, this,
1251 &GMainWindow::OnGameListNavigateToGamedbEntry); 1253 &GMainWindow::OnGameListNavigateToGamedbEntry);
1254 connect(game_list, &GameList::CreateShortcut, this, &GMainWindow::OnGameListCreateShortcut);
1252 connect(game_list, &GameList::AddDirectory, this, &GMainWindow::OnGameListAddDirectory); 1255 connect(game_list, &GameList::AddDirectory, this, &GMainWindow::OnGameListAddDirectory);
1253 connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, 1256 connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this,
1254 &GMainWindow::OnGameListAddDirectory); 1257 &GMainWindow::OnGameListAddDirectory);
@@ -2378,6 +2381,138 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
2378 QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory)); 2381 QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory));
2379} 2382}
2380 2383
2384void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
2385 GameListShortcutTarget target) {
2386 // Get path to yuzu executable
2387 const QStringList args = QApplication::arguments();
2388 std::filesystem::path yuzu_command = args[0].toStdString();
2389
2390#if defined(__linux__) || defined(__FreeBSD__)
2391 // If relative path, make it an absolute path
2392 if (yuzu_command.c_str()[0] == '.') {
2393 yuzu_command = Common::FS::GetCurrentDir() / yuzu_command;
2394 }
2395
2396#if defined(__linux__)
2397 // Warn once if we are making a shortcut to a volatile AppImage
2398 const std::string appimage_ending =
2399 std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage");
2400 if (yuzu_command.string().ends_with(appimage_ending) &&
2401 !UISettings::values.shortcut_already_warned) {
2402 if (QMessageBox::warning(this, tr("Create Shortcut"),
2403 tr("This will create a shortcut to the current AppImage. This may "
2404 "not work well if you update. Continue?"),
2405 QMessageBox::StandardButton::Ok |
2406 QMessageBox::StandardButton::Cancel) ==
2407 QMessageBox::StandardButton::Cancel) {
2408 return;
2409 }
2410 UISettings::values.shortcut_already_warned = true;
2411 }
2412#endif // __linux__
2413#endif // __linux__ || __FreeBSD__
2414
2415 std::filesystem::path target_directory{};
2416 // Determine target directory for shortcut
2417#if defined(__linux__) || defined(__FreeBSD__)
2418 const char* home = std::getenv("HOME");
2419 const std::filesystem::path home_path = (home == nullptr ? "~" : home);
2420 const char* xdg_data_home = std::getenv("XDG_DATA_HOME");
2421
2422 if (target == GameListShortcutTarget::Desktop) {
2423 target_directory = home_path / "Desktop";
2424 if (!Common::FS::IsDir(target_directory)) {
2425 QMessageBox::critical(this, tr("Create Shortcut"),
2426 tr("Cannot create shortcut on desktop. Path doesn't exist"),
2427 QMessageBox::StandardButton::Ok);
2428 return;
2429 }
2430 } else if (target == GameListShortcutTarget::Applications) {
2431 target_directory =
2432 (xdg_data_home == nullptr ? home_path / ".local/share/applications" : xdg_data_home);
2433 if (!Common::FS::IsDir(target_directory)) {
2434 QMessageBox::critical(
2435 this, tr("Create Shortcut"),
2436 tr("Cannot create shortcut in applications menu. Path doesn't exist"),
2437 QMessageBox::StandardButton::Ok);
2438 return;
2439 }
2440 }
2441#endif
2442
2443 const std::string game_file_name = std::filesystem::path(game_path).filename().string();
2444 // Determine full paths for icon and shortcut
2445#if defined(__linux__) || defined(__FreeBSD__)
2446 const std::filesystem::path icon_path =
2447 Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir) /
2448 (program_id == 0 ? fmt::format("{}.png", game_file_name)
2449 : fmt::format("{:016X}/icon.png", program_id));
2450 const std::filesystem::path shortcut_path =
2451 target_directory / (program_id == 0 ? fmt::format("{}.desktop", game_file_name)
2452 : fmt::format("{:016X}.desktop", program_id));
2453#else
2454 const std::filesystem::path icon_path{};
2455 const std::filesystem::path shortcut_path{};
2456#endif
2457
2458 // Get title from game file
2459 const FileSys::PatchManager pm{program_id, system->GetFileSystemController(),
2460 system->GetContentProvider()};
2461 const auto control = pm.GetControlMetadata();
2462 const auto loader = Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read));
2463
2464 std::string title{fmt::format("{:016X}", program_id)};
2465
2466 if (control.first != nullptr) {
2467 title = control.first->GetApplicationName();
2468 } else {
2469 loader->ReadTitle(title);
2470 }
2471
2472 // Get icon from game file
2473 std::vector<u8> icon_image_file{};
2474 if (control.second != nullptr) {
2475 icon_image_file = control.second->ReadAllBytes();
2476 } else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) {
2477 LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path);
2478 }
2479
2480 QImage icon_jpeg = QImage::fromData(icon_image_file.data(), icon_image_file.size());
2481#if defined(__linux__) || defined(__FreeBSD__)
2482 // Convert and write the icon as a PNG
2483 if (!icon_jpeg.save(QString::fromStdString(icon_path.string()))) {
2484 LOG_ERROR(Frontend, "Could not write icon as PNG to file");
2485 } else {
2486 LOG_INFO(Frontend, "Wrote an icon to {}", icon_path);
2487 }
2488#endif // __linux__
2489
2490#if defined(__linux__) || defined(__FreeBSD__)
2491 const std::string comment =
2492 tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString();
2493 const std::string arguments = fmt::format("-g \"{:s}\"", game_path);
2494 const std::string categories = "Game;Emulator;Qt;";
2495 const std::string keywords = "Switch;Nintendo;";
2496#else
2497 const std::string comment{};
2498 const std::string arguments{};
2499 const std::string categories{};
2500 const std::string keywords{};
2501#endif
2502 if (!CreateShortcut(shortcut_path.string(), title, comment, icon_path.string(),
2503 yuzu_command.string(), arguments, categories, keywords)) {
2504 QMessageBox::critical(this, tr("Create Shortcut"),
2505 tr("Failed to create a shortcut at %1")
2506 .arg(QString::fromStdString(shortcut_path.string())));
2507 return;
2508 }
2509
2510 LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path);
2511 QMessageBox::information(
2512 this, tr("Create Shortcut"),
2513 tr("Successfully created a shortcut to %1").arg(QString::fromStdString(title)));
2514}
2515
2381void GMainWindow::OnGameListOpenDirectory(const QString& directory) { 2516void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
2382 std::filesystem::path fs_path; 2517 std::filesystem::path fs_path;
2383 if (directory == QStringLiteral("SDMC")) { 2518 if (directory == QStringLiteral("SDMC")) {
@@ -3296,6 +3431,38 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file
3296 } 3431 }
3297} 3432}
3298 3433
3434bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::string& title,
3435 const std::string& comment, const std::string& icon_path,
3436 const std::string& command, const std::string& arguments,
3437 const std::string& categories, const std::string& keywords) {
3438#if defined(__linux__) || defined(__FreeBSD__)
3439 // This desktop file template was writting referencing
3440 // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
3441 std::string shortcut_contents{};
3442 shortcut_contents.append("[Desktop Entry]\n");
3443 shortcut_contents.append("Type=Application\n");
3444 shortcut_contents.append("Version=1.0\n");
3445 shortcut_contents.append(fmt::format("Name={:s}\n", title));
3446 shortcut_contents.append(fmt::format("Comment={:s}\n", comment));
3447 shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path));
3448 shortcut_contents.append(fmt::format("TryExec={:s}\n", command));
3449 shortcut_contents.append(fmt::format("Exec={:s} {:s}\n", command, arguments));
3450 shortcut_contents.append(fmt::format("Categories={:s}\n", categories));
3451 shortcut_contents.append(fmt::format("Keywords={:s}\n", keywords));
3452
3453 std::ofstream shortcut_stream(shortcut_path);
3454 if (!shortcut_stream.is_open()) {
3455 LOG_WARNING(Common, "Failed to create file {:s}", shortcut_path);
3456 return false;
3457 }
3458 shortcut_stream << shortcut_contents;
3459 shortcut_stream.close();
3460
3461 return true;
3462#endif
3463 return false;
3464}
3465
3299void GMainWindow::OnLoadAmiibo() { 3466void GMainWindow::OnLoadAmiibo() {
3300 if (emu_thread == nullptr || !emu_thread->IsRunning()) { 3467 if (emu_thread == nullptr || !emu_thread->IsRunning()) {
3301 return; 3468 return;
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 62d629973..a0f7aa77d 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -38,6 +38,7 @@ class QProgressDialog;
38class WaitTreeWidget; 38class WaitTreeWidget;
39enum class GameListOpenTarget; 39enum class GameListOpenTarget;
40enum class GameListRemoveTarget; 40enum class GameListRemoveTarget;
41enum class GameListShortcutTarget;
41enum class DumpRomFSTarget; 42enum class DumpRomFSTarget;
42enum class InstalledEntryType; 43enum class InstalledEntryType;
43class GameListPlaceholder; 44class GameListPlaceholder;
@@ -293,6 +294,8 @@ private slots:
293 void OnGameListCopyTID(u64 program_id); 294 void OnGameListCopyTID(u64 program_id);
294 void OnGameListNavigateToGamedbEntry(u64 program_id, 295 void OnGameListNavigateToGamedbEntry(u64 program_id,
295 const CompatibilityList& compatibility_list); 296 const CompatibilityList& compatibility_list);
297 void OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
298 GameListShortcutTarget target);
296 void OnGameListOpenDirectory(const QString& directory); 299 void OnGameListOpenDirectory(const QString& directory);
297 void OnGameListAddDirectory(); 300 void OnGameListAddDirectory();
298 void OnGameListShowList(bool show); 301 void OnGameListShowList(bool show);
@@ -365,6 +368,10 @@ private:
365 bool CheckDarkMode(); 368 bool CheckDarkMode();
366 369
367 QString GetTasStateDescription() const; 370 QString GetTasStateDescription() const;
371 bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
372 const std::string& comment, const std::string& icon_path,
373 const std::string& command, const std::string& arguments,
374 const std::string& categories, const std::string& keywords);
368 375
369 std::unique_ptr<Ui::MainWindow> ui; 376 std::unique_ptr<Ui::MainWindow> ui;
370 377
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h
index 452038cd9..2006b883e 100644
--- a/src/yuzu/uisettings.h
+++ b/src/yuzu/uisettings.h
@@ -138,6 +138,7 @@ struct Values {
138 138
139 bool configuration_applied; 139 bool configuration_applied;
140 bool reset_to_defaults; 140 bool reset_to_defaults;
141 bool shortcut_already_warned{false};
141 Settings::Setting<bool> disable_web_applet{true, "disable_web_applet"}; 142 Settings::Setting<bool> disable_web_applet{true, "disable_web_applet"};
142}; 143};
143 144