Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 4:5af270662505 | 5:51ae25154b70 |
|---|---|
| 1 #ifdef _WIN32 | 1 #ifdef _WIN32 |
| 2 #include <shlobj.h> | 2 #include <shlobj.h> |
| 3 #elif defined(APPLE) | 3 #elif defined(MACOSX) |
| 4 #include <NSSearchPathForDirectoriesInDomains.h> | 4 #include "sys/osx/filesystem.h" |
| 5 #endif | 5 #endif |
| 6 #include <filesystem> | 6 #include <filesystem> |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <QMessageBox> | |
| 8 #include "config.h" | 9 #include "config.h" |
| 9 #include "filesystem.h" | 10 #include "filesystem.h" |
| 11 #include "string_utils.h" | |
| 10 | 12 |
| 11 std::filesystem::path get_config_path(void) { | 13 std::filesystem::path get_config_path(void) { |
| 12 std::filesystem::path cfg_path; | 14 std::filesystem::path cfg_path; |
| 13 #ifdef _WIN32 | 15 #ifdef _WIN32 |
| 14 char buf[PATH_MAX+1]; | 16 char buf[PATH_MAX+1]; |
| 15 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) | 17 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) |
| 16 cfg_path = std::filesystem::path(buf) / CONFIG_NAME; | 18 cfg_path = std::filesystem::path(buf) / CONFIG_NAME; |
| 17 #elif defined(MACOSX) | 19 #elif defined(MACOSX) |
| 18 /* hope and pray that std::filesystem can handle tildes... */ | 20 /* hope and pray that std::filesystem can handle tildes... */ |
| 19 CFString string = (CFString)NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); | 21 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(osx::GetApplicationSupportDirectory())) / CONFIG_DIR / CONFIG_NAME; |
| 20 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(std::string(CFStringGetCStringPtr(string, UTF8)))); | |
| 21 #else // just assume POSIX | 22 #else // just assume POSIX |
| 22 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME; | 23 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME; |
| 23 #endif | 24 #endif |
| 24 return cfg_path; | 25 return cfg_path; |
| 25 } | 26 } |
