summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/yuzu/main.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 7ae30abde..d9e8b751b 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -2422,34 +2422,47 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
2422 if (target == GameListShortcutTarget::Desktop) { 2422 if (target == GameListShortcutTarget::Desktop) {
2423 target_directory = home_path / "Desktop"; 2423 target_directory = home_path / "Desktop";
2424 if (!Common::FS::IsDir(target_directory)) { 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( 2425 QMessageBox::critical(
2435 this, tr("Create Shortcut"), 2426 this, tr("Create Shortcut"),
2436 tr("Cannot create shortcut in applications menu. Path doesn't exist"), 2427 tr("Cannot create shortcut on desktop. Path \"%1\" does not exist.")
2428 .arg(QString::fromStdString(target_directory)),
2437 QMessageBox::StandardButton::Ok); 2429 QMessageBox::StandardButton::Ok);
2438 return; 2430 return;
2439 } 2431 }
2432 } else if (target == GameListShortcutTarget::Applications) {
2433 target_directory = (xdg_data_home == nullptr ? home_path / ".local/share" : xdg_data_home) /
2434 "applications";
2435 if (!Common::FS::CreateDirs(target_directory)) {
2436 QMessageBox::critical(this, tr("Create Shortcut"),
2437 tr("Cannot create shortcut in applications menu. Path \"%1\" "
2438 "does not exist and cannot be created.")
2439 .arg(QString::fromStdString(target_directory)),
2440 QMessageBox::StandardButton::Ok);
2441 return;
2442 }
2440 } 2443 }
2441#endif 2444#endif
2442 2445
2443 const std::string game_file_name = std::filesystem::path(game_path).filename().string(); 2446 const std::string game_file_name = std::filesystem::path(game_path).filename().string();
2444 // Determine full paths for icon and shortcut 2447 // Determine full paths for icon and shortcut
2445#if defined(__linux__) || defined(__FreeBSD__) 2448#if defined(__linux__) || defined(__FreeBSD__)
2446 const std::filesystem::path icon_path = 2449 std::filesystem::path system_icons_path =
2447 Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir) / 2450 (xdg_data_home == nullptr ? home_path / ".local/share/" : xdg_data_home) /
2448 (program_id == 0 ? fmt::format("{}.png", game_file_name) 2451 "icons/hicolor/256x256";
2449 : fmt::format("{:016X}/icon.png", program_id)); 2452 if (!Common::FS::CreateDirs(system_icons_path)) {
2453 QMessageBox::critical(
2454 this, tr("Create Icon"),
2455 tr("Cannot create icon file. Path \"%1\" does not exist and cannot be created.")
2456 .arg(QString::fromStdString(system_icons_path)),
2457 QMessageBox::StandardButton::Ok);
2458 return;
2459 }
2460 std::filesystem::path icon_path =
2461 system_icons_path / (program_id == 0 ? fmt::format("yuzu-{}.png", game_file_name)
2462 : fmt::format("yuzu-{:016X}.png", program_id));
2450 const std::filesystem::path shortcut_path = 2463 const std::filesystem::path shortcut_path =
2451 target_directory / (program_id == 0 ? fmt::format("{}.desktop", game_file_name) 2464 target_directory / (program_id == 0 ? fmt::format("yuzu-{}.desktop", game_file_name)
2452 : fmt::format("{:016X}.desktop", program_id)); 2465 : fmt::format("yuzu-{:016X}.desktop", program_id));
2453#else 2466#else
2454 const std::filesystem::path icon_path{}; 2467 const std::filesystem::path icon_path{};
2455 const std::filesystem::path shortcut_path{}; 2468 const std::filesystem::path shortcut_path{};
@@ -2477,13 +2490,14 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
2477 LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); 2490 LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path);
2478 } 2491 }
2479 2492
2480 QImage icon_jpeg = QImage::fromData(icon_image_file.data(), icon_image_file.size()); 2493 QImage icon_jpeg =
2494 QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
2481#if defined(__linux__) || defined(__FreeBSD__) 2495#if defined(__linux__) || defined(__FreeBSD__)
2482 // Convert and write the icon as a PNG 2496 // Convert and write the icon as a PNG
2483 if (!icon_jpeg.save(QString::fromStdString(icon_path.string()))) { 2497 if (!icon_jpeg.save(QString::fromStdString(icon_path.string()))) {
2484 LOG_ERROR(Frontend, "Could not write icon as PNG to file"); 2498 LOG_ERROR(Frontend, "Could not write icon as PNG to file");
2485 } else { 2499 } else {
2486 LOG_INFO(Frontend, "Wrote an icon to {}", icon_path); 2500 LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string());
2487 } 2501 }
2488#endif // __linux__ 2502#endif // __linux__
2489 2503
@@ -2507,7 +2521,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
2507 return; 2521 return;
2508 } 2522 }
2509 2523
2510 LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path); 2524 LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path.string());
2511 QMessageBox::information( 2525 QMessageBox::information(
2512 this, tr("Create Shortcut"), 2526 this, tr("Create Shortcut"),
2513 tr("Successfully created a shortcut to %1").arg(QString::fromStdString(title))); 2527 tr("Successfully created a shortcut to %1").arg(QString::fromStdString(title)));