From 7518f8375ada09637e64b3adbe44234252facbf4 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Mon, 22 Mar 2021 18:23:04 +0100 Subject: [PATCH 1/2] Added option to clear the cache partitions from the GUI --- src/gui/WndMain.cpp | 46 ++++++++++++++++++++++++++++++++++++++ src/gui/resource/Cxbx.rc | 1 + src/gui/resource/ResCxbx.h | 1 + 3 files changed, 48 insertions(+) diff --git a/src/gui/WndMain.cpp b/src/gui/WndMain.cpp index 76ace225c..9faac466c 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 < 8; ++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..a213c3d4c 100644 --- a/src/gui/resource/Cxbx.rc +++ b/src/gui/resource/Cxbx.rc @@ -713,6 +713,7 @@ BEGIN MENUITEM "Ignore Invalid Xbe Sections", ID_SETTINGS_IGNOREINVALIDXBESEC,MFT_STRING,MFS_ENABLED MENUITEM "Allow Admin Privilege", ID_SETTINGS_ALLOWADMINPRIVILEGE,MFT_STRING,MFS_ENABLED MENUITEM "", -1, MFT_SEPARATOR + MENUITEM "Clear cache partitions", ID_SETTINGS_CLEAR_PARTITIONS,MFT_STRING,MFS_ENABLED MENUITEM "Reset To Defaults", ID_SETTINGS_INITIALIZE,MFT_STRING,MFS_ENABLED END POPUP "E&mulation", 65535,MFT_STRING,MFS_ENABLED 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 From 721d83eaf1de78dde7dfc05ca2364e27e78133f9 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Mon, 22 Mar 2021 19:41:06 +0100 Subject: [PATCH 2/2] Addressed review remarks --- src/gui/WndMain.cpp | 2 +- src/gui/resource/Cxbx.rc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/WndMain.cpp b/src/gui/WndMain.cpp index 9faac466c..6541142f9 100644 --- a/src/gui/WndMain.cpp +++ b/src/gui/WndMain.cpp @@ -104,7 +104,7 @@ unsigned ClearCachePartitions() std::error_code err; unsigned has_any_err = 0; - for (int partition_num = 3; partition_num < 8; ++partition_num) { + 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) { diff --git a/src/gui/resource/Cxbx.rc b/src/gui/resource/Cxbx.rc index a213c3d4c..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 @@ -713,7 +714,6 @@ BEGIN MENUITEM "Ignore Invalid Xbe Sections", ID_SETTINGS_IGNOREINVALIDXBESEC,MFT_STRING,MFS_ENABLED MENUITEM "Allow Admin Privilege", ID_SETTINGS_ALLOWADMINPRIVILEGE,MFT_STRING,MFS_ENABLED MENUITEM "", -1, MFT_SEPARATOR - MENUITEM "Clear cache partitions", ID_SETTINGS_CLEAR_PARTITIONS,MFT_STRING,MFS_ENABLED MENUITEM "Reset To Defaults", ID_SETTINGS_INITIALIZE,MFT_STRING,MFS_ENABLED END POPUP "E&mulation", 65535,MFT_STRING,MFS_ENABLED