Skip to content

Commit

Permalink
Merge #2617 Show progress bar while loading registry
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Dec 26, 2018
2 parents a7ebcfd + cea8ac9 commit c536f13
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Confirm quit with pending change set or conflicts (#2599 by: HebaruSan; reviewed: politas)
- [Multiple] Warn before launching KSP with installed incompatible modules (#2601 by: HebaruSan; reviewed: politas)
- [GUI] Allow selection of text in mod info panel (#2610 by: DasSkelett; reviewed: HebaruSan)
- [Multiple] Show progress bar while loading registry (#2617 by: HebaruSan; reviewed: politas)

### Bugfixes
- [GUI] Fix platform checks and crash on Mac OS X (#2600 by: HebaruSan; reviewed: politas)
Expand Down
3 changes: 2 additions & 1 deletion Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
20 changes: 11 additions & 9 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
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<string, Repository> sortedRepositories = registry_manager.registry.Repositories;
List<CkanModule> allAvail = new List<CkanModule>();
Expand All @@ -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
{
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -372,7 +373,7 @@ private static bool RelationshipsAreEquivalent(List<RelationshipDescriptor> a, L
/// <returns>
/// Number of modules found in repo
/// </returns>
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)
{
Expand All @@ -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)
Expand All @@ -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;
}

/// <summary>
Expand Down
27 changes: 26 additions & 1 deletion GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,47 @@ private void _UpdateFilters()

public void UpdateModsList(Boolean repo_updated = false, IEnumerable<ModChange> mc = null)
{
Util.Invoke(this, () => _UpdateModsList(repo_updated, mc ?? new List<ModChange>()));
// Run the update in the background so the UI thread can appear alive
Task.Factory.StartNew(() =>
_UpdateModsList(repo_updated, mc ?? new List<ModChange>())
);
}

private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> 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<GUIMod>();
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))
);

if (mc != null)
{
AddLogMessage("Restoring change set...");
foreach (ModChange change in mc)
{
// Propagate IsInstallChecked and IsUpgradeChecked to the next generation
Expand All @@ -176,6 +191,7 @@ private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> mc)
}
}

AddLogMessage("Preserving new flags...");
var old_modules = mainModList.Modules.ToDictionary(m => m, m => m.IsIncompatible);
if (repo_updated)
{
Expand Down Expand Up @@ -207,11 +223,13 @@ private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> mc)
}
}

AddLogMessage("Populating mod list...");
// Update our mod listing
mainModList.ConstructModList(gui_mods.ToList(), mc, configuration.HideEpochs, configuration.HideV);
mainModList.Modules = new ReadOnlyCollection<GUIMod>(
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));
Expand All @@ -232,7 +250,14 @@ private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> 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)
Expand Down
2 changes: 1 addition & 1 deletion GUI/MainRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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.");
Expand Down

0 comments on commit c536f13

Please sign in to comment.