From f078f0d7f8369c845633d99cddb8934c33cf97c8 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 18 Apr 2019 11:41:07 -0500 Subject: [PATCH] Fix Newly Compatible filter with repo autoupdate --- GUI/MainInstall.cs | 4 ++-- GUI/MainModList.cs | 16 ++++++++-------- GUI/MainRepo.cs | 29 +++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/GUI/MainInstall.cs b/GUI/MainInstall.cs index 58037964e1..7c77a62722 100644 --- a/GUI/MainInstall.cs +++ b/GUI/MainInstall.cs @@ -364,7 +364,7 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e) if (result.Key && !installCanceled) { // Rebuilds the list of GUIMods - UpdateModsList(false, null); + UpdateModsList(null); if (modChangedCallback != null) { @@ -385,7 +385,7 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e) { // User cancelled the installation // Rebuilds the list of GUIMods - UpdateModsList(false, ChangeSet); + UpdateModsList(ChangeSet); UpdateChangesDialog(null, installWorker); if (result.Key) { FailWaitDialog("Cancellation to late, process complete!", "User canceled the process manually, but all mods already (un)installed/upgraded.", "Process complete!", result.Key); diff --git a/GUI/MainModList.cs b/GUI/MainModList.cs index 3c1b05371c..4c1e6e52f7 100644 --- a/GUI/MainModList.cs +++ b/GUI/MainModList.cs @@ -156,15 +156,15 @@ private void _UpdateFilters() } } - public void UpdateModsList(Boolean repo_updated = false, IEnumerable mc = null) + public void UpdateModsList(IEnumerable mc = null, Dictionary old_modules = null) { // Run the update in the background so the UI thread can appear alive Task.Factory.StartNew(() => - _UpdateModsList(repo_updated, mc ?? new List()) + _UpdateModsList(mc ?? new List(), old_modules) ); } - private void _UpdateModsList(bool repo_updated, IEnumerable mc) + private void _UpdateModsList(IEnumerable mc, Dictionary old_modules = null) { log.Info("Updating the mod list"); @@ -209,13 +209,12 @@ private void _UpdateModsList(bool repo_updated, IEnumerable mc) } AddLogMessage("Preserving new flags..."); - var old_modules = mainModList.Modules.ToDictionary(m => m, m => m.IsIncompatible); - if (repo_updated) + if (old_modules != null) { foreach (GUIMod gm in gui_mods) { bool oldIncompat; - if (old_modules.TryGetValue(gm, out oldIncompat)) + if (old_modules.TryGetValue(gm.Identifier, out oldIncompat)) { // Found it; check if newly compatible if (!gm.IsIncompatible && oldIncompat) @@ -232,8 +231,9 @@ private void _UpdateModsList(bool repo_updated, IEnumerable mc) } else { - //Copy the new mod flag from the old list. - var old_new_mods = new HashSet(old_modules.Keys.Where(m => m.IsNew)); + // Copy the new mod flag from the old list. + var old_new_mods = new HashSet( + mainModList.Modules.Where(m => m.IsNew)); foreach (var gui_mod in gui_mods.Where(m => old_new_mods.Contains(m))) { gui_mod.IsNew = true; diff --git a/GUI/MainRepo.cs b/GUI/MainRepo.cs index d1b591fdd5..2fc34454d7 100644 --- a/GUI/MainRepo.cs +++ b/GUI/MainRepo.cs @@ -1,9 +1,11 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Net; using System.Timers; using System.Linq; using Newtonsoft.Json; +using CKAN.Versioning; namespace CKAN { @@ -64,7 +66,22 @@ private void UpdateRepo(object sender, DoWorkEventArgs e) try { AddStatusMessage("Updating repositories..."); - e.Result = Repo.UpdateAllRepositories(RegistryManager.Instance(CurrentInstance), CurrentInstance, Manager.Cache, GUI.user); + + // Note the current mods' compatibility for the NewlyCompatible filter + KspVersionCriteria versionCriteria = CurrentInstance.VersionCriteria(); + IRegistryQuerier registry = RegistryManager.Instance(CurrentInstance).registry; + Dictionary oldModules = registry.Available(versionCriteria) + .ToDictionary(m => m.identifier, m => false); + registry.Incompatible(versionCriteria) + .Where(m => !oldModules.ContainsKey(m.identifier)) + .ToList() + .ForEach(m => oldModules.Add(m.identifier, true)); + + RepoUpdateResult result = Repo.UpdateAllRepositories( + RegistryManager.Instance(CurrentInstance), + CurrentInstance, Manager.Cache, GUI.user); + e.Result = new KeyValuePair>( + result, oldModules); } catch (UriFormatException ex) { @@ -82,7 +99,11 @@ private void UpdateRepo(object sender, DoWorkEventArgs e) private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e) { - switch (e.Result as RepoUpdateResult?) + var resultPair = e.Result as KeyValuePair>?; + RepoUpdateResult? result = resultPair?.Key; + Dictionary oldModules = resultPair?.Value; + + switch (result) { case RepoUpdateResult.NoChanges: AddStatusMessage("Repositories already up to date."); @@ -90,7 +111,7 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e) // Load rows if grid empty, otherwise keep current if (ModList.Rows.Count < 1) { - UpdateModsList(true, ChangeSet); + UpdateModsList(ChangeSet); } break; @@ -100,7 +121,7 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e) case RepoUpdateResult.Updated: default: - UpdateModsList(true, ChangeSet); + UpdateModsList(ChangeSet, oldModules); AddStatusMessage("Repositories successfully updated."); ShowRefreshQuestion(); HideWaitDialog(true);