Added recursion depth limit to scan directories

This commit is contained in:
Pablo Santana 2025-01-28 15:46:29 +01:00
parent abafd68a3d
commit be46e4c103

View File

@ -7,7 +7,15 @@
#include "compatibility_info.h"
#include "game_info.h"
void ScanDirectoryRecursively(const QString& dir, QStringList& filePaths) {
// Maximum depth to search for games in subdirectories
const int max_recursion_depth = 5;
void ScanDirectoryRecursively(const QString& dir, QStringList& filePaths, int current_depth = 0) {
// Stop recursion if we've reached the maximum depth
if (current_depth >= max_recursion_depth) {
return;
}
QDir directory(dir);
QFileInfoList entries = directory.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
@ -20,8 +28,8 @@ void ScanDirectoryRecursively(const QString& dir, QStringList& filePaths) {
if (QFile::exists(entry.filePath() + "/sce_sys/param.sfo")) {
filePaths.append(entry.absoluteFilePath());
} else {
// If not a game directory, recursively scan it
ScanDirectoryRecursively(entry.absoluteFilePath(), filePaths);
// If not a game directory, recursively scan it with increased depth
ScanDirectoryRecursively(entry.absoluteFilePath(), filePaths, current_depth + 1);
}
}
}
@ -34,7 +42,7 @@ void GameInfoClass::GetGameInfo(QWidget* parent) {
for (const auto& installLoc : Config::getGameInstallDirs()) {
QString installDir;
Common::FS::PathToQString(installDir, installLoc);
ScanDirectoryRecursively(installDir, filePaths);
ScanDirectoryRecursively(installDir, filePaths, 0);
}
m_games = QtConcurrent::mapped(filePaths, [&](const QString& path) {