Added recursive search to pkg installing

This commit is contained in:
Pablo Santana 2025-01-29 16:31:33 +01:00
parent 5ad8aeb30c
commit 79cebcbef4
2 changed files with 37 additions and 6 deletions

View File

@ -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
*/

View File

@ -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<void>::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(