comparison src/core/filesystem.cpp @ 9:5c0397762b53

INCOMPLETE: megacommit :)
author Paper <mrpapersonic@gmail.com>
date Sun, 10 Sep 2023 03:59:16 -0400
parents src/filesystem.cpp@07a9095eaeed
children fc1bf97c528b
comparison
equal deleted inserted replaced
8:b1f73678ef61 9:5c0397762b53
1 #ifdef WIN32
2 #include <shlobj.h>
3 #elif defined(MACOSX)
4 #include "sys/osx/filesystem.h"
5 #elif defined(__linux__)
6 #include <pwd.h>
7 #include <sys/types.h>
8 #include <unistd.h>
9 #endif
10 #include "core/config.h"
11 #include "core/filesystem.h"
12 #include "core/strings.h"
13 #include <QMessageBox>
14 #include <filesystem>
15 #include <limits.h>
16
17 std::filesystem::path get_config_path(void) {
18 std::filesystem::path cfg_path;
19 #ifdef WIN32
20 char buf[PATH_MAX + 1];
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)
24 /* pass all of our problems to */
25 cfg_path = std::filesystem::path(osx::GetApplicationSupportDirectory()) / CONFIG_DIR / CONFIG_NAME;
26 #else // just assume POSIX
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__
33 #endif // !WIN32 && !MACOSX
34 return cfg_path;
35 }