annotate src/filesystem.cpp @ 4:5af270662505

Set override functions as override
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 12:08:16 -0400
parents 23d0d9319a00
children 51ae25154b70
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>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #elif defined(APPLE)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 #include <NSSearchPathForDirectoriesInDomains.h>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
6 #include <filesystem>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7 #include <limits.h>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
8 #include "config.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #include "filesystem.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 std::filesystem::path get_config_path(void) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 std::filesystem::path cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 #ifdef _WIN32
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 char buf[PATH_MAX+1];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 cfg_path = std::filesystem::path(buf) / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 #elif defined(MACOSX)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 /* hope and pray that std::filesystem can handle tildes... */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 CFString string = (CFString)NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(std::string(CFStringGetCStringPtr(string, UTF8))));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 #else // just assume POSIX
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 return cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 }