forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PTRun] Support plugin with library dependencies (microsoft#18435)
- Loading branch information
jacob
committed
May 23, 2022
1 parent
251ea6d
commit 2e90bb9
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
|
||
namespace Wox.Plugin | ||
{ | ||
internal class PluginLoadContext : AssemblyLoadContext | ||
{ | ||
private AssemblyDependencyResolver _resolver; | ||
|
||
public PluginLoadContext(string pluginPath) | ||
{ | ||
_resolver = new AssemblyDependencyResolver(pluginPath); | ||
} | ||
|
||
protected override Assembly Load(AssemblyName assemblyName) | ||
{ | ||
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); | ||
if (assemblyPath != null) | ||
{ | ||
return LoadFromAssemblyPath(assemblyPath); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) | ||
{ | ||
string libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName); | ||
if (libraryPath != null) | ||
{ | ||
return LoadUnmanagedDllFromPath(libraryPath); | ||
} | ||
|
||
return IntPtr.Zero; | ||
} | ||
} | ||
} |