SaveData:Displays all saves like a PSP for LISTALLDELETE mode.

This commit is contained in:
shenweip 2020-10-05 00:00:28 +08:00
parent c84f9542d7
commit 81ad9a930a
3 changed files with 52 additions and 13 deletions

View File

@ -180,7 +180,6 @@ int PSPSaveDialog::Init(int paramAddr)
display = DS_SAVE_LIST_CHOICE;
break;
case SCE_UTILITY_SAVEDATA_TYPE_LISTALLDELETE:
// TODO:Should displays all saves like a PSP?
DEBUG_LOG(SCEUTILITY, "Delete. Title: %s Save: %s File: %s", param.GetGameName(param.GetPspParam()).c_str(), param.GetGameName(param.GetPspParam()).c_str(), param.GetFileName(param.GetPspParam()).c_str());
if(param.GetFilenameCount() == 0)
display = DS_DELETE_NODATA;
@ -969,6 +968,8 @@ int PSPSaveDialog::Update(int animSpeed)
if (param.GetFilenameCount() == 0)
display = DS_DELETE_NODATA;
else if (param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTDELETE || param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTALLDELETE) {
if (currentSelectedSave > param.GetFilenameCount() - 1)
currentSelectedSave = param.GetFilenameCount() - 1;
display = DS_DELETE_LIST_CHOICE;
} else {
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
@ -1039,7 +1040,7 @@ void PSPSaveDialog::ExecuteIOAction() {
}
break;
case DS_DELETE_DELETING:
if (param.Delete(param.GetPspParam(),currentSelectedSave)) {
if (param.Delete(param.GetPspParam(), currentSelectedSave)) {
result = 0;
display = DS_DELETE_DONE;
} else {

View File

@ -322,12 +322,12 @@ bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId) {
}
// Sanity check, preventing full delete of savedata/ in MGS PW demo (!)
if (!strlen(param->gameName)) {
if (!strlen(param->gameName) && param->mode != SCE_UTILITY_SAVEDATA_TYPE_LISTALLDELETE) {
ERROR_LOG(SCEUTILITY, "Bad param with gameName empty - cannot delete save directory");
return false;
}
std::string dirPath = GetSaveFilePath(param,saveId);
std::string dirPath = GetSaveFilePath(param, GetSaveDir(saveId));
if (dirPath.size() == 0) {
ERROR_LOG(SCEUTILITY, "GetSaveFilePath returned empty - cannot delete save directory");
return false;
@ -1411,6 +1411,34 @@ int SavedataParam::SetPspParam(SceUtilitySavedataParam *param)
return 0;
}
if (param->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTALLDELETE) {
Clear();
int realCount = 0;
auto allSaves = pspFileSystem.GetDirListing(savePath);
saveDataListCount = (int)allSaves.size();
saveDataList = new SaveFileInfo[saveDataListCount];
for (auto save : allSaves) {
if (save.name == "." || save.name == "..")
continue;
std::string fileDataDir = savePath + save.name;
PSPFileInfo info = pspFileSystem.GetFileInfo(fileDataDir);
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, "", save.name);
realCount++;
}
saveNameListDataCount = realCount;
return 0;
}
bool listEmptyFile = true;
if (param->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTLOAD ||
param->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTDELETE)
@ -1548,13 +1576,16 @@ int SavedataParam::SetPspParam(SceUtilitySavedataParam *param)
return 0;
}
void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::string saveName)
void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::string saveName, std::string savrDir)
{
saveInfo.size = info.size;
saveInfo.saveName = saveName;
saveInfo.idx = 0;
saveInfo.modif_time = info.mtime;
std::string saveDir = savrDir == "" ? GetGameName(pspParam) + saveName : savrDir;
saveInfo.saveDir = saveDir;
// Start with a blank slate.
if (saveInfo.texture != NULL) {
if (!noSaveIcon || saveInfo.texture != noSaveIcon->texture) {
@ -1568,13 +1599,13 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
// Search save image icon0
// TODO : If icon0 don't exist, need to use icon1 which is a moving icon. Also play sound
std::string fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + ICON0_FILENAME;
std::string fileDataPath2 = savePath + saveDir + "/" + ICON0_FILENAME;
PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2);
if (info2.exists)
saveInfo.texture = new PPGeImage(fileDataPath2);
// Load info in PARAM.SFO
fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + SFO_FILENAME;
fileDataPath2 = savePath + saveDir + "/" + SFO_FILENAME;
info2 = pspFileSystem.GetFileInfo(fileDataPath2);
if (info2.exists) {
std::vector<u8> sfoData;
@ -1590,9 +1621,9 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
}
}
void SavedataParam::SetFileInfo(int idx, PSPFileInfo &info, std::string saveName)
void SavedataParam::SetFileInfo(int idx, PSPFileInfo &info, std::string saveName, std::string saveDir)
{
SetFileInfo(saveDataList[idx], info, saveName);
SetFileInfo(saveDataList[idx], info, saveName, saveDir);
saveDataList[idx].idx = idx;
}
@ -1641,11 +1672,16 @@ const SaveFileInfo& SavedataParam::GetFileInfo(int idx)
{
return saveDataList[idx];
}
std::string SavedataParam::GetFilename(int idx) const
{
return saveDataList[idx].saveName;
}
std::string SavedataParam::GetSaveDir(int idx) const {
return saveDataList[idx].saveDir;
}
int SavedataParam::GetSelectedSave()
{
// The slot # of the same save on LOAD/SAVE lists can dismatch so this isn't right anyhow

View File

@ -65,11 +65,11 @@ static const char *const utilitySavedataTypeNames[] = {
"SAVE",
"LISTLOAD",
"LISTSAVE",
"DELETE",
"LISTDELETE",
"LISTALLDELETE",
"SIZES",
"AUTODELETE",
"SINGLEDELETE",
"DELETE",
"LIST",
"FILES",
"MAKEDATASECURE",
@ -273,6 +273,7 @@ struct SaveFileInfo
{
s64 size;
std::string saveName;
std::string saveDir;
int idx;
char title[128];
@ -341,6 +342,7 @@ public:
int GetFilenameCount();
const SaveFileInfo& GetFileInfo(int idx);
std::string GetFilename(int idx) const;
std::string GetSaveDir(int idx) const;
int GetSelectedSave();
void SetSelectedSave(int idx);
@ -361,8 +363,8 @@ public:
private:
void Clear();
void SetFileInfo(int idx, PSPFileInfo &info, std::string saveName);
void SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::string saveName);
void SetFileInfo(int idx, PSPFileInfo &info, std::string saveName, std::string saveDir = "");
void SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::string saveName, std::string saveDir = "");
void ClearFileInfo(SaveFileInfo &saveInfo, const std::string &saveName);
int LoadSaveData(SceUtilitySavedataParam *param, const std::string &saveDirName, const std::string& dirPath, bool secureMode);