From 6f155ffa6a742864151dcb6ca26b5ae2196df714 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 11 Oct 2021 03:44:28 +0200 Subject: [PATCH] fix: only use a single task to download icons --- .../Internal/Windows/PluginInstallerWindow.cs | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 87908ec35..56578acb5 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -1060,20 +1060,11 @@ namespace Dalamud.Interface.Internal.Windows ImGui.SetCursorPos(startCursor); var iconTex = this.defaultIcon; - var hasIcon = this.pluginIconMap.TryGetValue(manifest.InternalName, out var cachedIconTex); - if (!hasIcon) - { - this.pluginIconMap.Add(manifest.InternalName, null); - Task.Run(async () => await this.DownloadPluginIconAsync(plugin, manifest, isThirdParty)); - } - else if (cachedIconTex != null) + + if (this.pluginIconMap.TryGetValue(manifest.InternalName, out var cachedIconTex) && cachedIconTex != null) { iconTex = cachedIconTex; } - else - { - // nothing - } var iconSize = ImGuiHelpers.ScaledVector2(64, 64); @@ -1943,6 +1934,7 @@ namespace Dalamud.Interface.Internal.Windows this.ResortPlugins(); this.UpdateCategoriesOnPluginsChange(); + Task.Run(() => this.DownloadPluginIconsAsync(this.pluginListAvailable.ToArray())); } private void OnInstalledPluginsChanged() @@ -2034,7 +2026,17 @@ namespace Dalamud.Interface.Internal.Windows this.errorModalOnNextFrame = true; } - private async Task DownloadPluginIconAsync(LocalPlugin? plugin, PluginManifest manifest, bool isThirdParty) + private async Task DownloadPluginIconsAsync(RemotePluginManifest[] plugins) + { + Log.Verbose("Starting icon download..."); + foreach (var plugin in plugins.Where(x => !this.pluginIconMap.ContainsKey(x.InternalName))) + { + this.pluginIconMap[plugin.InternalName] = null; + await this.DownloadPluginIconAsync(plugin, plugin.SourceRepo.IsThirdParty); + } + } + + private async Task DownloadPluginIconAsync(PluginManifest manifest, bool isThirdParty) { var interfaceManager = Service.Get(); var pluginManager = Service.Get(); @@ -2064,26 +2066,6 @@ namespace Dalamud.Interface.Internal.Windows return true; } - if (plugin != null && plugin.IsDev) - { - var file = this.GetPluginIconFileInfo(plugin); - if (file != null) - { - Log.Verbose($"Fetching icon for {manifest.InternalName} from {file.FullName}"); - - var bytes = await File.ReadAllBytesAsync(file.FullName); - if (!TryLoadIcon(bytes, file.FullName, manifest, interfaceManager, out var icon)) - return; - - this.pluginIconMap[manifest.InternalName] = icon; - Log.Verbose($"Plugin icon for {manifest.InternalName} loaded from disk"); - } - - // Dev plugins are likely going to look like a main repo plugin, the InstalledFrom field is going to be null. - // So instead, set the value manually so we download from the urls specified. - isThirdParty = true; - } - var useTesting = pluginManager.UseTesting(manifest); var url = this.GetPluginIconUrl(manifest, isThirdParty, useTesting); if (url != null)