From 112238fbd71d943eef1af0bcfddef550fae8860e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 6 Nov 2021 11:45:17 +1000 Subject: [PATCH] Config: Add cache folder --- .gitignore | 1 + pcsx2/Config.h | 1 + pcsx2/PathDefs.h | 1 + pcsx2/Pcsx2Config.cpp | 1 + pcsx2/gui/AppConfig.cpp | 30 ++++++++++++++++++++++++++++++ pcsx2/gui/AppConfig.h | 6 ++++-- 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index dfc0fbdf96a44..aacc223c32fd9 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ oprofile_data/ /bin/PCSX2-linux.sh /bin/GS*.txt /bin/bios +/bin/cache /bin/dumps /bin/help /bin/inis diff --git a/pcsx2/Config.h b/pcsx2/Config.h index cb5e2b0b2478b..0ada7164a7525 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -628,6 +628,7 @@ namespace EmuFolders extern wxDirName Cheats; extern wxDirName CheatsWS; extern wxDirName Resources; + extern wxDirName Cache; } // namespace EmuFolders ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/pcsx2/PathDefs.h b/pcsx2/PathDefs.h index 82b0bc9d81eb5..dbe3a20a8a43e 100644 --- a/pcsx2/PathDefs.h +++ b/pcsx2/PathDefs.h @@ -35,6 +35,7 @@ enum FoldersEnum_t FolderId_Cheats, FolderId_CheatsWS, + FolderId_Cache, FolderId_COUNT }; diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 0c042ab256cf1..eae5e29ea59fc 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -41,6 +41,7 @@ namespace EmuFolders wxDirName Cheats; wxDirName CheatsWS; wxDirName Resources; + wxDirName Cache; } // namespace EmuFolders void TraceLogFilters::LoadSave(SettingsWrapper& wrap) diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index ffccfc0b028a4..60f3165093cf7 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -108,6 +108,12 @@ namespace PathDefs static const wxDirName retval(L"resources"); return retval; } + + const wxDirName& Cache() + { + static const wxDirName retval(L"cache"); + return retval; + } }; // Specifies the root folder for the application install. @@ -254,6 +260,11 @@ namespace PathDefs #endif } + wxDirName GetCache() + { + return GetDocuments() + Base::Cache(); + } + wxDirName Get(FoldersEnum_t folderidx) { switch (folderidx) @@ -276,6 +287,8 @@ namespace PathDefs return GetCheats(); case FolderId_CheatsWS: return GetCheatsWS(); + case FolderId_Cache: + return GetCache(); case FolderId_Documents: return CustomDocumentsFolder; @@ -389,6 +402,8 @@ wxDirName& AppConfig::FolderOptions::operator[](FoldersEnum_t folderidx) return Cheats; case FolderId_CheatsWS: return CheatsWS; + case FolderId_Cache: + return Cache; case FolderId_Documents: return CustomDocumentsFolder; @@ -425,6 +440,8 @@ bool AppConfig::FolderOptions::IsDefault(FoldersEnum_t folderidx) const return UseDefaultCheats; case FolderId_CheatsWS: return UseDefaultCheatsWS; + case FolderId_Cache: + return UseDefaultCache; case FolderId_Documents: return false; @@ -496,6 +513,13 @@ void AppConfig::FolderOptions::Set(FoldersEnum_t folderidx, const wxString& src, EmuFolders::CheatsWS = GetResolvedFolder(FolderId_CheatsWS); break; + case FolderId_Cache: + Cache = src; + UseDefaultCache = useDefault; + EmuFolders::Cache = GetResolvedFolder(FolderId_Cache); + EmuFolders::Cache.Mkdir(); + break; + jNO_DEFAULT } } @@ -703,6 +727,7 @@ AppConfig::FolderOptions::FolderOptions() , Cheats(PathDefs::GetCheats()) , CheatsWS(PathDefs::GetCheatsWS()) , Resources(PathDefs::GetResources()) + , Cache(PathDefs::GetCache()) , RunIso(PathDefs::GetDocuments()) // raw default is always the Documents folder. , RunELF(PathDefs::GetDocuments()) // raw default is always the Documents folder. @@ -741,6 +766,7 @@ void AppConfig::FolderOptions::LoadSave(IniInterface& ini) IniEntryDirFile(Langs, rel); IniEntryDirFile(Cheats, rel); IniEntryDirFile(CheatsWS, rel); + IniEntryDirFile(Cache, rel); IniEntryDirFile(RunIso, rel); IniEntryDirFile(RunELF, rel); @@ -769,6 +795,10 @@ void AppSetEmuFolders() EmuFolders::Cheats = GetResolvedFolder(FolderId_Cheats); EmuFolders::CheatsWS = GetResolvedFolder(FolderId_CheatsWS); EmuFolders::Resources = g_Conf->Folders.Resources; + EmuFolders::Cache = GetResolvedFolder(FolderId_Cache); + + // Ensure cache directory exists, since we're going to write to it (e.g. game database) + EmuFolders::Cache.Mkdir(); } // ------------------------------------------------------------------------ diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index 877b5d91706de..27be8d7f0fa59 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -127,7 +127,8 @@ class AppConfig UseDefaultLogs:1, UseDefaultLangs:1, UseDefaultCheats:1, - UseDefaultCheatsWS:1; + UseDefaultCheatsWS:1, + UseDefaultCache:1; BITFIELD_END wxDirName @@ -139,7 +140,8 @@ class AppConfig Logs, Cheats, CheatsWS, - Resources; + Resources, + Cache; wxDirName RunIso; // last used location for Iso loading. wxDirName RunELF; // last used location for ELF loading.