diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/menu.cpp | 27 |
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 | ||
| 196 | static 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 | |||
| 195 | static std::string config_path() { | 206 | static 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 | ||
| 803 | void install_menu() { | 821 | void 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. |
