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

21
shared/Paths.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
// Where things live on disk.
//
// Assets: a release package keeps them next to the executables
// (`<exe dir>/assets` for the game, `<exe dir>/engine` for the engine's shaders,
// fonts, textures and models); a development build falls back to the source
// checkout paths baked in by CMake (BS_ASSET_DIR / HD2D_ENGINE_ASSET_DIR).
#include <filesystem>
#include <string>
namespace bs {
std::filesystem::path executableDir();
// %APPDATA%\brandling-safari on Windows, $XDG_DATA_HOME/brandling-safari or
// ~/.local/share/brandling-safari elsewhere. Created if missing.
std::filesystem::path userDataDir();
// Game asset root (contains characters/manifest.json).
const std::string& gameAssetDir();
} // namespace bs