private void Initialize()
{
try {
if ( !Directory.Exists( "plugins" ) ) {
Directory.CreateDirectory( "plugins" );
}
} catch ( Exception ex ) {
Logger.Log( LogType.Error, "PluginManager.Initialize: " + ex );
return;
}
// Load plugins
String[] plugins = Directory.GetFiles( "plugins", "*.dll" );
if ( plugins.Length == 0 ) {
Logger.Log( LogType.ConsoleOutput, "PluginManager: No plugins found" );
return;
} else {
Logger.Log( LogType.ConsoleOutput, "PluginManager: Loading " + plugins.Length + " plugins" );
foreach ( String plugin in plugins ) {
try {
String args = plugin.Substring( plugin.LastIndexOf("\\", System.StringComparison.Ordinal) + 1, plugin.IndexOf(".dll", System.StringComparison.Ordinal) - plugin.LastIndexOf("\\", System.StringComparison.Ordinal) - 1 );
Assembly assembly = Assembly.LoadFile( Path.GetFullPath( plugin ) );
if ( assembly != null )
{
Type pluginType = assembly.GetType( args + ".Init" );
if ( pluginType != null ) {
Plugins.Add( ( Plugin )Activator.CreateInstance( pluginType ) );
}
}
} catch ( Exception ex ) {
Logger.Log( LogType.Error, "PluginManager: Unable to load plugin at location " + plugin + ": " + ex );
}
}
}
LoadPlugins();
}