mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +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>
|
||||
#endif
|
||||
|
||||
static std::string GetHomeDirectory() {
|
||||
std::string directory;
|
||||
|
||||
#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;
|
||||
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 {
|
||||
|
||||
static std::string getDataDirectoryRoot() {
|
||||
#ifdef WIN32
|
||||
return GetHomeDirectory();
|
||||
@ -94,13 +85,6 @@ static std::string getDataDirectoryRoot() {
|
||||
#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 path(GetApplicationDirectory());
|
||||
path.append("/plugins/");
|
||||
@ -154,7 +138,6 @@ namespace musik { namespace core {
|
||||
std::string pathToProc = u8fmt("/proc/%d/exe", (int) getpid());
|
||||
readlink(pathToProc.c_str(), pathbuf, PATH_MAX);
|
||||
#endif
|
||||
|
||||
result.assign(pathbuf);
|
||||
size_t last = result.find_last_of("/");
|
||||
result = result.substr(0, last); /* remove filename component */
|
||||
@ -167,13 +150,19 @@ namespace musik { namespace core {
|
||||
std::string directory;
|
||||
|
||||
#ifdef WIN32
|
||||
DWORD bufferSize = GetEnvironmentVariable(L"USERPROFILE", 0, 0);
|
||||
DWORD bufferSize = GetEnvironmentVariable(L"APPDATA", 0, 0);
|
||||
wchar_t* buffer = new wchar_t[bufferSize + 2];
|
||||
GetEnvironmentVariable(L"USERPROFILE", buffer, bufferSize);
|
||||
GetEnvironmentVariable(L"APPDATA", buffer, bufferSize);
|
||||
directory.assign(u16to8(buffer));
|
||||
delete[] buffer;
|
||||
#else
|
||||
const char* result = std::getenv("XDG_CONFIG_HOME");
|
||||
if (result && strlen(result)) {
|
||||
directory = std::string(result);
|
||||
}
|
||||
else {
|
||||
directory = std::string(std::getenv("HOME"));
|
||||
}
|
||||
#endif
|
||||
|
||||
return directory;
|
||||
|
Loading…
Reference in New Issue
Block a user