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)
{
Payload = new Dictionary<string, object>();
if (message != null)
{
ID = message.ID;

View File

@ -26,7 +26,8 @@ namespace Zirconium.Core.Modules
public void LoadModules(string folderPath, string[] enabledModules)
{
var loaders = new List<PluginLoader>();
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);
}