mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-13 13:18:43 +02:00
Fix installation of mods with complex dependencies such as H3Evo
This commit is contained in:
parent
9d9c21f670
commit
eab03c24ee
@ -590,7 +590,7 @@ QStringList CModListView::getModsToInstall(QString mod)
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(result.removeDuplicates() == 0);
|
||||
result.removeDuplicates();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -262,6 +262,20 @@ void ModsPresetState::setSettingActive(const TModID & modName, const TModID & se
|
||||
currentPreset["settings"][modName][settingName].Bool() = isActive;
|
||||
}
|
||||
|
||||
void ModsPresetState::removeOldMods(const TModList & modsToKeep)
|
||||
{
|
||||
const std::string & currentPresetName = modConfig["activePreset"].String();
|
||||
JsonNode & currentPreset = modConfig["presets"][currentPresetName];
|
||||
|
||||
vstd::erase_if(currentPreset["mods"].Vector(), [&](const JsonNode & entry){
|
||||
return !vstd::contains(modsToKeep, entry.String());
|
||||
});
|
||||
|
||||
vstd::erase_if(currentPreset["settings"].Struct(), [&](const auto & entry){
|
||||
return !vstd::contains(modsToKeep, entry.first);
|
||||
});
|
||||
}
|
||||
|
||||
void ModsPresetState::eraseRootMod(const TModID & modName)
|
||||
{
|
||||
const std::string & currentPresetName = modConfig["activePreset"].String();
|
||||
@ -438,14 +452,10 @@ void ModManager::eraseMissingModsFromPreset()
|
||||
const TModList & installedMods = modsState->getInstalledMods();
|
||||
const TModList & rootMods = modsPreset->getActiveRootMods();
|
||||
|
||||
modsPreset->removeOldMods(installedMods);
|
||||
|
||||
for(const auto & rootMod : rootMods)
|
||||
{
|
||||
if(!vstd::contains(installedMods, rootMod))
|
||||
{
|
||||
modsPreset->eraseRootMod(rootMod);
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto & modSettings = modsPreset->getModSettings(rootMod);
|
||||
|
||||
for(const auto & modSetting : modSettings)
|
||||
@ -531,6 +541,23 @@ void ModManager::tryEnableMods(const TModList & modList)
|
||||
|
||||
testResolver.tryAddMods(additionalActiveMods, *modsStorage);
|
||||
|
||||
TModList additionalActiveSubmods;
|
||||
for (const auto & modName : modList)
|
||||
{
|
||||
if (modName.find('.') != std::string::npos)
|
||||
continue;
|
||||
|
||||
auto modSettings = modsPreset->getModSettings(modName);
|
||||
for (const auto & entry : modSettings)
|
||||
{
|
||||
TModID fullModID = modName + '.' + entry.first;
|
||||
if (entry.second && !vstd::contains(requiredActiveMods, fullModID))
|
||||
additionalActiveSubmods.push_back(fullModID);
|
||||
}
|
||||
}
|
||||
|
||||
testResolver.tryAddMods(additionalActiveSubmods, *modsStorage);
|
||||
|
||||
for (const auto & modName : modList)
|
||||
if (!vstd::contains(testResolver.getActiveMods(), modName))
|
||||
throw std::runtime_error("Failed to enable mod! Mod " + modName + " remains disabled!");
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
|
||||
void addRootMod(const TModID & modName);
|
||||
void eraseRootMod(const TModID & modName);
|
||||
void removeOldMods(const TModList & modsToKeep);
|
||||
|
||||
void setSettingActive(const TModID & modName, const TModID & settingName, bool isActive);
|
||||
void eraseModSetting(const TModID & modName, const TModID & settingName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user