From 4727ae4b3b274eddc13feb7649df496809336a61 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 1 Aug 2021 02:47:10 +0100 Subject: [PATCH 1/2] Make it possible to opt out of composing variables --- apps/opencs/model/doc/runner.cpp | 2 ++ apps/openmw/main.cpp | 4 ++++ components/files/configurationmanager.cpp | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index 8dafbaf5ae..f1179b1624 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -83,6 +83,8 @@ void CSMDoc::Runner::start (bool delayed) arguments << QString::fromUtf8 (("--data=\""+mProjectPath.parent_path().string()+"\"").c_str()); + arguments << "--replace=content"; + for (std::vector::const_iterator iter (mContentFiles.begin()); iter!=mContentFiles.end(); ++iter) { diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 324a18bdee..78be8974b3 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -44,6 +44,10 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat desc.add_options() ("help", "print help message") ("version", "print version information and quit") + + ("replace", bpo::value()->default_value(Files::EscapeStringVector(), "") + ->multitoken()->composing(), "settings where the values from the current source should replace those from lower-priority sources instead of being appended") + ("data", bpo::value()->default_value(Files::EscapePathContainer(), "data") ->multitoken()->composing(), "set data directories (later directories have higher priority)") diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 92d35a6b65..35679ef293 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -100,6 +100,17 @@ boost::program_options::variables_map ConfigurationManager::separateComposingVar void ConfigurationManager::mergeComposingVariables(boost::program_options::variables_map & first, boost::program_options::variables_map & second, boost::program_options::options_description& description) { + // There are a few places this assumes all variables are present in second, but it's never crashed in the wild, so it looks like that's guaranteed. + std::set replacedVariables; + if (description.find_nothrow("replace", false)) + { + auto replace = second["replace"]; + if (!replace.defaulted() && !replace.empty()) + { + std::vector replaceVector = replace.as().toStdStringVector(); + replacedVariables.insert(replaceVector.begin(), replaceVector.end()); + } + } for (const auto& option : description.options()) { if (option->semantic()->is_composing()) @@ -113,6 +124,12 @@ void ConfigurationManager::mergeComposingVariables(boost::program_options::varia continue; } + if (replacedVariables.count(name)) + { + firstPosition->second = second[name]; + continue; + } + if (second[name].defaulted() || second[name].empty()) continue; From 04e9b6d242f2fc110a65839a7b4051c09c67a026 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 1 Aug 2021 03:04:12 +0100 Subject: [PATCH 2/2] Abort on duplicate content file --- apps/openmw/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 78be8974b3..de0fb0df03 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -199,6 +199,15 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat Log(Debug::Error) << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..."; return false; } + std::set contentDedupe; + for (const auto& contentFile : content) + { + if (!contentDedupe.insert(contentFile).second) + { + Log(Debug::Error) << "Content file specified more than once: " << contentFile << ". Aborting..."; + return false; + } + } for (auto& file : content) {