mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Quick sanity check for EBOOT deletion. Fixes #20187, although arguably we should be even stricter.
This commit is contained in:
1 parent
95efd11bcb
commit
f3c1fa7c05
2 files changed
+25
No files matched your search
@@ -58,6 +58,7 @@ enum PSPDirectories {
|
||||
DIRECTORY_EXDATA,
|
||||
DIRECTORY_CUSTOM_SHADERS,
|
||||
DIRECTORY_CUSTOM_THEMES,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
class GraphicsContext;
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user