|
6 | 6 | using System.Linq;
|
7 | 7 | using System.Reflection;
|
8 | 8 | using System.Text.Json;
|
9 |
| -using System.Text.Json.Nodes; |
10 |
| -using System.Text.Json.Serialization.Metadata; |
11 | 9 | using System.Threading.Tasks;
|
12 | 10 | using CommunityToolkit.Mvvm.Input;
|
13 | 11 | using CurvaLauncher.Models;
|
14 | 12 | using CurvaLauncher.Plugins;
|
15 |
| -using CurvaLauncher.PluginInteraction; |
16 | 13 | using System.Diagnostics;
|
17 | 14 | using System.IO.Compression;
|
18 | 15 | using System.Runtime.Loader;
|
| 16 | +using IOPath = System.IO.Path; |
19 | 17 |
|
20 | 18 | namespace CurvaLauncher.Services;
|
21 | 19 |
|
@@ -141,34 +139,20 @@ private bool CoreLoadZipPlugin(AppConfig config, string zipFilePath, [NotNullWhe
|
141 | 139 | try
|
142 | 140 | {
|
143 | 141 | using var zipFile = File.OpenRead(zipFilePath);
|
144 |
| - using var zipArchive = new ZipArchive(zipFile, ZipArchiveMode.Read); |
145 |
| - var assemblyLoadContext = new AssemblyLoadContext(null, false); |
146 |
| - |
147 |
| - foreach (var entry in zipArchive.Entries) |
148 |
| - { |
149 |
| - if (!entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) |
150 |
| - { |
151 |
| - continue; |
152 |
| - } |
153 |
| - |
154 |
| - using var entryStream = entry.Open(); |
155 |
| - |
156 |
| - try |
157 |
| - { |
158 |
| - var assembly = assemblyLoadContext.LoadFromStream(entryStream); |
159 |
| - |
160 |
| - if (pluginInstance is null) |
161 |
| - { |
162 |
| - CoreLoadPluginFromAssembly(config, assembly, out pluginInstance); |
163 |
| - } |
164 |
| - } |
165 |
| - catch (Exception ex) |
166 |
| - { |
167 |
| - Debug.WriteLine($"DLL load failed, {ex}"); |
168 |
| - } |
169 |
| - } |
170 |
| - |
171 |
| - return pluginInstance is not null; |
| 142 | + string extractDir = IOPath.Combine(".cache", IOPath.GetFileNameWithoutExtension(zipFilePath)); |
| 143 | + if (Directory.Exists(extractDir)) |
| 144 | + Directory.Delete(extractDir, true); |
| 145 | + ZipFile.ExtractToDirectory(zipFile, extractDir); |
| 146 | + |
| 147 | + var manifestJson = File.ReadAllText(IOPath.Combine(extractDir, "Manifest.json")); |
| 148 | + var manifest = JsonSerializer.Deserialize<PluginManifest>(manifestJson); |
| 149 | + if (manifest is null) |
| 150 | + return false; |
| 151 | + |
| 152 | + var assemblyPath = IOPath.GetFullPath(IOPath.Combine(extractDir, manifest.Assembly)); |
| 153 | + var alc = new PluginAssemblyLoadContext(manifest.ID, assemblyPath); |
| 154 | + Assembly assembly = alc.LoadFromAssemblyPath(assemblyPath); |
| 155 | + return CoreLoadPluginFromAssembly(config, assembly, out pluginInstance); |
172 | 156 | }
|
173 | 157 | catch (Exception ex)
|
174 | 158 | {
|
|
0 commit comments