Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update changeset on Replace checkbox change, other replaced_by fixes #4128

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ public Replacement(CkanModule module)

public override string ToString()
=> string.Format(Properties.Resources.RelationshipResolverReplacementReason, Parent.name);

public override string DescribeWith(IEnumerable<SelectionReason> others)
=> string.Format(Properties.Resources.RelationshipResolverReplacementReason,
string.Join(", ", Enumerable.Repeat(this, 1).Concat(others).Select(r => r.Parent.name)));
}

public sealed class Suggested : SelectionReason
Expand Down
4 changes: 4 additions & 0 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@ private void ModGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e
gmod.SetAutoInstallChecked(row, AutoInstalled);
OnRegistryChanged?.Invoke();
break;
case "ReplaceCol":
UpdateChangeSetAndConflicts(currentInstance,
RegistryManager.Instance(currentInstance, repoData).registry);
break;
}
}
break;
Expand Down
5 changes: 4 additions & 1 deletion GUI/Main/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ private void InstallMods(object sender, DoWorkEventArgs e)
if (repl != null)
{
toUninstall.Add(repl.ToReplace);
toInstall.Add(repl.ReplaceWith);
if (!toInstall.Contains(repl.ReplaceWith))
{
toInstall.Add(repl.ReplaceWith);
}
}
break;
}
Expand Down
46 changes: 28 additions & 18 deletions GUI/Model/ModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ public Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string
{
var modules_to_install = new List<CkanModule>();
var modules_to_remove = new HashSet<CkanModule>();
var upgrading = new HashSet<CkanModule>();
var extraInstalls = new HashSet<CkanModule>();

changeSet.UnionWith(changeSet.Where(ch => ch.ChangeType == GUIModChangeType.Replace)
.Select(ch => registry.GetReplacement(ch.Mod, version))
.OfType<ModuleReplacement>()
.GroupBy(repl => repl.ReplaceWith)
.Select(grp => new ModChange(grp.Key, GUIModChangeType.Install,
grp.Select(repl => new SelectionReason.Replacement(repl.ToReplace))))
.ToHashSet());

foreach (var change in changeSet)
{
Expand All @@ -140,7 +148,7 @@ public Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string
case GUIModChangeType.Update:
var mod = (change as ModUpgrade)?.targetMod ?? change.Mod;
modules_to_install.Add(mod);
upgrading.Add(mod);
extraInstalls.Add(mod);
break;
case GUIModChangeType.Install:
modules_to_install.Add(change.Mod);
Expand All @@ -149,11 +157,10 @@ public Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string
modules_to_remove.Add(change.Mod);
break;
case GUIModChangeType.Replace:
ModuleReplacement repl = registry.GetReplacement(change.Mod, version);
if (repl != null)
if (registry.GetReplacement(change.Mod, version) is ModuleReplacement repl)
{
modules_to_remove.Add(repl.ToReplace);
modules_to_install.Add(repl.ReplaceWith);
extraInstalls.Add(repl.ReplaceWith);
}
break;
default:
Expand All @@ -172,14 +179,16 @@ public Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string
.ToList(),
modules_to_install))
{
if (installed_modules.TryGetValue(dependent, out CkanModule depMod))
if (!changeSet.Any(ch => ch.ChangeType == GUIModChangeType.Replace
&& ch.Mod.identifier == dependent)
&& installed_modules.TryGetValue(dependent, out CkanModule depMod))
{
CkanModule module_by_version = registry.GetModuleByVersion(depMod.identifier,
depMod.version)
?? registry.InstalledModule(dependent).Module;
changeSet.Add(new ModChange(module_by_version, GUIModChangeType.Remove,
var modByVer = registry.GetModuleByVersion(depMod.identifier,
depMod.version)
?? registry.InstalledModule(dependent).Module;
changeSet.Add(new ModChange(modByVer, GUIModChangeType.Remove,
new SelectionReason.DependencyRemoved()));
modules_to_remove.Add(module_by_version);
modules_to_remove.Add(modByVer);
}
}

Expand All @@ -197,11 +206,13 @@ public Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string

// Replace Install entries in changeset with the ones from resolver to get all the reasons
return new Tuple<IEnumerable<ModChange>, Dictionary<CkanModule, string>, List<string>>(
changeSet.Where(ch => !(ch.ChangeType is GUIModChangeType.Install))
changeSet.Where(ch => !(ch.ChangeType is GUIModChangeType.Install
// Leave in replacements
&& !ch.Reasons.Any(r => r is SelectionReason.Replacement)))
.OrderBy(ch => ch.Mod.identifier)
.Union(resolver.ModList()
// Changeset already contains Update changes for these
.Except(upgrading)
// Changeset already contains changes for these
.Except(extraInstalls)
.Where(m => !m.IsMetapackage)
.Select(m => new ModChange(m, GUIModChangeType.Install, resolver.ReasonsFor(m)))),
resolver.ConflictList,
Expand All @@ -226,12 +237,11 @@ private IEnumerable<InstalledModule> InstalledAfterChanges(
return registry.InstalledModules
.Where(im => !removingIdents.Contains(im.identifier))
.Concat(changeSet
.Where(ch => ch.ChangeType != GUIModChangeType.Remove)
.Where(ch => ch.ChangeType != GUIModChangeType.Remove
&& ch.ChangeType != GUIModChangeType.Replace)
.Select(ch => new InstalledModule(
null,
ch.ChangeType == GUIModChangeType.Replace
? registry.GetReplacement(ch.Mod, crit)?.ReplaceWith
: (ch as ModUpgrade)?.targetMod ?? ch.Mod,
(ch as ModUpgrade)?.targetMod ?? ch.Mod,
Enumerable.Empty<string>(),
false)));
}
Expand Down