public static void PluginObsolete(IAWBPlugin plugin)
            {
                if (!FailedPlugins.Contains(plugin))
                    FailedPlugins.Add(plugin);

                PluginObsolete(plugin.GetType().Assembly.Location);
            }
 void IAutoWikiBrowserCommands.SkipPage(IAWBPlugin sender, string reason)
 {
     ((IAutoWikiBrowserCommands)this).SkipPage(sender.Name, reason);
 }
 void IAutoWikiBrowserCommands.Start(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).Start(sender.Name);
 }
 void IAutoWikiBrowserCommands.GetDiff(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).GetDiff(sender.Name);
 }
 void IAutoWikiBrowserCommands.GetPreview(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).GetPreview(sender.Name);
 }
Example #6
0
 void IAutoWikiBrowserCommands.GetDiff(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).GetDiff(sender.Name);
 }
 private static void InitialisePlugin(IAWBPlugin plugin, IAutoWikiBrowser awb)
 {
     try
     {
         plugin.Initialise(awb);
     }
     catch (Exception ex)
     {
         ErrorHandler.Handle(ex);
     }
 }
Example #8
0
 /// <summary>
 /// Passes a reference of the main form to the plugin for initialisation
 /// </summary>
 /// <param name="plugin">IAWBPlugin to initialise</param>
 /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
 private static void InitialisePlugin(IAWBPlugin plugin, IAutoWikiBrowser awb)
 {
     plugin.Initialise(awb);
 }
Example #9
0
 /// <summary>
 /// Call when a plugin was added *after* application startup
 /// </summary>
 internal static void AddedPlugin(IAWBPlugin plugin)
 {
     // if we've already written to the remote database, we'll need to add details of this plugin when we next contact it, otherwise do nothing
     if (EstablishedContact) NewAWBPlugins.Add(plugin);
 }
Example #10
0
        /// <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.
                        // Maybe we want to try https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd409252(v=vs.100)

                        FailedAssemblies.Add(plugin);
                        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
            }
        }
Example #11
0
            /// <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("IListMakerPlugin") != null)
                                {
                                    IListMakerPlugin listMakerPlugin = (IListMakerPlugin)Activator.CreateInstance(t);

                                    if (LMPlugins.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);

                                    LMPlugins.Add(listMakerPlugin.Name, listMakerPlugin);

                                    if (afterStartup)
                                    {
                                        UsageStats.AddedPlugin(listMakerPlugin);
                                    }
                                }
                            }
                        }
                        catch (ReflectionTypeLoadException)
                        {
                            PluginObsolete(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
                }
            }
Example #12
0
 /// <summary>
 /// Gets the Version string of a IAWBPlugin
 /// </summary>
 /// <param name="plugin">IAWBPlugin to get Version of</param>
 /// <returns>Version String</returns>
 internal static string GetPluginVersionString(IAWBPlugin plugin)
 {
     return(Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString());
 }
Example #13
0
 void IAutoWikiBrowserCommands.Save(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).Save(sender.Name);
 }
Example #14
0
 void IAutoWikiBrowserCommands.GetPreview(IAWBPlugin sender)
 {
     ((IAutoWikiBrowserCommands)this).GetPreview(sender.Name);
 }
 /// <summary>
 /// Passes a reference of the main form to the plugin for initialisation
 /// </summary>
 /// <param name="plugin">IAWBPlugin to initialise</param>
 /// <param name="awb">IAutoWikiBrowser instance of AWB</param>
 private static void InitialisePlugin(IAWBPlugin plugin, IAutoWikiBrowser awb)
 {
     plugin.Initialise(awb);
 }
Example #16
0
            public static void PluginObsolete(IAWBPlugin plugin)
            {
                if (!FailedPlugins.Contains(plugin))
                    FailedPlugins.Add(plugin);

                PluginObsolete(plugin.GetType().Assembly.Location, plugin.GetType().Assembly.GetName().Version.ToString());
            }
 /// <summary>
 /// Gets the Version string of a IAWBPlugin
 /// </summary>
 /// <param name="plugin">IAWBPlugin to get Version of</param>
 /// <returns>Version String</returns>
 internal static string GetPluginVersionString(IAWBPlugin plugin)
 { return Assembly.GetAssembly(plugin.GetType()).GetName().Version.ToString(); }
Example #18
0
 void IAutoWikiBrowserCommands.SkipPage(IAWBPlugin sender, string reason)
 {
     ((IAutoWikiBrowserCommands)this).SkipPage(sender.Name, reason);
 }