From 12dc7163f6b05a45821e65055cabbc1e55f401ae Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Mon, 29 May 2017 03:42:45 +0200 Subject: [PATCH] Add savestates to the list(with automatic rename) --- Core/PSPLoaders.cpp | 26 ++++++++++++++++++++++++++ Core/SaveState.cpp | 28 +++++----------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 096ada69b7..dbebac183f 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -18,6 +18,7 @@ #include "file/file_util.h" #include "util/text/utf8.h" +#include "Common/FileUtil.h" #include "Common/StringUtils.h" #ifdef _WIN32 #include "Common/CommonWindows.h" @@ -333,5 +334,30 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) { INFO_LOG(LOADER, "%s", title); host->SetWindowTitle(title); + // Temporary code + // TODO: Remove this after ~ 1.6 + // It checks for old filenames for homebrew savestates(folder name) and rename them to new fakeID format + std::string savestateDir = GetSysDirectory(DIRECTORY_SAVESTATE); + savestateDir = ReplaceAll(savestateDir, "\\", "/"); +#ifdef _WIN32 + // Turn the slashes back to the Windows way. + savestateDir = ReplaceAll(savestateDir, "/", "\\"); +#endif + for (int i = 0; i < 5; i += 1) { + std::string oldName = StringFromFormat("%s%s_%i.ppst", savestateDir.c_str(), homebrewName.c_str(), i); + if (File::Exists(oldName)) { + std::string newName = StringFromFormat("%s%s_1.00_%i.ppst", savestateDir.c_str(), madeUpID.c_str(), i); + File::Rename(oldName, newName); + } + } + for (int i = 0; i < 5; i += 1) { + std::string oldName = StringFromFormat("%s%s_%i.jpg", savestateDir.c_str(), homebrewName.c_str(), i); + if (File::Exists(oldName)) { + std::string newName = StringFromFormat("%s%s_1.00_%i.jpg", savestateDir.c_str(), madeUpID.c_str(), i); + File::Rename(oldName, newName); + } + } + // End of temporary code + return __KernelLoadExec(finalName.c_str(), 0, error_string); } diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index dbda741aaf..242ed52cab 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -363,31 +363,13 @@ namespace SaveState std::string GenerateSaveSlotFilename(const std::string &gameFilename, int slot, const char *extension) { std::string discId = g_paramSFO.GetValueString("DISC_ID"); + std::string discVer = g_paramSFO.GetValueString("DISC_VERSION"); std::string fullDiscId; - if (discId.size()) { - fullDiscId = StringFromFormat("%s_%s", - g_paramSFO.GetValueString("DISC_ID").c_str(), - g_paramSFO.GetValueString("DISC_VERSION").c_str()); - } else { - // Okay, no discId. Probably homebrew, let's use the last part of the path name. - if (File::IsDirectory(gameFilename)) { - // EBOOT.PBP directory, most likely. - std::string path = gameFilename; - size_t slash = path.rfind('/'); // Always '/', not '\\', as we're in a virtual directory - if (slash != std::string::npos && slash < path.size() - 1) - path = path.substr(slash + 1); - fullDiscId = path; - } else { - // Probably a loose elf. - std::string fn = File::GetFilename(gameFilename); - size_t dot = fn.rfind('.'); - if (dot != std::string::npos) { - fullDiscId = fn.substr(0, dot); - } else { - fullDiscId = "elf"; // Fallback - } - } + if (discId.empty()) { + discId = g_paramSFO.GenerateFakeID(); + discVer = "1.00"; } + fullDiscId = StringFromFormat("%s_%s", discId.c_str(), discVer.c_str()); std::string temp = StringFromFormat("ms0:/PSP/PPSSPP_STATE/%s_%i.%s", fullDiscId.c_str(), slot, extension); std::string hostPath;