metaforce/Runtime/ConsoleVariables/FileStoreManager.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

#include "Runtime/ConsoleVariables/FileStoreManager.hpp"
#include "Runtime/CBasics.hpp"
#include "logvisor/logvisor.hpp"
#if _WIN32
#include <ShlObj.h>
#endif
2015-11-12 18:12:09 -08:00
2017-12-05 19:22:31 -08:00
#if WINDOWS_STORE
using namespace Windows::Storage;
#endif
namespace metaforce {
2016-03-04 15:02:44 -08:00
static logvisor::Module Log("FileStoreManager");
2015-11-12 18:12:09 -08:00
FileStoreManager::FileStoreManager(std::string_view domain) : m_domain(domain) {
2015-11-12 18:12:09 -08:00
#if _WIN32
2017-12-05 19:22:31 -08:00
#if !WINDOWS_STORE
2018-12-07 21:18:42 -08:00
WCHAR home[MAX_PATH];
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, home)))
Log.report(logvisor::Fatal, FMT_STRING("unable to locate profile for file store"));
std::string path = nowide::narrow(home);
2017-12-05 19:22:31 -08:00
#else
2018-12-07 21:18:42 -08:00
StorageFolder ^ cacheFolder = ApplicationData::Current->LocalCacheFolder;
std::string path(cacheFolder->Path->Data());
2017-12-05 19:22:31 -08:00
#endif
path += "/.heclrun";
CBasics::MakeDir(path.c_str());
path += '/';
2018-12-07 21:18:42 -08:00
path += domain.data();
CBasics::MakeDir(path.c_str());
2018-12-07 21:18:42 -08:00
m_storeRoot = path;
2015-11-12 18:12:09 -08:00
#else
const char* xdg_data_home = getenv("XDG_DATA_HOME");
std::string path;
if (xdg_data_home) {
if (xdg_data_home[0] != '/')
2020-04-11 15:48:11 -07:00
Log.report(logvisor::Fatal, FMT_STRING("invalid $XDG_DATA_HOME for file store (must be absolute)"));
path = xdg_data_home;
} else {
const char* home = getenv("HOME");
if (!home)
2020-04-11 15:48:11 -07:00
Log.report(logvisor::Fatal, FMT_STRING("unable to locate $HOME for file store"));
path = home;
2020-03-03 16:52:57 -08:00
path += "/.local/share";
}
2021-01-06 17:46:56 -08:00
path += "/hecl/";
2018-12-07 21:18:42 -08:00
path += domain.data();
if (CBasics::RecursiveMakeDir(path.c_str()) != 0)
2020-04-11 15:48:11 -07:00
Log.report(logvisor::Fatal, FMT_STRING("unable to mkdir at {}"), path);
2018-12-07 21:18:42 -08:00
m_storeRoot = path;
2015-11-12 18:12:09 -08:00
#endif
}
2018-12-07 21:18:42 -08:00
} // namespace hecl::Runtime