Exemple #1
0
        private static void PluginManager_AfterActivatePackage(ActivatePackageEventArgs eventArgs)
        {
            List <string>            lst = GetLoadOrderList(LoadOrderQueue.Default);
            List <BasePluginPointer> dependentPlugins =
                ListHelper.LoadList(PluginPaths.GlobalPluginListFile).Select(x => new BasePluginPointer(x))
                .Where(x => x.Dependencies.Contains(eventArgs.PackagePointer.PluginName)).ToList();

            foreach (BasePluginPointer dependentPlugin in dependentPlugins)
            {
                lst.Remove(dependentPlugin.PluginName);
                lst.Add(dependentPlugin.PluginName);
            }

            SetLoadOrderList(LoadOrderQueue.Default, lst);
        }
        /// <summary>
        ///     Activates a Package in the Plugin System.
        /// </summary>
        /// <param name="packageName">The Package to be activated.</param>
        /// <param name="addToExistingHosts">When True will add all plugins in the Package to Compatible Loaded Hosts.</param>
        internal static void ActivatePackage(string packageName, bool addToExistingHosts = false)
        {
            List <BasePluginPointer> globalPackages =
                ListHelper.LoadList(PluginPaths.GlobalPluginListFile).Select(x => new BasePluginPointer(x)).ToList();
            BasePluginPointer packageKey = globalPackages.FirstOrDefault(x => x.PluginName == packageName);

            if (packageKey != null)
            {
                List <string> installedPackages = ListHelper.LoadList(PluginPaths.PluginListFile).ToList();
                string        key = packageKey.ToKeyPair();

                if (!installedPackages.Contains(key))
                {
                    ActivatePackageEventArgs args = new ActivatePackageEventArgs(packageKey, true);
                    OnActivatePackage?.Invoke(args);
                    if (args.Cancel)
                    {
                        return;
                    }

                    installedPackages.Add(key);

                    ListHelper.SaveList(PluginPaths.PluginListFile, installedPackages.ToArray());
                    if (addToExistingHosts)
                    {
                        foreach (KeyValuePair <IPluginHost, List <IPlugin> > loadedPlugin in LoadedPlugins)
                        {
                            PluginAssemblyPointer ptr = new PluginAssemblyPointer(
                                packageKey.PluginName,
                                packageKey.PluginFile,
                                packageKey.PluginOrigin,
                                packageKey.PluginVersion.ToString(),
                                loadedPlugin.Key
                                );
                            PluginLoader.AddPluginsFromLoaderResult(ptr);
                        }
                    }

                    //UnloadPlugins(PluginHost);

                    //LoadPlugins(PluginHost);

                    AfterActivatePackage?.Invoke(new ActivatePackageEventArgs(packageKey, false));
                }
            }
        }