mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-09 12:11:04 +00:00
Enable loading plugins on server startup
This commit is contained in:
parent
394f9ab908
commit
5be00542b8
@ -24,6 +24,8 @@ namespace Zirconium.Core
|
|||||||
Router = new Router(this);
|
Router = new Router(this);
|
||||||
HostModuleAPI = new HostModuleAPI(this, Router);
|
HostModuleAPI = new HostModuleAPI(this, Router);
|
||||||
AuthManager = new AuthManager(this);
|
AuthManager = new AuthManager(this);
|
||||||
|
ModuleManager = new ModuleManager(HostModuleAPI);
|
||||||
|
ModuleManager.LoadModules(config.PluginsDirPath, config.EnabledPlugins);
|
||||||
Log.Info("Zirconium is initialized successfully");
|
Log.Info("Zirconium is initialized successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,13 @@ namespace Zirconium.Core.Modules
|
|||||||
_moduleMutex = new Mutex();
|
_moduleMutex = new Mutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadModules(string folderPath) {
|
public void LoadModules(string folderPath, string[] enabledModules)
|
||||||
|
{
|
||||||
var loaders = new List<PluginLoader>();
|
var loaders = new List<PluginLoader>();
|
||||||
|
if (folderPath == "") {
|
||||||
|
Logging.Log.Warning("Plugins folder path is not specified!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// create module loaders
|
// create module loaders
|
||||||
foreach (var dir in Directory.GetDirectories(folderPath))
|
foreach (var dir in Directory.GetDirectories(folderPath))
|
||||||
@ -32,6 +37,8 @@ namespace Zirconium.Core.Modules
|
|||||||
var dirName = Path.GetFileName(dir);
|
var dirName = Path.GetFileName(dir);
|
||||||
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)
|
||||||
{
|
{
|
||||||
var loader = PluginLoader.CreateFromAssemblyFile(
|
var loader = PluginLoader.CreateFromAssemblyFile(
|
||||||
pluginDll,
|
pluginDll,
|
||||||
@ -47,6 +54,7 @@ namespace Zirconium.Core.Modules
|
|||||||
loaders.Add(loader);
|
loaders.Add(loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create an instance of module types
|
// Create an instance of module types
|
||||||
foreach (var loader in loaders)
|
foreach (var loader in loaders)
|
||||||
|
Loading…
Reference in New Issue
Block a user