Files
se-launcher/CringePlugins/Loader/PluginMetadata.cs
zznty 03e2eb9551
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m41s
Build / Build Nuget package (NuGet) (push) Successful in 2m0s
Build / Build Nuget package (SharedCringe) (push) Successful in 2m42s
Build / Build Launcher (push) Successful in 3m57s
Build / Build Nuget package (CringePlugins) (push) Successful in 7m55s
display source for installed plugins
2024-11-04 01:18:56 +07:00

25 lines
1.0 KiB
C#

using System.Reflection;
using dnlib.DotNet;
using NuGet.Versioning;
namespace CringePlugins.Loader;
public record PluginMetadata(string Name, NuGetVersion Version, string Source)
{
public static PluginMetadata ReadFromEntrypoint(string entrypointPath)
{
var assembly = AssemblyDef.Load(entrypointPath);
var titleAttribute = assembly.CustomAttributes.Find(typeof(AssemblyTitleAttribute).FullName);
var versionAttribute = assembly.CustomAttributes.Find(typeof(AssemblyVersionAttribute).FullName);
var fileVersionAttribute = assembly.CustomAttributes.Find(typeof(AssemblyFileVersionAttribute).FullName);
var name = titleAttribute?.ConstructorArguments[0].Value as UTF8String ?? assembly.Name;
if (!NuGetVersion.TryParse(
(versionAttribute ?? fileVersionAttribute)?.ConstructorArguments[0].Value as UTF8String ?? "0.0.0.0",
out var version))
version = new(0, 0, 0, 0);
return new(name, version, "Local");
}
}