annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #ifdef WIN32
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #include <shlobj.h>
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
3 #elif defined(MACOSX)
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
4 #include "sys/osx/filesystem.h"
7
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
5 #elif defined(__linux__)
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
6 #include <pwd.h>
7
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
7 #include <sys/types.h>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
8 #include <unistd.h>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #endif
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
10 #include "core/config.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
11 #include "core/filesystem.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
12 #include "core/strings.h"
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
13 #include <QMessageBox>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 #include <filesystem>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 #include <limits.h>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 std::filesystem::path get_config_path(void) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 std::filesystem::path cfg_path;
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
19 #ifdef WIN32
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
20 char buf[PATH_MAX + 1];
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 cfg_path = std::filesystem::path(buf) / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 #elif defined(MACOSX)
7
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
24 /* pass all of our problems to */
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
25 cfg_path = std::filesystem::path(osx::GetApplicationSupportDirectory()) / CONFIG_DIR / CONFIG_NAME;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 #else // just assume POSIX
7
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
27 if (getenv("HOME") != NULL)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
28 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
29 #ifdef __linux__
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
30 else
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
31 cfg_path = std::filesystem::path(getpwuid(getuid())->pw_dir) / ".config" / CONFIG_DIR / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
32 #endif // __linux__
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
33 #endif // !WIN32 && !MACOSX
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 return cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 }