Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -492,7 +492,7 @@ void Core::getScriptPaths(std::vector<std::filesystem::path> *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])
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<DFHack::VersionInfoFactory>();
std::cerr << "Identifying DF version.\n";
try
{
local_vif->loadFile(path);
local_vif->loadFile(symbols_path);
}
catch(Error::All & err)
{
Expand Down
2 changes: 1 addition & 1 deletion library/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions library/VersionInfoFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ distribution.
#include <algorithm>
#include <map>
#include <iostream>
#include <filesystem>

#include "VersionInfoFactory.h"
#include "VersionInfo.h"
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion library/include/VersionInfoFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ distribution.
#pragma once

#include <memory>
#include <filesystem>

#include "Export.h"

Expand All @@ -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<const VersionInfo> getVersionInfoByMD5(std::string md5string) const;
std::shared_ptr<const VersionInfo> getVersionInfoByPETimestamp(uintptr_t timestamp) const;
Expand Down
4 changes: 2 additions & 2 deletions library/lua/helpdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[====['
Expand Down
9 changes: 5 additions & 4 deletions library/modules/DFSteam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ 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";
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;
Expand Down Expand Up @@ -208,9 +208,10 @@ 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";
auto command = procpath.string();
unsetenv("SteamAppId");
execl(command, command, NULL);
execl(command.c_str(), command.c_str(), NULL);
_exit(EXIT_FAILURE);
}

Expand Down
9 changes: 4 additions & 5 deletions plugins/orders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & parameters);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

{
Expand Down
Loading