Skip to content

Commit 777b243

Browse files
authored
Merge pull request #5754 from ab9rf/hack-path-2
fix more instances of `hack` hardcoding
2 parents 5af6036 + 6efba41 commit 777b243

7 files changed

Lines changed: 22 additions & 24 deletions

File tree

library/Core.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace DFHack {
124124

125125
static const std::filesystem::path getConfigDefaultsPath()
126126
{
127-
return Filesystem::getInstallDir() / "hack" / "data" / "dfhack-config-defaults";
127+
return Core::getInstance().getHackPath() / "data" / "dfhack-config-defaults";
128128
};
129129

130130
class MainThread {
@@ -492,7 +492,7 @@ void Core::getScriptPaths(std::vector<std::filesystem::path> *dest)
492492
if (save.size())
493493
dest->emplace_back(df_pref_path / "save" / save / "scripts");
494494
}
495-
dest->emplace_back(df_install_path / "hack" / "scripts");
495+
dest->emplace_back(getHackPath() / "scripts");
496496
for (auto & path : script_paths[2])
497497
dest->emplace_back(path);
498498
for (auto & path : script_paths[1])
@@ -1054,7 +1054,7 @@ void Core::fatal (std::string output, const char * title)
10541054

10551055
std::filesystem::path Core::getHackPath()
10561056
{
1057-
return p->getPath() / "hack";
1057+
return Filesystem::get_initial_cwd() / "hack";
10581058
}
10591059

10601060
df::viewscreen * Core::getTopViewscreen() {
@@ -1099,16 +1099,12 @@ bool Core::InitMainThread() {
10991099
}
11001100

11011101
// find out what we are...
1102-
#ifdef LINUX_BUILD
1103-
const char * path = "hack/symbols.xml";
1104-
#else
1105-
const char * path = "hack\\symbols.xml";
1106-
#endif
1102+
std::filesystem::path symbols_path = getHackPath() / "symbols.xml";
11071103
auto local_vif = std::make_unique<DFHack::VersionInfoFactory>();
11081104
std::cerr << "Identifying DF version.\n";
11091105
try
11101106
{
1111-
local_vif->loadFile(path);
1107+
local_vif->loadFile(symbols_path);
11121108
}
11131109
catch(Error::All & err)
11141110
{

library/Process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ uint32_t Process::getTickCount()
664664
#endif /* WIN32 */
665665
}
666666

667-
std::filesystem::path Process::getPath()
667+
[[deprecated]] std::filesystem::path Process::getPath()
668668
{
669669
#if defined(WIN32) || !defined(_DARWIN)
670670
return Filesystem::get_initial_cwd();

library/VersionInfoFactory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ distribution.
2929
#include <algorithm>
3030
#include <map>
3131
#include <iostream>
32+
#include <filesystem>
3233

3334
#include "VersionInfoFactory.h"
3435
#include "VersionInfo.h"
@@ -226,9 +227,9 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem)
226227
} // method
227228

228229
// load the XML file with offsets
229-
bool VersionInfoFactory::loadFile(string path_to_xml)
230+
bool VersionInfoFactory::loadFile(std::filesystem::path path_to_xml)
230231
{
231-
TiXmlDocument doc( path_to_xml.c_str() );
232+
TiXmlDocument doc( path_to_xml.string().c_str() );
232233
std::cerr << "Loading " << path_to_xml << " ... ";
233234
//bool loadOkay = doc.LoadFile();
234235
if (!doc.LoadFile())

library/include/VersionInfoFactory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ distribution.
2626
#pragma once
2727

2828
#include <memory>
29+
#include <filesystem>
2930

3031
#include "Export.h"
3132

@@ -38,7 +39,7 @@ namespace DFHack
3839
public:
3940
VersionInfoFactory();
4041
~VersionInfoFactory();
41-
bool loadFile( std::string path_to_xml);
42+
bool loadFile( std::filesystem::path path_to_xml);
4243
bool isInErrorState() const {return error;};
4344
std::shared_ptr<const VersionInfo> getVersionInfoByMD5(std::string md5string) const;
4445
std::shared_ptr<const VersionInfo> getVersionInfoByPETimestamp(uintptr_t timestamp) const;

library/lua/helpdb.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ local _ENV = mkmodule('helpdb')
55
local argparse = require('argparse')
66

77
-- paths
8-
local RENDERED_PATH = 'hack/docs/docs/tools/'
9-
local TAG_DEFINITIONS = 'hack/docs/docs/Tags.txt'
8+
local RENDERED_PATH = dfhack.getHackPath() .. '/docs/docs/tools/'
9+
local TAG_DEFINITIONS = dfhack.getHackPath() .. '/docs/docs/Tags.txt'
1010

1111
-- used when reading help text embedded in script sources
1212
local SCRIPT_DOC_BEGIN = '[====['

library/modules/DFSteam.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ static bool launchDFHack(color_ostream& out) {
157157
si.cb = sizeof(si);
158158
ZeroMemory(&pi, sizeof(pi));
159159

160-
static LPCWSTR procname = L"hack/launchdf.exe";
160+
auto procpath = Core::getInstance().getHackPath() / "launchdf.exe";
161161
static const char * env = "\0";
162162

163163
// note that the environment must be explicitly zeroed out and not NULL,
164164
// otherwise the launched process will inherit this process's environment,
165165
// and the Steam API in the launchdf process will think it is in DF's context.
166-
BOOL res = CreateProcessW(procname,
166+
BOOL res = CreateProcessW(procpath.wstring().c_str(),
167167
NULL, NULL, NULL, FALSE, 0, (LPVOID)env, NULL, &si, &pi);
168168

169169
return !!res;
@@ -208,9 +208,10 @@ static bool launchDFHack(color_ostream& out) {
208208
return false;
209209
} else if (pid == 0) {
210210
// child process
211-
static const char * command = "hack/launchdf";
211+
auto procpath = Core::getInstance().getHackPath() / "launchdf";
212+
auto command = procpath.string();
212213
unsetenv("SteamAppId");
213-
execl(command, command, NULL);
214+
execl(command.c_str(), command.c_str(), NULL);
214215
_exit(EXIT_FAILURE);
215216
}
216217

plugins/orders.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ DFHACK_PLUGIN("orders");
4444

4545
REQUIRE_GLOBAL(world);
4646

47-
static const std::string ORDERS_DIR = "dfhack-config/orders";
48-
static const std::string ORDERS_LIBRARY_DIR = "hack/data/orders";
47+
static std::filesystem::path ORDERS_DIR = std::filesystem::path("dfhack-config") / "orders";
48+
static std::filesystem::path ORDERS_LIBRARY_DIR = Core::getInstance().getHackPath() / "data" / "orders";
4949

5050
static command_result orders_command(color_ostream & out, std::vector<std::string> & parameters);
5151

@@ -506,7 +506,7 @@ static command_result orders_export_command(color_ostream & out, const std::stri
506506

507507
Filesystem::mkdir(ORDERS_DIR);
508508

509-
std::ofstream file(ORDERS_DIR + "/" + name + ".json");
509+
std::ofstream file(ORDERS_DIR / ( name + ".json"));
510510

511511
file << orders << std::endl;
512512

@@ -924,8 +924,7 @@ static command_result orders_import_command(color_ostream & out, const std::stri
924924
return CR_WRONG_USAGE;
925925
}
926926

927-
const std::string filename((is_library ? ORDERS_LIBRARY_DIR : ORDERS_DIR) +
928-
"/" + fname + ".json");
927+
auto filename((is_library ? ORDERS_LIBRARY_DIR : ORDERS_DIR) / (fname + ".json"));
929928
Json::Value orders;
930929

931930
{

0 commit comments

Comments
 (0)