mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-05 08:52:36 +00:00
Added recursive search by ID in cli mode
This commit is contained in:
parent
be46e4c103
commit
5ad8aeb30c
@ -176,6 +176,33 @@ void SetUserPath(PathType shad_path, const fs::path& new_path) {
|
|||||||
UserPaths.insert_or_assign(shad_path, new_path);
|
UserPaths.insert_or_assign(shad_path, new_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<fs::path> FindGameByID(const fs::path& dir, const std::string& game_id, int max_depth) {
|
||||||
|
if (max_depth < 0) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is the game we're looking for
|
||||||
|
if (dir.filename() == game_id && fs::exists(dir / "sce_sys" / "param.sfo")) {
|
||||||
|
auto eboot_path = dir / "eboot.bin";
|
||||||
|
if (fs::exists(eboot_path)) {
|
||||||
|
return eboot_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively search subdirectories
|
||||||
|
std::error_code ec;
|
||||||
|
for (const auto& entry : fs::directory_iterator(dir, ec)) {
|
||||||
|
if (!entry.is_directory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto found = FindGameByID(entry.path(), game_id, max_depth - 1)) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_QT_GUI
|
#ifdef ENABLE_QT_GUI
|
||||||
void PathToQString(QString& result, const std::filesystem::path& path) {
|
void PathToQString(QString& result, const std::filesystem::path& path) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef ENABLE_QT_GUI
|
#ifdef ENABLE_QT_GUI
|
||||||
@ -115,4 +116,18 @@ void PathToQString(QString& result, const std::filesystem::path& path);
|
|||||||
[[nodiscard]] std::filesystem::path PathFromQString(const QString& path);
|
[[nodiscard]] std::filesystem::path PathFromQString(const QString& path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively searches for a game directory by its ID.
|
||||||
|
* Limits search depth to prevent excessive filesystem traversal.
|
||||||
|
*
|
||||||
|
* @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)
|
||||||
|
*
|
||||||
|
* @returns Path to eboot.bin if found, std::nullopt otherwise
|
||||||
|
*/
|
||||||
|
[[nodiscard]] std::optional<std::filesystem::path> FindGameByID(const std::filesystem::path& dir,
|
||||||
|
const std::string& game_id,
|
||||||
|
int max_depth);
|
||||||
|
|
||||||
} // namespace Common::FS
|
} // namespace Common::FS
|
||||||
|
@ -167,12 +167,12 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Check if the provided path is a valid file
|
// Check if the provided path is a valid file
|
||||||
if (!std::filesystem::exists(eboot_path)) {
|
if (!std::filesystem::exists(eboot_path)) {
|
||||||
// If not a file, treat it as a game ID and search in install directories
|
// If not a file, treat it as a game ID and search in install directories recursively
|
||||||
bool game_found = false;
|
bool game_found = false;
|
||||||
|
const int max_depth = 5;
|
||||||
for (const auto& install_dir : Config::getGameInstallDirs()) {
|
for (const auto& install_dir : Config::getGameInstallDirs()) {
|
||||||
const auto candidate_path = install_dir / game_path / "eboot.bin";
|
if (auto found_path = Common::FS::FindGameByID(install_dir, game_path, max_depth)) {
|
||||||
if (std::filesystem::exists(candidate_path)) {
|
eboot_path = *found_path;
|
||||||
eboot_path = candidate_path;
|
|
||||||
game_found = true;
|
game_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -181,12 +181,12 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Check if the provided path is a valid file
|
// Check if the provided path is a valid file
|
||||||
if (!std::filesystem::exists(game_file_path)) {
|
if (!std::filesystem::exists(game_file_path)) {
|
||||||
// If not a file, treat it as a game ID and search in install directories
|
// If not a file, treat it as a game ID and search in install directories recursively
|
||||||
bool game_found = false;
|
bool game_found = false;
|
||||||
|
const int max_depth = 5;
|
||||||
for (const auto& install_dir : Config::getGameInstallDirs()) {
|
for (const auto& install_dir : Config::getGameInstallDirs()) {
|
||||||
auto potential_game_path = install_dir / game_path / "eboot.bin";
|
if (auto found_path = Common::FS::FindGameByID(install_dir, game_path, max_depth)) {
|
||||||
if (std::filesystem::exists(potential_game_path)) {
|
game_file_path = *found_path;
|
||||||
game_file_path = potential_game_path;
|
|
||||||
game_found = true;
|
game_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user