Prefer $XDG_CONFIG_HOME to $HOME on Unix platforms.

This commit is contained in:
casey langen 2020-12-09 23:57:56 -08:00
parent 8fdafde0d3
commit 7fbed05135

View File

@ -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;