Update some things.
This commit is contained in:
parent
f215bc3742
commit
4ad41f2e2e
34 changed files with 573 additions and 905 deletions
60
Shared/Paths.cpp
Normal file
60
Shared/Paths.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#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";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue