/// <summary> /// Call when a plugin was added *after* application startup /// </summary> internal static void AddedPlugin(IAWBBasePlugin plugin) { if (EstablishedContact) { NewAWBBasePlugins.Add(plugin); } }
/// <summary> /// Gets the Version string of a IAWBBasePlugin /// </summary> /// <param name="plugin">IAWBBasePlugin to get Version of</param> /// <returns>Version String</returns> internal static string GetPluginVersionString(IAWBBasePlugin plugin) { return(Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString()); }
/// <summary> /// Passes a reference of the main form to the plugin for initialisation /// </summary> /// <param name="plugin">IAWBBasePlugin (Or IAWBPlugin) to initialise</param> /// <param name="awb">IAutoWikiBrowser instance of AWB</param> private static void InitialisePlugin(IAWBBasePlugin plugin, IAutoWikiBrowser awb) { plugin.Initialise(awb); }
/// <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> /// Gets the Version string of a IAWBBasePlugin /// </summary> /// <param name="plugin">IAWBBasePlugin to get Version of</param> /// <returns>Version String</returns> internal static string GetPluginVersionString(IAWBBasePlugin plugin) { return Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString(); }
/// <summary> /// Call when a plugin was added *after* application startup /// </summary> internal static void AddedPlugin(IAWBBasePlugin plugin) { if (EstablishedContact) NewAWBBasePlugins.Add(plugin); }
/// <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 } }