9
|
1 #ifdef WIN32
|
2
|
2 #include <shlobj.h>
|
5
|
3 #elif defined(MACOSX)
|
|
4 #include "sys/osx/filesystem.h"
|
7
|
5 #elif defined(__linux__)
|
9
|
6 #include <pwd.h>
|
7
|
7 #include <sys/types.h>
|
9
|
8 #include <unistd.h>
|
2
|
9 #endif
|
9
|
10 #include "core/config.h"
|
|
11 #include "core/filesystem.h"
|
|
12 #include "core/strings.h"
|
|
13 #include <QMessageBox>
|
2
|
14 #include <filesystem>
|
|
15 #include <limits.h>
|
|
16
|
|
17 std::filesystem::path get_config_path(void) {
|
|
18 std::filesystem::path cfg_path;
|
9
|
19 #ifdef WIN32
|
|
20 char buf[PATH_MAX + 1];
|
2
|
21 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK)
|
|
22 cfg_path = std::filesystem::path(buf) / CONFIG_NAME;
|
|
23 #elif defined(MACOSX)
|
7
|
24 /* pass all of our problems to */
|
9
|
25 cfg_path = std::filesystem::path(osx::GetApplicationSupportDirectory()) / CONFIG_DIR / CONFIG_NAME;
|
2
|
26 #else // just assume POSIX
|
7
|
27 if (getenv("HOME") != NULL)
|
|
28 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME;
|
|
29 #ifdef __linux__
|
|
30 else
|
|
31 cfg_path = std::filesystem::path(getpwuid(getuid())->pw_dir) / ".config" / CONFIG_DIR / CONFIG_NAME;
|
|
32 #endif // __linux__
|
9
|
33 #endif // !WIN32 && !MACOSX
|
2
|
34 return cfg_path;
|
|
35 }
|