From a4b7bc522174aa6373ed2cef832525cee1ba8a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 24 Feb 2021 20:36:32 +0800 Subject: [PATCH] Use AppDomain to retrive the assembly that has been loaded, which contains the version --- .../Plugin/PluginAssemblyLoader.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs index 91fc90964..e1c6d6d5a 100644 --- a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs @@ -1,5 +1,6 @@ using Flow.Launcher.Infrastructure; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -11,14 +12,17 @@ namespace Flow.Launcher.Core.Plugin { private readonly AssemblyDependencyResolver dependencyResolver; - private static readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver; - private readonly AssemblyName assemblyName; + private static readonly List loadedAssembly; + static PluginAssemblyLoader() { - referencedPluginPackageDependencyResolver = - new AssemblyDependencyResolver(Path.Combine(Constant.ProgramDirectory, "Flow.Launcher.dll")); + loadedAssembly = new List(AppDomain.CurrentDomain.GetAssemblies()); + AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => + { + loadedAssembly.Add(args.LoadedAssembly); + }; } internal PluginAssemblyLoader(string assemblyFilePath) @@ -39,7 +43,7 @@ namespace Flow.Launcher.Core.Plugin // When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher // Otherwise duplicate assembly will be loaded, and some weird behavior will occur such as WinRT.dll // will fail to create - + if (assemblyPath == null || ExistsInReferencedPackage(assemblyName)) return null; @@ -49,13 +53,14 @@ namespace Flow.Launcher.Core.Plugin internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, params Type[] types) { var allTypes = assembly.ExportedTypes; - return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Intersect(types).Any()); } internal bool ExistsInReferencedPackage(AssemblyName assemblyName) { - return referencedPluginPackageDependencyResolver.ResolveAssemblyToPath(assemblyName) != null; + if (loadedAssembly.Any(a => a.FullName == assemblyName.FullName)) + return true; + return false; } } } \ No newline at end of file