diff --git a/loader/include/Geode/loader/Dirs.hpp b/loader/include/Geode/loader/Dirs.hpp index 226e210c..85fe9d9a 100644 --- a/loader/include/Geode/loader/Dirs.hpp +++ b/loader/include/Geode/loader/Dirs.hpp @@ -56,4 +56,9 @@ namespace geode::dirs { * Directory where crashlogs are stored */ GEODE_DLL std::filesystem::path getCrashlogsDir(); + /** + * Directory where mods' persistent files lie + * This directory is not deleted even when Geode is uninstalled + */ + GEODE_DLL std::filesystem::path getModPersistentDir(); } diff --git a/loader/include/Geode/loader/Mod.hpp b/loader/include/Geode/loader/Mod.hpp index 52a87771..000901f8 100644 --- a/loader/include/Geode/loader/Mod.hpp +++ b/loader/include/Geode/loader/Mod.hpp @@ -172,6 +172,11 @@ namespace geode { * Get the mod's config directory path */ std::filesystem::path getConfigDir(bool create = true) const; + /** + * Get the mod's persistent directory path + * This directory is not deleted even when Geode/mod is uninstalled + */ + std::filesystem::path getPersistentDir(bool create = true) const; /** * Returns true if this mod has any settings diff --git a/loader/src/loader/Dirs.cpp b/loader/src/loader/Dirs.cpp index 0ace53bd..74f93e72 100644 --- a/loader/src/loader/Dirs.cpp +++ b/loader/src/loader/Dirs.cpp @@ -24,15 +24,15 @@ std::filesystem::path dirs::getGeodeLogDir() { } std::filesystem::path dirs::getTempDir() { - return getGeodeDir() / "temp"; + return dirs::getGeodeDir() / "temp"; } std::filesystem::path dirs::getModsDir() { - return getGeodeDir() / "mods"; + return dirs::getGeodeDir() / "mods"; } std::filesystem::path dirs::getModsSaveDir() { - return getGeodeSaveDir() / "mods"; + return dirs::getGeodeSaveDir() / "mods"; } std::filesystem::path dirs::getModConfigDir() { @@ -46,3 +46,7 @@ std::filesystem::path dirs::getIndexDir() { std::filesystem::path dirs::getCrashlogsDir() { return crashlog::getCrashLogDirectory(); } + +std::filesystem::path dirs::getModPersistentDir() { + return dirs::getSaveDir() / "geode-persistent"; +} \ No newline at end of file diff --git a/loader/src/loader/Mod.cpp b/loader/src/loader/Mod.cpp index a4b71515..d046ce45 100644 --- a/loader/src/loader/Mod.cpp +++ b/loader/src/loader/Mod.cpp @@ -143,6 +143,10 @@ std::filesystem::path Mod::getConfigDir(bool create) const { return m_impl->getConfigDir(create); } +std::filesystem::path Mod::getPersistentDir(bool create) const { + return m_impl->getPersistentDir(create); +} + bool Mod::hasSettings() const { return m_impl->hasSettings(); } diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index 0ccff4a3..68b1638d 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -656,6 +656,14 @@ std::filesystem::path Mod::Impl::getConfigDir(bool create) const { return dir; } +std::filesystem::path Mod::Impl::getPersistentDir(bool create) const { + auto dir = dirs::getModPersistentDir() / m_metadata.getID(); + if (create) { + (void)file::createDirectoryAll(dir); + } + return dir; +} + std::string_view Mod::Impl::expandSpriteName(std::string_view name) { std::string nameKey(name); if (m_expandedSprites.contains(nameKey)) return m_expandedSprites[nameKey]; diff --git a/loader/src/loader/ModImpl.hpp b/loader/src/loader/ModImpl.hpp index f33bc0ad..e57ead56 100644 --- a/loader/src/loader/ModImpl.hpp +++ b/loader/src/loader/ModImpl.hpp @@ -113,6 +113,7 @@ namespace geode { std::filesystem::path getSaveDir() const; std::filesystem::path getConfigDir(bool create = true) const; + std::filesystem::path getPersistentDir(bool create = true) const; bool hasSettings() const; std::vector getSettingKeys() const;