Savedata:Corrects the performances when the data is broken.

This commit is contained in:
shenweip 2020-10-01 15:41:27 +08:00
parent b8c1845e3a
commit c84f9542d7
4 changed files with 94 additions and 38 deletions

View File

@ -136,9 +136,14 @@ int PSPSaveDialog::Init(int paramAddr)
{
case SCE_UTILITY_SAVEDATA_TYPE_LOAD:
DEBUG_LOG(SCEUTILITY, "Loading. Title: %s Save: %s File: %s", param.GetGameName(param.GetPspParam()).c_str(), param.GetSaveName(param.GetPspParam()).c_str(), param.GetFileName(param.GetPspParam()).c_str());
if (param.GetFileInfo(0).size != 0)
display = DS_LOAD_CONFIRM;
else
if (param.GetFileInfo(0).size != 0) {
if (param.GetFileInfo(0).broken) {
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN;
display = DS_LOAD_FAILED;
} else {
display = DS_LOAD_CONFIRM;
}
} else
display = DS_LOAD_NODATA;
break;
case SCE_UTILITY_SAVEDATA_TYPE_AUTOLOAD:
@ -461,7 +466,11 @@ void PSPSaveDialog::DisplaySaveDataInfo1() {
std::lock_guard<std::mutex> guard(paramLock);
const SaveFileInfo &saveInfo = param.GetFileInfo(currentSelectedSave);
if (saveInfo.size == 0) {
if (saveInfo.broken) {
auto di = GetI18NCategory("Dialog");
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
PPGeDrawText(di->T("Corrupted Data"), 180, 136, textStyle);
} else if (saveInfo.size == 0) {
auto di = GetI18NCategory("Dialog");
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
PPGeDrawText(di->T("NEW DATA"), 180, 136, textStyle);
@ -811,7 +820,7 @@ int PSPSaveDialog::Update(int animSpeed)
DisplaySaveIcon(true);
DisplaySaveDataInfo2();
DisplayMessage(di->T("LoadingFailed", "Unable to load data."));
DisplayMessage(di->T("LoadingFailed", "Load failed\nThe data is corrupted."));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_LOAD);
@ -821,7 +830,6 @@ int PSPSaveDialog::Update(int animSpeed)
if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_LOAD) {
display = DS_LOAD_LIST_CHOICE;
} else {
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
}
}
@ -937,7 +945,10 @@ int PSPSaveDialog::Update(int animSpeed)
DisplayBanner(DB_DELETE);
if (IsButtonPressed(cancelButtonFlag)) {
display = DS_DELETE_LIST_CHOICE;
if (param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTDELETE || param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTALLDELETE)
display = DS_DELETE_LIST_CHOICE;
else
StartFade(false);
}
EndDraw();
@ -1009,10 +1020,12 @@ int PSPSaveDialog::Update(int animSpeed)
}
void PSPSaveDialog::ExecuteIOAction() {
auto &result = param.GetPspParam()->common.result;
std::lock_guard<std::mutex> guard(paramLock);
switch (display) {
case DS_LOAD_LOADING:
if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave) == 0) {
result = param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave);
if (result == 0) {
display = DS_LOAD_DONE;
} else {
display = DS_LOAD_FAILED;
@ -1027,8 +1040,10 @@ void PSPSaveDialog::ExecuteIOAction() {
break;
case DS_DELETE_DELETING:
if (param.Delete(param.GetPspParam(),currentSelectedSave)) {
result = 0;
display = DS_DELETE_DONE;
} else {
//result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;// What the result should be?
display = DS_DELETE_FAILED;
}
break;
@ -1109,15 +1124,9 @@ void PSPSaveDialog::ExecuteNotVisibleIOAction() {
break;
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
if (!param.IsSaveDirectoryExist(param.GetPspParam())){
result = param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE);
if(result == SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA)
result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
} else if (!param.IsSfoFileExist(param.GetPspParam())) {
result = SCE_UTILITY_SAVEDATA_ERROR_RW_DATA_BROKEN;
} else if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE) == 0) {
result = 0;
} else {
result = SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND;
}
break;
case SCE_UTILITY_SAVEDATA_TYPE_ERASE:
case SCE_UTILITY_SAVEDATA_TYPE_ERASESECURE:

View File

@ -31,6 +31,7 @@
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN (0x80110306)
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA (0x80110307)
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_PARAM (0x80110308)
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_FILE_NOT_FOUND (0x80110309)
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_INTERNAL (0x8011030b)
#define SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK (0x80110321)

View File

@ -341,27 +341,39 @@ bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId) {
return true;
}
int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
if (!param) {
return SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND;
}
if (param->fileName[0] == '\0') {
return 0;
}
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());
std::string fileName = GetFileName(param);
std::string dirPath = savePath + subFolder;
std::string filePath = dirPath + "/" + fileName;
std::string sfoPath = dirPath + "/" + SFO_FILENAME;
if (!pspFileSystem.GetFileInfo(dirPath).exists) {
return SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
}
if (!pspFileSystem.GetFileInfo(sfoPath).exists)
return SCE_UTILITY_SAVEDATA_ERROR_RW_DATA_BROKEN;
if (fileName != "" && !pspFileSystem.GetFileInfo(filePath).exists) {
return SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND;
}
if (fileName == "") {
return 0;
}
PSPFileInfo info = pspFileSystem.GetFileInfo(filename);
if (info.exists) {
pspFileSystem.RemoveFile(filename);
} else {
return SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND;
if (!subFolder.size()) {
ERROR_LOG(SCEUTILITY, "Bad subfolder, ignoring delete of %s", filePath.c_str());
return 0;
}
pspFileSystem.RemoveFile(filePath);
return 0;
}
@ -577,7 +589,23 @@ int SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &saveD
return SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
}
bool isRWMode = param->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATA || param->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE;
std::string dirPath = GetSaveFilePath(param, GetSaveDir(param, saveDirName));
std::string fileName = GetFileName(param);
std::string filePath = dirPath + "/" + fileName;
std::string sfoPath = dirPath + "/" + SFO_FILENAME;
if (!pspFileSystem.GetFileInfo(dirPath).exists) {
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA : SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
}
if (!pspFileSystem.GetFileInfo(sfoPath).exists)
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_DATA_BROKEN : SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN;
if (fileName != "" && !pspFileSystem.GetFileInfo(filePath).exists) {
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND : SCE_UTILITY_SAVEDATA_ERROR_LOAD_FILE_NOT_FOUND;
}
LoadSFO(param, dirPath); // Load sfo
@ -595,15 +623,10 @@ int SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &saveD
// Load SND0.AT3
LoadFile(dirPath, SND0_FILENAME, &param->snd0FileData);
std::string fileName = GetFileName(param);
if (fileName == "") {
// Don't load savedata but return success.
return 0;
}
std::string filePath = dirPath + "/" + fileName;
if (!pspFileSystem.GetFileInfo(filePath).exists) {
return SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
}
int result = LoadSaveData(param, saveDirName, dirPath, secureMode);
if (result != 0)
@ -1456,6 +1479,16 @@ int SavedataParam::SetPspParam(SceUtilitySavedataParam *param)
std::string fileDataDir = savePath + GetGameName(param) + thisSaveName;
PSPFileInfo info = pspFileSystem.GetFileInfo(fileDataDir);
if (info.exists) {
auto allFiles = pspFileSystem.GetDirListing(fileDataDir);
bool firstFile = true;
for (auto file : allFiles) {
if (firstFile) {
// Use a file in save directory to determine the directory info.
info = file;
firstFile = false;
} else
info.size += file.size;
}
SetFileInfo(realCount, info, thisSaveName);
DEBUG_LOG(SCEUTILITY,"%s Exist",fileDataDir.c_str());
@ -1486,6 +1519,16 @@ int SavedataParam::SetPspParam(SceUtilitySavedataParam *param)
PSPFileInfo info = pspFileSystem.GetFileInfo(fileDataDir);
if (info.exists)
{
auto allFiles = pspFileSystem.GetDirListing(fileDataDir);
bool firstFile = true;
for (auto file : allFiles) {
if (firstFile) {
// Use a file in save directory to determine the directory info.
info = file;
firstFile = false;
} else
info.size += file.size;
}
SetFileInfo(0, info, GetSaveName(param));
DEBUG_LOG(SCEUTILITY,"%s Exist",fileDataDir.c_str());
@ -1533,17 +1576,17 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
// Load info in PARAM.SFO
fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + SFO_FILENAME;
info2 = pspFileSystem.GetFileInfo(fileDataPath2);
if (info2.exists)
{
if (info2.exists) {
std::vector<u8> sfoData;
pspFileSystem.ReadEntireFile(fileDataPath2, sfoData);
ParamSFOData sfoFile;
if (sfoFile.ReadSFO(sfoData))
{
if (sfoFile.ReadSFO(sfoData)) {
SetStringFromSFO(sfoFile, "TITLE", saveInfo.title, sizeof(saveInfo.title));
SetStringFromSFO(sfoFile, "SAVEDATA_TITLE", saveInfo.saveTitle, sizeof(saveInfo.saveTitle));
SetStringFromSFO(sfoFile, "SAVEDATA_DETAIL", saveInfo.saveDetail, sizeof(saveInfo.saveDetail));
}
} else {
saveInfo.broken = true;
}
}
@ -1557,6 +1600,7 @@ void SavedataParam::ClearFileInfo(SaveFileInfo &saveInfo, const std::string &sav
saveInfo.size = 0;
saveInfo.saveName = saveName;
saveInfo.idx = 0;
saveInfo.broken = false;
if (saveInfo.texture != NULL) {
if (!noSaveIcon || saveInfo.texture != noSaveIcon->texture) {
delete saveInfo.texture;

View File

@ -279,11 +279,13 @@ struct SaveFileInfo
char saveTitle[128];
char saveDetail[1024];
bool broken;
tm modif_time;
PPGeImage *texture;
SaveFileInfo() : size(0), saveName(""), idx(0), texture(NULL)
SaveFileInfo() : size(0), saveName(""), idx(0), texture(NULL), broken(false)
{
memset(title, 0, 128);
memset(saveTitle, 0, 128);