mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
Improve plugin metadata
This commit is contained in:
@@ -35,7 +35,8 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
|
||||
|
||||
public string? Path => path;
|
||||
|
||||
public bool IsLocalPlugin => string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString());
|
||||
public bool IsLocalPlugin => pluginMetadata.IsLocalPlugin;
|
||||
|
||||
public ICommand Command => command;
|
||||
|
||||
public ButtonData InstallUninstallButtonData => new(mode == Mode.Install ? PackIconKind.Download : PackIconKind.Remove, GetInstallUninstallButtonText(), true, Command);
|
||||
|
||||
@@ -113,6 +113,7 @@ public partial class PluginManager : Window
|
||||
foreach (string pluginPath in Directory.GetDirectories(pluginsPath))
|
||||
{
|
||||
string pluginMetadataPath = Path.Combine(pluginPath, "metadata.json");
|
||||
|
||||
if (!File.Exists(pluginMetadataPath))
|
||||
{
|
||||
continue;
|
||||
@@ -128,17 +129,18 @@ public partial class PluginManager : Window
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(pluginMetadata, new CommandHandler(async () => await Remove(pluginPath, pluginMetadata.Id)), PluginEntryDataContext.Mode.Uninstall, pluginPath));
|
||||
_ = pluginIds.Add(pluginMetadata.Id);
|
||||
|
||||
if (string.IsNullOrEmpty(pluginMetadata.ProfileUri?.ToString()))
|
||||
if (pluginMetadata.IsLocalPlugin)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Mod mod = await modIoClient.Games[ModIoGameId].Mods[pluginMetadata.Id].Get();
|
||||
|
||||
if (DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).DateTime > pluginMetadata.Updated && !pluginMetadata.Tags.Contains("Does Not Support Unloading"))
|
||||
if (DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).DateTime > pluginMetadata.Updated && pluginMetadata.SupportsUnloading)
|
||||
{
|
||||
await Remove(pluginPath, pluginMetadata.Id);
|
||||
await Install(mod);
|
||||
pluginManagerDataContext.IsLoading = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@ public class PluginMetadata
|
||||
|
||||
public List<string> Tags { get; set; } = [];
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SupportsUnloading => !Tags.Contains("Does Not Support Unloading");
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsLocalPlugin => string.IsNullOrWhiteSpace(ProfileUri?.ToString());
|
||||
|
||||
public PluginMetadata(Mod mod)
|
||||
{
|
||||
Name = mod.Name ?? mod.Id.ToString();
|
||||
|
||||
@@ -218,17 +218,17 @@ public partial class PluginWindow : Window
|
||||
{
|
||||
Assembly dll;
|
||||
|
||||
if (PluginMetadata.Tags.Contains("Does Not Support Unloading"))
|
||||
{
|
||||
dll = Assembly.LoadFrom($"{PluginFolderPath}\\main.dll");
|
||||
}
|
||||
else
|
||||
if (PluginMetadata.SupportsUnloading)
|
||||
{
|
||||
byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll");
|
||||
using MemoryStream assemblyStream = new(assemblyData);
|
||||
|
||||
dll = assemblyLoadContext.LoadFromStream(assemblyStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
dll = Assembly.LoadFrom($"{PluginFolderPath}\\main.dll");
|
||||
}
|
||||
|
||||
Type? instanceType = Array.Find(dll.GetTypes(), type => type.GetTypeInfo().BaseType == typeof(Plugin));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user