Skip to content
Snippets Groups Projects
Commit 63b53d79 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk
Browse files

fileutils: create JAMI base directory for windows

Use custom JAMI environment variables to change
data, config, cache dir on runtime

Change-Id: I5d345922ba1aba2a4e372c85554b104e4cef8594
parent 964a2d8a
Branches
No related tags found
No related merge requests found
......@@ -93,13 +93,29 @@
char* envvar_ = getenv((str)); \
envvar_ ? envvar_ : ""; \
})
#else
#define PROTECTED_GETENV(str) ""
#endif
#define XDG_DATA_HOME (PROTECTED_GETENV("XDG_DATA_HOME"))
#define XDG_CONFIG_HOME (PROTECTED_GETENV("XDG_CONFIG_HOME"))
#define XDG_CACHE_HOME (PROTECTED_GETENV("XDG_CACHE_HOME"))
#else
const wchar_t*
winGetEnv(const wchar_t* name)
{
const DWORD buffSize = 65535;
static wchar_t buffer[buffSize];
if (GetEnvironmentVariable(name, buffer, buffSize)) {
return buffer;
} else {
return L"";
}
}
#define PROTECTED_GETENV(str) winGetEnv(str)
#define JAMI_DATA_HOME PROTECTED_GETENV(L"JAMI_DATA_HOME")
#define JAMI_CONFIG_HOME PROTECTED_GETENV(L"JAMI_CONFIG_HOME")
#define JAMI_CACHE_HOME PROTECTED_GETENV(L"JAMI_CACHE_HOME")
#endif
#define PIDFILE ".ring.pid"
#define ERASE_BLOCK 4096
......@@ -544,11 +560,16 @@ get_cache_dir(const char* pkg)
#elif defined(__APPLE__)
return get_home_dir() + DIR_SEPARATOR_STR + "Library" + DIR_SEPARATOR_STR + "Caches"
+ DIR_SEPARATOR_STR + pkg;
#else
#ifdef _WIN32
const std::wstring cache_home(JAMI_CACHE_HOME);
if (not cache_home.empty())
return jami::to_string(cache_home);
#else
const std::string cache_home(XDG_CACHE_HOME);
if (not cache_home.empty())
return cache_home;
else
#endif
return get_home_dir() + DIR_SEPARATOR_STR + ".cache" + DIR_SEPARATOR_STR + pkg;
#endif
}
......@@ -616,6 +637,10 @@ get_data_dir(const char* pkg)
return get_home_dir() + DIR_SEPARATOR_STR + "Library" + DIR_SEPARATOR_STR
+ "Application Support" + DIR_SEPARATOR_STR + pkg;
#elif defined(_WIN32)
const std::wstring data_home(JAMI_DATA_HOME);
if (not data_home.empty())
return jami::to_string(data_home) + DIR_SEPARATOR_STR + pkg;
if (!strcmp(pkg, "ring")) {
return get_home_dir() + DIR_SEPARATOR_STR + ".local" + DIR_SEPARATOR_STR
+ "share" DIR_SEPARATOR_STR + pkg;
......@@ -669,10 +694,13 @@ get_config_dir(const char* pkg)
if (not paths.empty())
configdir = paths[0] + DIR_SEPARATOR_STR + std::string(".config");
#elif defined(__APPLE__)
configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + "Library"
+ DIR_SEPARATOR_STR + "Application Support" + DIR_SEPARATOR_STR + pkg;
configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + "Library" + DIR_SEPARATOR_STR
+ "Application Support" + DIR_SEPARATOR_STR + pkg;
#elif defined(_WIN32)
if (!strcmp(pkg, "ring")) {
const std::wstring xdg_env(JAMI_CONFIG_HOME);
if (not xdg_env.empty()) {
configdir = jami::to_string(xdg_env) + DIR_SEPARATOR_STR + pkg;
} else if (!strcmp(pkg, "ring")) {
configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR
+ pkg;
} else {
......@@ -684,8 +712,8 @@ get_config_dir(const char* pkg)
if (not xdg_env.empty())
configdir = xdg_env + DIR_SEPARATOR_STR + pkg;
else
configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + ".config"
+ DIR_SEPARATOR_STR + pkg;
configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR
+ pkg;
#endif
if (fileutils::recursive_mkdir(configdir.data(), 0700) != true) {
// If directory creation failed
......@@ -785,7 +813,8 @@ eraseFile_win32(const std::string& path, bool dosync)
#else
bool eraseFile_posix(const std::string& path, bool dosync)
bool
eraseFile_posix(const std::string& path, bool dosync)
{
int fd = open(path.c_str(), O_WRONLY);
if (fd == -1) {
......@@ -950,5 +979,5 @@ accessFile(const std::string& file, int mode)
#endif
}
} // namespace jami
} // namespace fileutils
} // namespace jami
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment