From cea8ac96cc6c9217a39dfc79e20c90a9369168df Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Wed, 19 Dec 2018 06:12:42 +0000 Subject: [PATCH] Show progress bar while loading registry --- Cmdline/Action/Update.cs | 3 ++- Core/Net/Repo.cs | 20 +++++++++++--------- GUI/MainModList.cs | 27 ++++++++++++++++++++++++++- GUI/MainRepo.cs | 2 +- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Cmdline/Action/Update.cs b/Cmdline/Action/Update.cs index b86f65a6be..90351b9e5e 100644 --- a/Cmdline/Action/Update.cs +++ b/Cmdline/Action/Update.cs @@ -153,7 +153,8 @@ private void UpdateRepository(CKAN.KSP ksp, string repository = null) ? CKAN.Repo.UpdateAllRepositories(registry_manager, ksp, manager.Cache, user) : CKAN.Repo.Update(registry_manager, ksp, user, repository); - user.RaiseMessage("Updated information on {0} available modules", updated); + user.RaiseMessage("Updated information on {0} available modules", + registry_manager.registry.Available(ksp.VersionCriteria()).Count); } } } diff --git a/Core/Net/Repo.cs b/Core/Net/Repo.cs index afdfc9ce11..1f92adf97f 100644 --- a/Core/Net/Repo.cs +++ b/Core/Net/Repo.cs @@ -28,7 +28,7 @@ public static class Repo /// Optionally takes a URL to the zipfile repo to download. /// Returns the number of unique modules updated. /// - public static int UpdateAllRepositories(RegistryManager registry_manager, KSP ksp, NetModuleCache cache, IUser user) + public static bool UpdateAllRepositories(RegistryManager registry_manager, KSP ksp, NetModuleCache cache, IUser user) { SortedDictionary sortedRepositories = registry_manager.registry.Repositories; List allAvail = new List(); @@ -42,7 +42,7 @@ public static int UpdateAllRepositories(RegistryManager registry_manager, KSP ks { // Report failure if any repo fails, rather than losing half the list. // UpdateRegistry will have alerted the user to specific errors already. - return 0; + return false; } else { @@ -66,13 +66,14 @@ public static int UpdateAllRepositories(RegistryManager registry_manager, KSP ks HandleModuleChanges(metadataChanges, user, ksp, cache); } - // Return how many we got! - return registry_manager.registry.Available(ksp.VersionCriteria()).Count; + // Registry.Available is slow, just return success, + // caller can check it if it's really needed + return true; } else { // Return failure - return 0; + return false; } } @@ -372,7 +373,7 @@ private static bool RelationshipsAreEquivalent(List a, L /// /// Number of modules found in repo /// - public static int Update(RegistryManager registry_manager, KSP ksp, IUser user, string repo = null) + public static bool Update(RegistryManager registry_manager, KSP ksp, IUser user, string repo = null) { if (repo == null) { @@ -383,7 +384,7 @@ public static int Update(RegistryManager registry_manager, KSP ksp, IUser user, } // Same as above, just with a Uri instead of string for the repo - public static int Update(RegistryManager registry_manager, KSP ksp, IUser user, Uri repo = null) + public static bool Update(RegistryManager registry_manager, KSP ksp, IUser user, Uri repo = null) { // Use our default repo, unless we've been told otherwise. if (repo == null) @@ -405,8 +406,9 @@ public static int Update(RegistryManager registry_manager, KSP ksp, IUser user, ShowUserInconsistencies(registry_manager.registry, user); - // Return how many we got! - return registry_manager.registry.Available(ksp.VersionCriteria()).Count; + // Registry.Available is slow, just return success, + // caller can check it if it's really needed + return true; } /// diff --git a/GUI/MainModList.cs b/GUI/MainModList.cs index 7fd739d5ec..df34cccfc2 100644 --- a/GUI/MainModList.cs +++ b/GUI/MainModList.cs @@ -141,25 +141,39 @@ private void _UpdateFilters() public void UpdateModsList(Boolean repo_updated = false, IEnumerable mc = null) { - Util.Invoke(this, () => _UpdateModsList(repo_updated, mc ?? new List())); + // Run the update in the background so the UI thread can appear alive + Task.Factory.StartNew(() => + _UpdateModsList(repo_updated, mc ?? new List()) + ); } private void _UpdateModsList(bool repo_updated, IEnumerable mc) { log.Info("Updating the mod list"); + ResetProgress(); + tabController.RenameTab("WaitTabPage", "Loading modules"); + ShowWaitDialog(false); + tabController.SetTabLock(true); + SwitchEnabledState(); + ClearLog(); + + AddLogMessage("Loading registry..."); KspVersionCriteria versionCriteria = CurrentInstance.VersionCriteria(); IRegistryQuerier registry = RegistryManager.Instance(CurrentInstance).registry; + AddLogMessage("Loading installed modules..."); var gui_mods = new HashSet(); gui_mods.UnionWith( registry.InstalledModules .Select(instMod => new GUIMod(instMod, registry, versionCriteria)) ); + AddLogMessage("Loading available modules..."); gui_mods.UnionWith( registry.Available(versionCriteria) .Select(m => new GUIMod(m, registry, versionCriteria)) ); + AddLogMessage("Loading incompatible modules..."); gui_mods.UnionWith( registry.Incompatible(versionCriteria) .Select(m => new GUIMod(m, registry, versionCriteria, true)) @@ -167,6 +181,7 @@ private void _UpdateModsList(bool repo_updated, IEnumerable mc) if (mc != null) { + AddLogMessage("Restoring change set..."); foreach (ModChange change in mc) { // Propagate IsInstallChecked and IsUpgradeChecked to the next generation @@ -176,6 +191,7 @@ 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) { @@ -207,11 +223,13 @@ private void _UpdateModsList(bool repo_updated, IEnumerable mc) } } + AddLogMessage("Populating mod list..."); // Update our mod listing mainModList.ConstructModList(gui_mods.ToList(), mc, configuration.HideEpochs, configuration.HideV); mainModList.Modules = new ReadOnlyCollection( mainModList.full_list_of_mod_rows.Values.Select(row => row.Tag as GUIMod).ToList()); + AddLogMessage("Updating filters..."); //TODO Consider using smart enumeration pattern so stuff like this is easier FilterToolButton.DropDownItems[0].Text = String.Format("Compatible ({0})", mainModList.CountModsByFilter(GUIModFilter.Compatible)); @@ -232,7 +250,14 @@ private void _UpdateModsList(bool repo_updated, IEnumerable mc) var has_any_updates = gui_mods.Any(mod => mod.HasUpdate); UpdateAllToolButton.Enabled = has_any_updates; UpdateFilters(this); + + AddLogMessage("Updating tray..."); UpdateTrayInfo(); + + HideWaitDialog(true); + tabController.HideTab("WaitTabPage"); + tabController.SetTabLock(false); + SwitchEnabledState(); } public void MarkModForInstall(string identifier, bool uncheck = false) diff --git a/GUI/MainRepo.cs b/GUI/MainRepo.cs index 5016a612cf..452fe84a1f 100644 --- a/GUI/MainRepo.cs +++ b/GUI/MainRepo.cs @@ -92,7 +92,7 @@ private void UpdateRepo(object sender, DoWorkEventArgs e) private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e) { - if ((e.Result as int? ?? 0) > 0) + if (e.Result as bool? ?? true) { UpdateModsList(true, ChangeSet); AddStatusMessage("Repositories successfully updated.");