/// <summary> /// Loads all the plugins from the directory where AWB resides /// </summary> /// <param name="awb">IAutoWikiBrowser instance of AWB</param> /// <param name="Plugins">Array of Plugin Names</param> /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param> internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup) { try { foreach (string Plugin in Plugins) { if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll") || Plugin.EndsWith("WikiFunctions.dll")) { continue; } Assembly asm = null; try { asm = Assembly.LoadFile(Plugin); } catch { } if (asm != null) { Type[] types = asm.GetTypes(); foreach (Type t in types) { if (t.GetInterface("IAWBPlugin") != null) { IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t); Items.Add(plugin.Name, plugin); InitialisePlugin(plugin, awb); if (afterStartup) { UsageStats.AddedPlugin(plugin); } } else if (t.GetInterface("IListMakerPlugin") != null) { IListMakerPlugin plugin = (IListMakerPlugin)Activator.CreateInstance(t); WikiFunctions.Controls.Lists.ListMaker.AddProvider(plugin); if (afterStartup) { UsageStats.AddedPlugin(plugin); } } } } } } catch (Exception ex) { #if debug ErrorHandler.Handle(ex); #else MessageBox.Show(ex.Message, "Problem loading plugins"); #endif } }
internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup) { try { foreach (string Plugin in Plugins) { if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll")) { continue; } Assembly asm = null; try { asm = Assembly.LoadFile(Plugin); } catch { } if (asm != null) { Type[] types = asm.GetTypes(); foreach (Type t in types) { if (t.GetInterface("IAWBPlugin") != null) { IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t); Items.Add(plugin.Name, plugin); if (plugin.Name == "Kingbotk Plugin" && t.Assembly.GetName().Version.Major < 2) { MessageBox.Show("You are using an out of date version of the Kingbotk Plugin. Please upgrade.", "Kingbotk Plugin", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } InitialisePlugin(plugin, awb); if (afterStartup) { UsageStats.AddedPlugin(plugin); } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Problem loading plugins"); } }
/// <summary> /// Loads all the plugins from the directory where AWB resides /// </summary> /// <param name="awb">IAutoWikiBrowser instance of AWB</param> /// <param name="plugins">Array of Plugin Names</param> /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param> internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup) { try { foreach (string plugin in plugins) { if (plugin.EndsWith("DotNetWikiBot.dll") || plugin.EndsWith("Diff.dll") || plugin.EndsWith("WikiFunctions.dll")) { continue; } Assembly asm = null; try { asm = Assembly.LoadFile(plugin); } catch { } if (asm == null) { continue; } try { foreach (Type t in asm.GetTypes()) { if (t.GetInterface("IAWBPlugin") != null) { IAWBPlugin awbPlugin = (IAWBPlugin)Activator.CreateInstance(t); if (AWBPlugins.ContainsKey(awbPlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + awbPlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB Plugin"); break; } InitialisePlugin(awbPlugin, awb); AWBPlugins.Add(awbPlugin.Name, awbPlugin); if (afterStartup) { UsageStats.AddedPlugin(awbPlugin); } } else if (t.GetInterface("IAWBBasePlugin") != null) //IAWBBasePlugin needs to be checked after IAWBPlugin, as IAWBPlugin extends IAWBBasePlugin { IAWBBasePlugin awbBasePlugin = (IAWBBasePlugin)Activator.CreateInstance(t); if (AWBBasePlugins.ContainsKey(awbBasePlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + awbBasePlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB Base Plugin"); break; } InitialisePlugin(awbBasePlugin, awb); AWBBasePlugins.Add(awbBasePlugin.Name, awbBasePlugin); if (afterStartup) { UsageStats.AddedPlugin(awbBasePlugin); } } else if (t.GetInterface("IListMakerPlugin") != null) { IListMakerPlugin listMakerPlugin = (IListMakerPlugin)Activator.CreateInstance(t); if (ListMakerPlugins.ContainsKey(listMakerPlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + listMakerPlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB ListMaker Plugin"); break; } WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin); ListMakerPlugins.Add(listMakerPlugin.Name, listMakerPlugin); if (afterStartup) { UsageStats.AddedPlugin(listMakerPlugin); } } } } catch (ReflectionTypeLoadException) { PluginObsolete(plugin, asm.GetName().Version.ToString()); } catch (MissingMemberException) { PluginObsolete(plugin, asm.GetName().Version.ToString()); } catch (Exception ex) { ErrorHandler.Handle(ex); } } } catch (Exception ex) { #if debug ErrorHandler.Handle(ex); #else MessageBox.Show(ex.Message, "Problem loading plugins"); #endif } }
/// <summary> /// Loads all the plugins from the directory where AWB resides /// </summary> /// <param name="awb">IAutoWikiBrowser instance of AWB</param> /// <param name="plugins">Array of Plugin Names</param> /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param> internal static void LoadPlugins(IAutoWikiBrowser awb, string[] plugins, bool afterStartup) { try { // ignore known DLL files that aren't plugins such as WikiFunctions.dll plugins = plugins.Where(p => !NotPlugins.Any(n => p.EndsWith(n + ".dll"))).ToArray(); foreach (string plugin in plugins) { Assembly asm; try { asm = Assembly.LoadFile(plugin); } catch (NotSupportedException) { // https://phabricator.wikimedia.org/T208787 // Windows is probably blocking loading of the plugin for "Security" reasons // NotSupportedException // On the file, right click, properties, unblock (check or press button), apply, ok. // Need to put it in a message box or something // Else, maybe we want to try https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd409252(v=vs.100) continue; } #if DEBUG catch (Exception ex) { Tools.WriteDebug(plugin, ex.ToString()); continue; } #else catch (Exception) { continue; } #endif if (asm == null) { continue; } try { foreach (Type t in asm.GetTypes()) { if (t.GetInterface("IAWBPlugin") != null) { IAWBPlugin awbPlugin = (IAWBPlugin)Activator.CreateInstance(t); if (AWBPlugins.ContainsKey(awbPlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + awbPlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB Plugin"); break; } InitialisePlugin(awbPlugin, awb); AWBPlugins.Add(awbPlugin.Name, awbPlugin); if (afterStartup) { UsageStats.AddedPlugin(awbPlugin); } } else if (t.GetInterface("IAWBBasePlugin") != null) //IAWBBasePlugin needs to be checked after IAWBPlugin, as IAWBPlugin extends IAWBBasePlugin { IAWBBasePlugin awbBasePlugin = (IAWBBasePlugin)Activator.CreateInstance(t); if (AWBBasePlugins.ContainsKey(awbBasePlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + awbBasePlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB Base Plugin"); break; } InitialisePlugin(awbBasePlugin, awb); AWBBasePlugins.Add(awbBasePlugin.Name, awbBasePlugin); if (afterStartup) { UsageStats.AddedPlugin(awbBasePlugin); } } else if (t.GetInterface("IListMakerPlugin") != null) { IListMakerPlugin listMakerPlugin = (IListMakerPlugin)Activator.CreateInstance(t); if (ListMakerPlugins.ContainsKey(listMakerPlugin.Name)) { MessageBox.Show( "A plugin with the name \"" + listMakerPlugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.\r\nThis was loaded from the plugin file \"" + plugin + "\".", "Duplicate AWB ListMaker Plugin"); break; } WikiFunctions.Controls.Lists.ListMaker.AddProvider(listMakerPlugin); ListMakerPlugins.Add(listMakerPlugin.Name, listMakerPlugin); if (afterStartup) { UsageStats.AddedPlugin(listMakerPlugin); } } } } catch (ReflectionTypeLoadException) { PluginObsolete(plugin, asm.GetName().Version.ToString()); } catch (MissingMemberException) { PluginObsolete(plugin, asm.GetName().Version.ToString()); } catch (Exception ex) { ErrorHandler.HandleException(ex); } } } catch (Exception ex) { #if DEBUG ErrorHandler.HandleException(ex); #else MessageBox.Show(ex.Message, "Problem loading plugins"); #endif } }
/// <summary> /// Loads all the plugins from the directory where AWB resides /// </summary> /// <param name="awb">IAutoWikiBrowser instance of AWB</param> /// <param name="Plugins">Array of Plugin Names</param> /// <param name="afterStartup">Whether the plugin(s) are being loaded post-startup</param> internal static void LoadPlugins(IAutoWikiBrowser awb, string[] Plugins, bool afterStartup) { try { foreach (string Plugin in Plugins) { if (Plugin.EndsWith("DotNetWikiBot.dll") || Plugin.EndsWith("Diff.dll") || Plugin.EndsWith("WikiFunctions.dll")) { continue; } Assembly asm = null; try { asm = Assembly.LoadFile(Plugin); } catch { } if (asm == null) { continue; } try { foreach (Type t in asm.GetTypes()) { if (t.GetInterface("IAWBPlugin") != null) { IAWBPlugin plugin = (IAWBPlugin)Activator.CreateInstance(t); if (Items.ContainsKey(plugin.Name)) { MessageBox.Show("A plugin with the name \"" + plugin.Name + "\", has already been added.\r\nPlease remove old duplicates from your AutoWikiBrowser Directory, and restart AWB.", "Duplicate AWB Plugin"); continue; } InitialisePlugin(plugin, awb); Items.Add(plugin.Name, plugin); if (afterStartup) { UsageStats.AddedPlugin(plugin); } } else if (t.GetInterface("IListMakerPlugin") != null) { IListMakerPlugin plugin = (IListMakerPlugin)Activator.CreateInstance(t); WikiFunctions.Controls.Lists.ListMaker.AddProvider(plugin); if (afterStartup) { UsageStats.AddedPlugin(plugin); } } } } catch (MissingMemberException) { PluginObsolete(Plugin); } catch (Exception ex) { ErrorHandler.Handle(ex); } } } catch (Exception ex) { #if debug ErrorHandler.Handle(ex); #else MessageBox.Show(ex.Message, "Problem loading plugins"); #endif } }