From f92bfc62f109ee85e16dc0b0cca93b08684706b8 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 2 Dec 2021 16:41:15 +0000 Subject: [PATCH] [PTRun][Hotfix]Don't load duplicate plugins (#14776) --- .../PowerLauncher/Plugin/PluginManager.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs b/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs index b9bcf0580f..29ae0bf5de 100644 --- a/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs +++ b/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO.Abstractions; using System.Linq; @@ -52,6 +53,24 @@ namespace PowerLauncher.Plugin { _allPlugins = PluginConfig.Parse(Directories) .Where(x => x.Language.ToUpperInvariant() == AllowedLanguage.CSharp) + .GroupBy(x => x.ID) // Deduplicates plugins by ID, choosing for each ID the highest DLL product version. This fixes issues such as https://github.com/microsoft/PowerToys/issues/14701 + .Select(g => g.OrderByDescending(x => // , where an upgrade didn't remove older versions of the plugins. + { + try + { + // Return a comparable produce version. + var fileVersion = FileVersionInfo.GetVersionInfo(x.ExecuteFilePath); + return ((uint)fileVersion.ProductMajorPart << 48) + | ((uint)fileVersion.ProductMinorPart << 32) + | ((uint)fileVersion.ProductBuildPart << 16) + | ((uint)fileVersion.ProductPrivatePart); + } + catch (System.IO.FileNotFoundException) + { + // We'll get an error when loading the DLL later on if there's not a decent version of this plugin. + return 0U; + } + }).First()) .Select(x => new PluginPair(x)) .ToList(); } @@ -168,7 +187,7 @@ namespace PowerLauncher.Plugin { List results = null; var metadata = pair.Metadata; - var milliseconds = Stopwatch.Debug($"PluginManager.QueryForPlugin - Cost for {metadata.Name}", () => + var milliseconds = Wox.Infrastructure.Stopwatch.Debug($"PluginManager.QueryForPlugin - Cost for {metadata.Name}", () => { if (delayedExecution && (pair.Plugin is IDelayedExecutionPlugin)) {