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

Refactor Contents tab refreshing #4001

Merged
merged 1 commit into from
Jan 16, 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
6 changes: 6 additions & 0 deletions Core/Net/NetModuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public NetModuleCache(string path)
cache = new NetFileCache(path);
}

public event Action<CkanModule> ModStored;
public event Action<CkanModule> ModPurged;

// Simple passthrough wrappers
public void Dispose()
{
Expand All @@ -50,6 +53,7 @@ public void Dispose()
public void RemoveAll()
{
cache.RemoveAll();
ModPurged?.Invoke(null);
}
public void MoveFrom(string fromDir)
{
Expand Down Expand Up @@ -215,6 +219,7 @@ public string Store(CkanModule module, string path, IProgress<long> progress, st
var success = cache.Store(module.download[0], path, description ?? module.StandardName(), move);
// Make sure completion is signalled so progress bars go away
progress?.Report(100);
ModStored?.Invoke(module);
return success;
}

Expand Down Expand Up @@ -318,6 +323,7 @@ public bool Purge(CkanModule module)
}
}
}
ModPurged?.Invoke(module);
return true;
}

Expand Down
14 changes: 0 additions & 14 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
{
get
{
var configuration = Main.Instance.configuration;

Check warning on line 89 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 89 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 89 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.8, Debug)

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

Check warning on line 89 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.'

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

View workflow job for this annotation

GitHub Actions / build (6.10, 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 @@ -99,7 +99,7 @@
}
}

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

Check warning on line 102 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 102 in GUI/Controls/ManageMods.cs

View workflow job for this annotation

GitHub Actions / build (6.8, Debug)

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

Check warning on line 102 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.'

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

View workflow job for this annotation

GitHub Actions / build (6.10, Release)

'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 @@ -187,7 +187,7 @@
ClearStatusBar?.Invoke();
}

var inst = Main.Instance.CurrentInstance;

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

View workflow job for this annotation

GitHub Actions / build (6.10, Release)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'
var registry = RegistryManager.Instance(inst, repoData).registry;
if (prevConflicts != null)
{
Expand Down Expand Up @@ -1109,20 +1109,6 @@
{
Main.Instance.Manager.Cache.Purge(mod);
}

// Update all mods that share the same ZIP
var allGuiMods = AllGUIMods();
foreach (var otherMod in selected.ToModule().GetDownloadsGroup(
allGuiMods.Values.Select(guiMod => guiMod.ToModule())
.Where(mod => mod != null)))
{
allGuiMods[otherMod.identifier].UpdateIsCached();
}

// Reapply searches in case is:cached or not:cached is active
UpdateFilters();

Main.Instance.RefreshModContentsTree();
}
}

Expand Down
2 changes: 2 additions & 0 deletions GUI/Controls/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Autofac;

using CKAN.Versioning;
using CKAN.GUI.Attributes;

namespace CKAN.GUI
{
Expand Down Expand Up @@ -45,6 +46,7 @@
get => selectedModule;
}

[ForbidGUICalls]
public void RefreshModContentsTree()
{
Contents.RefreshModContentsTree();
Expand Down Expand Up @@ -100,7 +102,7 @@
LoadTab(SelectedModule);
}

private GameInstanceManager manager => Main.Instance.Manager;

Check warning on line 105 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Debug)

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

Check warning on line 105 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.8, Debug)

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

Check warning on line 105 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.12, Release)

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

Check warning on line 105 in GUI/Controls/ModInfo.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.'

Check warning on line 105 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.10, Release)

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

Check warning on line 105 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Release)

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

private int TextBoxStringHeight(TextBox tb)
=> tb.Padding.Vertical + tb.Margin.Vertical
Expand Down Expand Up @@ -136,7 +138,7 @@
});
}

private ModuleLabelList ModuleLabels => Main.Instance.ManageMods.mainModList.ModuleLabels;

Check warning on line 141 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Debug)

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

Check warning on line 141 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.8, Debug)

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

Check warning on line 141 in GUI/Controls/ModInfo.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.'

Check warning on line 141 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.10, Release)

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

Check warning on line 141 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Release)

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

private void UpdateTagsAndLabels(CkanModule mod)
{
Expand All @@ -149,7 +151,7 @@
.OrderBy(t => t.Key)
.Select(t => t.Value),
ModuleLabels?.LabelsFor(manager.CurrentInstance.Name)
.Where(l => l.ContainsModule(Main.Instance.CurrentInstance.game, mod.identifier))

Check warning on line 154 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Debug)

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

Check warning on line 154 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (6.10, Release)

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

Check warning on line 154 in GUI/Controls/ModInfo.cs

View workflow job for this annotation

GitHub Actions / build (latest, Release)

'Main.Instance' is obsolete: 'Main.Instance is a global singleton. Find a better way to access this object.'
.OrderBy(l => l.Name));
Util.Invoke(tagsLabelsLinkList, () =>
{
Expand Down
3 changes: 3 additions & 0 deletions GUI/Controls/ModInfoTabs/Contents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Runtime.Versioning;
#endif

using CKAN.GUI.Attributes;

namespace CKAN.GUI
{
#if NET5_0_OR_GREATER
Expand All @@ -35,6 +37,7 @@
get => selectedModule;
}

[ForbidGUICalls]
public void RefreshModContentsTree()
{
if (currentModContentsModule != null)
Expand All @@ -47,7 +50,7 @@

private GUIMod selectedModule;
private CkanModule currentModContentsModule;
private GameInstanceManager manager => Main.Instance.Manager;

Check warning on line 53 in GUI/Controls/ModInfoTabs/Contents.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 53 in GUI/Controls/ModInfoTabs/Contents.cs

View workflow job for this annotation

GitHub Actions / build (latest, Debug)

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

Check warning on line 53 in GUI/Controls/ModInfoTabs/Contents.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 53 in GUI/Controls/ModInfoTabs/Contents.cs

View workflow job for this annotation

GitHub Actions / build (6.12, Release)

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

private void ContentsPreviewTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
Expand Down Expand Up @@ -90,7 +93,7 @@
ContentsPreviewTree.Enabled = true;
ContentsPreviewTree.Nodes.Clear();
var rootNode = ContentsPreviewTree.Nodes.Add("", module.ToString(), "folderZip", "folderZip");
if (!Main.Instance.Manager.Cache.IsMaybeCachedZip(module))

Check warning on line 96 in GUI/Controls/ModInfoTabs/Contents.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.'
{
NotCachedLabel.Text = Properties.Resources.ModInfoNotCached;
ContentsDownloadButton.Enabled = true;
Expand Down
12 changes: 1 addition & 11 deletions GUI/Dialogs/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,9 @@ private void PurgeAllMenuItem_Click(object sender, EventArgs e)

if (deleteConfirmationDialog.ShowYesNoDialog(this, confirmationText) == DialogResult.Yes)
{
// tell the cache object to nuke itself
// Tell the cache object to nuke itself
Main.Instance.Manager.Cache.RemoveAll();

// forcibly tell all mod rows to re-check cache state
foreach (DataGridViewRow row in Main.Instance.ManageMods.ModGrid.Rows)
{
var mod = row.Tag as GUIMod;
mod?.UpdateIsCached();
}

// finally, clear the preview contents list
Main.Instance.RefreshModContentsTree();

UpdateCacheInfo(coreConfig.DownloadCacheDir);
}
}
Expand Down
13 changes: 7 additions & 6 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public Main(string[] cmdlineArgs, GameInstanceManager mgr)
Manager = new GameInstanceManager(currentUser);
}

Manager.Cache.ModStored += OnModStoredOrPurged;
Manager.Cache.ModPurged += OnModStoredOrPurged;

tabController = new TabController(MainTabControl);
tabController.ShowTab("ManageModsTabPage");

Expand Down Expand Up @@ -593,11 +596,6 @@ private void SetupDefaultSearch()
}
}

public void RefreshModContentsTree()
{
ModInfo.RefreshModContentsTree();
}

private void ExitToolButton_Click(object sender, EventArgs e)
{
Close();
Expand Down Expand Up @@ -785,7 +783,10 @@ public bool PreFilterMessage(ref Message m)

private void ManageMods_OnSelectedModuleChanged(GUIMod m)
{
ActiveModInfo = m;
if (MainTabControl.SelectedTab == ManageModsTabPage)
{
ActiveModInfo = m;
}
}

private GUIMod ActiveModInfo
Expand Down
34 changes: 19 additions & 15 deletions GUI/Main/MainDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void StartDownload(GUIMod module)
{
// Just pass to the existing worker
downloader.DownloadModules(new List<CkanModule> { module.ToCkanModule() });
UpdateCachedByDownloads(module);
});
}
else
Expand Down Expand Up @@ -81,36 +80,41 @@ public void PostModCaching(object sender, RunWorkerCompletedEventArgs e)
}
else
{
Util.Invoke(this, () => _PostModCaching((GUIMod)e.Result));
// Close progress tab and switch back to mod list
HideWaitDialog();
EnableMainWindow();
}
}

[ForbidGUICalls]
private void UpdateCachedByDownloads(GUIMod module)
private void UpdateCachedByDownloads(CkanModule module)
{
// Update all mods that share the same ZIP
var allGuiMods = ManageMods.AllGUIMods();
foreach (var otherMod in module.ToModule().GetDownloadsGroup(
allGuiMods.Values.Select(guiMod => guiMod.ToModule())
.Where(mod => mod != null)))
var affectedMods =
module?.GetDownloadsGroup(allGuiMods.Values
.Select(guiMod => guiMod.ToModule())
.Where(mod => mod != null))
.Select(other => allGuiMods[other.identifier])
?? allGuiMods.Values;
foreach (var otherMod in affectedMods)
{
allGuiMods[otherMod.identifier].UpdateIsCached();
otherMod.UpdateIsCached();
}
}

private void _PostModCaching(GUIMod module)
[ForbidGUICalls]
private void OnModStoredOrPurged(CkanModule module)
{
UpdateCachedByDownloads(module);

// Reapply searches in case is:cached or not:cached is active
ManageMods.UpdateFilters();

// User might have selected another row. Show current in tree.
RefreshModContentsTree();

// Close progress tab and switch back to mod list
HideWaitDialog();
EnableMainWindow();
if (module == null
|| ModInfo.SelectedModule?.Identifier == module.identifier)
{
ModInfo.RefreshModContentsTree();
}
}
}
}
Loading