mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Prefer $XDG_CONFIG_HOME to $HOME on Unix platforms.
This commit is contained in:
parent
8fdafde0d3
commit
7fbed05135
@ -70,22 +70,13 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::string GetHomeDirectory() {
|
static inline void silentDelete(const std::string fn) {
|
||||||
std::string directory;
|
boost::system::error_code ec;
|
||||||
|
boost::filesystem::remove(boost::filesystem::path(fn), ec);
|
||||||
#ifdef WIN32
|
|
||||||
DWORD bufferSize = GetEnvironmentVariable(L"APPDATA", 0, 0);
|
|
||||||
wchar_t *buffer = new wchar_t[bufferSize + 2];
|
|
||||||
GetEnvironmentVariable(L"APPDATA", buffer, bufferSize);
|
|
||||||
directory.assign(u16to8(buffer));
|
|
||||||
delete[] buffer;
|
|
||||||
#else
|
|
||||||
directory = std::string(std::getenv("HOME"));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace musik { namespace core {
|
||||||
|
|
||||||
static std::string getDataDirectoryRoot() {
|
static std::string getDataDirectoryRoot() {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
return GetHomeDirectory();
|
return GetHomeDirectory();
|
||||||
@ -94,13 +85,6 @@ static std::string getDataDirectoryRoot() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void silentDelete(const std::string fn) {
|
|
||||||
boost::system::error_code ec;
|
|
||||||
boost::filesystem::remove(boost::filesystem::path(fn), ec);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace musik { namespace core {
|
|
||||||
|
|
||||||
std::string GetPluginDirectory() {
|
std::string GetPluginDirectory() {
|
||||||
std::string path(GetApplicationDirectory());
|
std::string path(GetApplicationDirectory());
|
||||||
path.append("/plugins/");
|
path.append("/plugins/");
|
||||||
@ -154,7 +138,6 @@ namespace musik { namespace core {
|
|||||||
std::string pathToProc = u8fmt("/proc/%d/exe", (int) getpid());
|
std::string pathToProc = u8fmt("/proc/%d/exe", (int) getpid());
|
||||||
readlink(pathToProc.c_str(), pathbuf, PATH_MAX);
|
readlink(pathToProc.c_str(), pathbuf, PATH_MAX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
result.assign(pathbuf);
|
result.assign(pathbuf);
|
||||||
size_t last = result.find_last_of("/");
|
size_t last = result.find_last_of("/");
|
||||||
result = result.substr(0, last); /* remove filename component */
|
result = result.substr(0, last); /* remove filename component */
|
||||||
@ -167,13 +150,19 @@ namespace musik { namespace core {
|
|||||||
std::string directory;
|
std::string directory;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
DWORD bufferSize = GetEnvironmentVariable(L"USERPROFILE", 0, 0);
|
DWORD bufferSize = GetEnvironmentVariable(L"APPDATA", 0, 0);
|
||||||
wchar_t* buffer = new wchar_t[bufferSize + 2];
|
wchar_t* buffer = new wchar_t[bufferSize + 2];
|
||||||
GetEnvironmentVariable(L"USERPROFILE", buffer, bufferSize);
|
GetEnvironmentVariable(L"APPDATA", buffer, bufferSize);
|
||||||
directory.assign(u16to8(buffer));
|
directory.assign(u16to8(buffer));
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
#else
|
#else
|
||||||
|
const char* result = std::getenv("XDG_CONFIG_HOME");
|
||||||
|
if (result && strlen(result)) {
|
||||||
|
directory = std::string(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
directory = std::string(std::getenv("HOME"));
|
directory = std::string(std::getenv("HOME"));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
|
Loading…
Reference in New Issue
Block a user