From 056dd45c1603da99e163bff64845a26370b3986e Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 17 Mar 2026 15:09:36 -0500 Subject: [PATCH 1/3] fix more instances of `hack` hardcoding also in some places switch to using pathnames instead of strings for paths --- library/Core.cpp | 14 +++++--------- library/Process.cpp | 2 +- library/VersionInfoFactory.cpp | 5 +++-- library/include/VersionInfoFactory.h | 3 ++- library/lua/helpdb.lua | 4 ++-- library/modules/DFSteam.cpp | 6 ++++-- plugins/orders.cpp | 9 ++++----- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index a5cd996667..8979cb3eee 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -124,7 +124,7 @@ namespace DFHack { static const std::filesystem::path getConfigDefaultsPath() { - return Filesystem::getInstallDir() / "hack" / "data" / "dfhack-config-defaults"; + return Core::getInstance().getHackPath() / "data" / "dfhack-config-defaults"; }; class MainThread { @@ -492,7 +492,7 @@ void Core::getScriptPaths(std::vector *dest) if (save.size()) dest->emplace_back(df_pref_path / "save" / save / "scripts"); } - dest->emplace_back(df_install_path / "hack" / "scripts"); + dest->emplace_back(getHackPath() / "scripts"); for (auto & path : script_paths[2]) dest->emplace_back(path); for (auto & path : script_paths[1]) @@ -1054,7 +1054,7 @@ void Core::fatal (std::string output, const char * title) std::filesystem::path Core::getHackPath() { - return p->getPath() / "hack"; + return Filesystem::get_initial_cwd() / "hack"; } df::viewscreen * Core::getTopViewscreen() { @@ -1099,16 +1099,12 @@ bool Core::InitMainThread() { } // find out what we are... - #ifdef LINUX_BUILD - const char * path = "hack/symbols.xml"; - #else - const char * path = "hack\\symbols.xml"; - #endif + std::filesystem::path symbols_path = getHackPath() / "symbols.xml"; auto local_vif = std::make_unique(); std::cerr << "Identifying DF version.\n"; try { - local_vif->loadFile(path); + local_vif->loadFile(symbols_path); } catch(Error::All & err) { diff --git a/library/Process.cpp b/library/Process.cpp index 3e3ba6db80..c45e5aea45 100644 --- a/library/Process.cpp +++ b/library/Process.cpp @@ -664,7 +664,7 @@ uint32_t Process::getTickCount() #endif /* WIN32 */ } -std::filesystem::path Process::getPath() +[[deprecated]] std::filesystem::path Process::getPath() { #if defined(WIN32) || !defined(_DARWIN) return Filesystem::get_initial_cwd(); diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index b4f6eefc78..94e2560e37 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -29,6 +29,7 @@ distribution. #include #include #include +#include #include "VersionInfoFactory.h" #include "VersionInfo.h" @@ -226,9 +227,9 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem) } // method // load the XML file with offsets -bool VersionInfoFactory::loadFile(string path_to_xml) +bool VersionInfoFactory::loadFile(std::filesystem::path path_to_xml) { - TiXmlDocument doc( path_to_xml.c_str() ); + TiXmlDocument doc( path_to_xml.string().c_str() ); std::cerr << "Loading " << path_to_xml << " ... "; //bool loadOkay = doc.LoadFile(); if (!doc.LoadFile()) diff --git a/library/include/VersionInfoFactory.h b/library/include/VersionInfoFactory.h index 060d622ecd..92a5f94e10 100644 --- a/library/include/VersionInfoFactory.h +++ b/library/include/VersionInfoFactory.h @@ -26,6 +26,7 @@ distribution. #pragma once #include +#include #include "Export.h" @@ -38,7 +39,7 @@ namespace DFHack public: VersionInfoFactory(); ~VersionInfoFactory(); - bool loadFile( std::string path_to_xml); + bool loadFile( std::filesystem::path path_to_xml); bool isInErrorState() const {return error;}; std::shared_ptr getVersionInfoByMD5(std::string md5string) const; std::shared_ptr getVersionInfoByPETimestamp(uintptr_t timestamp) const; diff --git a/library/lua/helpdb.lua b/library/lua/helpdb.lua index 0bd64d29cc..5af55f5697 100644 --- a/library/lua/helpdb.lua +++ b/library/lua/helpdb.lua @@ -5,8 +5,8 @@ local _ENV = mkmodule('helpdb') local argparse = require('argparse') -- paths -local RENDERED_PATH = 'hack/docs/docs/tools/' -local TAG_DEFINITIONS = 'hack/docs/docs/Tags.txt' +local RENDERED_PATH = dfhack.getHackPath() .. '/docs/docs/tools/' +local TAG_DEFINITIONS = dfhack.getHackPath() .. '/docs/docs/Tags.txt' -- used when reading help text embedded in script sources local SCRIPT_DOC_BEGIN = '[====[' diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index 10074eef29..b7453a0db5 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -157,7 +157,8 @@ static bool launchDFHack(color_ostream& out) { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); - static LPCWSTR procname = L"hack/launchdf.exe"; + auto procpath = Core.getInstance().getHackPath() / "launchdf.exe"; + LPCWSTR procname = procpath.wstring().c_str(); static const char * env = "\0"; // note that the environment must be explicitly zeroed out and not NULL, @@ -208,7 +209,8 @@ static bool launchDFHack(color_ostream& out) { return false; } else if (pid == 0) { // child process - static const char * command = "hack/launchdf"; + auto procpath = Core.getInstance().getHackPath() / "launchdf.exe"; + char * command = procpath.string().c_str(); unsetenv("SteamAppId"); execl(command, command, NULL); _exit(EXIT_FAILURE); diff --git a/plugins/orders.cpp b/plugins/orders.cpp index 4bdff21fe2..95932acb52 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -44,8 +44,8 @@ DFHACK_PLUGIN("orders"); REQUIRE_GLOBAL(world); -static const std::string ORDERS_DIR = "dfhack-config/orders"; -static const std::string ORDERS_LIBRARY_DIR = "hack/data/orders"; +static std::filesystem::path ORDERS_DIR = std::filesystem::path("dfhack-config") / "orders"; +static std::filesystem::path ORDERS_LIBRARY_DIR = Core::getInstance().getHackPath() / "data" / "orders"; static command_result orders_command(color_ostream & out, std::vector & parameters); @@ -506,7 +506,7 @@ static command_result orders_export_command(color_ostream & out, const std::stri Filesystem::mkdir(ORDERS_DIR); - std::ofstream file(ORDERS_DIR + "/" + name + ".json"); + std::ofstream file(ORDERS_DIR / ( name + ".json")); file << orders << std::endl; @@ -924,8 +924,7 @@ static command_result orders_import_command(color_ostream & out, const std::stri return CR_WRONG_USAGE; } - const std::string filename((is_library ? ORDERS_LIBRARY_DIR : ORDERS_DIR) + - "/" + fname + ".json"); + auto filename((is_library ? ORDERS_LIBRARY_DIR : ORDERS_DIR) / (fname + ".json")); Json::Value orders; { From d959609a64e5d5c281dd956cc6e53add461f4a14 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 17 Mar 2026 15:15:02 -0500 Subject: [PATCH 2/3] fix typo --- library/modules/DFSteam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index b7453a0db5..7e42414c72 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -209,7 +209,7 @@ static bool launchDFHack(color_ostream& out) { return false; } else if (pid == 0) { // child process - auto procpath = Core.getInstance().getHackPath() / "launchdf.exe"; + auto procpath = Core::getInstance().getHackPath() / "launchdf.exe"; char * command = procpath.string().c_str(); unsetenv("SteamAppId"); execl(command, command, NULL); From 8afcf1b5141333c41b95ada60d3dc9314b4d8f2b Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 17 Mar 2026 15:22:52 -0500 Subject: [PATCH 3/3] dangle me not --- library/modules/DFSteam.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index 7e42414c72..400c489232 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -157,14 +157,13 @@ static bool launchDFHack(color_ostream& out) { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); - auto procpath = Core.getInstance().getHackPath() / "launchdf.exe"; - LPCWSTR procname = procpath.wstring().c_str(); + auto procpath = Core::getInstance().getHackPath() / "launchdf.exe"; static const char * env = "\0"; // note that the environment must be explicitly zeroed out and not NULL, // otherwise the launched process will inherit this process's environment, // and the Steam API in the launchdf process will think it is in DF's context. - BOOL res = CreateProcessW(procname, + BOOL res = CreateProcessW(procpath.wstring().c_str(), NULL, NULL, NULL, FALSE, 0, (LPVOID)env, NULL, &si, &pi); return !!res; @@ -210,9 +209,9 @@ static bool launchDFHack(color_ostream& out) { } else if (pid == 0) { // child process auto procpath = Core::getInstance().getHackPath() / "launchdf.exe"; - char * command = procpath.string().c_str(); + auto command = procpath.string(); unsetenv("SteamAppId"); - execl(command, command, NULL); + execl(command.c_str(), command.c_str(), NULL); _exit(EXIT_FAILURE); }