Mercurial > minori
comparison src/core/filesystem.cc @ 250:c130f47f6f48
*: many many changes
e.g. the search page is actually implemented now!
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Sun, 04 Feb 2024 21:17:17 -0500 |
| parents | 2f5a9247e501 |
| children | 862d0d8619f6 |
comparison
equal
deleted
inserted
replaced
| 249:6b2441c776dd | 250:c130f47f6f48 |
|---|---|
| 1 #ifdef WIN32 | |
| 2 # include <shlobj.h> | |
| 3 #elif defined(MACOSX) | |
| 4 # include "sys/osx/filesystem.h" | |
| 5 #elif defined(__linux__) | |
| 6 # include <pwd.h> | |
| 7 # include <sys/types.h> | |
| 8 #endif | |
| 9 | |
| 10 #ifndef WIN32 | |
| 11 # include <errno.h> | |
| 12 # include <unistd.h> | |
| 13 # include <sys/stat.h> | |
| 14 #endif | |
| 15 | |
| 16 #include "core/filesystem.h" | 1 #include "core/filesystem.h" |
| 17 #include "core/config.h" | 2 #include "core/config.h" |
| 18 #include "core/strings.h" | 3 #include "core/strings.h" |
| 4 | |
| 5 #include <QStandardPaths> | |
| 6 | |
| 19 #include <filesystem> | 7 #include <filesystem> |
| 20 #include <limits.h> | |
| 21 | 8 |
| 22 namespace Filesystem { | 9 namespace Filesystem { |
| 23 | 10 |
| 24 /* this runs fs::create_directories() on the | 11 /* this runs fs::create_directories() on the |
| 25 PARENT directory. */ | 12 PARENT directory. */ |
| 31 if (!std::filesystem::exists(parent)) | 18 if (!std::filesystem::exists(parent)) |
| 32 std::filesystem::create_directories(parent); | 19 std::filesystem::create_directories(parent); |
| 33 } | 20 } |
| 34 | 21 |
| 35 std::filesystem::path GetDotPath() { | 22 std::filesystem::path GetDotPath() { |
| 23 /* | |
| 24 * Windows: ~/AppData/Roaming/Minori | |
| 25 * macOS: ~/Library/Application Support/Minori | |
| 26 * ...: ~/.config/minori | |
| 27 * | |
| 28 * FIXME: are windows and mac properly cased? | |
| 29 */ | |
| 36 #ifdef WIN32 | 30 #ifdef WIN32 |
| 37 std::filesystem::path path; | 31 return Strings::ToUtf8String(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); |
| 38 wchar_t* buf; | 32 #else |
| 39 | 33 return Strings::ToUtf8String(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); |
| 40 if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &buf) == S_OK) | 34 #endif |
| 41 path = buf; | |
| 42 else | |
| 43 return std::filesystem::path(); | |
| 44 | |
| 45 CoTaskMemFree(buf); | |
| 46 | |
| 47 return path / CONFIG_DIR; | |
| 48 #elif defined(MACOSX) | |
| 49 std::string appsupport; | |
| 50 if (!osx::GetApplicationSupportDirectory(appsupport)) | |
| 51 return ""; | |
| 52 | |
| 53 return std::filesystem::path(appsupport) / CONFIG_DIR; | |
| 54 #else // just assume POSIX | |
| 55 std::filesystem::path path; | |
| 56 const char* home = getenv("HOME"); | |
| 57 | |
| 58 # ifdef __linux__ | |
| 59 if (!home) | |
| 60 home = getpwuid(getuid())->pw_dir; | |
| 61 # endif // __linux__ | |
| 62 | |
| 63 /* only do this if the home directory was really found */ | |
| 64 if (home) | |
| 65 return std::filesystem::path(home) / ".config" / CONFIG_DIR; | |
| 66 else | |
| 67 return std::filesystem::path(); | |
| 68 #endif // !WIN32 && !MACOSX | |
| 69 } | 35 } |
| 70 | 36 |
| 71 std::filesystem::path GetConfigPath() { | 37 std::filesystem::path GetConfigPath() { |
| 72 return GetDotPath() / CONFIG_NAME; | 38 return GetDotPath() / CONFIG_NAME; |
| 73 } | 39 } |
