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
pull/593/head
psi29a 3 years ago
parent ffa91b07dd
commit 10b799653b

@ -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)
{

@ -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)")
@ -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<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)
{

@ -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;

Loading…
Cancel
Save