]> git.deb.at Git - rhonda/impostor.git/commitdiff
Make it possible to read plugin information from csproj attributes
authorjs6pak <kubastaron@hotmail.com>
Tue, 13 Apr 2021 21:13:52 +0000 (23:13 +0200)
committerjs6pak <kubastaron@hotmail.com>
Tue, 13 Apr 2021 21:13:52 +0000 (23:13 +0200)
src/Impostor.Api/Plugins/ImpostorPluginAttribute.cs
src/Impostor.Plugins.Debugger/DebugPlugin.cs
src/Impostor.Plugins.Debugger/Impostor.Plugins.Debugger.csproj
src/Impostor.Plugins.Example/ExamplePlugin.cs
src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj
src/Impostor.Server/Plugins/PluginInformation.cs

index c921f9f1717db58b159599b0f24081b11ac25d3a..1281261e3090fcdc4f3286778c8f6165c5e9c212 100644 (file)
@@ -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; }
     }
 }
index c22442c8f3a6191df284bf557b7f0cf27b639b01..970d0b9415aee3383cfac2ac447f36e2db1b58f0 100644 (file)
@@ -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
     {
     }
index 8fce4f8861e95d444d341317be2746001234cbf9..2aa762518a27dfe374071b659e19060a39dd98ae 100644 (file)
@@ -3,6 +3,10 @@
   <PropertyGroup>
     <TargetFramework>net5.0</TargetFramework>
     <OutputType>Library</OutputType>
+
+    <Version>1.0.0</Version>
+    <AssemblyTitle>Debugger</AssemblyTitle>
+    <Authors>Gerard</Authors>
   </PropertyGroup>
 
   <ItemGroup>
index 7d88079b9c93684d98cd619548ff160545162427..07f4d86f768277512b992139901ca77a282a3143 100644 (file)
@@ -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<ExamplePlugin> _logger;
index f0ebef3dcff96b499ab6a20192111d2517c12b89..2cfa53b0045fe015ae37992151b177a22d27be80 100644 (file)
@@ -2,6 +2,10 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.1</TargetFramework>
+
+    <Version>1.0.0</Version>
+    <AssemblyTitle>Example</AssemblyTitle>
+    <Authors>AeonLucid</Authors>
   </PropertyGroup>
 
   <ItemGroup>
index 7da76716803400e2b01bd7b4134c07ea6c5f13bf..d4ac7f64930aca2fa3ebc2d4fea05c4ab8870e1c 100644 (file)
@@ -14,6 +14,11 @@ namespace Impostor.Server.Plugins
         {
             _attribute = pluginType.GetCustomAttribute<ImpostorPluginAttribute>()!;
 
+            var assembly = pluginType.Assembly;
+            Name = _attribute.Name ?? assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title ?? assembly.GetName().Name!;
+            Author = _attribute.Author ?? assembly.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company ?? string.Empty;
+            Version = _attribute.Version ?? assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? assembly.GetName().Version!.ToString();
+
             Dependencies = pluginType.GetCustomAttributes<ImpostorDependencyAttribute>().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<DependencyInformation> Dependencies { get; }