public void Initialize() { try { if (GlobalOptions.PluginsEnabled == false) { Log.Info("Plugins are globally disabled - exiting PluginControl.Initialize()"); return; } Log.Info("Plugins are globally enabled - entering PluginControl.Initialize()"); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); if (!Directory.Exists("Plugins")) { Log.Warn("Directory " + path + " not found. No Plugins will be available."); MyPlugins = new List <IPlugin>(); return; } myDirectoryCatalog = new DirectoryCatalog(path: path, searchPattern: "*.dll"); catalog = new AggregateCatalog(); Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath); catalog.Catalogs.Add(myDirectoryCatalog); container = new CompositionContainer(catalog); //Fill the imports of this object StartWatch(); container.ComposeParts(this); Log.Info("Plugins found: " + MyPlugins.Count()); Log.Info("Plugins active: " + MyActivePlugins.Count()); foreach (var plugin in MyActivePlugins) { try { Log.Info("Initializing Plugin " + plugin.ToString()); plugin.CustomInitialize(Program.MainForm); plugin.SetIsUnitTest(Utils.IsUnitTest); } catch (Exception e) { Log.Error(e); } } Log.Info("Initializing Plugins finished."); } catch (System.Security.SecurityException e) { string msg = "Well, the Plugin wanted to do something that requires Admin rights. Let's just ignore this: " + Environment.NewLine + Environment.NewLine; msg += e.ToString(); Log.Warn(e, msg); } catch (Exception e) { Log.Fatal(e); throw; } }
public void Initialize() { try { RegisterChummerProtocol(); if (GlobalOptions.PluginsEnabled == false) { Log.Info("Plugins are globally disabled - exiting PluginControl.Initialize()"); return; } Log.Info("Plugins are globally enabled - entering PluginControl.Initialize()"); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); if (!Directory.Exists(path)) { string msg = "Directory " + path + " not found. No Plugins will be available."; MyPlugins = new List <IPlugin>(); throw new ArgumentException(msg); } catalog = new AggregateCatalog(); var plugindirectories = Directory.GetDirectories(path); if (!plugindirectories.Any()) { throw new ArgumentException("No Plugin-Subdirectories in " + path + " !"); } foreach (var plugindir in plugindirectories) { Log.Trace("Searching in " + plugindir + " for plugin.txt or dlls containing the interface."); //search for a textfile, that tells me what dll to parse string infofile = Path.Combine(plugindir, "plugin.txt"); if (File.Exists(infofile)) { Log.Trace(infofile + " found: parsing it!"); System.IO.StreamReader file = new System.IO.StreamReader(infofile); string line; while ((line = file.ReadLine()) != null) { string plugindll = Path.Combine(plugindir, line); Log.Trace(infofile + " containes line: " + plugindll + " - trying to find it..."); if (File.Exists(plugindll)) { FileInfo fi = new FileInfo(plugindll); myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: fi.Name); Log.Info("Searching for plugin-interface in dll: " + plugindll); catalog.Catalogs.Add(myDirectoryCatalog); } else { Log.Warn("Could not find dll from " + infofile + ": " + plugindll); myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll"); myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll"); Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath); catalog.Catalogs.Add(myDirectoryCatalog); } } file.Close(); } else { myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll"); Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath); catalog.Catalogs.Add(myDirectoryCatalog); } } container = new CompositionContainer(catalog); //Fill the imports of this object StartWatch(); container.ComposeParts(this); Log.Info("Plugins found: " + MyPlugins.Count()); if (!MyPlugins.Any()) { throw new ArgumentException("No plugins found in " + path + "."); } Log.Info("Plugins active: " + MyActivePlugins.Count()); foreach (var plugin in MyActivePlugins) { try { Log.Info("Initializing Plugin " + plugin.ToString()); plugin.SetIsUnitTest(Utils.IsUnitTest); plugin.CustomInitialize(Program.MainForm); } catch (ApplicationException e) { throw; } catch (Exception e) { Log.Error(e); } } Log.Info("Initializing Plugins finished."); } catch (System.Security.SecurityException e) { string msg = "Well, the Plugin wanted to do something that requires Admin rights. Let's just ignore this: " + Environment.NewLine + Environment.NewLine; msg += e.ToString(); Log.Warn(e, msg); } catch (Exception e) { if (e is ApplicationException) { throw; } Log.Fatal(e); throw; } }