diff options
Diffstat (limited to 'src/zencore')
| -rw-r--r-- | src/zencore/filesystem.cpp | 30 | ||||
| -rw-r--r-- | src/zencore/include/zencore/filesystem.h | 2 | ||||
| -rw-r--r-- | src/zencore/include/zencore/testutils.h | 2 |
3 files changed, 33 insertions, 1 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index ac2aabbf0..93383a656 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -14,6 +14,9 @@ #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> +# include <ShlObj.h> +# pragma comment(lib, "shell32.lib") +# pragma comment(lib, "ole32.lib") #endif #if ZEN_PLATFORM_WINDOWS @@ -28,6 +31,7 @@ ZEN_THIRD_PARTY_INCLUDES_END # include <fcntl.h> # include <sys/resource.h> # include <sys/stat.h> +# include <pwd.h> # include <unistd.h> #endif @@ -38,6 +42,7 @@ ZEN_THIRD_PARTY_INCLUDES_END # include <sys/resource.h> # include <sys/stat.h> # include <sys/syslimits.h> +# include <pwd.h> # include <unistd.h> #endif @@ -1702,6 +1707,31 @@ SearchPathForExecutable(std::string_view ExecutableName) #endif } +std::filesystem::path +PickDefaultSystemRootDirectory() +{ +#if ZEN_PLATFORM_WINDOWS + // Pick sensible default + PWSTR ProgramDataDir = nullptr; + HRESULT hRes = SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &ProgramDataDir); + + if (SUCCEEDED(hRes)) + { + std::filesystem::path FinalPath(ProgramDataDir); + FinalPath /= L"Epic\\Zen"; + ::CoTaskMemFree(ProgramDataDir); + + return FinalPath; + } + + return L""; +#else // ZEN_PLATFORM_WINDOWS + int UserId = getuid(); + const passwd* Passwd = getpwuid(UserId); + return std::filesystem::path(Passwd->pw_dir) / ".zen"; +#endif // ZEN_PLATFORM_WINDOWS +} + ////////////////////////////////////////////////////////////////////////// // // Testing related code follows... diff --git a/src/zencore/include/zencore/filesystem.h b/src/zencore/include/zencore/filesystem.h index 897a63d8c..2cd663afb 100644 --- a/src/zencore/include/zencore/filesystem.h +++ b/src/zencore/include/zencore/filesystem.h @@ -221,6 +221,8 @@ std::filesystem::path SearchPathForExecutable(std::string_view ExecutableName); std::error_code RotateFiles(const std::filesystem::path& Filename, std::size_t MaxFiles); std::error_code RotateDirectories(const std::filesystem::path& DirectoryName, std::size_t MaxDirectories); +std::filesystem::path PickDefaultSystemRootDirectory(); + ////////////////////////////////////////////////////////////////////////// void filesystem_forcelink(); // internal diff --git a/src/zencore/include/zencore/testutils.h b/src/zencore/include/zencore/testutils.h index 215fb71a8..6a1c0184b 100644 --- a/src/zencore/include/zencore/testutils.h +++ b/src/zencore/include/zencore/testutils.h @@ -18,7 +18,7 @@ public: ScopedTemporaryDirectory(); ~ScopedTemporaryDirectory(); - std::filesystem::path& Path() { return m_RootPath; } + const std::filesystem::path& Path() const { return m_RootPath; } private: std::filesystem::path m_RootPath; |