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
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
namespace hecl
|
2015-11-13 02:12:09 +00:00
|
|
|
{
|
|
|
|
namespace Runtime
|
|
|
|
{
|
2016-03-04 23:02:44 +00:00
|
|
|
static logvisor::Module Log("FileStoreManager");
|
2015-11-13 02:12:09 +00:00
|
|
|
|
|
|
|
FileStoreManager::FileStoreManager(const SystemString& domain)
|
|
|
|
: m_domain(domain)
|
|
|
|
{
|
|
|
|
#if _WIN32
|
2015-11-14 08:48:31 +00:00
|
|
|
WCHAR home[MAX_PATH];
|
|
|
|
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, home)))
|
2016-03-04 23:02:44 +00:00
|
|
|
Log.report(logvisor::Fatal, _S("unable to locate profile for file store"));
|
2015-11-14 08:48:31 +00:00
|
|
|
|
|
|
|
SystemString path(home);
|
|
|
|
|
|
|
|
path += _S("/.heclrun");
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
hecl::MakeDir(path.c_str());
|
2015-11-14 08:48:31 +00:00
|
|
|
path += _S('/') + domain;
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
hecl::MakeDir(path.c_str());
|
2015-11-14 08:48:31 +00:00
|
|
|
m_storeRoot = path;
|
2015-11-13 02:12:09 +00:00
|
|
|
#else
|
|
|
|
const char* home = getenv("HOME");
|
|
|
|
if (!home)
|
2016-03-04 23:02:44 +00:00
|
|
|
Log.report(logvisor::Fatal, "unable to locate $HOME for file store");
|
2015-11-13 02:12:09 +00:00
|
|
|
std::string path(home);
|
|
|
|
path += "/.heclrun";
|
2015-11-16 04:30:06 +00:00
|
|
|
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
2016-03-04 23:02:44 +00:00
|
|
|
Log.report(logvisor::Fatal, "unable to mkdir at %s", path.c_str());
|
2015-11-13 02:12:09 +00:00
|
|
|
path += '/' + domain;
|
2015-11-16 04:30:06 +00:00
|
|
|
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
2016-03-04 23:02:44 +00:00
|
|
|
Log.report(logvisor::Fatal, "unable to mkdir at %s", path.c_str());
|
2015-11-13 02:12:09 +00:00
|
|
|
m_storeRoot = path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|