From e4182431ce31b5fd02bf884329107b8d4a3f249d Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 26 Oct 2026 17:50:46 +0100 Subject: Config: store in $XDG_CONFIG_HOME/hl2hake/config --- src/menu.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 11ed222..c3bb9ae 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -4,6 +4,7 @@ #include #include #include +#include // --------------------------------------------------------------------------- // ConMsg (tier0 console printer — prints to in-game console) @@ -192,11 +193,28 @@ static void rebuild_visible() { // config persistence (INI format) // --------------------------------------------------------------------------- +static void mkdir_p(const std::string &path) { + for (size_t i = 1; i <= path.size(); i++) { + if (i != path.size() && path[i] != '/') + continue; + std::string p = path.substr(0, i); + if (!p.empty() && p != "/") + mkdir(p.c_str(), 0755); + } +} + static std::string config_path() { - size_t slash = g_engine.path.find_last_of('/'); - if (slash == std::string::npos) - return "hl2hake.cfg"; - return g_engine.path.substr(0, slash + 1) + "hl2hake.cfg"; + const char *xdg = getenv("XDG_CONFIG_HOME"); + std::string base; + if (xdg && *xdg) { + base = xdg; + } else { + const char *home = getenv("HOME"); + base = (home && *home) ? std::string(home) + "/.config" : "."; + } + std::string dir = base + "/hl2hake"; + mkdir_p(dir); + return dir + "/config"; } [[maybe_unused]] static const char *sdl_scancode_name(int sc) { @@ -802,6 +820,7 @@ static ISurface *find_surface_interface() { void install_menu() { build_tree(); + logf("config: %s", config_path().c_str()); config_load(); // resolve ISurface once (used by the DrawPrintText hook in hl2h.cpp and // by outer_draw). DrawPrintText hook is installed from hkdCreateMove. -- cgit v1.2.3