Mercurial > minori
comparison src/filesystem.cpp @ 1:1ae666fdf9e2
*: initial commit
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 08 Aug 2023 19:49:15 -0400 |
parents | |
children | 23d0d9319a00 |
comparison
equal
deleted
inserted
replaced
0:5a76e1b94163 | 1:1ae666fdf9e2 |
---|---|
1 #ifdef _WIN32 | |
2 #include <shlobj.h> | |
3 #elif defined(APPLE) | |
4 #include <NSSearchPathForDirectoriesInDomains.h> | |
5 #endif | |
6 #include <filesystem> | |
7 #include <limits.h> | |
8 #include "config.h" | |
9 #include "filesystem.h" | |
10 | |
11 std::filesystem::path get_config_path(void) { | |
12 std::filesystem::path cfg_path; | |
13 #ifdef _WIN32 | |
14 char buf[PATH_MAX+1]; | |
15 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) | |
16 cfg_path = std::filesystem::path(buf) / CONFIG_NAME; | |
17 #elif defined(MACOSX) | |
18 /* hope and pray that std::filesystem can handle tildes... */ | |
19 CFString string = (CFString)NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); | |
20 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(std::string(CFStringGetCStringPtr(string, UTF8)))); | |
21 #else // just assume POSIX | |
22 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME; | |
23 #endif | |
24 return cfg_path; | |
25 } |