Ejemplo n.º 1
0
 public void ConfigureSelectedItem(ListView listview)
 {
     if (listview.SelectedItems.Count > 0)
     {
         PluginAttribute pluginAttribute = (PluginAttribute)listview.SelectedItems[0].Tag;
         if (pluginAttribute != null)
         {
             IGreenshotPlugin plugin = plugins[pluginAttribute];
             plugin.Configure();
         }
     }
 }
Ejemplo n.º 2
0
        private static List <IProcessor> GetPluginsProcessors()
        {
            List <IProcessor> processors = new List <IProcessor>();

            foreach (PluginAttribute pluginAttribute in PluginHelper.Instance.Plugins.Keys)
            {
                IGreenshotPlugin plugin = PluginHelper.Instance.Plugins[pluginAttribute];
                try {
                    var procs = plugin.Processors();
                    if (procs != null)
                    {
                        processors.AddRange(procs);
                    }
                } catch (Exception ex) {
                    LOG.ErrorFormat("Couldn't get processors from the plugin {0}", pluginAttribute.Name);
                    LOG.Error(ex);
                }
            }
            processors.Sort();
            return(processors);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to get all the destinations from the plugins
        /// </summary>
        /// <returns>List<IDestination></returns>
        private static List <IDestination> GetPluginDestinations()
        {
            List <IDestination> destinations = new List <IDestination>();

            foreach (PluginAttribute pluginAttribute in PluginHelper.Instance.Plugins.Keys)
            {
                IGreenshotPlugin plugin = PluginHelper.Instance.Plugins[pluginAttribute];
                try {
                    foreach (IDestination destination in plugin.Destinations())
                    {
                        if (coreConfig.ExcludeDestinations == null || !coreConfig.ExcludeDestinations.Contains(destination.Designation))
                        {
                            destinations.Add(destination);
                        }
                    }
                } catch (Exception ex) {
                    LOG.ErrorFormat("Couldn't get destinations from the plugin {0}", pluginAttribute.Name);
                    LOG.Error(ex);
                }
            }
            destinations.Sort();
            return(destinations);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Load the plugins
        /// </summary>
        public void LoadPlugins()
        {
            List <string> pluginFiles = new List <string>();

            if (IniConfig.IsPortable)
            {
                findPluginsOnPath(pluginFiles, PafPath);
            }
            else
            {
                findPluginsOnPath(pluginFiles, PluginPath);
                findPluginsOnPath(pluginFiles, ApplicationPath);
            }

            Dictionary <string, PluginAttribute> tmpAttributes = new Dictionary <string, PluginAttribute>();
            Dictionary <string, Assembly>        tmpAssemblies = new Dictionary <string, Assembly>();

            // Loop over the list of available files and get the Plugin Attributes
            foreach (string pluginFile in pluginFiles)
            {
                //LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile);
                try {
                    Assembly          assembly         = Assembly.LoadFrom(pluginFile);
                    PluginAttribute[] pluginAttributes = assembly.GetCustomAttributes(typeof(PluginAttribute), false) as PluginAttribute[];
                    if (pluginAttributes.Length > 0)
                    {
                        PluginAttribute pluginAttribute = pluginAttributes[0];

                        if (string.IsNullOrEmpty(pluginAttribute.Name))
                        {
                            AssemblyProductAttribute[] assemblyProductAttributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false) as AssemblyProductAttribute[];
                            if (assemblyProductAttributes.Length > 0)
                            {
                                pluginAttribute.Name = assemblyProductAttributes[0].Product;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if (string.IsNullOrEmpty(pluginAttribute.CreatedBy))
                        {
                            AssemblyCompanyAttribute[] assemblyCompanyAttributes = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false) as AssemblyCompanyAttribute[];
                            if (assemblyCompanyAttributes.Length > 0)
                            {
                                pluginAttribute.CreatedBy = assemblyCompanyAttributes[0].Company;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        pluginAttribute.Version = assembly.GetName().Version.ToString();
                        pluginAttribute.DllFile = pluginFile;

                        // check if this plugin is already available
                        PluginAttribute checkPluginAttribute = null;
                        if (tmpAttributes.ContainsKey(pluginAttribute.Name))
                        {
                            checkPluginAttribute = tmpAttributes[pluginAttribute.Name];
                        }

                        if (checkPluginAttribute != null)
                        {
                            Log.WarnFormat("Duplicate plugin {0} found", pluginAttribute.Name);
                            if (isNewer(pluginAttribute.Version, checkPluginAttribute.Version))
                            {
                                // Found is newer
                                tmpAttributes[pluginAttribute.Name] = pluginAttribute;
                                tmpAssemblies[pluginAttribute.Name] = assembly;
                                Log.InfoFormat("Loading the newer plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            }
                            else
                            {
                                Log.InfoFormat("Skipping (as the duplicate is newer or same version) the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            }
                            continue;
                        }
                        if (CoreConfig.ExcludePlugins != null && CoreConfig.ExcludePlugins.Contains(pluginAttribute.Name))
                        {
                            Log.WarnFormat("Exclude list: {0}", CoreConfig.ExcludePlugins.ToArray());
                            Log.WarnFormat("Skipping the excluded plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            continue;
                        }
                        if (CoreConfig.IncludePlugins != null && CoreConfig.IncludePlugins.Count > 0 && !CoreConfig.IncludePlugins.Contains(pluginAttribute.Name))
                        {
                            // Whitelist is set
                            Log.WarnFormat("Include list: {0}", CoreConfig.IncludePlugins.ToArray());
                            Log.WarnFormat("Skipping the not included plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            continue;
                        }
                        Log.InfoFormat("Loading the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                        tmpAttributes[pluginAttribute.Name] = pluginAttribute;
                        tmpAssemblies[pluginAttribute.Name] = assembly;
                    }
                    else
                    {
                        Log.ErrorFormat("Can't find the needed Plugin Attribute ({0}) in the assembly of the file \"{1}\", skipping this file.", typeof(PluginAttribute), pluginFile);
                    }
                } catch (Exception e) {
                    Log.Warn("Can't load file: " + pluginFile, e);
                }
            }
            foreach (string pluginName in tmpAttributes.Keys)
            {
                try {
                    PluginAttribute pluginAttribute = tmpAttributes[pluginName];
                    Assembly        assembly        = tmpAssemblies[pluginName];
                    Type            entryType       = assembly.GetType(pluginAttribute.EntryType);
                    if (entryType == null)
                    {
                        Log.ErrorFormat("Can't find the in the PluginAttribute referenced type {0} in \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile);
                        continue;
                    }
                    try {
                        IGreenshotPlugin plugin = (IGreenshotPlugin)Activator.CreateInstance(entryType);
                        if (plugin != null)
                        {
                            if (plugin.Initialize(this, pluginAttribute))
                            {
                                plugins.Add(pluginAttribute, plugin);
                            }
                            else
                            {
                                Log.InfoFormat("Plugin {0} not initialized!", pluginAttribute.Name);
                            }
                        }
                        else
                        {
                            Log.ErrorFormat("Can't create an instance of the in the PluginAttribute referenced type {0} from \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile);
                        }
                    } catch (Exception e) {
                        Log.Error("Can't load Plugin: " + pluginAttribute.Name, e);
                    }
                } catch (Exception e) {
                    Log.Error("Can't load Plugin: " + pluginName, e);
                }
            }
        }
Ejemplo n.º 5
0
        public void LoadPlugins(MainForm mainForm, ICaptureHost captureHost)
        {
            // Copy ContextMenu
            mainMenu = mainForm.MainMenu;

            List <string> pluginFiles = new List <string>();

            if (IniConfig.IsPortable && Directory.Exists(pafPath))
            {
                foreach (string pluginFile in Directory.GetFiles(pafPath, "*.gsp", SearchOption.AllDirectories))
                {
                    pluginFiles.Add(pluginFile);
                }
            }
            else
            {
                if (Directory.Exists(pluginPath))
                {
                    foreach (string pluginFile in Directory.GetFiles(pluginPath, "*.gsp", SearchOption.AllDirectories))
                    {
                        pluginFiles.Add(pluginFile);
                    }
                }

                if (Directory.Exists(applicationPath))
                {
                    foreach (string pluginFile in Directory.GetFiles(applicationPath, "*.gsp", SearchOption.AllDirectories))
                    {
                        pluginFiles.Add(pluginFile);
                    }
                }
            }

            Dictionary <string, PluginAttribute> tmpAttributes = new Dictionary <string, PluginAttribute>();
            Dictionary <string, Assembly>        tmpAssemblies = new Dictionary <string, Assembly>();

            // Loop over the list of available files and get the Plugin Attributes
            foreach (string pluginFile in pluginFiles)
            {
                LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile);
                try {
                    Assembly          assembly         = Assembly.LoadFile(pluginFile);
                    PluginAttribute[] pluginAttributes = assembly.GetCustomAttributes(typeof(PluginAttribute), false) as PluginAttribute[];
                    if (pluginAttributes.Length > 0)
                    {
                        PluginAttribute pluginAttribute = pluginAttributes[0];

                        AssemblyProductAttribute[] assemblyProductAttributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false) as AssemblyProductAttribute[];
                        if (assemblyProductAttributes.Length > 0)
                        {
                            pluginAttribute.Name = assemblyProductAttributes[0].Product;
                        }
                        else
                        {
                            continue;
                        }
                        pluginAttribute.Version = assembly.GetName().Version.ToString();
                        pluginAttribute.DllFile = pluginFile;

                        // check if this plugin is already available
                        PluginAttribute checkPluginAttribute = null;
                        try {
                            checkPluginAttribute = tmpAttributes[pluginAttribute.Name];
                        } catch {
                        }

                        if (checkPluginAttribute != null)
                        {
                            LOG.WarnFormat("Duplicate plugin {0} found", pluginAttribute.Name);
                            if (isNewer(pluginAttribute.Version, checkPluginAttribute.Version))
                            {
                                // Found is newer
                                tmpAttributes[pluginAttribute.Name] = pluginAttribute;
                                tmpAssemblies[pluginAttribute.Name] = assembly;
                                LOG.InfoFormat("Loading the newer plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            }
                            else
                            {
                                LOG.InfoFormat("Skipping (as the duplicate is newer or same version) the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            }
                            continue;
                        }
                        else
                        {
                            if (conf.ExcludePlugins != null && conf.ExcludePlugins.Contains(pluginAttribute.Name))
                            {
                                LOG.WarnFormat("Exclude list: {0}", conf.ExcludePlugins.ToArray());
                                LOG.WarnFormat("Skipping the excluded plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                                continue;
                            }
                            if (conf.IncludePlugins != null && conf.IncludePlugins.Count > 0 && !conf.IncludePlugins.Contains(pluginAttribute.Name))
                            {
                                // Whitelist is set
                                LOG.WarnFormat("Include list: {0}", conf.IncludePlugins.ToArray());
                                LOG.WarnFormat("Skipping the not included plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                                continue;
                            }
                            LOG.InfoFormat("Loading the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile);
                            tmpAttributes[pluginAttribute.Name] = pluginAttribute;
                            tmpAssemblies[pluginAttribute.Name] = assembly;
                        }
                    }
                    else
                    {
                        LOG.ErrorFormat("Can't find the needed Plugin Attribute ({0}) in the assembly of the file \"{1}\", skipping this file.", typeof(PluginAttribute), pluginFile);
                    }
                } catch (Exception e) {
                    LOG.Warn("Can't load file: " + pluginFile, e);
                }
            }
            foreach (string pluginName in tmpAttributes.Keys)
            {
                try {
                    PluginAttribute pluginAttribute = tmpAttributes[pluginName];
                    Assembly        assembly        = tmpAssemblies[pluginName];
                    Type            entryType       = assembly.GetType(pluginAttribute.EntryType);
                    if (entryType == null)
                    {
                        LOG.ErrorFormat("Can't find the in the PluginAttribute referenced type {0} in \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile);
                        continue;
                    }
                    try {
                        IGreenshotPlugin plugin = (IGreenshotPlugin)Activator.CreateInstance(entryType);
                        if (plugin != null)
                        {
                            if (plugin.Initialize(this, captureHost, pluginAttribute))
                            {
                                plugins.Add(pluginAttribute, plugin);
                            }
                            else
                            {
                                LOG.InfoFormat("Plugin {0} not initialized!", pluginAttribute.Name);
                            }
                        }
                        else
                        {
                            LOG.ErrorFormat("Can't create an instance of the in the PluginAttribute referenced type {0} from \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile);
                        }
                    } catch (Exception e) {
                        LOG.Error("Can't load Plugin: " + pluginAttribute.Name, e);
                    }
                } catch (Exception e) {
                    LOG.Error("Can't load Plugin: " + pluginName, e);
                }
            }
        }