annotate src/filesystem.cpp @ 1:1ae666fdf9e2

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