mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-27 01:45:35 -05:00
fix getSaveDir not working with nonascii paths
This commit is contained in:
parent
7e609467eb
commit
56b7b66b93
4 changed files with 46 additions and 15 deletions
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -150,6 +150,7 @@ CCPoint cocos::getMousePos() {
|
|||
}
|
||||
|
||||
ghc::filesystem::path dirs::getGameDir() {
|
||||
static auto path = [] {
|
||||
std::array<char, PATH_MAX> gddir;
|
||||
|
||||
uint32_t out = PATH_MAX;
|
||||
|
@ -158,6 +159,14 @@ ghc::filesystem::path dirs::getGameDir() {
|
|||
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
|
||||
|
|
|
@ -9,6 +9,7 @@ using namespace geode::prelude;
|
|||
#include <ghc/fs_fwd.hpp>
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <ShlObj.h>
|
||||
#include <shlwapi.h>
|
||||
#include <shobjidl.h>
|
||||
#include <sstream>
|
||||
|
@ -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<WCHAR, MAX_PATH + 1> 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
|
||||
|
|
Loading…
Reference in a new issue