mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
5979fe5eef
* BTCPay Extensions Part 2 This PR cleans up the extension system a bit in that: * It renames the test extension to a more uniform name * Allows yo uto have system extensions, which are extensions but bundled by default with the release (and cannot be removed) * Adds a tool to help you generate an extension package from a csproj * Refactors the UI extension points to a view component * Moves some more interfaces to the Abstractions csproj * Rename to plugins
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using BTCPayServer.Contracts;
|
|
|
|
namespace BTCPayServer.PluginPacker
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var directory = args[0];
|
|
var name = args[1];
|
|
var outputDir = args[2];
|
|
var outputFile = Path.Combine(outputDir, name);
|
|
var rootDLLPath = Path.Combine(directory, name +".dll");
|
|
if (!File.Exists(rootDLLPath) )
|
|
{
|
|
throw new Exception($"{rootDLLPath} could not be found");
|
|
}
|
|
|
|
var assembly = Assembly.LoadFrom(rootDLLPath);
|
|
var extension = GetAllExtensionTypesFromAssembly(assembly).FirstOrDefault();
|
|
if (extension is null)
|
|
{
|
|
throw new Exception($"{rootDLLPath} is not a valid plugin");
|
|
}
|
|
|
|
var loadedPlugin = (IBTCPayServerPlugin)Activator.CreateInstance(extension);
|
|
var json = JsonSerializer.Serialize(loadedPlugin);
|
|
Directory.CreateDirectory(outputDir);
|
|
if (File.Exists(outputFile + ".btcpay"))
|
|
{
|
|
File.Delete(outputFile + ".btcpay");
|
|
}
|
|
ZipFile.CreateFromDirectory(directory, outputFile + ".btcpay", CompressionLevel.Optimal, false);
|
|
File.WriteAllText(outputFile + ".btcpay.json", json);
|
|
}
|
|
|
|
private static Type[] GetAllExtensionTypesFromAssembly(Assembly assembly)
|
|
{
|
|
return assembly.GetTypes().Where(type =>
|
|
typeof(IBTCPayServerPlugin).IsAssignableFrom(type) &&
|
|
!type.IsAbstract).ToArray();
|
|
}
|
|
}
|
|
}
|