Skip to content

Commit

Permalink
Merge #4037 Properly clear AD upgrades from changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 17, 2024
2 parents 20ad5c0 + 0024b56 commit e8cb3de
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Fixes for installing .ckan files and DarkKAN mods (#4006 by: HebaruSan)
- [Core] Only auto-delete manually installed DLLs if also replacing them (#4024 by: HebaruSan)
- [Multiple] Show repo ETag and parsing errors in Failed Downloads (#4030 by: HebaruSan)
- [Multiple] Properly clear AD upgrades from changeset (#4037 by: HebaruSan)

### Internal

Expand Down
4 changes: 1 addition & 3 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,9 @@ private void AddReason(CkanModule module, SelectionReason reason)
private readonly Dictionary<string, CkanModule> modlist = new Dictionary<string, CkanModule>();
private readonly List<CkanModule> user_requested_mods = new List<CkanModule>();

//TODO As the conflict detection gets more advanced there is a greater need to have messages in here
// as recreating them from reasons is no longer possible.
private readonly List<ModPair> conflicts = new List<ModPair>();
private readonly Dictionary<CkanModule, List<SelectionReason>> reasons =
new Dictionary<CkanModule, List<SelectionReason>>(new NameComparer());
new Dictionary<CkanModule, List<SelectionReason>>();

private readonly IRegistryQuerier registry;
private readonly GameVersionCriteria versionCrit;
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/ManageMods.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 96 additions & 60 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,34 +502,36 @@ private static bool SearchesExcludeInstalled(List<ModSearch> searches)

public void MarkAllUpdates()
{
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
WithFrozenChangeset(() =>
{
var mod = row.Tag as GUIMod;
if (mod?.HasUpdate ?? false)
foreach (var row in mainModList.full_list_of_mod_rows.Values)
{
if (!Main.Instance.LabelsHeld(mod.Identifier))
var mod = row.Tag as GUIMod;
if (mod?.HasUpdate ?? false)
{
mod.SetUpgradeChecked(row, UpdateCol, true);
if (!Main.Instance.LabelsHeld(mod.Identifier))
{
mod.SetUpgradeChecked(row, UpdateCol, true);
}
}
}
}
// only sort by Update column if checkbox in settings checked
if (Main.Instance.configuration.AutoSortByUpdate)
{
// Retain their current sort as secondaries
AddSort(UpdateCol, true);
UpdateFilters();
// Select the top row and scroll the list to it.
if (ModGrid.Rows.Count > 0)
// only sort by Update column if checkbox in settings checked
if (Main.Instance.configuration.AutoSortByUpdate)
{
ModGrid.CurrentCell = ModGrid.Rows[0].Cells[SelectableColumnIndex()];
// Retain their current sort as secondaries
AddSort(UpdateCol, true);
UpdateFilters();
// Select the top row and scroll the list to it.
if (ModGrid.Rows.Count > 0)
{
ModGrid.CurrentCell = ModGrid.Rows[0].Cells[SelectableColumnIndex()];
}
}
}
ModGrid.Refresh();
});
}

private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
private void UpdateAllToolButton_Click(object sender, EventArgs e)
{
MarkAllUpdates();
}
Expand Down Expand Up @@ -898,9 +900,9 @@ private void ModGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e
gui_mod.SetReplaceChecked(row, ReplaceCol);
break;
}
UpdateChangeSetAndConflicts(
Main.Instance.CurrentInstance,
RegistryManager.Instance(Main.Instance.CurrentInstance, repoData).registry);
var inst = Main.Instance.CurrentInstance;
UpdateChangeSetAndConflicts(inst,
RegistryManager.Instance(inst, repoData).registry);
}
}
}
Expand All @@ -922,11 +924,19 @@ public void RemoveChangesetItem(ModChange change)
switch (change.ChangeType)
{
case GUIModChangeType.Install:
guiMod.SetInstallChecked(row, Installed, false);
if (guiMod.IsAutodetected)
{
guiMod.SetUpgradeChecked(row, UpdateCol, false);
}
else
{
guiMod.SetInstallChecked(row, Installed, false);
return;
}
break;
case GUIModChangeType.Remove:
guiMod.SetInstallChecked(row, Installed, true);
break;
return;
case GUIModChangeType.Update:
guiMod.SetUpgradeChecked(row, UpdateCol, false);
break;
Expand Down Expand Up @@ -963,66 +973,92 @@ private void ModGrid_LostFocus(object sender, EventArgs e)

private void InstallAllCheckbox_CheckChanged(object sender, EventArgs e)
{
try
WithFrozenChangeset(() =>
{
freezeChangeSet = true;
if (InstallAllCheckbox.Checked)
{
// Reset changeset
ClearChangeSet();
}
else
{
// Uninstall all
var checkedRows = mainModList.full_list_of_mod_rows.Values
.Where(r => (r.Tag as GUIMod)?.IsInstallChecked ?? false);
foreach (var row in checkedRows)
// Uninstall all and cancel upgrades
foreach (var row in mainModList.full_list_of_mod_rows.Values)
{
(row.Tag as GUIMod)?.SetInstallChecked(row, Installed, false);
if (row.Tag is GUIMod gmod)
{
if (gmod.IsUpgradeChecked)
{
gmod.SetUpgradeChecked(row, UpdateCol, false);
}
if (gmod.IsInstallChecked)
{
gmod.SetInstallChecked(row, Installed, false);
}
}
}
}
}
finally
{
// Don't let anything ever prevent us from unfreezing the changeset
freezeChangeSet = false;
ModGrid.Refresh();
UpdateChangeSetAndConflicts(
Main.Instance.CurrentInstance,
RegistryManager.Instance(Main.Instance.CurrentInstance, repoData).registry);
}
});
}

public void ClearChangeSet()
{
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
WithFrozenChangeset(() =>
{
GUIMod mod = row.Tag as GUIMod;
if (mod.IsInstallChecked != mod.IsInstalled)
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
{
mod.SetInstallChecked(row, Installed, mod.IsInstalled);
GUIMod mod = row.Tag as GUIMod;
if (mod.IsInstallChecked != mod.IsInstalled)
{
mod.SetInstallChecked(row, Installed, mod.IsInstalled);
}
else if (mod.InstalledMod != null)
{
var registry = RegistryManager.Instance(Main.Instance.CurrentInstance, repoData).registry;
mod.SelectedMod = registry.GetModuleByVersion(
mod.InstalledMod.identifier, mod.InstalledMod.Module.version)
?? mod.InstalledMod.Module;
}
mod.SetUpgradeChecked(row, UpdateCol, false);
mod.SetReplaceChecked(row, ReplaceCol, false);
}
else if (mod.InstalledMod != null)
// Marking a mod as AutoInstalled can immediately queue it for removal if there is no dependent mod.
// Reset the state of the AutoInstalled checkbox for these by deducing it from the changeset.
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
{
var registry = RegistryManager.Instance(Main.Instance.CurrentInstance, repoData).registry;
mod.SelectedMod = registry.GetModuleByVersion(
mod.InstalledMod.identifier, mod.InstalledMod.Module.version)
?? mod.InstalledMod.Module;
GUIMod mod = row.Tag as GUIMod;
if (mod.InstalledMod != null
&& ChangeSet.Contains(new ModChange(mod.InstalledMod?.Module,
GUIModChangeType.Remove,
new SelectionReason.NoLongerUsed())))
{
mod.SetAutoInstallChecked(row, AutoInstalled, false);
}
}
mod.SetUpgradeChecked(row, UpdateCol, false);
mod.SetReplaceChecked(row, ReplaceCol, false);
});
}

private void WithFrozenChangeset(Action action)
{
if (freezeChangeSet)
{
// Already frozen by some outer block, let it handle the cleanup
action?.Invoke();
}
// Marking a mod as AutoInstalled can immediately queue it for removal if there is no dependent mod.
// Reset the state of the AutoInstalled checkbox for these by deducing it from the changeset.
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
else
{
GUIMod mod = row.Tag as GUIMod;
if (mod.InstalledMod != null
&& ChangeSet.Contains(new ModChange(mod.InstalledMod?.Module,
GUIModChangeType.Remove,
new SelectionReason.NoLongerUsed())))
freezeChangeSet = true;
try
{
action?.Invoke();
}
finally
{
mod.SetAutoInstallChecked(row, AutoInstalled, false);
// Don't let anything ever prevent us from unfreezing the changeset
freezeChangeSet = false;
ModGrid.Refresh();
var inst = Main.Instance.CurrentInstance;
UpdateChangeSetAndConflicts(inst, RegistryManager.Instance(inst, repoData).registry);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion GUI/Main/MainChangeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ private void Changeset_OnCancelChanges(bool reset)
if (reset)
{
ManageMods.ClearChangeSet();
UpdateChangesDialog(null, null);
}
tabController.ShowTab("ManageModsTabPage");
}
Expand Down
32 changes: 18 additions & 14 deletions GUI/Model/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public CkanModule SelectedMod
}
Main.Instance.ManageMods.MarkModForInstall(Identifier, selectedMod == null);

var inst = Main.Instance.CurrentInstance;
Main.Instance.ManageMods.UpdateChangeSetAndConflicts(
Main.Instance.Manager.CurrentInstance,
RegistryManager.Instance(Main.Instance.Manager.CurrentInstance,
inst,
RegistryManager.Instance(inst,
ServiceLocator.Container.Resolve<RepositoryDataManager>()).registry);

OnPropertyChanged();
Expand Down Expand Up @@ -122,8 +123,8 @@ public string GameCompatibility
/// otherwise false.
/// </returns>
public bool IsInstallable()
// Compatible mods are installable, but so are mods that are already installed
=> !IsIncompatible || IsInstalled;
// Compatible mods are installable, but so are mods that are already installed
=> !IsIncompatible || IsInstalled;

public string Version
=> IsInstalled ? InstalledVersion : LatestVersion;
Expand Down Expand Up @@ -218,13 +219,13 @@ public GUIMod(CkanModule mod,
/// <param name="registry">CKAN registry object for current game instance</param>
/// <param name="current_game_version">Current game version</param>
/// <param name="incompatible">If true, mark this module as incompatible</param>
public GUIMod(string identifier,
RepositoryDataManager repoDataMgr,
IRegistryQuerier registry,
GameVersionCriteria current_game_version,
bool? incompatible,
bool hideEpochs,
bool hideV)
private GUIMod(string identifier,
RepositoryDataManager repoDataMgr,
IRegistryQuerier registry,
GameVersionCriteria current_game_version,
bool? incompatible,
bool hideEpochs,
bool hideV)
{
Identifier = identifier;
IsAutodetected = registry.IsAutodetected(identifier);
Expand Down Expand Up @@ -330,7 +331,7 @@ public IEnumerable<ModChange> GetModChanges()
?? InstalledMod?.Module.Equals(SelectedMod)
// Both null
?? true;
if (IsInstalled && (IsInstallChecked && HasUpdate && IsUpgradeChecked))
if (IsInstalled && IsInstallChecked && HasUpdate && IsUpgradeChecked)
{
yield return new ModUpgrade(Mod,
GUIModChangeType.Update,
Expand Down Expand Up @@ -395,13 +396,16 @@ public void SetUpgradeChecked(DataGridViewRow row, DataGridViewColumn col, bool?
if (old_value != value)
{
update_cell.Value = value;
SelectedMod = value ? LatestCompatibleMod : (SelectedMod ?? InstalledMod?.Module);
SelectedMod = value ? LatestCompatibleMod
: IsAutodetected ? null
: (SelectedMod ?? InstalledMod?.Module);
}
else if (!set_value_to.HasValue)
{
var isLatest = (LatestCompatibleMod?.Equals(selectedMod) ?? false);
SelectedMod = value ? LatestCompatibleMod
: isLatest ? InstalledMod?.Module : SelectedMod;
: isLatest ? InstalledMod?.Module
: SelectedMod;
}
}
}
Expand Down

0 comments on commit e8cb3de

Please sign in to comment.