comparison src/filesystem.cpp @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents 51ae25154b70
children
comparison
equal deleted inserted replaced
6:1d82f6e04d7d 7:07a9095eaeed
1 #ifdef _WIN32 1 #ifdef _WIN32
2 #include <shlobj.h> 2 #include <shlobj.h>
3 #elif defined(MACOSX) 3 #elif defined(MACOSX)
4 #include "sys/osx/filesystem.h" 4 #include "sys/osx/filesystem.h"
5 #elif defined(__linux__)
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <pwd.h>
5 #endif 9 #endif
6 #include <filesystem> 10 #include <filesystem>
7 #include <limits.h> 11 #include <limits.h>
8 #include <QMessageBox> 12 #include <QMessageBox>
9 #include "config.h" 13 #include "config.h"
15 #ifdef _WIN32 19 #ifdef _WIN32
16 char buf[PATH_MAX+1]; 20 char buf[PATH_MAX+1];
17 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) 21 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK)
18 cfg_path = std::filesystem::path(buf) / CONFIG_NAME; 22 cfg_path = std::filesystem::path(buf) / CONFIG_NAME;
19 #elif defined(MACOSX) 23 #elif defined(MACOSX)
20 /* hope and pray that std::filesystem can handle tildes... */ 24 /* pass all of our problems to */
21 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(osx::GetApplicationSupportDirectory())) / CONFIG_DIR / CONFIG_NAME; 25 cfg_path = std::filesystem::path(StringUtils::Utf8ToWstr(osx::GetApplicationSupportDirectory())) / CONFIG_DIR / CONFIG_NAME;
22 #else // just assume POSIX 26 #else // just assume POSIX
23 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME; 27 if (getenv("HOME") != NULL)
28 cfg_path = std::filesystem::path(getenv("HOME")) / ".config" / CONFIG_DIR / CONFIG_NAME;
29 #ifdef __linux__
30 else
31 cfg_path = std::filesystem::path(getpwuid(getuid())->pw_dir) / ".config" / CONFIG_DIR / CONFIG_NAME;
32 #endif // __linux__
24 #endif 33 #endif
25 return cfg_path; 34 return cfg_path;
26 } 35 }