Skip to content

Commit 215c260

Browse files
committed
Fix | Find MainPlugin Typ
1 parent bb80d74 commit 215c260

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

ShadowPluginLoader.WinUI/Checkers/MetaDataChecker.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Text.Json;
56
using System.Text.Json.Nodes;
67
using System.Threading.Tasks;
@@ -59,23 +60,40 @@ public TMeta LoadMetaData(string zip)
5960

6061
public void CheckMetaDataValid(TMeta meta)
6162
{
62-
throw new NotImplementedException();
6363
}
6464

65+
/// <summary>
66+
/// <inheritdoc />
67+
/// </summary>
68+
/// <exception cref="PluginImportException"></exception>
6569
public async Task<Type> GetMainPluginType(TMeta meta)
6670
{
6771
if (!DllFiles.TryGetValue(meta.Id, out var path))
6872
{
6973
throw new PluginImportException($"{meta.Id} Dll Path Not Found");
7074
}
7175

72-
var asm = await ApplicationExtensionHost.Current.LoadExtensionAsync(path);
73-
if (!EntryPoints.TryGetValue("MainPlugin", out var mainTypeName) || mainTypeName == null)
76+
var assemblyName = Path.GetFileNameWithoutExtension(path);
77+
var assembly = AppDomain.CurrentDomain.GetAssemblies()
78+
.FirstOrDefault(assembly => assembly.GetName().Name == assemblyName);
79+
if (assembly == null)
80+
{
81+
var asm = await ApplicationExtensionHost.Current.LoadExtensionAsync(path);
82+
assembly = asm.ForeignAssembly;
83+
}
84+
85+
if (!EntryPoints.TryGetValue(meta.Id, out var entryPoints) || entryPoints == null)
86+
{
87+
throw new PluginImportException($"{meta.Id} EntryPoints Not Found");
88+
}
89+
90+
if (!entryPoints.AsObject()
91+
.TryGetPropertyValue("MainPlugin", out var mainTypeName) || mainTypeName == null)
7492
{
7593
throw new PluginImportException($"{meta.Id} MainPlugin(EntryPoint) Not Found");
7694
}
7795

78-
var mainType = asm.ForeignAssembly.GetType(mainTypeName.GetValue<string>());
96+
var mainType = assembly.GetType(mainTypeName.GetValue<string>());
7997
if (mainType == null)
8098
{
8199
throw new PluginImportException($"{meta.Id} MainPlugin(Type) Not Found");

ShadowPluginLoader.WinUI/ShadowPluginLoader.WinUI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<TargetFrameworks>net6.0-windows10.0.17763.0;net8.0-windows10.0.17763.0;net9.0-windows10.0.17763.0</TargetFrameworks>
44
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
55
<RootNamespace>ShadowPluginLoader.WinUI</RootNamespace>
6-
<!-- <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>-->
6+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
77
<UseWinUI>true</UseWinUI>
88
<Nullable>enable</Nullable>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<NoWarn>MSB3277</NoWarn>
1111
<EnableMsixTooling>true</EnableMsixTooling>
1212
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1313
<!-- Nuget -->
14-
<Version>2.1.1</Version>
14+
<Version>2.1.3</Version>
1515
<PackageId>ShadowPluginLoader.WinUI</PackageId>
1616
<Owner>kitUIN</Owner>
1717
<Authors>kitUIN</Authors>
@@ -34,7 +34,7 @@
3434
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
3535
<PackageReference Include="ShadowPluginLoader.SourceGenerator" Version="2.0.4" />
3636
<PackageReference Include="kitUIN.CustomExtensions.WinUI" Version="0.6.4" />
37-
<PackageReference Include="ShadowPluginLoader.Tool" Version="2.1.5" />
37+
<PackageReference Include="ShadowPluginLoader.Tool" Version="2.1.6" />
3838
<PackageReference Include="SharpCompress" Version="0.39.0" />
3939
</ItemGroup>
4040
<ItemGroup>

0 commit comments

Comments
 (0)