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

Properly clear AD upgrades from changeset #4037

Merged
merged 1 commit into from
Feb 17, 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: 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 @@ -88,7 +88,7 @@
{
get
{
var configuration = Main.Instance.configuration;

Check warning on line 91 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.12, Debug)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'

Check warning on line 91 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.10, Debug)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'

Check warning on line 91 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.8, Release)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'
// Make sure we don't return any column the GUI doesn't know about.
var unknownCols = configuration.SortColumns.Where(col => !ModGrid.Columns.Contains(col)).ToList();
foreach (var unknownCol in unknownCols)
Expand All @@ -101,7 +101,7 @@
}
}

private List<bool> descending => Main.Instance.configuration.MultiSortDescending;

Check warning on line 104 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.12, Debug)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'

public event Action<GUIMod> OnSelectedModuleChanged;
public event Action<List<ModChange>, Dictionary<GUIMod, string>> OnChangeSetChanged;
Expand Down Expand Up @@ -502,34 +502,36 @@

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 @@
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 @@
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 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
Loading