mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use AppDomain to retrive the assembly that has been loaded, which contains the version
This commit is contained in:
parent
9e343ebff4
commit
a4b7bc5221
1 changed files with 12 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
using Flow.Launcher.Infrastructure;
|
using Flow.Launcher.Infrastructure;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
@ -11,14 +12,17 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
{
|
{
|
||||||
private readonly AssemblyDependencyResolver dependencyResolver;
|
private readonly AssemblyDependencyResolver dependencyResolver;
|
||||||
|
|
||||||
private static readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver;
|
|
||||||
|
|
||||||
private readonly AssemblyName assemblyName;
|
private readonly AssemblyName assemblyName;
|
||||||
|
|
||||||
|
private static readonly List<Assembly> loadedAssembly;
|
||||||
|
|
||||||
static PluginAssemblyLoader()
|
static PluginAssemblyLoader()
|
||||||
{
|
{
|
||||||
referencedPluginPackageDependencyResolver =
|
loadedAssembly = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
new AssemblyDependencyResolver(Path.Combine(Constant.ProgramDirectory, "Flow.Launcher.dll"));
|
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
|
||||||
|
{
|
||||||
|
loadedAssembly.Add(args.LoadedAssembly);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
internal PluginAssemblyLoader(string assemblyFilePath)
|
internal PluginAssemblyLoader(string assemblyFilePath)
|
||||||
|
|
@ -49,13 +53,14 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, params Type[] types)
|
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, params Type[] types)
|
||||||
{
|
{
|
||||||
var allTypes = assembly.ExportedTypes;
|
var allTypes = assembly.ExportedTypes;
|
||||||
|
|
||||||
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Intersect(types).Any());
|
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Intersect(types).Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool ExistsInReferencedPackage(AssemblyName assemblyName)
|
internal bool ExistsInReferencedPackage(AssemblyName assemblyName)
|
||||||
{
|
{
|
||||||
return referencedPluginPackageDependencyResolver.ResolveAssemblyToPath(assemblyName) != null;
|
if (loadedAssembly.Any(a => a.FullName == assemblyName.FullName))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue