Qt: only show shortcut confirmation once

This commit is contained in:
Megamouse 2025-03-20 03:01:58 +01:00
parent 8f3eff293d
commit ccecd1a627
3 changed files with 108 additions and 82 deletions

View file

@ -1031,14 +1031,24 @@ void game_list_frame::ItemSelectionChangedSlot()
Q_EMIT NotifyGameSelection(game); Q_EMIT NotifyGameSelection(game);
} }
void game_list_frame::CreateShortcuts(const game_info& gameinfo, const std::set<gui::utils::shortcut_location>& locations) void game_list_frame::CreateShortcuts(const std::vector<game_info>& games, const std::set<gui::utils::shortcut_location>& locations)
{ {
if (locations.empty()) if (games.empty())
{ {
game_list_log.error("Failed to create shortcuts for %s. No locations selected.", qstr(gameinfo->info.name).simplified()); game_list_log.notice("Skip creating shortcuts. No games selected.");
return; return;
} }
if (locations.empty())
{
game_list_log.error("Failed to create shortcuts. No locations selected.");
return;
}
bool success = true;
for (const game_info& gameinfo : games)
{
std::string gameid_token_value; std::string gameid_token_value;
const std::string dev_flash = g_cfg_vfs.get_dev_flash(); const std::string dev_flash = g_cfg_vfs.get_dev_flash();
@ -1086,11 +1096,10 @@ void game_list_frame::CreateShortcuts(const game_info& gameinfo, const std::set<
if (!fs::create_path(target_icon_dir)) if (!fs::create_path(target_icon_dir))
{ {
game_list_log.error("Failed to create shortcut path %s (%s)", qstr(gameinfo->info.name).simplified(), target_icon_dir, fs::g_tls_error); game_list_log.error("Failed to create shortcut path %s (%s)", qstr(gameinfo->info.name).simplified(), target_icon_dir, fs::g_tls_error);
return; success = false;
continue;
} }
bool success = true;
for (const gui::utils::shortcut_location& location : locations) for (const gui::utils::shortcut_location& location : locations)
{ {
std::string destination; std::string destination;
@ -1120,19 +1129,22 @@ void game_list_frame::CreateShortcuts(const game_info& gameinfo, const std::set<
success = false; success = false;
} }
} }
}
#ifdef _WIN32 #ifdef _WIN32
if (locations.size() > 1 || !locations.contains(gui::utils::shortcut_location::rpcs3_shortcuts)) if (locations.size() == 1 && locations.contains(gui::utils::shortcut_location::rpcs3_shortcuts))
#endif
{ {
return;
}
#endif
if (success) if (success)
{ {
QMessageBox::information(this, tr("Success!"), tr("Successfully created shortcut(s).")); QMessageBox::information(this, tr("Success!"), tr("Successfully created shortcut(s)."));
} }
else else
{ {
QMessageBox::warning(this, tr("Warning!"), tr("Failed to create shortcut(s)!")); QMessageBox::warning(this, tr("Warning!"), tr("Failed to create one or more shortcuts!"));
}
} }
} }
@ -1378,7 +1390,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
QAction* create_desktop_shortcut = manage_game_menu->addAction(tr("&Create Desktop Shortcut")); QAction* create_desktop_shortcut = manage_game_menu->addAction(tr("&Create Desktop Shortcut"));
connect(create_desktop_shortcut, &QAction::triggered, this, [this, gameinfo]() connect(create_desktop_shortcut, &QAction::triggered, this, [this, gameinfo]()
{ {
CreateShortcuts(gameinfo, {gui::utils::shortcut_location::desktop}); CreateShortcuts({gameinfo}, {gui::utils::shortcut_location::desktop});
}); });
#ifdef _WIN32 #ifdef _WIN32
QAction* create_start_menu_shortcut = manage_game_menu->addAction(tr("&Create Start Menu Shortcut")); QAction* create_start_menu_shortcut = manage_game_menu->addAction(tr("&Create Start Menu Shortcut"));
@ -1389,7 +1401,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
#endif #endif
connect(create_start_menu_shortcut, &QAction::triggered, this, [this, gameinfo]() connect(create_start_menu_shortcut, &QAction::triggered, this, [this, gameinfo]()
{ {
CreateShortcuts(gameinfo, {gui::utils::shortcut_location::applications}); CreateShortcuts({gameinfo}, {gui::utils::shortcut_location::applications});
}); });
manage_game_menu->addSeparator(); manage_game_menu->addSeparator();

View file

@ -59,7 +59,7 @@ public:
const std::vector<game_info>& GetGameInfo() const; const std::vector<game_info>& GetGameInfo() const;
void CreateShortcuts(const game_info& gameinfo, const std::set<gui::utils::shortcut_location>& locations); void CreateShortcuts(const std::vector<game_info>& games, const std::set<gui::utils::shortcut_location>& locations);
bool IsEntryVisible(const game_info& game, bool search_fallback = false) const; bool IsEntryVisible(const game_info& game, bool search_fallback = false) const;

View file

@ -2497,7 +2497,13 @@ void main_window::ShowOptionalGamePreparations(const QString& title, const QStri
locations.insert(gui::utils::shortcut_location::applications); locations.insert(gui::utils::shortcut_location::applications);
} }
if (locations.empty() && !create_caches)
{
return;
}
std::vector<game_info> game_data; std::vector<game_info> game_data;
std::vector<game_info> game_data_shortcuts;
for (const auto& [boot_path, title_id] : paths) for (const auto& [boot_path, title_id] : paths)
{ {
@ -2507,7 +2513,10 @@ void main_window::ShowOptionalGamePreparations(const QString& title, const QStri
{ {
if (Emu.IsPathInsideDir(boot_path, gameinfo->info.path)) if (Emu.IsPathInsideDir(boot_path, gameinfo->info.path))
{ {
m_game_list_frame->CreateShortcuts(gameinfo, locations); if (!locations.empty())
{
game_data_shortcuts.push_back(gameinfo);
}
if (create_caches) if (create_caches)
{ {
@ -2520,6 +2529,11 @@ void main_window::ShowOptionalGamePreparations(const QString& title, const QStri
} }
} }
if (!game_data_shortcuts.empty() && !locations.empty())
{
m_game_list_frame->CreateShortcuts(game_data_shortcuts, locations);
}
if (!game_data.empty()) if (!game_data.empty())
{ {
m_game_list_frame->BatchCreateCPUCaches(game_data); m_game_list_frame->BatchCreateCPUCaches(game_data);