Finally fix module manager, so it now works as expected

This commit is contained in:
ChronosX88 2020-07-19 14:47:25 +04:00
parent 964223444a
commit 1133ca8a76
2 changed files with 15 additions and 11 deletions

View File

@ -30,6 +30,7 @@ namespace Zirconium.Core.Models
public BaseMessage(BaseMessage message, bool reply) public BaseMessage(BaseMessage message, bool reply)
{ {
Payload = new Dictionary<string, object>();
if (message != null) if (message != null)
{ {
ID = message.ID; ID = message.ID;

View File

@ -26,7 +26,8 @@ namespace Zirconium.Core.Modules
public void LoadModules(string folderPath, string[] enabledModules) public void LoadModules(string folderPath, string[] enabledModules)
{ {
var loaders = new List<PluginLoader>(); var loaders = new List<PluginLoader>();
if (folderPath == "") { if (folderPath == "")
{
Logging.Log.Warning("Plugins folder path is not specified!"); Logging.Log.Warning("Plugins folder path is not specified!");
return; return;
} }
@ -35,24 +36,26 @@ namespace Zirconium.Core.Modules
foreach (var dir in Directory.GetDirectories(folderPath)) foreach (var dir in Directory.GetDirectories(folderPath))
{ {
var dirName = Path.GetFileName(dir); var dirName = Path.GetFileName(dir);
if (enabledModules.Where(x => x == dirName).FirstOrDefault() == null) {
continue;
}
var pluginDll = Path.Combine(dir, dirName + ".dll"); var pluginDll = Path.Combine(dir, dirName + ".dll");
if (File.Exists(pluginDll)) if (File.Exists(pluginDll))
{ {
if (enabledModules.Where(x => x == pluginDll).FirstOrDefault() != null) Logging.Log.Debug("found plugin " + dirName);
{ Logging.Log.Debug("try to init plugin " + dirName);
var loader = PluginLoader.CreateFromAssemblyFile( var loader = PluginLoader.CreateFromAssemblyFile(
pluginDll, pluginDll,
sharedTypes: new[] { sharedTypes: new[] {
typeof(IModuleAPI), typeof(IModuleAPI),
typeof(IHostModuleAPI), typeof(IHostModuleAPI),
typeof(IC2SMessageHandler), typeof(IC2SMessageHandler),
typeof(ICoreEventHandler), typeof(ICoreEventHandler),
typeof(BaseMessage), typeof(BaseMessage),
typeof(CoreEvent) 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 // This assumes the implementation of IPlugin has a parameterless constructor
IModuleAPI module = (IModuleAPI)Activator.CreateInstance(pluginType); IModuleAPI module = (IModuleAPI)Activator.CreateInstance(pluginType);
Console.WriteLine($"Created module instance '{module.GetModuleUniqueName()}'."); Logging.Log.Debug($"Created module instance '{module.GetModuleUniqueName()}'.");
module.Initialize(_hostModuleAPI); module.Initialize(_hostModuleAPI);
_modules.Add(module); _modules.Add(module);
} }