summaryrefslogtreecommitdiffstats
path: root/src/menu.cpp
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-26 17:50:46 +0100
committersalmonik <salmonik@tuta.io>2026-10-26 17:50:46 +0100
commite4182431ce31b5fd02bf884329107b8d4a3f249d (patch)
treecbf42ddef0e61814445e976cdb6296b64b0f4d7a /src/menu.cpp
parentABH: silent auto-ABH on the jump tick (diff)
downloadhl2h-e4182431ce31b5fd02bf884329107b8d4a3f249d.tar.gz
hl2h-e4182431ce31b5fd02bf884329107b8d4a3f249d.zip
Config: store in $XDG_CONFIG_HOME/hl2hake/config
Diffstat (limited to '')
-rw-r--r--src/menu.cpp27
1 files 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 @@
4#include <cstdio> 4#include <cstdio>
5#include <cstdlib> 5#include <cstdlib>
6#include <cstring> 6#include <cstring>
7#include <sys/stat.h>
7 8
8// --------------------------------------------------------------------------- 9// ---------------------------------------------------------------------------
9// ConMsg (tier0 console printer — prints to in-game console) 10// ConMsg (tier0 console printer — prints to in-game console)
@@ -192,11 +193,28 @@ static void rebuild_visible() {
192// config persistence (INI format) 193// config persistence (INI format)
193// --------------------------------------------------------------------------- 194// ---------------------------------------------------------------------------
194 195
196static void mkdir_p(const std::string &path) {
197 for (size_t i = 1; i <= path.size(); i++) {
198 if (i != path.size() && path[i] != '/')
199 continue;
200 std::string p = path.substr(0, i);
201 if (!p.empty() && p != "/")
202 mkdir(p.c_str(), 0755);
203 }
204}
205
195static std::string config_path() { 206static std::string config_path() {
196 size_t slash = g_engine.path.find_last_of('/'); 207 const char *xdg = getenv("XDG_CONFIG_HOME");
197 if (slash == std::string::npos) 208 std::string base;
198 return "hl2hake.cfg"; 209 if (xdg && *xdg) {
199 return g_engine.path.substr(0, slash + 1) + "hl2hake.cfg"; 210 base = xdg;
211 } else {
212 const char *home = getenv("HOME");
213 base = (home && *home) ? std::string(home) + "/.config" : ".";
214 }
215 std::string dir = base + "/hl2hake";
216 mkdir_p(dir);
217 return dir + "/config";
200} 218}
201 219
202[[maybe_unused]] static const char *sdl_scancode_name(int sc) { 220[[maybe_unused]] static const char *sdl_scancode_name(int sc) {
@@ -802,6 +820,7 @@ static ISurface *find_surface_interface() {
802 820
803void install_menu() { 821void install_menu() {
804 build_tree(); 822 build_tree();
823 logf("config: %s", config_path().c_str());
805 config_load(); 824 config_load();
806 // resolve ISurface once (used by the DrawPrintText hook in hl2h.cpp and 825 // resolve ISurface once (used by the DrawPrintText hook in hl2h.cpp and
807 // by outer_draw). DrawPrintText hook is installed from hkdCreateMove. 826 // by outer_draw). DrawPrintText hook is installed from hkdCreateMove.