diff --git a/src/gui/WndMain.cpp b/src/gui/WndMain.cpp index 76ace225c..6541142f9 100644 --- a/src/gui/WndMain.cpp +++ b/src/gui/WndMain.cpp @@ -98,6 +98,36 @@ void ClearSymbolCache(const char sStorageLocation[MAX_PATH]) printf("Cleared HLE Cache\n"); } +unsigned ClearCachePartitions() +{ + const std::string &partition_path = g_Settings->GetDataLocation() + "\\EmuDisk\\Partition"; + std::error_code err; + unsigned has_any_err = 0; + + for (int partition_num = 3; partition_num < 6; ++partition_num) { + const std::string &partition = partition_path + std::to_string(partition_num); + for (const auto &directory_entry : std::filesystem::directory_iterator(partition, err)) { + if (err) { + has_any_err |= 1; + } + else { + std::filesystem::remove_all(directory_entry, err); + if (err) { + has_any_err |= 1; + } + } + } + + const std::string &partition_bin = partition + ".bin"; + std::filesystem::remove(partition_bin, err); + if (err) { + has_any_err |= 1; + } + } + + return has_any_err; +} + void WndMain::InitializeSettings() { g_Settings->Delete(); @@ -1088,6 +1118,22 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP } break; + case ID_SETTINGS_CLEAR_PARTITIONS: + { + if (m_bIsStarted) { + PopupError(m_hwnd, "Cannot clear the cache partitions while a title is running."); + } + else { + if (ClearCachePartitions()) { + PopupError(m_hwnd, "An errror has occoured while clearing the cache partitions."); + } + else { + PopupInfo(m_hwnd, "Cleared the cache partitions."); + } + } + } + break; + case ID_SETTINGS_INITIALIZE: { PopupReturn ret = PopupWarningEx(m_hwnd, PopupButtons::YesNo, PopupReturn::No, diff --git a/src/gui/resource/Cxbx.rc b/src/gui/resource/Cxbx.rc index cff7032d9..89febd896 100644 --- a/src/gui/resource/Cxbx.rc +++ b/src/gui/resource/Cxbx.rc @@ -691,6 +691,7 @@ BEGIN MENUITEM "&Clear entire Symbol Cache", ID_CACHE_CLEARHLECACHE_ALL,MFT_STRING,MFS_ENABLED MENUITEM "&Rescan title Symbol Cache", ID_CACHE_CLEARHLECACHE_CURRENT,MFT_STRING,MFS_ENABLED END + MENUITEM "Clear Cache Partitions", ID_SETTINGS_CLEAR_PARTITIONS,MFT_STRING,MFS_ENABLED MENUITEM "", -1, MFT_SEPARATOR POPUP "Experimental", 65535,MFT_STRING,MFS_ENABLED BEGIN diff --git a/src/gui/resource/ResCxbx.h b/src/gui/resource/ResCxbx.h index eab4e2379..9574e366a 100644 --- a/src/gui/resource/ResCxbx.h +++ b/src/gui/resource/ResCxbx.h @@ -304,6 +304,7 @@ #define ID_SETTINGS_CACHE 40083 #define ID_CACHE_CLEARHLECACHE_ALL 40084 #define ID_CACHE_CLEARHLECACHE_CURRENT 40085 +#define ID_SETTINGS_CLEAR_PARTITIONS 40086 #define ID_SETTINGS_HACKS 40088 #define ID_HACKS_DISABLEPIXELSHADERS 40089 #define ID_LED 40090