57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Collections.Generic;
|
|
using VisionAsist.SDK;
|
|
using System.Linq;
|
|
|
|
namespace VisionAsist.Models;
|
|
|
|
public class Core
|
|
{
|
|
public class Modules
|
|
{
|
|
public string Name { get; set; }
|
|
public IModule Module { get; set; }
|
|
public string[] commands { get; set; }
|
|
}
|
|
|
|
public static List<Modules> modulelist = new();
|
|
static string Plugin = Path.Combine(AppContext.BaseDirectory, "Modules");
|
|
|
|
static Core()
|
|
{
|
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
|
Console.InputEncoding = System.Text.Encoding.UTF8;
|
|
|
|
if (!Directory.Exists(Plugin))
|
|
{
|
|
Directory.CreateDirectory(Plugin);
|
|
}
|
|
|
|
string[] folderNames = new DirectoryInfo(Plugin)
|
|
.GetDirectories()
|
|
.Select(d => d.Name)
|
|
.ToArray();
|
|
|
|
foreach (string folderName in folderNames)
|
|
{
|
|
string mpn = Path.Combine(Plugin, folderName, "Module.dll");
|
|
if (File.Exists(mpn))
|
|
{
|
|
Assembly assembly = Assembly.LoadFrom(mpn);
|
|
var type = assembly.GetTypes().FirstOrDefault(t =>
|
|
typeof(IModule).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
|
|
if (type != null)
|
|
{
|
|
var module = (IModule)Activator.CreateInstance(type)!;
|
|
modulelist.Add(new Modules { Name = module.Name, Module = module, commands = module.GetCommands() });
|
|
foreach (var cmd in module.GetCommands())
|
|
{
|
|
Console.WriteLine($"- {cmd}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |