1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-17 10:10:23 +00:00

Merge branch 'opt-out-compose' into 'master'

Make it possible to opt out of composing variables

Closes #6186

See merge request OpenMW/openmw!1076
This commit is contained in:
psi29a 2021-08-01 08:53:52 +00:00
commit 15d278de55
3 changed files with 32 additions and 0 deletions

View File

@ -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<std::string>::const_iterator iter (mContentFiles.begin());
iter!=mContentFiles.end(); ++iter)
{

View File

@ -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<Files::EscapeStringVector>()->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<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")
->multitoken()->composing(), "set data directories (later directories have higher priority)")
@ -195,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<std::string> 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)
{

View File

@ -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<std::string> replacedVariables;
if (description.find_nothrow("replace", false))
{
auto replace = second["replace"];
if (!replace.defaulted() && !replace.empty())
{
std::vector<std::string> replaceVector = replace.as<Files::EscapeStringVector>().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;