2016-03-04 23:02:44 +00:00
|
|
|
#include "hecl/Runtime.hpp"
|
|
|
|
#include "logvisor/logvisor.hpp"
|
2015-11-14 08:48:31 +00:00
|
|
|
#if _WIN32
|
|
|
|
#include <ShlObj.h>
|
|
|
|
#endif
|
2015-11-13 02:12:09 +00:00
|
|
|
|
2017-12-06 03:22:31 +00:00
|
|
|
#if WINDOWS_STORE
|
|
|
|
using namespace Windows::Storage;
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
namespace hecl::Runtime {
|
2016-03-04 23:02:44 +00:00
|
|
|
static logvisor::Module Log("FileStoreManager");
|
2015-11-13 02:12:09 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
FileStoreManager::FileStoreManager(SystemStringView domain) : m_domain(domain) {
|
2015-11-13 02:12:09 +00:00
|
|
|
#if _WIN32
|
2017-12-06 03:22:31 +00:00
|
|
|
#if !WINDOWS_STORE
|
2018-12-08 05:18:42 +00:00
|
|
|
WCHAR home[MAX_PATH];
|
|
|
|
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, home)))
|
2019-07-20 04:22:58 +00:00
|
|
|
Log.report(logvisor::Fatal, fmt(_SYS_STR("unable to locate profile for file store")));
|
2015-11-14 08:48:31 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
SystemString path(home);
|
2017-12-06 03:22:31 +00:00
|
|
|
#else
|
2018-12-08 05:18:42 +00:00
|
|
|
StorageFolder ^ cacheFolder = ApplicationData::Current->LocalCacheFolder;
|
|
|
|
SystemString path(cacheFolder->Path->Data());
|
2017-12-06 03:22:31 +00:00
|
|
|
#endif
|
2018-12-08 05:18:42 +00:00
|
|
|
path += _SYS_STR("/.heclrun");
|
2015-11-14 08:48:31 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
hecl::MakeDir(path.c_str());
|
|
|
|
path += _SYS_STR('/');
|
|
|
|
path += domain.data();
|
2015-11-14 08:48:31 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
hecl::MakeDir(path.c_str());
|
|
|
|
m_storeRoot = path;
|
2015-11-13 02:12:09 +00:00
|
|
|
#else
|
2018-12-08 05:18:42 +00:00
|
|
|
const char* home = getenv("HOME");
|
|
|
|
if (!home)
|
2019-07-20 04:22:58 +00:00
|
|
|
Log.report(logvisor::Fatal, fmt("unable to locate $HOME for file store"));
|
2018-12-08 05:18:42 +00:00
|
|
|
std::string path(home);
|
|
|
|
path += "/.heclrun";
|
|
|
|
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
2019-07-20 04:22:58 +00:00
|
|
|
Log.report(logvisor::Fatal, fmt("unable to mkdir at {}"), path);
|
2018-12-08 05:18:42 +00:00
|
|
|
path += '/';
|
|
|
|
path += domain.data();
|
|
|
|
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
2019-07-20 04:22:58 +00:00
|
|
|
Log.report(logvisor::Fatal, fmt("unable to mkdir at {}"), path);
|
2018-12-08 05:18:42 +00:00
|
|
|
m_storeRoot = path;
|
2015-11-13 02:12:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
} // namespace hecl::Runtime
|