/// <summary>
        /// Determines if the specified plugin is active.
        /// </summary>
        /// <param name="p_strPath">The path to the plugin whose active status is to be determined.</param>
        /// <returns><c>true</c> if the specified plugin is active;
        /// <c>false</c> otherwise.</returns>
        public bool IsPluginActive(string p_strPath)
        {
            string strPath = p_strPath;

            if (!Path.IsPathRooted(p_strPath))
            {
                strPath = Path.Combine(GameMode.PluginDirectory, GameMode.GetModFormatAdjustedPath(null, p_strPath, true));
            }
            return(ActivePlugins.Contains(ManagedPluginRegistry.GetPlugin(strPath)));
        }
Exemple #2
0
        /// <summary>
        /// Determines if the specified plugin is active.
        /// </summary>
        /// <param name="p_strPath">The path to the plugin whose active status is to be determined.</param>
        /// <returns><c>true</c> if the specified plugin is active;
        /// <c>false</c> otherwise.</returns>
        public bool IsPluginActive(string p_strPath)
        {
            string strPath = p_strPath;

            if (!Path.IsPathRooted(p_strPath))
            {
                strPath = Path.Combine(GameMode.GameModeEnvironmentInfo.InstallationPath, p_strPath);
            }
            return(ActivePlugins.Contains(ManagedPluginRegistry.GetPlugin(strPath)));
        }
Exemple #3
0
        /// <summary>
        ///   Retrieves a list of currently active plugins.
        /// </summary>
        /// <returns>A list of currently active plugins.</returns>
        public string[] GetActivePlugins()
        {
            PermissionsManager.CurrentPermissions.Assert();
            var strPlugins    = Program.GameMode.PluginManager.SortPluginList(ActivePlugins.ToArray());
            var intTrimLength =
                Program.GameMode.PluginsPath.Trim(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Length + 1;

            for (var i = 0; i < strPlugins.Length; i++)
            {
                strPlugins[i] = strPlugins[i].Remove(0, intTrimLength);
            }
            return(strPlugins);
        }
Exemple #4
0
        /// <summary>
        /// Deactivates all the enabled plugins.
        /// </summary>
        public void PluginsDisableAll()
        {
            List <Plugin> lstActivePlugins = ActivePlugins.ToList();

            foreach (string criticalPlugin in OrderedCriticalPluginNames)
            {
                Plugin plgCritical = PluginManager.GetRegisteredPlugin(criticalPlugin);
                if (plgCritical != null)
                {
                    lstActivePlugins.Remove(plgCritical);
                }
            }

            ManagingMultiplePlugins(this, new EventArgs <IBackgroundTask>(PluginManager.ManageMultiplePluginsTask(lstActivePlugins, false, ConfirmUpdaterAction)));
        }
Exemple #5
0
        /// <summary>
        /// Writes the current load order and the id of the specified game mode to the specified
        /// <see cref="TextWriter"/> and returns the number of plugins written.
        /// </summary>
        /// <param name="p_twWriter">The TextWriter to export the current load order to.</param>
        /// <returns>The number of plugins exported.</returns>
        private int ExportLoadOrder(TextWriter p_twWriter)
        {
            if (p_twWriter == null)
            {
                throw new ArgumentNullException("p_twWriter");
            }

            p_twWriter.WriteLine("GameMode={0}", CurrentGameMode.ModeId);
            p_twWriter.WriteLine();

            int intNumPluginsExported = 0;

            foreach (Plugin p in ManagedPlugins)
            {
                p_twWriter.WriteLine(Path.GetFileName(p.Filename) + "=" + (ActivePlugins.Contains(p) ? "1" : "0"));
                intNumPluginsExported++;
            }

            return(intNumPluginsExported);
        }
Exemple #6
0
        /// <summary>
        ///   Sets the activated status of a plugin (i.e., and esp or esm file).
        /// </summary>
        /// <param name="p_strName">The name of the plugin to activate or deactivate.</param>
        /// <param name="p_booActivate">Whether to activate the plugin.</param>
        /// <exception cref="IllegalFilePathException">Thrown if the given path is not safe.</exception>
        /// <exception cref="FileNotFoundException">
        ///   Thrown if the given plugin name
        ///   is invalid or does not exist.
        /// </exception>
        public void SetPluginActivation(string p_strName, bool p_booActivate)
        {
            if (p_strName.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
            {
                throw new IllegalFilePathException(p_strName);
            }
            PermissionsManager.CurrentPermissions.Assert();
            var strFullPath = Path.Combine(Program.GameMode.PluginsPath, p_strName);

            if (!File.Exists(strFullPath))
            {
                throw new FileNotFoundException("Plugin does not exist", p_strName);
            }

            if (p_booActivate)
            {
                ActivePlugins.Add(strFullPath);
            }
            else
            {
                ActivePlugins.Remove(strFullPath);
            }
        }
Exemple #7
0
        /// <summary>
        /// Handles changes to the plugin activation state made by external programs (or manually)
        /// </summary>
        private void LoadOrderManager_ActivePluginUpdate(object sender, EventArgs e)
        {
            if (ModActivationMonitor.IsInstalling)
            {
                return;
            }

            List <string> lstNewActiveList;
            List <string> lstActivatedPlugins = new List <string>();
            List <string> lstDisabledPlugins  = new List <string>();
            List <string> lstActivePlugins;

            if (sender != null)
            {
                try
                {
                    lstNewActiveList = ((string[])sender).ToList();
                }
                catch
                {
                    return;
                }

                if (ActivePlugins.Count > 0)
                {
                    lstActivePlugins = ActivePlugins.Select(x => x.Filename).ToList();
                    var ActivatedPlugins = lstNewActiveList.Except(lstActivePlugins, StringComparer.InvariantCultureIgnoreCase);
                    if (ActivatedPlugins != null)
                    {
                        lstActivatedPlugins = ActivatedPlugins.ToList();
                    }

                    var DisabledPlugins = lstActivePlugins.Except(lstNewActiveList, StringComparer.InvariantCultureIgnoreCase);
                    if (DisabledPlugins != null)
                    {
                        lstDisabledPlugins = DisabledPlugins.ToList();
                    }
                }
                else
                {
                    lstActivatedPlugins = lstNewActiveList;
                }

                foreach (string plugin in lstActivatedPlugins)
                {
                    if (!PluginManager.IsPluginRegistered(plugin))
                    {
                        PluginManager.AddPlugin(plugin);
                    }

                    if (PluginManager.IsPluginRegistered(plugin))
                    {
                        PluginManager.ActivatePlugin(plugin);
                    }
                }
                foreach (string plugin in lstDisabledPlugins)
                {
                    if (PluginManager.IsPluginRegistered(plugin))
                    {
                        PluginManager.DeactivatePlugin(plugin);
                    }
                }
            }
        }