mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
Check "Does Not Support Unloading" tag to not use AssemblyLoadContext
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Modio.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DesktopMagic.Plugins;
|
||||
@@ -27,6 +29,8 @@ public class PluginMetadata
|
||||
|
||||
public string? Version { get; set; }
|
||||
|
||||
public List<string> Tags { get; set; } = [];
|
||||
|
||||
public PluginMetadata(Mod mod)
|
||||
{
|
||||
Name = mod.Name ?? mod.Id.ToString();
|
||||
@@ -39,6 +43,7 @@ public class PluginMetadata
|
||||
Description = mod.DescriptionPlaintext;
|
||||
Summary = mod.Summary;
|
||||
Version = mod.Modfile?.Version;
|
||||
Tags = mod.Tags.Select(t => t.Name).Where(t => t is not null).ToList()!;
|
||||
}
|
||||
|
||||
public PluginMetadata(string name, uint id)
|
||||
|
||||
@@ -216,10 +216,19 @@ public partial class PluginWindow : Window
|
||||
object? instance = pluginClassInstance;
|
||||
if (instance is null)
|
||||
{
|
||||
byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll");
|
||||
using MemoryStream assemblyStream = new(assemblyData);
|
||||
Assembly dll;
|
||||
|
||||
Assembly dll = assemblyLoadContext.LoadFromStream(assemblyStream);
|
||||
if (PluginMetadata.Tags.Contains("Does Not Support Unloading"))
|
||||
{
|
||||
dll = Assembly.LoadFrom($"{PluginFolderPath}\\main.dll");
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll");
|
||||
using MemoryStream assemblyStream = new(assemblyData);
|
||||
|
||||
dll = assemblyLoadContext.LoadFromStream(assemblyStream);
|
||||
}
|
||||
|
||||
Type? instanceType = Array.Find(dll.GetTypes(), type => type.GetTypeInfo().BaseType == typeof(Plugin));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user