From d7cc42d40e9ab38b28424983b9ce7c3e4970ac01 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Fri, 10 Apr 2026 20:58:48 -0700 Subject: [PATCH] fix: implement `StdFilesystem::getBasePath` for windows, macos, linux --- targets/platform/fs/std/StdFilesystem.cpp | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/targets/platform/fs/std/StdFilesystem.cpp b/targets/platform/fs/std/StdFilesystem.cpp index 84421efde..945d4b14f 100644 --- a/targets/platform/fs/std/StdFilesystem.cpp +++ b/targets/platform/fs/std/StdFilesystem.cpp @@ -6,6 +6,12 @@ #include #endif +#if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#endif + namespace platform_internal { IPlatformFilesystem& PlatformFilesystem_get() { static StdFilesystem instance; @@ -82,15 +88,23 @@ std::size_t StdFilesystem::fileSize(const std::filesystem::path& path) { } std::filesystem::path StdFilesystem::getBasePath() { -#if defined(__linux__) - char buf[4096]; - ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); +#if defined(_WIN32) + wchar_t buf[4096]; + DWORD len = GetModuleFileNameW(nullptr, buf, sizeof(buf) / sizeof(wchar_t)); if (len > 0) { - buf[len] = '\0'; return std::filesystem::path(buf).parent_path(); } -#endif +#elif defined(__APPLE__) + char buf[4096]; + uint32_t size = sizeof(buf); + if (_NSGetExecutablePath(buf, &size) == 0) { + return std::filesystem::path(buf).parent_path(); + } +#elif defined(__linux__) + return std::filesystem::read_symlink("/proc/self/exe").parent_path(); +#else return std::filesystem::current_path(); +#endif } std::filesystem::path StdFilesystem::getUserDataPath() { return getBasePath(); } \ No newline at end of file