From 551c61bf2781250d2817a7429a7a6c4b98ed7dc4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 14 Apr 2020 15:08:13 -0400 Subject: [PATCH] yuzu: game_list: Fix 'Open Save Data Location' for device saves. --- src/yuzu/game_list.cpp | 8 +++--- src/yuzu/game_list.h | 2 +- src/yuzu/main.cpp | 64 ++++++++++++++++++++++++++++-------------- src/yuzu/main.h | 2 +- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index dccbabcbfb..bfb600df04 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -488,11 +488,11 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, std::string pat auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); navigate_to_gamedb_entry->setVisible(it != compatibility_list.end() && program_id != 0); - connect(open_save_location, &QAction::triggered, [this, program_id]() { - emit OpenFolderRequested(program_id, GameListOpenTarget::SaveData); + connect(open_save_location, &QAction::triggered, [this, program_id, path]() { + emit OpenFolderRequested(GameListOpenTarget::SaveData, path); }); - connect(open_lfs_location, &QAction::triggered, [this, program_id]() { - emit OpenFolderRequested(program_id, GameListOpenTarget::ModData); + connect(open_lfs_location, &QAction::triggered, [this, program_id, path]() { + emit OpenFolderRequested(GameListOpenTarget::ModData, path); }); connect(open_transferable_shader_cache, &QAction::triggered, [this, program_id]() { emit OpenTransferableShaderCacheRequested(program_id); }); diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 878d944138..a38cb2fc35 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -73,7 +73,7 @@ public: signals: void GameChosen(QString game_path); void ShouldCancelWorker(); - void OpenFolderRequested(u64 program_id, GameListOpenTarget target); + void OpenFolderRequested(GameListOpenTarget target, const std::string& game_path); void OpenTransferableShaderCacheRequested(u64 program_id); void DumpRomFSRequested(u64 program_id, const std::string& game_path); void CopyTIDRequested(u64 program_id); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 86e8a1d491..437464797e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1154,40 +1154,62 @@ void GMainWindow::OnGameListLoadFile(QString game_path) { BootGame(game_path); } -void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target) { +void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path) { std::string path; QString open_target; + + const auto v_file = Core::GetGameFileFromPath(vfs, game_path); + const auto loader = Loader::GetLoader(v_file); + FileSys::NACP control{}; + u64 program_id{}; + + loader->ReadControlData(control); + loader->ReadProgramId(program_id); + + const bool has_user_save{control.GetDefaultNormalSaveSize() > 0}; + const bool has_device_save{control.GetDeviceSaveDataSize() > 0}; + + ASSERT_MSG(has_user_save != has_device_save, "Game uses both user and device savedata?"); + switch (target) { case GameListOpenTarget::SaveData: { open_target = tr("Save Data"); const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); ASSERT(program_id != 0); - const auto select_profile = [this] { - QtProfileSelectionDialog dialog(this); - dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | - Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); - dialog.setWindowModality(Qt::WindowModal); + if (has_user_save) { + // User save data + const auto select_profile = [this] { + QtProfileSelectionDialog dialog(this); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); - if (dialog.exec() == QDialog::Rejected) { - return -1; + if (dialog.exec() == QDialog::Rejected) { + return -1; + } + + return dialog.GetIndex(); + }; + + const auto index = select_profile(); + if (index == -1) { + return; } - return dialog.GetIndex(); - }; - - const auto index = select_profile(); - if (index == -1) { - return; + Service::Account::ProfileManager manager; + const auto user_id = manager.GetUser(static_cast(index)); + ASSERT(user_id); + path = nand_dir + FileSys::SaveDataFactory::GetFullPath( + FileSys::SaveDataSpaceId::NandUser, + FileSys::SaveDataType::SaveData, program_id, user_id->uuid, 0); + } else { + // Device save data + path = nand_dir + FileSys::SaveDataFactory::GetFullPath( + FileSys::SaveDataSpaceId::NandUser, + FileSys::SaveDataType::SaveData, program_id, {}, 0); } - Service::Account::ProfileManager manager; - const auto user_id = manager.GetUser(static_cast(index)); - ASSERT(user_id); - path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, - FileSys::SaveDataType::SaveData, - program_id, user_id->uuid, 0); - if (!FileUtil::Exists(path)) { FileUtil::CreateFullPath(path); FileUtil::CreateDir(path); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 60b17c54a7..1495a1b268 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -183,7 +183,7 @@ private slots: void OnMenuReportCompatibility(); /// Called whenever a user selects a game in the game list widget. void OnGameListLoadFile(QString game_path); - void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target); + void OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path); void OnTransferableShaderCacheOpenFile(u64 program_id); void OnGameListDumpRomFS(u64 program_id, const std::string& game_path); void OnGameListCopyTID(u64 program_id);