60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
#include "Paths.h"
|
|
|
|
namespace Artifact {
|
|
|
|
Path getDataPath() {
|
|
Path base;
|
|
|
|
// ────────────────────────────────────────────────
|
|
// 1. Windows — AppData/Roaming (most common choice)
|
|
// ────────────────────────────────────────────────
|
|
#ifdef _WIN32
|
|
const char* appdata = std::getenv("APPDATA");
|
|
if (!appdata || !fs::exists(appdata)) {
|
|
throw std::runtime_error("Cannot find APPDATA environment variable");
|
|
}
|
|
base = Path(appdata) / organization / GAME;
|
|
|
|
#elif defined(__APPLE__)
|
|
// ────────────────────────────────────────────────
|
|
// 2. macOS — Application Support
|
|
// ────────────────────────────────────────────────
|
|
const char* home = std::getenv("HOME");
|
|
if (!home) throw std::runtime_error("Cannot find HOME");
|
|
base = Path(home) / "Library" / "Application Support" / GAME;
|
|
|
|
#else
|
|
// ────────────────────────────────────────────────
|
|
// 3. Linux / BSD / Steam Deck — XDG_DATA_HOME
|
|
// ────────────────────────────────────────────────
|
|
const char* xdg_data = std::getenv("XDG_DATA_HOME");
|
|
if (xdg_data && *xdg_data) {
|
|
base = fs::path(xdg_data) / game;
|
|
} else {
|
|
const char* home = std::getenv("HOME");
|
|
if (!home) throw std::runtime_error("Cannot find HOME");
|
|
base = Path(home) / ".local" / "share" / GAME;
|
|
}
|
|
#endif
|
|
|
|
// Create folder structure if it doesn't exist
|
|
std::error_code ec;
|
|
std::filesystem::create_directories(base, ec);
|
|
|
|
if (ec) {
|
|
throw std::runtime_error("Failed to create directory: " +
|
|
base.string() + " → " + ec.message());
|
|
}
|
|
|
|
return base;
|
|
}
|
|
|
|
Path getClientConfigPath() {
|
|
return getDataPath() / "client.conf";
|
|
}
|
|
|
|
Path getServerConfigPath() {
|
|
return getDataPath() / "server.conf";
|
|
}
|
|
|
|
}
|