Skip to content

Commit

Permalink
Allow replacement by conflicting modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Mar 7, 2019
1 parent 6b4cd14 commit 240bbcd
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,21 @@ public async Task<IEnumerable<ModChange>> ComputeChangeSetFromModList(
throw new ArgumentOutOfRangeException();
}
}

var installed_modules =
registry.InstalledModules.Select(imod => imod.Module).ToDictionary(mod => mod.identifier, mod => mod);
foreach (var dependency in registry.FindReverseDependencies(
modules_to_remove
.Select(mod => mod.identifier)
.Except(modules_to_install.Select(m => m.identifier))
))
{
//TODO This would be a good place to have a event that alters the row's graphics to show it will be removed
CkanModule module_by_version = registry.GetModuleByVersion(installed_modules[dependency].identifier,
installed_modules[dependency].version) ?? registry.InstalledModule(dependency).Module;
changeSet.Add(new ModChange(new GUIMod(module_by_version, registry, version), GUIModChangeType.Remove, null));
modules_to_remove.Add(module_by_version);
}

bool handled_all_too_many_provides = false;
while (!handled_all_too_many_provides)
Expand All @@ -694,7 +707,7 @@ public async Task<IEnumerable<ModChange>> ComputeChangeSetFromModList(
{
new RelationshipResolver(
modules_to_install,
null,
modules_to_remove,
RelationshipResolver.DependsOnlyOpts(),
registry, version);
handled_all_too_many_provides = true;
Expand All @@ -717,21 +730,9 @@ public async Task<IEnumerable<ModChange>> ComputeChangeSetFromModList(
}
}

foreach (var dependency in registry.FindReverseDependencies(
modules_to_remove
.Select(mod => mod.identifier)
.Except(modules_to_install.Select(m => m.identifier))
))
{
//TODO This would be a good place to have a event that alters the row's graphics to show it will be removed
CkanModule module_by_version = registry.GetModuleByVersion(installed_modules[dependency].identifier,
installed_modules[dependency].version) ?? registry.InstalledModule(dependency).Module;
changeSet.Add(new ModChange(new GUIMod(module_by_version, registry, version), GUIModChangeType.Remove, null));
}

var resolver = new RelationshipResolver(
modules_to_install,
changeSet.Where(change => change.ChangeType.Equals(GUIModChangeType.Remove)).Select(m => m.Mod.ToModule()),
modules_to_remove,
RelationshipResolver.DependsOnlyOpts(), registry, version);
changeSet.UnionWith(
resolver.ModList()
Expand Down

0 comments on commit 240bbcd

Please sign in to comment.