Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/core/filesystem.cc Wed Jan 24 20:18:59 2024 -0500 +++ b/src/core/filesystem.cc Sun Feb 04 21:17:17 2024 -0500 @@ -1,23 +1,10 @@ -#ifdef WIN32 -# include <shlobj.h> -#elif defined(MACOSX) -# include "sys/osx/filesystem.h" -#elif defined(__linux__) -# include <pwd.h> -# include <sys/types.h> -#endif - -#ifndef WIN32 -# include <errno.h> -# include <unistd.h> -# include <sys/stat.h> -#endif - #include "core/filesystem.h" #include "core/config.h" #include "core/strings.h" + +#include <QStandardPaths> + #include <filesystem> -#include <limits.h> namespace Filesystem { @@ -33,39 +20,18 @@ } std::filesystem::path GetDotPath() { + /* + * Windows: ~/AppData/Roaming/Minori + * macOS: ~/Library/Application Support/Minori + * ...: ~/.config/minori + * + * FIXME: are windows and mac properly cased? + */ #ifdef WIN32 - std::filesystem::path path; - wchar_t* buf; - - if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &buf) == S_OK) - path = buf; - else - return std::filesystem::path(); - - CoTaskMemFree(buf); - - return path / CONFIG_DIR; -#elif defined(MACOSX) - std::string appsupport; - if (!osx::GetApplicationSupportDirectory(appsupport)) - return ""; - - return std::filesystem::path(appsupport) / CONFIG_DIR; -#else // just assume POSIX - std::filesystem::path path; - const char* home = getenv("HOME"); - -# ifdef __linux__ - if (!home) - home = getpwuid(getuid())->pw_dir; -# endif // __linux__ - - /* only do this if the home directory was really found */ - if (home) - return std::filesystem::path(home) / ".config" / CONFIG_DIR; - else - return std::filesystem::path(); -#endif // !WIN32 && !MACOSX + return Strings::ToUtf8String(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); +#else + return Strings::ToUtf8String(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); +#endif } std::filesystem::path GetConfigPath() {