Esempio n. 1
0
        /// <summary>
        ///     Loads the best version of the given plugin.
        /// </summary>
        public void Load()
        {
            Log.DebugFormat("Found {0} version(s) of plugin '{1}', finding compatible ones...", _pluginsByVersion.Count, _id);

            var compatiblePlugins = _pluginsByVersion.Where(x => !(x.Value.Archive is EmptyPluginArchive))
                                    .Where(x => IsCompatible(x.Value.Archive.Index))
                                    .OrderByDescending(x => x.Key)
                                    .Select(x => x.Value).ToList();

            if (compatiblePlugins.Any())
            {
                Log.DebugFormat("Found {0} compatible version(s) of plugin '{1}', loading newest...", _pluginsByVersion.Count, _id);

                // It's possible that despite our best efforts, the plugin with the highest version
                // refuses to be loaded (for example because it's broken, or the compatibility check might miss something).
                // If that's the case, we try to load earlier versions until we either find one that works or
                // give up...
                if (TryLoad(compatiblePlugins, out var loadedPlugin))
                {
                    _selectedPlugin        = CreateDescription(loadedPlugin);
                    _selectedPluginArchive = loadedPlugin.Archive;
                    _status.IsLoaded       = true;
                }
                else
                {
                    _selectedPlugin = new PluginDescription
                    {
                        Id    = _id,
                        Error = "The plugin couldn't be loaded",
                        PluginImplementations = new IPluginImplementationDescription[0]
                    };
                    var plugin = compatiblePlugins.First();                     //< Never empty: we have at least 1 plugin
                    _selectedPlugin.FilePath = plugin.FilePath;
                    _selectedPlugin.Version  = plugin.Archive.Index.Version;

                    _status.IsLoaded = false;
                }
            }
            else
            {
                Log.ErrorFormat("Found 0 compatible version(s) of plugin '{0}' (tried all {1} version(s) of this plugin)", _id, _pluginsByVersion.Count);

                _selectedPlugin = new PluginDescription
                {
                    Id    = _id,
                    Error = "The plugin couldn\'t be loaded",
                    PluginImplementations = new IPluginImplementationDescription[0]
                };

                if (_pluginsByVersion.Any())                 //< Might be empty
                {
                    var plugin = _pluginsByVersion.Values.First();
                    _selectedPlugin.FilePath = plugin.FilePath;
                    _selectedPlugin.Version  = plugin.Archive.Index.Version;
                }

                _status.IsLoaded = false;
            }
        }
Esempio n. 2
0
        private void Add(string pluginPath, PluginId id, Version pluginVersion, IPluginArchive archive)
        {
            if (!_plugins.TryGetValue(id, out var pluginGroup))
            {
                pluginGroup = new PluginGroup(id);
                _plugins.Add(id, pluginGroup);
            }

            pluginGroup.Add(pluginPath, pluginVersion, archive);
        }
Esempio n. 3
0
        public void Add(string pluginPath, Version pluginVersion, IPluginArchive archive)
        {
            if (_pluginsByVersion.TryGetValue(pluginVersion, out var existingPlugin))
            {
                Log.WarnFormat("Ignoring plugin '{0}', an identical version has already been loaded from '{1}'!",
                               pluginPath,
                               existingPlugin.FilePath);
                return;
            }

            _pluginsByVersion.Add(pluginVersion, new Plugin(archive, pluginPath));
            _status.IsInstalled = true;
        }
Esempio n. 4
0
        private PluginGroup Add(string pluginPath, IPluginArchive archive)
        {
            var id = new PluginId(archive.Index.Id);

            if (!_plugins.TryGetValue(id, out var pluginGroup))
            {
                pluginGroup = new PluginGroup(id);
                _plugins.Add(id, pluginGroup);
            }

            var version = archive.Index.Version;

            pluginGroup.Add(pluginPath, version, archive);
            return(pluginGroup);
        }
Esempio n. 5
0
 public void Add(string pluginPath, Version pluginVersion, IPluginArchive archive)
 {
     _pluginsByVersion.Add(pluginVersion, new Plugin(archive, pluginPath));
     _status.IsInstalled = true;
 }
Esempio n. 6
0
 public Plugin(IPluginArchive archive, string filePath)
 {
     Archive  = archive;
     FilePath = filePath;
 }