From 79cebcbef4e5a4e4388f5743c60b11c891a51c56 Mon Sep 17 00:00:00 2001 From: Pablo Santana Date: Wed, 29 Jan 2025 16:31:33 +0100 Subject: [PATCH] Added recursive search to pkg installing --- src/common/path_util.h | 2 +- src/qt_gui/main_window.cpp | 41 +++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/common/path_util.h b/src/common/path_util.h index e477a7f6b..fbb68b228 100644 --- a/src/common/path_util.h +++ b/src/common/path_util.h @@ -122,7 +122,7 @@ void PathToQString(QString& result, const std::filesystem::path& path); * * @param dir Base directory to start the search from * @param game_id The game ID to search for - * @param max_depth Maximum directory depth to search (default: 2) + * @param max_depth Maximum directory depth to search * * @returns Path to eboot.bin if found, std::nullopt otherwise */ diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 3ee392613..74090aeb5 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -728,12 +728,42 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int InstallDirSelect ids; ids.exec(); auto game_install_dir = ids.getSelectedDirectory(); - auto game_folder_path = game_install_dir / pkg.GetTitleID(); QString pkgType = QString::fromStdString(pkg.GetPkgFlags()); bool use_game_update = pkgType.contains("PATCH") && Config::getSeparateUpdateEnabled(); - auto game_update_path = use_game_update - ? game_install_dir / (std::string(pkg.GetTitleID()) + "-UPDATE") - : game_folder_path; + + // Default paths + auto game_folder_path = game_install_dir / pkg.GetTitleID(); + auto game_update_path = use_game_update + ? game_folder_path.parent_path() / (std::string{pkg.GetTitleID()} + "-UPDATE") + : game_folder_path; + const int max_depth = 5; + + if (pkgType.contains("PATCH")) { + // For patches, try to find the game recursively + auto found_game = Common::FS::FindGameByID(game_install_dir, + std::string{pkg.GetTitleID()}, max_depth); + if (found_game.has_value()) { + game_folder_path = found_game.value().parent_path(); + game_update_path = use_game_update + ? game_folder_path.parent_path() / (std::string{pkg.GetTitleID()} + "-UPDATE") + : game_folder_path; + } + } else { + // For base games, we check if the game is already installed + auto found_game = Common::FS::FindGameByID(game_install_dir, + std::string{pkg.GetTitleID()}, max_depth); + if (found_game.has_value()) { + game_folder_path = found_game.value().parent_path(); + } + // If the game is not found, we install it in the game install directory + else { + game_folder_path = game_install_dir / pkg.GetTitleID(); + } + game_update_path = use_game_update + ? game_folder_path.parent_path() / (std::string{pkg.GetTitleID()} + "-UPDATE") + : game_folder_path; + } + QString gameDirPath; Common::FS::PathToQString(gameDirPath, game_folder_path); QDir game_dir(gameDirPath); @@ -878,7 +908,8 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int connect(&futureWatcher, &QFutureWatcher::finished, this, [=, this]() { if (pkgNum == nPkg) { QString path; - Common::FS::PathToQString(path, game_install_dir); + // We want to show the parent path instead of the full path + Common::FS::PathToQString(path, game_folder_path.parent_path()); QMessageBox extractMsgBox(this); extractMsgBox.setWindowTitle(tr("Extraction Finished")); extractMsgBox.setText(