diff --git a/loader/src/loader/Dirs.cpp b/loader/src/loader/Dirs.cpp index b23e558b..f5bc107f 100644 --- a/loader/src/loader/Dirs.cpp +++ b/loader/src/loader/Dirs.cpp @@ -18,15 +18,6 @@ namespace { } } -ghc::filesystem::path dirs::getSaveDir() { -#ifdef GEODE_IS_MACOS - // not using ~/Library/Caches - return ghc::filesystem::path("/Users/Shared/Geode"); -#else - return weaklyCanonical(CCFileUtils::sharedFileUtils()->getWritablePath().c_str()); -#endif -} - ghc::filesystem::path dirs::getGeodeDir() { return dirs::getGameDir() / "geode"; } diff --git a/loader/src/platform/ios/util.mm b/loader/src/platform/ios/util.mm index 2e1505bf..8a029fae 100644 --- a/loader/src/platform/ios/util.mm +++ b/loader/src/platform/ios/util.mm @@ -33,4 +33,8 @@ ghc::filesystem::path dirs::getGameDir() { return ghc::filesystem::current_path(); } +ghc::filesystem::path dirs::getSaveDir() { + return weaklyCanonical(CCFileUtils::sharedFileUtils()->getWritablePath().c_str()); +} + #endif diff --git a/loader/src/platform/mac/util.mm b/loader/src/platform/mac/util.mm index c5aa3ec3..5e21154c 100644 --- a/loader/src/platform/mac/util.mm +++ b/loader/src/platform/mac/util.mm @@ -150,14 +150,23 @@ CCPoint cocos::getMousePos() { } ghc::filesystem::path dirs::getGameDir() { - std::array gddir; + static auto path = [] { + std::array gddir; - uint32_t out = PATH_MAX; - _NSGetExecutablePath(gddir.data(), &out); + uint32_t out = PATH_MAX; + _NSGetExecutablePath(gddir.data(), &out); - ghc::filesystem::path gdpath = gddir.data(); - auto currentPath = gdpath.parent_path().parent_path(); - return currentPath; + ghc::filesystem::path gdpath = gddir.data(); + auto currentPath = gdpath.parent_path().parent_path(); + return currentPath; + }(); + + return path; +} + +ghc::filesystem::path dirs::getSaveDir() { + // not using ~/Library/Caches + return ghc::filesystem::path("/Users/Shared/Geode"); } #endif diff --git a/loader/src/platform/windows/util.cpp b/loader/src/platform/windows/util.cpp index 2ee767c6..ad34bb2b 100644 --- a/loader/src/platform/windows/util.cpp +++ b/loader/src/platform/windows/util.cpp @@ -9,6 +9,7 @@ using namespace geode::prelude; #include #include #include +#include #include #include #include @@ -129,4 +130,30 @@ ghc::filesystem::path dirs::getGameDir() { return path; } +ghc::filesystem::path dirs::getSaveDir() { + // only fetch the path once, since ofc it'll never change + // throughout the execution + static const auto path = [] { + std::array buffer; + GetModuleFileNameW(NULL, buffer.data(), MAX_PATH + 1); + + auto executablePath = ghc::filesystem::path(buffer.data()); + auto executableName = executablePath.filename().wstring(); + executableName = executableName.substr(0, executableName.find_last_of(L".")); + + if (SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer.data()) >= 0) { + auto appdataPath = ghc::filesystem::path(buffer.data()); + auto savePath = appdataPath / executableName; + + if (SHCreateDirectoryExW(NULL, savePath.wstring().c_str(), NULL) >= 0) { + return savePath; + } + } + + return executablePath.parent_path(); + }(); + + return path; +} + #endif