Skip to content

Commit

Permalink
Merge #3726 Use changeset tab for reinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 25, 2022
2 parents 3f9b2f0 + 0363516 commit 2b447ed
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.

- [GUI] Remove duplicate Install changes for upgrades (#3706 by: HebaruSan; reviewed: techman83)
- [GUI] Fix GUI freeze with non-empty changeset at startup (#3708 by: HebaruSan; reviewed: techman83)
- [GUI] Use changeset tab for reinstall (#3726 by: HebaruSan; reviewed: techman83)

### Internal

Expand Down
7 changes: 5 additions & 2 deletions GUI/Controls/Changeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public Changeset()

public void LoadChangeset(List<ModChange> changes, List<ModuleLabel> AlertLabels)
{
changeset = changes;
alertLabels = AlertLabels;
ChangesListView.Items.Clear();
if (changes != null)
Expand Down Expand Up @@ -46,7 +47,7 @@ public ListView.SelectedListViewItemCollection SelectedItems

public event Action<ListView.SelectedListViewItemCollection> OnSelectedItemsChanged;

public event Action OnConfirmChanges;
public event Action<List<ModChange>> OnConfirmChanges;
public event Action<bool> OnCancelChanges;

private void ChangesListView_SelectedIndexChanged(object sender, EventArgs e)
Expand All @@ -56,11 +57,12 @@ private void ChangesListView_SelectedIndexChanged(object sender, EventArgs e)

private void ConfirmChangesButton_Click(object sender, EventArgs e)
{
OnConfirmChanges?.Invoke();
OnConfirmChanges?.Invoke(changeset);
}

private void CancelChangesButton_Click(object sender, EventArgs e)
{
changeset = null;
OnCancelChanges?.Invoke(true);
}

Expand Down Expand Up @@ -92,6 +94,7 @@ private ListViewItem makeItem(ModChange change)
};
}

private List<ModChange> changeset;
private List<ModuleLabel> alertLabels;
}
}
56 changes: 31 additions & 25 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using log4net;

using CKAN.Extensions;
using CKAN.Versioning;

namespace CKAN.GUI
Expand Down Expand Up @@ -995,37 +996,42 @@ private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
if (module == null || !module.IsCKAN)
return;

YesNoDialog reinstallDialog = new YesNoDialog();
string confirmationText = string.Format(Properties.Resources.MainReinstallConfirm, module.Name);
if (reinstallDialog.ShowYesNoDialog(Main.Instance, confirmationText) == DialogResult.No)
return;

IRegistryQuerier registry = RegistryManager.Instance(Main.Instance.CurrentInstance).registry;

// Build the list of changes, first the mod to remove:
List<ModChange> toReinstall = new List<ModChange>()
{
new ModChange(module.ToModule(), GUIModChangeType.Remove)
};
// Then everything we need to re-install:
var revdep = registry.FindReverseDependencies(new List<string>() { module.Identifier });
// Find everything we need to re-install
var revdep = registry.FindReverseDependencies(new List<string>() { module.Identifier })
.Select(ident => registry.InstalledModule(ident))
.ToHashSet();
var goners = revdep.Union(
registry.FindRemovableAutoInstalled(
registry.InstalledModules
.Where(im => !revdep.Contains(im.identifier))
.Where(im => !revdep.Contains(im))
.ToList(),
Main.Instance.CurrentInstance.VersionCriteria())
.Select(im => im.Module.identifier));
foreach (string id in goners)
{
toReinstall.Add(new ModChange(
(mainModList.full_list_of_mod_rows[id]?.Tag as GUIMod).ToModule(),
GUIModChangeType.Install));
}
if (StartChangeSet != null)
{
StartChangeSet(toReinstall);
}
Main.Instance.CurrentInstance.VersionCriteria()));

// Build the list of changes
StartChangeSet?.Invoke(goners
.SelectMany(instMod => instMod.AutoInstalled
? new ModChange[]
{
new ModChange(instMod.Module, GUIModChangeType.Remove),
// Let resolver find it so the auto-installed flag is set
}
: new ModChange[]
{
new ModChange(instMod.Module, GUIModChangeType.Remove),
new ModChange(
// Install current available mod from registry, if found
registry.GetModuleByVersion(instMod.identifier, instMod.Module.version)
?? instMod.Module,
GUIModChangeType.Install,
// Preserve auto-installed checkbox
instMod.AutoInstalled
// We don't use the depending mod here, so just fake it
? (SelectionReason)new SelectionReason.Depends(module.ToModule())
: new SelectionReason.UserRequested()),
})
.ToList());
}

private void purgeContentsToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
7 changes: 3 additions & 4 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ private void ManageMods_OnChangeSetChanged(List<ModChange> changeset)
if (changeset != null && changeset.Any())
{
tabController.ShowTab("ChangesetTabPage", 1, false);
UpdateChangesDialog(changeset.ToList());
UpdateChangesDialog(changeset);
auditRecommendationsMenuItem.Enabled = false;
}
else
Expand Down Expand Up @@ -862,9 +862,8 @@ private void GameExit(GameInstance inst)
// This is used by Reinstall
private void ManageMods_StartChangeSet(List<ModChange> changeset)
{
Wait.StartWaiting(InstallMods, PostInstallMods, true,
new KeyValuePair<List<ModChange>, RelationshipResolverOptions>(
changeset, RelationshipResolver.DependsOnlyOpts()));
UpdateChangesDialog(changeset);
tabController.ShowTab("ChangesetTabPage", 1);
}

private void RefreshModList(Dictionary<string, bool> oldModules = null)
Expand Down
17 changes: 7 additions & 10 deletions GUI/Main/MainChangeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ private void Changeset_OnCancelChanges(bool reset)
tabController.ShowTab("ManageModsTabPage");
}

private void Changeset_OnConfirmChanges()
private void Changeset_OnConfirmChanges(List<ModChange> changeset)
{
DisableMainWindow();

// Using the changeset passed in can cause issues with versions.
// An example is Mechjeb for FAR at 25/06/2015 with a 1.0.2 install.
// TODO Work out why this is.
try
{
Wait.StartWaiting(InstallMods, PostInstallMods, true,
new KeyValuePair<List<ModChange>, RelationshipResolverOptions>(
ManageMods.mainModList
.ComputeUserChangeSet(RegistryManager.Instance(CurrentInstance).registry, CurrentInstance.VersionCriteria())
changeset
.Where(change =>
// Skip dependencies so auto-installed checkbox is set
!(change.Reasons.Any(reason =>
reason is SelectionReason.Depends)))
.ToList(),
RelationshipResolver.DependsOnlyOpts()
)
);
RelationshipResolver.DependsOnlyOpts()));
}
catch (InvalidOperationException)
{
Expand Down

0 comments on commit 2b447ed

Please sign in to comment.