Windows support

This commit is contained in:
Gabrieal Jimmy
2026-10-02 16:04:30 -05:00
parent 34fa21139f
commit d31689cf86
14 changed files with 242 additions and 57 deletions

61
shared/Paths.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include "Paths.h"
#include <cstdlib>
#if defined(_WIN32)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#endif
#ifndef BS_ASSET_DIR
#define BS_ASSET_DIR "assets"
#endif
namespace bs {
namespace fs = std::filesystem;
fs::path executableDir() {
#if defined(_WIN32)
std::wstring buf(32768, L'\0');
DWORD n = GetModuleFileNameW(nullptr, buf.data(), DWORD(buf.size()));
buf.resize(n);
return fs::path(buf).parent_path();
#else
std::error_code ec;
fs::path exe = fs::read_symlink("/proc/self/exe", ec);
return ec ? fs::current_path() : exe.parent_path();
#endif
}
fs::path userDataDir() {
fs::path base;
#if defined(_WIN32)
if (const char* a = std::getenv("APPDATA"); a && *a) base = a;
#else
if (const char* x = std::getenv("XDG_DATA_HOME"); x && *x) base = x;
else if (const char* h = std::getenv("HOME"); h && *h) base = fs::path(h) / ".local/share";
#endif
if (base.empty()) base = ".";
fs::path d = base / "brandling-safari";
std::error_code ec;
fs::create_directories(d, ec);
return d;
}
const std::string& gameAssetDir() {
static const std::string dir = [] {
fs::path packaged = executableDir() / "assets";
std::error_code ec;
if (fs::exists(packaged / "characters" / "manifest.json", ec)) return packaged.string();
return std::string(BS_ASSET_DIR);
}();
return dir;
}
} // namespace bs