From 1133ca8a76068f129a73953e34c1d8aff28ff4ad Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sun, 19 Jul 2020 14:47:25 +0400 Subject: [PATCH] Finally fix module manager, so it now works as expected --- src/Zirconium/Core/Models/BaseMessage.cs | 1 + src/Zirconium/Core/Modules/ModuleManager.cs | 25 ++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Zirconium/Core/Models/BaseMessage.cs b/src/Zirconium/Core/Models/BaseMessage.cs index 88f52fd..60066b4 100644 --- a/src/Zirconium/Core/Models/BaseMessage.cs +++ b/src/Zirconium/Core/Models/BaseMessage.cs @@ -30,6 +30,7 @@ namespace Zirconium.Core.Models public BaseMessage(BaseMessage message, bool reply) { + Payload = new Dictionary(); if (message != null) { ID = message.ID; diff --git a/src/Zirconium/Core/Modules/ModuleManager.cs b/src/Zirconium/Core/Modules/ModuleManager.cs index 640dc8e..2fd15ca 100644 --- a/src/Zirconium/Core/Modules/ModuleManager.cs +++ b/src/Zirconium/Core/Modules/ModuleManager.cs @@ -26,7 +26,8 @@ namespace Zirconium.Core.Modules public void LoadModules(string folderPath, string[] enabledModules) { var loaders = new List(); - if (folderPath == "") { + if (folderPath == "") + { Logging.Log.Warning("Plugins folder path is not specified!"); return; } @@ -35,24 +36,26 @@ namespace Zirconium.Core.Modules foreach (var dir in Directory.GetDirectories(folderPath)) { var dirName = Path.GetFileName(dir); + if (enabledModules.Where(x => x == dirName).FirstOrDefault() == null) { + continue; + } var pluginDll = Path.Combine(dir, dirName + ".dll"); if (File.Exists(pluginDll)) { - if (enabledModules.Where(x => x == pluginDll).FirstOrDefault() != null) - { - var loader = PluginLoader.CreateFromAssemblyFile( - pluginDll, - sharedTypes: new[] { + Logging.Log.Debug("found plugin " + dirName); + Logging.Log.Debug("try to init plugin " + dirName); + var loader = PluginLoader.CreateFromAssemblyFile( + pluginDll, + sharedTypes: new[] { typeof(IModuleAPI), typeof(IHostModuleAPI), typeof(IC2SMessageHandler), typeof(ICoreEventHandler), typeof(BaseMessage), typeof(CoreEvent) - } - ); - loaders.Add(loader); - } + } + ); + loaders.Add(loader); } } @@ -66,7 +69,7 @@ namespace Zirconium.Core.Modules { // This assumes the implementation of IPlugin has a parameterless constructor IModuleAPI module = (IModuleAPI)Activator.CreateInstance(pluginType); - Console.WriteLine($"Created module instance '{module.GetModuleUniqueName()}'."); + Logging.Log.Debug($"Created module instance '{module.GetModuleUniqueName()}'."); module.Initialize(_hostModuleAPI); _modules.Add(module); }