Skip to content

Commit

Permalink
Savedata: Update filelist on file erasure.
Browse files Browse the repository at this point in the history
Also stop reporting as "not coded."
  • Loading branch information
unknownbrackets committed Oct 16, 2022
1 parent cbe31af commit 29e7a53
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Core/Dialog/PSPSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static bool IsNotVisibleAction(SceUtilitySavedataType type) {
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_ERASESECURE:
case SCE_UTILITY_SAVEDATA_TYPE_ERASE:
case SCE_UTILITY_SAVEDATA_TYPE_DELETEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_AUTODELETE:
return true;
Expand Down Expand Up @@ -222,6 +224,8 @@ int PSPSaveDialog::Init(int paramAddr)
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_ERASESECURE:
case SCE_UTILITY_SAVEDATA_TYPE_ERASE:
case SCE_UTILITY_SAVEDATA_TYPE_DELETEDATA:
display = DS_NONE;
break;
Expand Down
43 changes: 38 additions & 5 deletions Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <algorithm>
#include <memory>
#include "Common/Log.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Data/Format/ZIMLoad.h"
Expand All @@ -36,14 +38,15 @@
#include "Core/HW/MemoryStick.h"
#include "Core/Util/PPGeDraw.h"

#include <algorithm>

static const std::string ICON0_FILENAME = "ICON0.PNG";
static const std::string ICON1_FILENAME = "ICON1.PMF";
static const std::string PIC1_FILENAME = "PIC1.PNG";
static const std::string SND0_FILENAME = "SND0.AT3";
static const std::string SFO_FILENAME = "PARAM.SFO";

static const int FILE_LIST_COUNT_MAX = 99;
static const u32 FILE_LIST_TOTAL_SIZE = sizeof(SaveSFOFileListEntry) * FILE_LIST_COUNT_MAX;

static const std::string savePath = "ms0:/PSP/SAVEDATA/";

namespace
Expand Down Expand Up @@ -382,6 +385,39 @@ int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
ClearCaches();
pspFileSystem.RemoveFile(filePath);

// Update PARAM.SFO to remove the file, if it was in the list.
std::shared_ptr<ParamSFOData> sfoFile = LoadCachedSFO(sfoPath);
if (sfoFile) {
// Note: do not update values such as TITLE in this operation.
u32 fileListSize = 0;
SaveSFOFileListEntry *fileList = (SaveSFOFileListEntry *)sfoFile->GetValueData("SAVEDATA_FILE_LIST", &fileListSize);
size_t fileListCount = fileListSize / sizeof(SaveSFOFileListEntry);
bool changed = false;
for (size_t i = 0; i < fileListCount; ++i) {
if (strncmp(fileList[i].filename, fileName.c_str(), sizeof(fileList[i].filename)) != 0)
continue;

memset(fileList[i].filename, 0, sizeof(fileList[i].filename));
memset(fileList[i].hash, 0, sizeof(fileList[i].hash));
changed = true;
break;
}

if (changed) {
std::unique_ptr<u8[]> updatedList(new u8[fileListSize]);
memcpy(updatedList.get(), fileList, fileListSize);
sfoFile->SetValue("SAVEDATA_FILE_LIST", updatedList.get(), fileListSize, (int)FILE_LIST_TOTAL_SIZE);

u8 *sfoData;
size_t sfoSize;
sfoFile->WriteSFO(&sfoData, &sfoSize);

ClearCaches();
WritePSPFile(sfoPath, sfoData, (SceSize)sfoSize);
delete[] sfoData;
}
}

return 0;
}

Expand Down Expand Up @@ -470,8 +506,6 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD

// Always write and update the file list.
// For each file, 13 bytes for filename, 16 bytes for file hash (0 in PPSSPP), 3 byte for padding
const int FILE_LIST_COUNT_MAX = 99;
const u32 FILE_LIST_TOTAL_SIZE = sizeof(SaveSFOFileListEntry) * FILE_LIST_COUNT_MAX;
u32 tmpDataSize = 0;
SaveSFOFileListEntry *tmpDataOrig = (SaveSFOFileListEntry *)sfoFile->GetValueData("SAVEDATA_FILE_LIST", &tmpDataSize);
SaveSFOFileListEntry *updatedList = new SaveSFOFileListEntry[FILE_LIST_COUNT_MAX];
Expand Down Expand Up @@ -825,7 +859,6 @@ std::vector<SaveSFOFileListEntry> SavedataParam::GetSFOEntries(const std::string
return result;
}

const int FILE_LIST_COUNT_MAX = 99;
u32 sfoFileListSize = 0;
SaveSFOFileListEntry *sfoFileList = (SaveSFOFileListEntry *)sfoFile->GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize);
const u32 count = std::min((u32)FILE_LIST_COUNT_MAX, sfoFileListSize / (u32)sizeof(SaveSFOFileListEntry));
Expand Down

0 comments on commit 29e7a53

Please sign in to comment.