From 10b799653bd132b8122bc893c086bcba31f4e575 Mon Sep 17 00:00:00 2001 From: psi29a Date: Sun, 1 Aug 2021 08:53:52 +0000 Subject: [PATCH] Merge branch 'opt-out-compose' into 'master' Make it possible to opt out of composing variables Closes #6186 See merge request OpenMW/openmw!1076 (cherry picked from commit 15d278de554818fef6fecf300456800523e91adf) 4727ae4b Make it possible to opt out of composing variables 04e9b6d2 Abort on duplicate content file --- apps/opencs/model/doc/runner.cpp | 2 ++ apps/openmw/main.cpp | 13 +++++++++++++ components/files/configurationmanager.cpp | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index ccdff1444..927bda080 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 709ffda2c..8f7e16058 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)") @@ -192,6 +196,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) { diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 92d35a6b6..35679ef29 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;