From 2ce4571c3a194c2296ab5577c1388c231dc9be70 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 17 Jun 2025 00:24:42 +0100 Subject: [PATCH 1/8] Handle paths passed on the command line properly Fixes https://gitlab.com/OpenMW/openmw/-/issues/8567. Also maybe horribly breaks lots of things because it removes some insanity from https://gitlab.com/OpenMW/openmw/-/merge_requests/86, which would set the CWD to the local directory just in case any local-relative paths were expressed relatively without the explicit base being the local path. --- apps/bulletobjecttool/main.cpp | 1 + apps/essimporter/main.cpp | 1 + apps/navmeshtool/main.cpp | 1 + apps/openmw/main.cpp | 2 ++ components/files/linuxpath.cpp | 8 -------- components/files/macospath.cpp | 5 ----- components/files/windowspath.cpp | 4 ---- 7 files changed, 5 insertions(+), 17 deletions(-) diff --git a/apps/bulletobjecttool/main.cpp b/apps/bulletobjecttool/main.cpp index 5cb275a53d..66f710df72 100644 --- a/apps/bulletobjecttool/main.cpp +++ b/apps/bulletobjecttool/main.cpp @@ -125,6 +125,7 @@ namespace } Files::ConfigurationManager config; + config.processPaths(variables, std::filesystem::current_path()); config.readConfiguration(variables, desc); Debug::setupLogging(config.getLogPath(), applicationName); diff --git a/apps/essimporter/main.cpp b/apps/essimporter/main.cpp index f0833e9d81..50e11e2c5a 100644 --- a/apps/essimporter/main.cpp +++ b/apps/essimporter/main.cpp @@ -40,6 +40,7 @@ Allowed options)"); bpo::notify(variables); Files::ConfigurationManager cfgManager(true); + cfgManager.processPaths(variables, std::filesystem::current_path()); cfgManager.readConfiguration(variables, desc); const auto& essFile = variables["mwsave"].as(); diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index e148e60d54..65ee6df6b1 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -143,6 +143,7 @@ namespace NavMeshTool } Files::ConfigurationManager config; + config.processPaths(variables, std::filesystem::current_path()); config.readConfiguration(variables, desc); Debug::setupLogging(config.getLogPath(), applicationName); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 812a6ffd85..12b327c222 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -61,6 +61,8 @@ bool parseOptions(int argc, char** argv, OMW::Engine& engine, Files::Configurati return false; } + cfgMgr.processPaths(variables, std::filesystem::current_path()); + cfgMgr.readConfiguration(variables, desc); Debug::setupLogging(cfgMgr.getLogPath(), "OpenMW"); diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 4dbe119917..aa8c410748 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -51,14 +51,6 @@ namespace Files LinuxPath::LinuxPath(const std::string& application_name) : mName(application_name) { - std::error_code ec; - current_path(getLocalPath(), ec); - const auto err = ec.value(); - if (err != 0) - { - Log(Debug::Warning) << "Error " << err << " " << std::generic_category().message(errno) - << " when changing current directory"; - } } std::filesystem::path LinuxPath::getUserConfigPath() const diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 4b37c2fb26..f98bb72a8f 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -64,11 +64,6 @@ namespace Files MacOsPath::MacOsPath(const std::string& application_name) : mName(application_name) { - std::filesystem::path binary_path = getBinaryPath(); - std::error_code ec; - std::filesystem::current_path(binary_path.parent_path(), ec); - if (ec.value() != 0) - Log(Debug::Warning) << "Error " << ec.message() << " when changing current directory"; } std::filesystem::path MacOsPath::getUserConfigPath() const diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 6fb9845976..77faa23131 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -26,10 +26,6 @@ namespace Files WindowsPath::WindowsPath(const std::string& application_name) : mName(application_name) { - std::error_code ec; - current_path(getLocalPath(), ec); - if (ec.value() != 0) - Log(Debug::Warning) << "Error " << ec.value() << " when changing current directory"; } std::filesystem::path WindowsPath::getUserConfigPath() const From acbc0a9b8f00289c5f3459a9e6d7eeffe057a35e Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 00:19:14 +0100 Subject: [PATCH 2/8] Fix launching other binaries when the CWD is not the binary directory --- apps/opencs/model/doc/runner.cpp | 22 ++++++++++------------ components/process/processinvoker.cpp | 11 +++-------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index d647d6b498..a9274ee5dc 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -2,11 +2,8 @@ #include -#if defined(Q_OS_MAC) #include #include -#endif - #include #include #include @@ -55,16 +52,17 @@ void CSMDoc::Runner::start(bool delayed) QString path = "openmw"; #ifdef Q_OS_WIN - path.append(QString(".exe")); -#elif defined(Q_OS_MAC) - QDir dir(QCoreApplication::applicationDirPath()); - dir.cdUp(); - dir.cdUp(); - dir.cdUp(); - path = dir.absoluteFilePath(path.prepend("OpenMW.app/Contents/MacOS/")); -#else - path.prepend(QString("./")); + path.append(QLatin1String(".exe")); #endif + QDir dir(QCoreApplication::applicationDirPath()); +#ifdef Q_OS_MAC + // the CS and engine are in separate .app directories + dir.cdUp(); + dir.cdUp(); + dir.cdUp(); + path.prepend("OpenMW.app/Contents/MacOS/") +#endif + path = dir.absoluteFilePath(path); mStartup = new QTemporaryFile(this); mStartup->open(); diff --git a/components/process/processinvoker.cpp b/components/process/processinvoker.cpp index 9489076acb..04058c492d 100644 --- a/components/process/processinvoker.cpp +++ b/components/process/processinvoker.cpp @@ -1,13 +1,11 @@ #include "processinvoker.hpp" +#include #include #include #include #include -#if defined(Q_OS_MAC) -#include -#endif Process::ProcessInvoker::ProcessInvoker(QObject* parent) : QObject(parent) @@ -60,12 +58,9 @@ bool Process::ProcessInvoker::startProcess(const QString& name, const QStringLis QString path(name); #ifdef Q_OS_WIN path.append(QLatin1String(".exe")); -#elif defined(Q_OS_MAC) - QDir dir(QCoreApplication::applicationDirPath()); - path = dir.absoluteFilePath(name); -#else - path.prepend(QLatin1String("./")); #endif + QDir dir(QCoreApplication::applicationDirPath()); + path = dir.absoluteFilePath(path); QFileInfo info(path); From 9a28216cda34950b045281af1d2fa25fe87b1dff Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 00:19:22 +0100 Subject: [PATCH 3/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0c43be25..479a19d905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -236,6 +236,7 @@ Bug #8465: Blue screen w/ antialiasing and post-processing on macOS Bug #8503: Camera does not handle NaN gracefully Bug #8541: Lua: util.color:asHex produces wrong output for some colors + Bug #8567: Token replacement does not work via CLI and relative paths passed via the command line are not relative to the CWD Feature #1415: Infinite fall failsafe Feature #2566: Handle NAM9 records for manual cell references Feature #3501: OpenMW-CS: Instance Editing - Shortcuts for axial locking From 276e0e67650fd836768bacf2a6d93403c6aba281 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 00:22:58 +0100 Subject: [PATCH 4/8] Remove vestigial include --- components/files/linuxpath.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index aa8c410748..2e74948fff 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -7,7 +7,6 @@ #include #include -#include #include namespace From f7b8091117569e263b59c35efa7162a2f5327a08 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 00:23:52 +0100 Subject: [PATCH 5/8] Add missing semicolon --- apps/opencs/model/doc/runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index a9274ee5dc..4019fbfe57 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -60,7 +60,7 @@ void CSMDoc::Runner::start(bool delayed) dir.cdUp(); dir.cdUp(); dir.cdUp(); - path.prepend("OpenMW.app/Contents/MacOS/") + path.prepend("OpenMW.app/Contents/MacOS/"); #endif path = dir.absoluteFilePath(path); From 323ee5f79d7c29961e33f1e55af4cd00ac8424f3 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 00:27:08 +0100 Subject: [PATCH 6/8] Remove a line break that clang-format was fussing about --- components/process/processinvoker.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/components/process/processinvoker.cpp b/components/process/processinvoker.cpp index 04058c492d..f1af67d20d 100644 --- a/components/process/processinvoker.cpp +++ b/components/process/processinvoker.cpp @@ -6,7 +6,6 @@ #include #include - Process::ProcessInvoker::ProcessInvoker(QObject* parent) : QObject(parent) { From bee9716262321f6f2067718d63e41797f153d65e Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 16:32:21 +0100 Subject: [PATCH 7/8] Fix getLocalPath for MacOS --- components/files/macospath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index f98bb72a8f..8a18ed144a 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -97,7 +97,7 @@ namespace Files std::filesystem::path MacOsPath::getLocalPath() const { - return std::filesystem::path("../Resources/"); + return getBinaryPath() / "../Resources"; } std::filesystem::path MacOsPath::getGlobalDataPath() const From 71d334fe7903a1920a75c86d38c528b87a975860 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 19 Jun 2025 19:55:26 +0100 Subject: [PATCH 8/8] Fix MacOS even more --- components/files/macospath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 8a18ed144a..191f3b15a6 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -97,7 +97,7 @@ namespace Files std::filesystem::path MacOsPath::getLocalPath() const { - return getBinaryPath() / "../Resources"; + return getBinaryPath().parent_path().parent_path() / "Resources"; } std::filesystem::path MacOsPath::getGlobalDataPath() const