From e1a6fdda98e3baad712acd89edac5251e7e4ba90 Mon Sep 17 00:00:00 2001 From: js6pak Date: Tue, 13 Apr 2021 23:13:52 +0200 Subject: [PATCH] Make it possible to read plugin information from csproj attributes --- src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs | 11 ++++++++--- src/Impostor.Plugins.Debugger/DebugPlugin.cs | 2 +- .../Impostor.Plugins.Debugger.csproj | 4 ++++ src/Impostor.Plugins.Example/ExamplePlugin.cs | 2 +- .../Impostor.Plugins.Example.csproj | 4 ++++ src/Impostor.Server/Plugins/PluginInformation.cs | 11 ++++++++--- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs b/src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs index c921f9f..1281261 100644 --- a/src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs +++ b/src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs @@ -5,6 +5,11 @@ namespace Impostor.Api.Plugins [AttributeUsage(AttributeTargets.Class)] public class ImpostorPluginAttribute : Attribute { + public ImpostorPluginAttribute(string id) + { + Id = id; + } + public ImpostorPluginAttribute(string id, string name, string author, string version) { Id = id; @@ -15,10 +20,10 @@ namespace Impostor.Api.Plugins public string Id { get; } - public string Name { get; } + public string? Name { get; } - public string Author { get; } + public string? Author { get; } - public string Version { get; } + public string? Version { get; } } } diff --git a/src/Impostor.Plugins.Debugger/DebugPlugin.cs b/src/Impostor.Plugins.Debugger/DebugPlugin.cs index c22442c..970d0b9 100644 --- a/src/Impostor.Plugins.Debugger/DebugPlugin.cs +++ b/src/Impostor.Plugins.Debugger/DebugPlugin.cs @@ -2,7 +2,7 @@ using Impostor.Api.Plugins; namespace Impostor.Plugins.Debugger { - [ImpostorPlugin("gg.impostor.debugger", "Debugger", "Gerard", "1.0.0")] + [ImpostorPlugin("gg.impostor.debugger")] public class DebugPlugin : PluginBase { } diff --git a/src/Impostor.Plugins.Debugger/Impostor.Plugins.Debugger.csproj b/src/Impostor.Plugins.Debugger/Impostor.Plugins.Debugger.csproj index 8fce4f8..2aa7625 100644 --- a/src/Impostor.Plugins.Debugger/Impostor.Plugins.Debugger.csproj +++ b/src/Impostor.Plugins.Debugger/Impostor.Plugins.Debugger.csproj @@ -3,6 +3,10 @@ net5.0 Library + + 1.0.0 + Debugger + Gerard diff --git a/src/Impostor.Plugins.Example/ExamplePlugin.cs b/src/Impostor.Plugins.Example/ExamplePlugin.cs index 7d88079..07f4d86 100644 --- a/src/Impostor.Plugins.Example/ExamplePlugin.cs +++ b/src/Impostor.Plugins.Example/ExamplePlugin.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace Impostor.Plugins.Example { - [ImpostorPlugin("gg.impostor.example", "Example", "AeonLucid", "1.0.0")] + [ImpostorPlugin("gg.impostor.example")] public class ExamplePlugin : PluginBase { private readonly ILogger _logger; diff --git a/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj b/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj index f0ebef3..2cfa53b 100644 --- a/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj +++ b/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj @@ -2,6 +2,10 @@ netstandard2.1 + + 1.0.0 + Example + AeonLucid diff --git a/src/Impostor.Server/Plugins/PluginInformation.cs b/src/Impostor.Server/Plugins/PluginInformation.cs index 7da7671..d4ac7f6 100644 --- a/src/Impostor.Server/Plugins/PluginInformation.cs +++ b/src/Impostor.Server/Plugins/PluginInformation.cs @@ -14,6 +14,11 @@ namespace Impostor.Server.Plugins { _attribute = pluginType.GetCustomAttribute()!; + var assembly = pluginType.Assembly; + Name = _attribute.Name ?? assembly.GetCustomAttribute()?.Title ?? assembly.GetName().Name!; + Author = _attribute.Author ?? assembly.GetCustomAttribute()?.Company ?? string.Empty; + Version = _attribute.Version ?? assembly.GetCustomAttribute()?.InformationalVersion ?? assembly.GetName().Version!.ToString(); + Dependencies = pluginType.GetCustomAttributes().Select(t => new DependencyInformation(t)).ToList(); Startup = startup; PluginType = pluginType; @@ -21,11 +26,11 @@ namespace Impostor.Server.Plugins public string Id => _attribute.Id; - public string Name => _attribute.Name; + public string Name { get; } - public string Author => _attribute.Author; + public string Author { get; } - public string Version => _attribute.Version; + public string Version { get; } public List Dependencies { get; } -- 2.39.5