annotate src/filesystem.cpp @ 5:51ae25154b70

Fix OS X support code
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 13:10:34 -0400
parents 23d0d9319a00
children 07a9095eaeed
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"
2
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>
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
8 #include <QMessageBox>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #include "config.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 #include "filesystem.h"
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
11 #include "string_utils.h"
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 std::filesystem::path get_config_path(void) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 std::filesystem::path cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 #ifdef _WIN32
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 char buf[PATH_MAX+1];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 cfg_path = std::filesystem::path(buf) / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 #elif defined(MACOSX)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 /* hope and pray that std::filesystem can handle tildes... */
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
21 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(osx::GetApplicationSupportDirectory())) / CONFIG_DIR / CONFIG_NAME;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 #else // just assume POSIX
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 return cfg_path;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 }