mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add sanity checks to refuse to delete bad savedata (resulted in devastating delete of SAVEDATA/ in MGS PW!)
Thanks QWEmct for reporting in #6600. This is not a full fix, really, a "NEW DATA" savegame should not show up in the delete list, but at least this prevents the bad thing from happening.
This commit is contained in:
parent
c8ac26e502
commit
7802bf57f0
1 changed files with 30 additions and 11 deletions
|
@ -252,6 +252,9 @@ std::string SavedataParam::GetSaveFilePath(const SceUtilitySavedataParam *param,
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!saveDir.size())
|
||||||
|
return "";
|
||||||
|
|
||||||
return savePath + saveDir;
|
return savePath + saveDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,14 +314,23 @@ bool SavedataParam::HasKey(const SceUtilitySavedataParam *param) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId)
|
bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId) {
|
||||||
{
|
if (!param) {
|
||||||
if (!param)
|
return false;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
// Sanity check, preventing full delete of savedata/ in MGS PW demo (!)
|
||||||
|
if (!strlen(param->gameName)) {
|
||||||
|
ERROR_LOG(SCEUTILITY, "Bad param with gameName empty - cannot delete save directory");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dirPath = GetSaveFilePath(param,saveId);
|
std::string dirPath = GetSaveFilePath(param,saveId);
|
||||||
|
if (dirPath.size() == 0) {
|
||||||
|
ERROR_LOG(SCEUTILITY, "GetSaveFilePath returned empty - cannot delete save directory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pspFileSystem.GetFileInfo(dirPath).exists) {
|
if (!pspFileSystem.GetFileInfo(dirPath).exists) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -328,21 +340,28 @@ bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId)
|
||||||
}
|
}
|
||||||
|
|
||||||
int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
|
int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
|
||||||
if(!param)
|
if (!param) {
|
||||||
return SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
|
return SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
|
||||||
if (param->fileName[0] == '\0')
|
}
|
||||||
|
if (param->fileName[0] == '\0') {
|
||||||
return SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
|
return SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string subFolder = GetGameName(param) + GetSaveName(param);
|
||||||
|
std::string filename = savePath + subFolder + "/" + GetFileName(param);
|
||||||
|
if (!subFolder.size()) {
|
||||||
|
ERROR_LOG(SCEUTILITY, "Bad subfolder, ignoring delete of %s", filename.c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::string filename = savePath + GetGameName(param) + GetSaveName(param) + "/" + GetFileName(param);
|
|
||||||
PSPFileInfo info = pspFileSystem.GetFileInfo(filename);
|
PSPFileInfo info = pspFileSystem.GetFileInfo(filename);
|
||||||
if (info.exists)
|
if (info.exists) {
|
||||||
pspFileSystem.RemoveFile(filename);
|
pspFileSystem.RemoveFile(filename);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveDirName, bool secureMode)
|
bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveDirName, bool secureMode) {
|
||||||
{
|
|
||||||
if (!param) {
|
if (!param) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue