Skip to content

Commit

Permalink
Merge #3637 Update mod list through Wait.StartWaiting
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 20, 2022
2 parents 6bc1dbf + c23aadd commit 2f3d817
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file.
- [CLI] Create a system menu entry for command prompt (#3622 by: HebaruSan; reviewed: techman83)
- [Multiple] Internationalize Core, CmdLine, ConsoleUI, and AutoUpdater (#3482 by: HebaruSan; reviewed: techman83)
- [Multiple] Check free space before downloading (#3631 by: HebaruSan; reviewed: techman83)
- [Multiple] Many improvements for failed downloads (#3635 by: HebaruSan; reviewed: techman83)
- [Multiple] Many improvements for failed downloads (#3635, #3637 by: HebaruSan; reviewed: techman83)

## Bugfixes

Expand Down
25 changes: 6 additions & 19 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.ComponentModel;

using log4net;

using CKAN.Versioning;

namespace CKAN.GUI
Expand Down Expand Up @@ -83,8 +86,7 @@ private List<bool> descending
public event Action OnRegistryChanged;

public event Action<List<ModChange>> StartChangeSet;
public event Action OpenProgressTab;
public event Action CloseProgressTab;
public event Action<Dictionary<string, bool>> OnRefresh;
public event Action<IEnumerable<GUIMod>> LabelsAfterUpdate;

private IEnumerable<ModChange> ChangeSet
Expand Down Expand Up @@ -1066,26 +1068,15 @@ private void _UpdateFilters()
}
}

public async void UpdateModsList(Dictionary<string, bool> old_modules = null)
public void Update(object sender, DoWorkEventArgs e)
{
// Run the update in the background so the UI thread can appear alive
// Await it so potential (fatal) errors are thrown, not swallowed.
// Need to be on the GUI thread to get the translated strings
Main.Instance.tabController.RenameTab("WaitTabPage", Properties.Resources.MainModListWaitTitle);
await Task.Factory.StartNew(() =>
_UpdateModsList(old_modules)
);
_UpdateModsList(e.Argument as Dictionary<string, bool>);
}

private void _UpdateModsList(Dictionary<string, bool> old_modules = null)
{
log.Info("Updating the mod list");

if (OpenProgressTab != null)
{
OpenProgressTab();
}

Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListLoadingRegistry);
GameVersionCriteria versionCriteria = Main.Instance.CurrentInstance.VersionCriteria();
IRegistryQuerier registry = RegistryManager.Instance(Main.Instance.CurrentInstance).registry;
Expand Down Expand Up @@ -1205,10 +1196,6 @@ private void _UpdateModsList(Dictionary<string, bool> old_modules = null)

Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListUpdatingTray);

if (CloseProgressTab != null)
{
CloseProgressTab();
}
Util.Invoke(this, () => ModGrid.Focus());
}

Expand Down
3 changes: 1 addition & 2 deletions GUI/Main/Main.Designer.cs

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

28 changes: 15 additions & 13 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void CurrentInstanceUpdated(bool allowRepoUpdate)
else
{
SetupDefaultSearch();
ManageMods.UpdateModsList();
ManageMods_OnRefresh();
}
}
ManageMods.InstanceUpdated(CurrentInstance);
Expand Down Expand Up @@ -607,7 +607,7 @@ private void CompatibleGameVersionsToolStripMenuItem_Click(object sender, EventA
if (dialog.ShowDialog() != DialogResult.Cancel)
{
// This takes a while, so don't do it if they cancel out
ManageMods.UpdateModsList();
ManageMods_OnRefresh();
}
}

Expand Down Expand Up @@ -811,20 +811,22 @@ private void ManageMods_StartChangeSet(List<ModChange> changeset)
changeset, RelationshipResolver.DependsOnlyOpts()));
}

private void ManageMods_OpenProgressTab()
private void ManageMods_OnRefresh(Dictionary<string, bool> oldModules = null)
{
ResetProgress();
tabController.RenameTab("WaitTabPage", Properties.Resources.MainModListWaitTitle);
ShowWaitDialog();
tabController.SetTabLock(true);
Util.Invoke(this, SwitchEnabledState);
}

private void ManageMods_CloseProgressTab()
{
Util.Invoke(this, UpdateTrayInfo);
HideWaitDialog(true);
tabController.SetTabLock(false);
Util.Invoke(this, SwitchEnabledState);
tabController.SetTabLock(true);
Wait.StartWaiting(
ManageMods.Update,
(sender, e) => {
HideWaitDialog(true);
tabController.SetTabLock(false);
Util.Invoke(this, SwitchEnabledState);
SetupDefaultSearch();
},
false,
oldModules);
}
}
}
3 changes: 1 addition & 2 deletions GUI/Main/MainDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ private void _PostModCaching(GUIMod module)
{
module.UpdateIsCached();
// Update mod list in case is:cached or not:cached filters are active
ManageMods.UpdateModsList();
HideWaitDialog(true);
ManageMods_OnRefresh();
// User might have selected another row. Show current in tree.
UpdateModContentsTree(ModInfo.SelectedModule.ToCkanModule(), true);
}
Expand Down
2 changes: 1 addition & 1 deletion GUI/Main/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e)
// The Result property throws if InstallMods threw (!!!)
KeyValuePair<bool, ModChanges> result = (KeyValuePair<bool, ModChanges>) e.Result;
// Rebuilds the list of GUIMods
ManageMods.UpdateModsList();
ManageMods_OnRefresh();

Util.Invoke(this, () => Enabled = true);
Util.Invoke(menuStrip1, () => menuStrip1.Enabled = true);
Expand Down
20 changes: 12 additions & 8 deletions GUI/Main/MainRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,34 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
// Load rows if grid empty, otherwise keep current
if (ManageMods.ModGrid.Rows.Count < 1)
{
ManageMods.UpdateModsList();
ManageMods_OnRefresh();
}
else
{
Util.Invoke(this, SwitchEnabledState);
Util.Invoke(this, ManageMods.ModGrid.Select);
}
SetupDefaultSearch();
break;

case RepoUpdateResult.Failed:
AddStatusMessage(Properties.Resources.MainRepoFailed);
HideWaitDialog(false);
Util.Invoke(this, SwitchEnabledState);
Util.Invoke(this, ManageMods.ModGrid.Select);
SetupDefaultSearch();
break;

case RepoUpdateResult.Updated:
default:
ManageMods.UpdateModsList(oldModules);
AddStatusMessage(Properties.Resources.MainRepoSuccess);
ShowRefreshQuestion();
HideWaitDialog(true);
UpgradeNotification();
Util.Invoke(this, SwitchEnabledState);
ManageMods_OnRefresh(oldModules);
break;
}

tabController.HideTab("WaitTabPage");
Util.Invoke(this, SwitchEnabledState);
Util.Invoke(this, RecreateDialogs);
Util.Invoke(this, ManageMods.ModGrid.Select);
SetupDefaultSearch();
}

private void ShowRefreshQuestion()
Expand Down

0 comments on commit 2f3d817

Please sign in to comment.