From 36079b86d0f4155fddc476845fc0404b5f19591c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 19:53:19 +0200 Subject: [PATCH] Optimize away a couple of existence checks --- Core/Dialog/SavedataParam.cpp | 41 +++++++++++++---------------- Core/Dialog/SavedataParam.h | 2 +- Core/FileSystems/MetaFileSystem.cpp | 1 + 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 3d9b260ee4..14c6860f39 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -602,19 +602,19 @@ int SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &saveD return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA : SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA; } - if (!pspFileSystem.GetFileInfo(sfoPath).exists) + // Load sfo + if (!LoadSFO(param, dirPath)) { 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 - // Don't know what it is, but PSP always respond this and this unlock some game param->bind = 1021; - // Load another files,seems these are required by some games, e.g. Fushigi no Dungeon Fuurai no Shiren 4 Plus. + // Load another files, seems these are required by some games, e.g. Fushigi no Dungeon Fuurai no Shiren 4 Plus. // Load ICON0.PNG LoadFile(dirPath, ICON0_FILENAME, ¶m->icon0FileData); @@ -793,35 +793,33 @@ u32 SavedataParam::LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, return 0; } -void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath) { +bool SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath) { ParamSFOData sfoFile; - std::string sfopath = dirPath+"/" + SFO_FILENAME; - PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath); - if (sfoInfo.exists) { - // Read sfo - std::vector sfoData; - if (pspFileSystem.ReadEntireFile(sfopath, sfoData) >= 0) { - sfoFile.ReadSFO(sfoData); + std::string sfopath = dirPath + "/" + SFO_FILENAME; + std::vector sfoData; + if (pspFileSystem.ReadEntireFile(sfopath, sfoData) >= 0) { + sfoFile.ReadSFO(sfoData); - // copy back info in request - strncpy(param->sfoParam.title,sfoFile.GetValueString("TITLE").c_str(),128); - strncpy(param->sfoParam.savedataTitle,sfoFile.GetValueString("SAVEDATA_TITLE").c_str(),128); - strncpy(param->sfoParam.detail,sfoFile.GetValueString("SAVEDATA_DETAIL").c_str(),1024); - param->sfoParam.parentalLevel = sfoFile.GetValueInt("PARENTAL_LEVEL"); - } + // copy back info in request + strncpy(param->sfoParam.title,sfoFile.GetValueString("TITLE").c_str(),128); + strncpy(param->sfoParam.savedataTitle,sfoFile.GetValueString("SAVEDATA_TITLE").c_str(),128); + strncpy(param->sfoParam.detail,sfoFile.GetValueString("SAVEDATA_DETAIL").c_str(),1024); + param->sfoParam.parentalLevel = sfoFile.GetValueInt("PARENTAL_LEVEL"); } + return true; } std::vector SavedataParam::GetSFOEntries(const std::string &dirPath) { std::vector result; const std::string sfoPath = dirPath + "/" + SFO_FILENAME; - if (!pspFileSystem.GetFileInfo(sfoPath).exists) - return result; ParamSFOData sfoFile; std::vector sfoData; - if (pspFileSystem.ReadEntireFile(dirPath + "/" + SFO_FILENAME, sfoData) >= 0) + if (pspFileSystem.ReadEntireFile(sfoPath, sfoData) >= 0) { sfoFile.ReadSFO(sfoData); + } else { + return result; + } const int FILE_LIST_COUNT_MAX = 99; u32 sfoFileListSize = 0; @@ -1164,7 +1162,6 @@ int SavedataParam::GetSizes(SceUtilitySavedataParam *param) NotifyMemInfo(MemBlockFlags::WRITE, param->utilityData.ptr, sizeof(SceUtilitySavedataUsedDataInfo), "SavedataGetSizes"); } return ret; - } bool SavedataParam::GetList(SceUtilitySavedataParam *param) diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 7011d45e37..fc215a97b9 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -366,7 +366,7 @@ private: int LoadSaveData(SceUtilitySavedataParam *param, const std::string &saveDirName, const std::string& dirPath, bool secureMode); u32 LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, const u8 *saveData, int &saveSize, int prevCryptMode, const u8 *expectedHash, bool &saveDone); u32 LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize); - void LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath); + bool LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath); void LoadFile(const std::string& dirPath, const std::string& filename, PspUtilitySavedataFileData *fileData); int DecryptSave(unsigned int mode, unsigned char *data, int *dataLen, int *alignedLen, unsigned char *cryptkey, const u8 *expectedHash); diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index 7192630ae2..4ac716aa57 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -598,6 +598,7 @@ int MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector if (result != dataSize) return SCE_KERNEL_ERROR_ERROR; + return 0; }