diff --git a/Core/System.h b/Core/System.h index 3ca344ee86..f867c746aa 100644 --- a/Core/System.h +++ b/Core/System.h @@ -58,6 +58,7 @@ enum PSPDirectories { DIRECTORY_EXDATA, DIRECTORY_CUSTOM_SHADERS, DIRECTORY_CUSTOM_THEMES, + COUNT, }; class GraphicsContext; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index eb8b9ff4ab..4b099a4f15 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -73,6 +73,19 @@ GameInfo::~GameInfo() { fileLoader.reset(); } +bool IsReasonableEbootDirectory(Path path) { + // First some sanity checks. + if (path == Path("/")) { + return false; + } + for (int i = 0; i < (int)PSPDirectories::COUNT; i++) { + if (path == GetSysDirectory((PSPDirectories)i)) { + return false; + } + } + return true; +} + bool GameInfo::Delete() { switch (fileType) { case IdentifiedFileType::PSP_ISO: @@ -90,6 +103,17 @@ bool GameInfo::Delete() { { // TODO: This could be handled by Core/Util/GameManager too somehow. Path directoryToRemove = ResolvePBPDirectory(filePath_); + + // Check that the directory isn't the base of the GAME folder, or something similarly stupid. + // This can happen if the PBP is misplaced, see issue #20187 + if (!IsReasonableEbootDirectory(directoryToRemove)) { + // Just delete the eboot. + File::Delete(filePath_); + g_recentFiles.Remove(filePath_.ToString()); + return true; + } + + // Delete the whole tree. We better be sure, see IsReasonableEbootDirectory. INFO_LOG(Log::System, "Deleting directory %s", directoryToRemove.c_str()); if (!File::DeleteDirRecursively(directoryToRemove)) { ERROR_LOG(Log::System, "Failed to delete file");