mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 11:03:45 +01:00
Merge pull request #1999 from unknownbrackets/savedata
Implement the filelist savedata mode properly + other save fixes
This commit is contained in:
commit
c85add4ede
10 files changed
+255
-128
No files matched your search
@@ -58,7 +58,7 @@ void PSPDialog::DisplayMessage(std::string text)
|
||||
PPGeDrawTextWrapped(text.c_str(), 40, 50, 420, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(0xFFFFFFFF));
|
||||
}
|
||||
|
||||
int PSPDialog::Shutdown()
|
||||
int PSPDialog::Shutdown(bool force)
|
||||
{
|
||||
status = SCE_UTILITY_STATUS_SHUTDOWN;
|
||||
return 0;
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
virtual ~PSPDialog();
|
||||
|
||||
virtual int Update();
|
||||
virtual int Shutdown();
|
||||
virtual int Shutdown(bool force = false);
|
||||
virtual void DoState(PointerWrap &p);
|
||||
|
||||
enum DialogStatus
|
||||
|
||||
@@ -239,7 +239,7 @@ int PSPMsgDialog::Abort()
|
||||
return PSPDialog::Shutdown();
|
||||
}
|
||||
|
||||
int PSPMsgDialog::Shutdown()
|
||||
int PSPMsgDialog::Shutdown(bool force)
|
||||
{
|
||||
return PSPDialog::Shutdown();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
virtual int Init(unsigned int paramAddr);
|
||||
virtual int Update();
|
||||
virtual int Shutdown();
|
||||
virtual int Shutdown(bool force = false);
|
||||
virtual void DoState(PointerWrap &p);
|
||||
int Abort();
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ int PSPSaveDialog::Init(int paramAddr)
|
||||
switch (param.GetPspParam()->focus)
|
||||
{
|
||||
case SCE_UTILITY_SAVEDATA_FOCUS_NAME:
|
||||
// TODO: This should probably force not using the list?
|
||||
currentSelectedSave = 0;
|
||||
break;
|
||||
case SCE_UTILITY_SAVEDATA_FOCUS_FIRSTLIST:
|
||||
@@ -219,7 +220,21 @@ const std::string PSPSaveDialog::GetSelectedSaveDirName()
|
||||
return param.GetSaveDirName(param.GetPspParam());
|
||||
// Intentional fallthrough when saveName not valid.
|
||||
|
||||
// TODO: Maybe also WRITEDATA/READDATA/MAKEDATA/DELETEDATA/SINGLEDELETE?
|
||||
// TODO: Test these to see what they use for the filename.
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATA:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_ERASESECURE:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_ERASE:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_DELETEDATA:
|
||||
if (param.GetSaveDirName(param.GetPspParam(), currentSelectedSave) == "<>")
|
||||
return param.GetSaveDirName(param.GetPspParam());
|
||||
// Intentional fallthrough when saveName not valid.
|
||||
|
||||
// TODO: Maybe also SINGLEDELETE/etc?
|
||||
|
||||
default:
|
||||
return param.GetSaveDirName(param.GetPspParam(), currentSelectedSave);
|
||||
@@ -770,10 +785,7 @@ int PSPSaveDialog::Update()
|
||||
status = SCE_UTILITY_STATUS_FINISHED;
|
||||
break;
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_FILES:
|
||||
if (param.GetFilesList(param.GetPspParam()))
|
||||
param.GetPspParam()->result = 0;
|
||||
else
|
||||
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
|
||||
param.GetPspParam()->result = param.GetFilesList(param.GetPspParam());
|
||||
status = SCE_UTILITY_STATUS_FINISHED;
|
||||
break;
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_GETSIZE:
|
||||
@@ -804,6 +816,7 @@ int PSPSaveDialog::Update()
|
||||
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
|
||||
status = SCE_UTILITY_STATUS_FINISHED;
|
||||
break;
|
||||
// TODO: Should reset the directory's other files.
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATA:
|
||||
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE:
|
||||
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE))
|
||||
@@ -847,9 +860,9 @@ int PSPSaveDialog::Update()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PSPSaveDialog::Shutdown()
|
||||
int PSPSaveDialog::Shutdown(bool force)
|
||||
{
|
||||
if (status != SCE_UTILITY_STATUS_FINISHED)
|
||||
if (status != SCE_UTILITY_STATUS_FINISHED && !force)
|
||||
return SCE_ERROR_UTILITY_INVALID_STATUS;
|
||||
|
||||
PSPDialog::Shutdown();
|
||||
|
||||
@@ -30,9 +30,10 @@
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_PARAM (0x80110308)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_LOAD_INTERNAL (0x8011030b)
|
||||
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK (0x80110321)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA (0x80110327)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS (0x8011032c)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK (0x80110321)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA (0x80110327)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS (0x80110328)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS (0x8011032c)
|
||||
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_SAVE_NO_MS (0x80110381)
|
||||
#define SCE_UTILITY_SAVEDATA_ERROR_SAVE_EJECT_MS (0x80110382)
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
|
||||
virtual int Init(int paramAddr);
|
||||
virtual int Update();
|
||||
virtual int Shutdown();
|
||||
virtual int Shutdown(bool force = false);
|
||||
virtual void DoState(PointerWrap &p);
|
||||
|
||||
private :
|
||||
|
||||
+169
-106
@@ -15,19 +15,21 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "SavedataParam.h"
|
||||
#include "image/png_load.h"
|
||||
#include "../HLE/sceKernelMemory.h"
|
||||
#include "../ELF/ParamSFO.h"
|
||||
#include "../HLE/sceChnnlsv.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "Core/Dialog/SavedataParam.h"
|
||||
#include "Core/Dialog/PSPSaveDialog.h"
|
||||
#include "Core/HLE/sceKernelMemory.h"
|
||||
#include "Core/HLE/sceChnnlsv.h"
|
||||
#include "Core/ELF/ParamSFO.h"
|
||||
#include "Core/HW/MemoryStick.h"
|
||||
#include "PSPSaveDialog.h"
|
||||
|
||||
std::string icon0Name = "ICON0.PNG";
|
||||
std::string icon1Name = "ICON1.PMF";
|
||||
std::string pic1Name = "PIC1.PNG";
|
||||
std::string snd0Name = "SND0.AT3";
|
||||
std::string sfoName = "PARAM.SFO";
|
||||
#include "image/png_load.h"
|
||||
|
||||
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";
|
||||
|
||||
std::string savePath = "ms0:/PSP/SAVEDATA/";
|
||||
|
||||
@@ -78,13 +80,6 @@ namespace
|
||||
return result != 0;
|
||||
}
|
||||
|
||||
struct EncryptFileInfo
|
||||
{
|
||||
int fileVersion;
|
||||
u8 key[16];
|
||||
int sdkVersion;
|
||||
};
|
||||
|
||||
bool PSPMatch(std::string text, std::string regexp)
|
||||
{
|
||||
if(text.empty() && regexp.empty())
|
||||
@@ -294,7 +289,7 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &save
|
||||
|
||||
// SAVE PARAM.SFO
|
||||
ParamSFOData sfoFile;
|
||||
std::string sfopath = dirPath+"/"+sfoName;
|
||||
std::string sfopath = dirPath+"/" + SFO_FILENAME;
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) // Read old sfo if exist
|
||||
{
|
||||
@@ -316,40 +311,43 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &save
|
||||
sfoFile.SetValue("SAVEDATA_DIRECTORY", GetSaveDir(param, saveDirName), 64);
|
||||
|
||||
// For each file, 13 bytes for filename, 16 bytes for file hash (0 in PPSSPP), 3 byte for padding
|
||||
const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3;
|
||||
const int FILE_LIST_COUNT_MAX = 99;
|
||||
const int FILE_LIST_TOTAL_SIZE = FILE_LIST_ITEM_SIZE * FILE_LIST_COUNT_MAX;
|
||||
u32 tmpDataSize = 0;
|
||||
u8* tmpDataOrig = sfoFile.GetValueData("SAVEDATA_FILE_LIST", &tmpDataSize);
|
||||
u8* tmpData = new u8[FILE_LIST_TOTAL_SIZE];
|
||||
|
||||
if (tmpDataOrig != NULL)
|
||||
memcpy(tmpData, tmpDataOrig, tmpDataSize > FILE_LIST_TOTAL_SIZE ? FILE_LIST_TOTAL_SIZE : tmpDataSize);
|
||||
else
|
||||
memset(tmpData, 0, FILE_LIST_TOTAL_SIZE);
|
||||
|
||||
if (param->dataBuf != 0)
|
||||
if (secureMode)
|
||||
{
|
||||
char *fName = (char*)tmpData;
|
||||
for(int i = 0; i < FILE_LIST_COUNT_MAX; i++)
|
||||
{
|
||||
if(fName[0] == 0)
|
||||
break; // End of list
|
||||
if(strncmp(fName,GetFileName(param).c_str(),20) == 0)
|
||||
break;
|
||||
fName += FILE_LIST_ITEM_SIZE;
|
||||
}
|
||||
const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3;
|
||||
const int FILE_LIST_COUNT_MAX = 99;
|
||||
const int FILE_LIST_TOTAL_SIZE = FILE_LIST_ITEM_SIZE * FILE_LIST_COUNT_MAX;
|
||||
u32 tmpDataSize = 0;
|
||||
u8 *tmpDataOrig = sfoFile.GetValueData("SAVEDATA_FILE_LIST", &tmpDataSize);
|
||||
u8 *tmpData = new u8[FILE_LIST_TOTAL_SIZE];
|
||||
|
||||
if (fName + 13 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE)
|
||||
snprintf(fName, 13, "%s",GetFileName(param).c_str());
|
||||
if (fName + 13 + 16 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE)
|
||||
memcpy(fName+13, cryptedHash, 16);
|
||||
if (tmpDataOrig != NULL)
|
||||
memcpy(tmpData, tmpDataOrig, tmpDataSize > FILE_LIST_TOTAL_SIZE ? FILE_LIST_TOTAL_SIZE : tmpDataSize);
|
||||
else
|
||||
memset(tmpData, 0, FILE_LIST_TOTAL_SIZE);
|
||||
|
||||
if (param->dataBuf != 0)
|
||||
{
|
||||
char *fName = (char*)tmpData;
|
||||
for(int i = 0; i < FILE_LIST_COUNT_MAX; i++)
|
||||
{
|
||||
if(fName[0] == 0)
|
||||
break; // End of list
|
||||
if(strncmp(fName,GetFileName(param).c_str(),20) == 0)
|
||||
break;
|
||||
fName += FILE_LIST_ITEM_SIZE;
|
||||
}
|
||||
|
||||
if (fName + 13 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE)
|
||||
snprintf(fName, 13, "%s",GetFileName(param).c_str());
|
||||
if (fName + 13 + 16 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE)
|
||||
memcpy(fName+13, cryptedHash, 16);
|
||||
}
|
||||
sfoFile.SetValue("SAVEDATA_FILE_LIST", tmpData, FILE_LIST_TOTAL_SIZE, FILE_LIST_TOTAL_SIZE);
|
||||
delete[] tmpData;
|
||||
}
|
||||
sfoFile.SetValue("SAVEDATA_FILE_LIST", tmpData, FILE_LIST_TOTAL_SIZE, FILE_LIST_TOTAL_SIZE);
|
||||
delete[] tmpData;
|
||||
|
||||
// Init param with 0. This will be used to detect crypted save or not on loading
|
||||
tmpData = new u8[128];
|
||||
u8 *tmpData = new u8[128];
|
||||
memset(tmpData, 0, 128);
|
||||
sfoFile.SetValue("SAVEDATA_PARAMS", tmpData, 128, 128);
|
||||
delete[] tmpData;
|
||||
@@ -409,21 +407,21 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &save
|
||||
if (param->icon0FileData.buf)
|
||||
{
|
||||
u8* data_ = (u8*)Memory::GetPointer(param->icon0FileData.buf);
|
||||
std::string icon0path = dirPath+"/"+icon0Name;
|
||||
std::string icon0path = dirPath + "/" + ICON0_FILENAME;
|
||||
WritePSPFile(icon0path, data_, param->icon0FileData.bufSize);
|
||||
}
|
||||
// SAVE ICON1
|
||||
if (param->icon1FileData.buf)
|
||||
{
|
||||
u8* data_ = (u8*)Memory::GetPointer(param->icon1FileData.buf);
|
||||
std::string icon1path = dirPath+"/"+icon1Name;
|
||||
std::string icon1path = dirPath + "/" + ICON1_FILENAME;
|
||||
WritePSPFile(icon1path, data_, param->icon1FileData.bufSize);
|
||||
}
|
||||
// SAVE PIC1
|
||||
if (param->pic1FileData.buf)
|
||||
{
|
||||
u8* data_ = (u8*)Memory::GetPointer(param->pic1FileData.buf);
|
||||
std::string pic1path = dirPath+"/"+pic1Name;
|
||||
std::string pic1path = dirPath + "/" + PIC1_FILENAME;
|
||||
WritePSPFile(pic1path, data_, param->pic1FileData.bufSize);
|
||||
}
|
||||
|
||||
@@ -431,24 +429,10 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &save
|
||||
if (param->snd0FileData.buf)
|
||||
{
|
||||
u8* data_ = (u8*)Memory::GetPointer(param->snd0FileData.buf);
|
||||
std::string snd0path = dirPath+"/"+snd0Name;
|
||||
std::string snd0path = dirPath + "/" + SND0_FILENAME;
|
||||
WritePSPFile(snd0path, data_, param->snd0FileData.bufSize);
|
||||
}
|
||||
|
||||
// Save Encryption Data
|
||||
{
|
||||
EncryptFileInfo encryptInfo;
|
||||
SceSize dataSize = sizeof(encryptInfo); // version + key + sdkVersion
|
||||
memset(&encryptInfo,0,dataSize);
|
||||
|
||||
encryptInfo.fileVersion = 1;
|
||||
encryptInfo.sdkVersion = sceKernelGetCompiledSdkVersion();
|
||||
if(param->size > 1500)
|
||||
memcpy(encryptInfo.key,param->key,16);
|
||||
|
||||
std::string encryptInfoPath = dirPath+"/"+"ENCRYPT_INFO.BIN";
|
||||
WritePSPFile(encryptInfoPath, (u8*)&encryptInfo, dataSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -485,7 +469,7 @@ bool SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &save
|
||||
strncpy(param->saveName, saveDirName.c_str(), 20);
|
||||
|
||||
ParamSFOData sfoFile;
|
||||
std::string sfopath = dirPath+"/"+sfoName;
|
||||
std::string sfopath = dirPath+"/" + SFO_FILENAME;
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) // Read sfo
|
||||
{
|
||||
@@ -854,51 +838,126 @@ bool SavedataParam::GetList(SceUtilitySavedataParam *param)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SavedataParam::GetFilesList(SceUtilitySavedataParam *param)
|
||||
int SavedataParam::GetFilesList(SceUtilitySavedataParam *param)
|
||||
{
|
||||
if (!param) {
|
||||
return false;
|
||||
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS;
|
||||
}
|
||||
// TODO : Need to be checked against more game
|
||||
|
||||
u32 dataAddr = param->fileListAddr;
|
||||
int foundFiles = 0;
|
||||
if (Memory::IsValidAddress(dataAddr)) {
|
||||
u32 fileInfosAddr = Memory::Read_U32(dataAddr + 24);
|
||||
//for Valkyria2, dataAddr+0 and dataAddr+12 has "5" for 5 files
|
||||
int numFiles = Memory::Read_U32(dataAddr);
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
// for each file (80 bytes):
|
||||
// u32 mode, u32 ??, u64 size, u64 ctime, u64 ??, u64 atime, u64 ???, u64 mtime, u64 ???
|
||||
// u8[16] filename (or 13 + padding?)
|
||||
u32 curFileInfoAddr = fileInfosAddr + i*80;
|
||||
if (Memory::IsValidAddress(curFileInfoAddr)) {
|
||||
char fileName[16];
|
||||
strncpy(fileName, Memory::GetCharPointer(curFileInfoAddr + 64),16);
|
||||
std::string filePath = savePath + GetGameName(param) + GetSaveName(param) + "/" + fileName;
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo(filePath);
|
||||
if (info.exists) {
|
||||
bool isCrypted = IsSaveEncrypted(param, GetSaveDirName(param, 0));
|
||||
Memory::Write_U32(0x21FF, curFileInfoAddr+0);
|
||||
if(isCrypted) // Crypted save are 16 bytes bigger
|
||||
Memory::Write_U64(info.size - 0x10, curFileInfoAddr+8);
|
||||
else
|
||||
Memory::Write_U64(info.size, curFileInfoAddr+8);
|
||||
if (!Memory::IsValidAddress(param->fileListAddr)) {
|
||||
ERROR_LOG_REPORT(HLE, "SavedataParam::GetFilesList(): bad fileList address %08x", param->fileListAddr);
|
||||
// Should crash.
|
||||
return -1;
|
||||
}
|
||||
|
||||
Memory::Write_U64(0,curFileInfoAddr + 16); // TODO ctime
|
||||
Memory::Write_U64(0,curFileInfoAddr + 24); // TODO unknow
|
||||
Memory::Write_U64(0,curFileInfoAddr + 32); // TODO atime
|
||||
Memory::Write_U64(0,curFileInfoAddr + 40); // TODO unknow
|
||||
Memory::Write_U64(0,curFileInfoAddr + 48); // TODO mtime
|
||||
Memory::Write_U64(0,curFileInfoAddr + 56); // TODO unknow
|
||||
foundFiles++;
|
||||
}
|
||||
auto fileList = Memory::GetStruct<SceUtilitySavedataFileListInfo>(param->fileListAddr);
|
||||
if (fileList->secureEntries.Valid() && fileList->maxSecureEntries > 99) {
|
||||
ERROR_LOG_REPORT(HLE, "SavedataParam::GetFilesList(): too many secure entries, %d", fileList->maxSecureEntries);
|
||||
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS;
|
||||
}
|
||||
if (fileList->normalEntries.Valid() && fileList->maxNormalEntries > 8192) {
|
||||
ERROR_LOG_REPORT(HLE, "SavedataParam::GetFilesList(): too many normal entries, %d", fileList->maxNormalEntries);
|
||||
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS;
|
||||
}
|
||||
if (fileList->systemEntries.Valid() && fileList->maxSystemEntries > 5) {
|
||||
ERROR_LOG_REPORT(HLE, "SavedataParam::GetFilesList(): too many system entries, %d", fileList->maxSystemEntries);
|
||||
return SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_PARAMS;
|
||||
}
|
||||
|
||||
std::string dirPath = savePath + GetGameName(param) + GetSaveName(param);
|
||||
if (!pspFileSystem.GetFileInfo(dirPath).exists) {
|
||||
DEBUG_LOG(HLE, "SavedataParam::GetFilesList(): directory %s does not exist", dirPath.c_str());
|
||||
return SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
|
||||
}
|
||||
|
||||
// Even if there are no files, initialize to 0.
|
||||
fileList->resultNumSecureEntries = 0;
|
||||
fileList->resultNumNormalEntries = 0;
|
||||
fileList->resultNumSystemEntries = 0;
|
||||
|
||||
// We need PARAMS.SFO's SAVEDATA_FILE_LIST to determine which entries are secure.
|
||||
PSPFileInfo sfoFileInfo = pspFileSystem.GetFileInfo(dirPath + "/" + SFO_FILENAME);
|
||||
std::set<std::string> secureFilenames;
|
||||
// TODO: Error code if not?
|
||||
if (sfoFileInfo.exists) {
|
||||
ParamSFOData sfoFile;
|
||||
size_t sfoSize = (size_t)sfoFileInfo.size;
|
||||
u8 *sfoData = new u8[sfoSize];
|
||||
if (ReadPSPFile(dirPath + "/" + SFO_FILENAME, &sfoData, sfoSize, NULL)){
|
||||
sfoFile.ReadSFO(sfoData, sfoSize);
|
||||
}
|
||||
delete[] sfoData;
|
||||
|
||||
u32 sfoFileListSize = 0;
|
||||
char *sfoFileList = (char *)sfoFile.GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize);
|
||||
const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3;
|
||||
const int FILE_LIST_COUNT_MAX = 99;
|
||||
|
||||
// Filenames are 13 bytes long at most. Add a NULL so there's no surprises.
|
||||
char temp[14];
|
||||
temp[13] = '\0';
|
||||
|
||||
for (int i = 0; i < FILE_LIST_COUNT_MAX; ++i) {
|
||||
// Ends at a NULL filename.
|
||||
if (sfoFileList[i * FILE_LIST_ITEM_SIZE] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(temp, &sfoFileList[i * FILE_LIST_ITEM_SIZE], 13);
|
||||
secureFilenames.insert(temp);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : verify if return true if at least 1 file found or only if all found
|
||||
return foundFiles > 0;
|
||||
// Does not list directories, nor recurse into them, and ignores files not ALL UPPERCASE.
|
||||
auto files = pspFileSystem.GetDirListing(dirPath);
|
||||
for (auto file = files.begin(), end = files.end(); file != end; ++file) {
|
||||
if (file->type == FILETYPE_DIRECTORY) {
|
||||
continue;
|
||||
}
|
||||
// TODO: What are the exact rules? It definitely skips lowercase, and allows FILE or FILE.EXT.
|
||||
if (file->name.find_first_of("abcdefghijklmnopqrstuvwxyz") != file->name.npos) {
|
||||
DEBUG_LOG(HLE, "SavedataParam::GetFilesList(): skipping file %s with lowercase", file->name.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isSystemFile = file->name == ICON0_FILENAME || file->name == ICON1_FILENAME || file->name == PIC1_FILENAME;
|
||||
isSystemFile = isSystemFile || file->name == SND0_FILENAME || file->name == SFO_FILENAME;
|
||||
|
||||
SceUtilitySavedataFileListEntry *entry = NULL;
|
||||
int sizeOffset = 0;
|
||||
if (isSystemFile) {
|
||||
if (fileList->systemEntries.Valid() && fileList->resultNumSystemEntries < fileList->maxSystemEntries) {
|
||||
entry = &fileList->systemEntries[fileList->resultNumSystemEntries++];
|
||||
}
|
||||
} else if (secureFilenames.find(file->name) != secureFilenames.end()) {
|
||||
if (fileList->secureEntries.Valid() && fileList->resultNumSecureEntries < fileList->maxSecureEntries) {
|
||||
entry = &fileList->secureEntries[fileList->resultNumSecureEntries++];
|
||||
}
|
||||
// Secure files are slightly bigger.
|
||||
bool isCrypted = IsSaveEncrypted(param, GetSaveDirName(param, 0));
|
||||
if (isCrypted) {
|
||||
sizeOffset = -0x10;
|
||||
}
|
||||
} else {
|
||||
if (fileList->normalEntries.Valid() && fileList->resultNumNormalEntries < fileList->maxNormalEntries) {
|
||||
entry = &fileList->normalEntries[fileList->resultNumNormalEntries++];
|
||||
}
|
||||
}
|
||||
|
||||
// Out of space for this file in the list.
|
||||
if (entry == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entry->st_mode = 0x21FF;
|
||||
entry->st_size = file->size + sizeOffset;
|
||||
// TODO: ctime, atime, mtime
|
||||
// TODO: Probably actually 13 + 3 pad...
|
||||
strncpy(entry->name, file->name.c_str(), 16);
|
||||
entry->name[15] = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SavedataParam::GetSize(SceUtilitySavedataParam *param)
|
||||
@@ -1006,6 +1065,10 @@ int SavedataParam::SetPspParam(SceUtilitySavedataParam *param)
|
||||
int realCount = 0;
|
||||
for (int i = 0; i < saveDataListCount; i++)
|
||||
{
|
||||
// TODO: Maybe we should fill the list with existing files instead?
|
||||
if (strcmp(saveNameListData[i], "<>") == 0)
|
||||
continue;
|
||||
|
||||
DEBUG_LOG(HLE,"Name : %s",saveNameListData[i]);
|
||||
|
||||
std::string fileDataPath = savePath+GetGameName(param) + saveNameListData[i] + "/" + param->fileName;
|
||||
@@ -1106,7 +1169,7 @@ 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 + "/" + icon0Name;
|
||||
std::string fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + ICON0_FILENAME;
|
||||
PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2);
|
||||
if (info2.exists)
|
||||
{
|
||||
@@ -1117,7 +1180,7 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
|
||||
}
|
||||
|
||||
// Load info in PARAM.SFO
|
||||
fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + sfoName;
|
||||
fileDataPath2 = savePath + GetGameName(pspParam) + saveName + "/" + SFO_FILENAME;
|
||||
info2 = pspFileSystem.GetFileInfo(fileDataPath2);
|
||||
if (info2.exists)
|
||||
{
|
||||
@@ -1322,7 +1385,7 @@ bool SavedataParam::IsSaveEncrypted(SceUtilitySavedataParam* param, const std::s
|
||||
|
||||
ParamSFOData sfoFile;
|
||||
std::string dirPath = GetSaveFilePath(param, GetSaveDir(param, saveDirName));
|
||||
std::string sfopath = dirPath+"/"+sfoName;
|
||||
std::string sfopath = dirPath + "/" + SFO_FILENAME;
|
||||
PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath);
|
||||
if(sfoInfo.exists) // Read sfo
|
||||
{
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../HLE/sceKernel.h"
|
||||
#include "../System.h"
|
||||
#include "Core/HLE/sceKernel.h"
|
||||
#include "Core/HLE/sceRtc.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
enum SceUtilitySavedataType
|
||||
{
|
||||
@@ -100,6 +101,29 @@ struct PspUtilitySavedataSizeInfo {
|
||||
char overwriteString[8];
|
||||
};
|
||||
|
||||
struct SceUtilitySavedataFileListEntry
|
||||
{
|
||||
int st_mode;
|
||||
u64 st_size;
|
||||
ScePspDateTime st_ctime;
|
||||
ScePspDateTime st_atime;
|
||||
ScePspDateTime st_mtime;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
struct SceUtilitySavedataFileListInfo
|
||||
{
|
||||
u32 maxSecureEntries;
|
||||
u32 maxNormalEntries;
|
||||
u32 maxSystemEntries;
|
||||
u32 resultNumSecureEntries;
|
||||
u32 resultNumNormalEntries;
|
||||
u32 resultNumSystemEntries;
|
||||
PSPPointer<SceUtilitySavedataFileListEntry> secureEntries;
|
||||
PSPPointer<SceUtilitySavedataFileListEntry> normalEntries;
|
||||
PSPPointer<SceUtilitySavedataFileListEntry> systemEntries;
|
||||
};
|
||||
|
||||
// Structure to hold the parameters for the sceUtilitySavedataInitStart function.
|
||||
struct SceUtilitySavedataParam
|
||||
{
|
||||
@@ -216,7 +240,7 @@ public:
|
||||
bool Load(SceUtilitySavedataParam* param, const std::string &saveDirName, int saveId = -1, bool secureMode = true);
|
||||
bool GetSizes(SceUtilitySavedataParam* param);
|
||||
bool GetList(SceUtilitySavedataParam* param);
|
||||
bool GetFilesList(SceUtilitySavedataParam* param);
|
||||
int GetFilesList(SceUtilitySavedataParam* param);
|
||||
bool GetSize(SceUtilitySavedataParam* param);
|
||||
bool IsSaveEncrypted(SceUtilitySavedataParam* param, const std::string &saveDirName);
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ void __UtilityDoState(PointerWrap &p)
|
||||
|
||||
void __UtilityShutdown()
|
||||
{
|
||||
saveDialog.Shutdown();
|
||||
msgDialog.Shutdown();
|
||||
oskDialog.Shutdown();
|
||||
netDialog.Shutdown();
|
||||
saveDialog.Shutdown(true);
|
||||
msgDialog.Shutdown(true);
|
||||
oskDialog.Shutdown(true);
|
||||
netDialog.Shutdown(true);
|
||||
}
|
||||
|
||||
int __UtilityGetStatus()
|
||||
|
||||
@@ -264,5 +264,31 @@ const char *GetAddressName(u32 address);
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PSPPointer
|
||||
{
|
||||
u32 ptr;
|
||||
|
||||
T &operator*() const
|
||||
{
|
||||
return *(T *)(Memory::base + ptr);
|
||||
}
|
||||
|
||||
T &operator[](int i) const
|
||||
{
|
||||
return *((T *)(Memory::base + ptr) + i);
|
||||
}
|
||||
|
||||
T *operator->() const
|
||||
{
|
||||
return (T *)(Memory::base + ptr);
|
||||
}
|
||||
|
||||
bool Valid() const
|
||||
{
|
||||
return Memory::IsValidAddress(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user