This commit is contained in:
2022-12-09 14:46:10 +02:00
parent 5bb13aa4a6
commit 0527d43dd2
12 changed files with 258 additions and 226 deletions

View File

@@ -4,8 +4,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using PluginManager.Others;
namespace PluginManager.Loaders;
internal class LoaderArgs : EventArgs
@@ -102,7 +100,7 @@ internal class Loader<T>
}
catch (Exception ex)
{
Functions.WriteErrFile(ex.ToString());
Logger.WriteErrFile(ex.ToString());
}

View File

@@ -5,7 +5,6 @@ using System.Linq;
using System.Reflection;
using PluginManager.Interfaces;
using PluginManager.Others;
namespace PluginManager.Loaders
{
@@ -47,7 +46,17 @@ namespace PluginManager.Loaders
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
foreach (var file in files)
{
Assembly.LoadFrom(file);
try
{
Assembly.LoadFrom(file);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
Logger.WriteLine("PluginName: " + new FileInfo(file).Name.Split('.')[0] + " not loaded");
continue;
}
if (FileLoaded != null)
{
var args = new LoaderArgs
@@ -116,7 +125,7 @@ namespace PluginManager.Loaders
}
catch (Exception ex)
{
Functions.WriteErrFile(ex.ToString());
Logger.WriteErrFile(ex.ToString());
return null;
}

View File

@@ -10,7 +10,6 @@ using Discord.WebSocket;
using PluginManager.Interfaces;
using PluginManager.Online;
using PluginManager.Online.Updates;
using PluginManager.Others;
namespace PluginManager.Loaders;
@@ -95,11 +94,11 @@ public class PluginLoader
Events = new List<DBEvent>();
SlashCommands = new List<DBSlashCommand>();
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
Logger.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
Logger.WriteLine("Loading plugins");
var loader = new LoaderV2("./Data/Plugins", "dll");
loader.FileLoaded += (args) => Functions.WriteLogFile($"{args.PluginName} file Loaded");
loader.FileLoaded += (args) => Logger.WriteLogFile($"{args.PluginName} file Loaded");
loader.PluginLoaded += Loader_PluginLoaded;
var res = loader.Load();
Events = res.Item1;