diff --git a/Core/Config.cpp b/Core/Config.cpp index 95daf8a869..8233a7fec2 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1030,6 +1030,7 @@ static ConfigSetting systemParamSettings[] = { ConfigSetting("WlanPowerSave", &g_Config.bWlanPowerSave, (bool) PSP_SYSTEMPARAM_WLAN_POWERSAVE_OFF, true, true), ReportedConfigSetting("EncryptSave", &g_Config.bEncryptSave, true, true, true), ConfigSetting("SavedataUpgradeVersion", &g_Config.bSavedataUpgrade, true, true, false), + ConfigSetting("MemStickSize", &g_Config.iMemStickSizeGB, 16, true, false), ConfigSetting(false), }; diff --git a/Core/Config.h b/Core/Config.h index f34d87c6f3..c73c48faae 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -123,6 +123,7 @@ public: std::string sRemoteISOSubdir; bool bRemoteDebuggerOnStartup; bool bMemStickInserted; + int iMemStickSizeGB; bool bLoadPlugins; int iScreenRotation; // The rotation angle of the PPSSPP UI. Only supported on Android and possibly other mobile platforms. diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index 31f7bf5689..c7f3b46c1c 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -669,3 +669,17 @@ void MetaFileSystem::DoState(PointerWrap &p) } } +u64 MetaFileSystem::getDirSize(const std::string &dirPath) { + u64 result = 0; + auto allFiles = GetDirListing(dirPath); + for (auto file : allFiles) { + if (file.name == "." || file.name == "..") + continue; + if (file.type == FILETYPE_DIRECTORY) { + result += getDirSize(dirPath + file.name + "/"); + } else { + result += file.size; + } + } + return result; +} diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index 8294ba16da..5d3984349a 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -129,4 +129,6 @@ public: std::lock_guard guard(lock); startingDirectory = dir; } + + u64 getDirSize(const std::string &dirPath); }; diff --git a/Core/HW/MemoryStick.cpp b/Core/HW/MemoryStick.cpp index f0d9a38708..da0058261f 100644 --- a/Core/HW/MemoryStick.cpp +++ b/Core/HW/MemoryStick.cpp @@ -71,15 +71,18 @@ u64 MemoryStick_SectorSize() { } u64 MemoryStick_FreeSpace() { - u64 freeSpace = pspFileSystem.FreeSpace("ms0:/"); - // Cap the memory stick size to avoid math errors when old games get sizes that were // hard to imagine back then. // We have a compat setting to make it even smaller for Harry Potter : Goblet of Fire, see #13266. - const u64 memStickSize = PSP_CoreParameter().compat.flags().ReportSmallMemstick ? smallMemstickSize : normalMemstickSize; - if (freeSpace < memStickSize) - return freeSpace; - return memStickSize; + const u64 memStickSize = PSP_CoreParameter().compat.flags().ReportSmallMemstick ? smallMemstickSize : (u64)g_Config.iMemStickSizeGB * 1024 * 1024 * 1024; + u64 usedSpace = pspFileSystem.getDirSize("ms0:/PSP/SAVEDATA/");// Assume the memory stick is only used to store savedata. + u64 freeSpace; + if (usedSpace >= memStickSize) + freeSpace = 0; + else + freeSpace = memStickSize - usedSpace; + + return freeSpace; } void MemoryStick_SetFatState(MemStickFatState state) { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 1ae64da3ce..49cff8f2e7 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -897,6 +897,7 @@ void GameSettingsScreen::CreateViews() { rewindFreq->SetZeroLabel(sy->T("Off")); systemSettings->Add(new CheckBox(&g_Config.bMemStickInserted, sy->T("Memory Stick inserted"))); + PopupSliderChoice *memStickSize = systemSettings->Add(new PopupSliderChoice(&g_Config.iMemStickSizeGB, 1, 128, sy->T("Change Memory Stick Size", "Change Memory Stick Size(GB)"), screenManager(), "GB")); systemSettings->Add(new ItemHeader(sy->T("General")));