diff --git a/ObservatoryCore/PluginManagement/PluginManager.cs b/ObservatoryCore/PluginManagement/PluginManager.cs index 70ba82b..57b861b 100644 --- a/ObservatoryCore/PluginManagement/PluginManager.cs +++ b/ObservatoryCore/PluginManagement/PluginManager.cs @@ -3,13 +3,14 @@ using Observatory.Utils; using System.Data; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO.Compression; using System.Reflection; +using System.Runtime.InteropServices; +using System.Runtime.Loader; using System.Text.Json; using System.Text.Json.Serialization; -using System.Runtime.Loader; -using System.IO.Compression; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; +using System.Text.RegularExpressions; namespace Observatory.PluginManagement { @@ -795,6 +796,8 @@ private void ReadDirectory(DirectoryInfo directory) private class PluginPackage { + private static readonly Regex VersionSuffixRegEx = new("-.*$"); + internal PluginPackage(string filePath, bool includeLegacyDeps = false) { var bundle = new PluginBundle(filePath); @@ -862,7 +865,8 @@ private void ProcessPluginManifest(PluginBundle bundle) var nameAndVersion = pluginLibraryEntry.Key.Split('/') ?? ["No Library", "0"]; PluginName = nameAndVersion.First() ?? string.Empty; - Version = new Version(nameAndVersion.Last() ?? "0"); + var versionWithoutSuffx = VersionSuffixRegEx.Replace(nameAndVersion.Last() ?? "0", ""); + Version = new Version(versionWithoutSuffx); foreach (var dependency in targets.Where(t => t.Key != pluginLibraryEntry.Key)) { diff --git a/ObservatoryCore/UI/PluginList.cs b/ObservatoryCore/UI/PluginList.cs index 35f81f7..2a2d303 100644 --- a/ObservatoryCore/UI/PluginList.cs +++ b/ObservatoryCore/UI/PluginList.cs @@ -13,6 +13,8 @@ internal class PluginList : TableLayoutPanel internal PluginList(IEnumerable plugins) { + SuspendLayout(); + ColumnCount = 7; _title = new() { @@ -62,6 +64,7 @@ Label createHeaderLabel(string text) int row = 2; var enabledPlugins = GetEnabledPlugins(); + List updateTasks = new(); foreach (var plugin in plugins) { @@ -162,7 +165,7 @@ Label createLineLabel(string text) AddWithLocation(pluginEnabled, row, 5); AddWithLocation(pluginMenu, row, 6); - Task.Run(() => + updateTasks.Add(new Task(() => { var thisRow = row; // Check for a plugin update. @@ -198,15 +201,32 @@ Label createLineLabel(string text) var startInfo = new ProcessStartInfo(updateInfo.Url ?? "https://observatory.xjph.net") { UseShellExecute = true }; Process.Start(startInfo); }; - AddWithLocation(updateLink, GetRow(pluginStatus), 4); + var row = GetRow(pluginStatus); Controls.Remove(pluginStatus); + AddWithLocation(updateLink, row, 4); } - }); + })); row++; } + ResumeLayout(); + Resize += PluginList_Resize; + + // Avoid blocking the main thread by running one or more update tasks. + Task.Run(() => + { + // Run the update tasks now that we've completely laid out the plugin list -- one at a time. + // This avoids the these tasks and the main thread trigging layout passes on the underlying TableLayoutPanel + // that end up conflicting with each other causing mysterious index-out-of-bounds and null errors deep + // within the Layout engine. + foreach (var t in updateTasks) + { + t.Start(); + t.Wait(); + } + }); } private void PluginList_Resize(object? sender, EventArgs e)