annotate src/filesystem.cpp @ 8:b1f73678ef61

update text paragraphs are now their own objects, as they should be
author Paper <mrpapersonic@gmail.com>
date Sat, 26 Aug 2023 03:39:34 -0400
parents 07a9095eaeed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
1 #ifdef _WIN32
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__)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
6 #include <unistd.h>
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
7 #include <sys/types.h>
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
8 #include <pwd.h>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 #include <filesystem>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 #include <limits.h>
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
12 #include <QMessageBox>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 #include "config.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 #include "filesystem.h"
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
15 #include "string_utils.h"
2
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;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 #ifdef _WIN32
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 char buf[PATH_MAX+1];
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 */
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
25 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(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__
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 return cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 }