Skip to content

Commit

Permalink
add persistent dir
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Sep 14, 2024
1 parent b3d5474 commit 68ab475
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions loader/include/Geode/loader/Dirs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 5 additions & 0 deletions loader/include/Geode/loader/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions loader/src/loader/Dirs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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";
}
4 changes: 4 additions & 0 deletions loader/src/loader/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions loader/src/loader/ModImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions loader/src/loader/ModImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> getSettingKeys() const;
Expand Down

0 comments on commit 68ab475

Please sign in to comment.