Example #1
0
 protected void ActivatePlugin(string p_strPlugin)
 {
     if ((GameMode.UsesPlugins) && (PluginManager.IsActivatiblePluginFile(p_strPlugin)))
     {
         PluginManager.ActivatePlugin(p_strPlugin);
     }
 }
 /// <summary>
 /// If valid the current plugin file will be set as active.
 /// </summary>
 protected void ActivatePlugin(string p_strPlugin)
 {
     if (FileInstaller.PluginCheck(p_strPlugin, false))
     {
         if (PluginManager.IsActivatiblePluginFile(p_strPlugin))
         {
             PluginManager.ActivatePlugin(p_strPlugin);
         }
     }
 }
Example #3
0
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <remarks>
        /// This method installs all of the files in the <see cref="IMod"/> being installed.
        /// </remarks>
        /// <param name="p_objArgs">Arguments to for the task execution.</param>
        /// <returns>A return value.</returns>
        protected override object DoWork(object[] p_objArgs)
        {
            char[]        chrDirectorySeperators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
            bool          booSecondaryInstall    = false;
            List <string> lstFiles = Mod.GetFileList();

            OverallProgressMaximum = lstFiles.Count;

            if (GameMode.RequiresModFileMerge)
            {
                GameMode.ModFileMerge(ActiveMods, Mod, false);
            }

            if (GameMode.HasSecondaryInstallPath)
            {
                booSecondaryInstall = GameMode.CheckSecondaryInstall(Mod);
            }

            foreach (string strFile in lstFiles)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                string strFixedPath = GameMode.GetModFormatAdjustedPath(Mod.Format, strFile, Mod);

                if (!string.IsNullOrEmpty(strFixedPath))
                {
                    if (!(GameMode.RequiresModFileMerge && (Path.GetFileName(strFile) == GameMode.MergedFileName)))
                    {
                        if (!(SkipReadme && Readme.IsValidExtension(Path.GetExtension(strFile).ToLower()) && (Path.GetDirectoryName(strFixedPath) == Path.GetFileName(GameMode.PluginDirectory))))
                        {
                            if (FileInstaller.InstallFileFromMod(strFile, strFixedPath, booSecondaryInstall))
                            {
                                if ((GameMode.UsesPlugins) && (PluginManager.IsActivatiblePluginFile(strFixedPath)))
                                {
                                    PluginManager.ActivatePlugin(strFixedPath);
                                }
                            }
                        }
                    }
                }
                StepOverallProgress();
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// Applies the load order specified by the given list of registered plugins
        /// </summary>
        /// <param name="p_lstRegisteredPlugins">The list of registered plugins.</param>
        /// <param name="p_booSortingOnly">Whether we just want to apply the sorting.</param>
        public void ApplyLoadOrder(Dictionary <Plugin, string> p_kvpRegisteredPlugins, bool p_booSortingOnly)
        {
            Transactions.TransactionScope tsTransaction = null;
            try
            {
                tsTransaction = new Transactions.TransactionScope();

                if (!p_booSortingOnly)
                {
                    foreach (KeyValuePair <Plugin, string> kvp in p_kvpRegisteredPlugins)
                    {
                        if (kvp.Value == "1")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.ActivatePlugin(kvp.Key);
                            }
                        }
                        if (kvp.Value == "0")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.DeactivatePlugin(kvp.Key);
                            }
                        }
                    }
                }

                PluginManager.SetPluginOrder(p_kvpRegisteredPlugins.Keys.ToList());

                tsTransaction.Complete();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (tsTransaction != null)
                {
                    tsTransaction.Dispose();
                }
            }
        }
Example #5
0
 /// <summary>
 /// Activates the given plugin.
 /// </summary>
 /// <param name="p_plgPlugin">The plugin to activate.</param>
 public void ActivatePlugin(Plugin p_plgPlugin)
 {
     PluginManager.ActivatePlugin(p_plgPlugin);
 }
Example #6
0
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <param name="p_objArgs">Arguments to for the task execution.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override object DoWork(object[] p_objArgs)
        {
            ConfirmActionMethod camConfirm = (ConfirmActionMethod)p_objArgs[0];
            bool   booLotsOfLinks          = false;
            int    intProgress             = 0;
            double dblRatio = 0;

            OverallMessage          = String.Format("{0} Mod Links: {1}", Disabling ? "Disabling" : "Activating", Mod.ModName);
            ItemMessage             = String.Format("{0}...", Disabling ? "Disabling" : "Activating");
            OverallProgress         = 0;
            OverallProgressStepSize = 1;
            OverallProgressMaximum  = 1;
            ShowItemProgress        = true;
            ItemProgress            = 0;

            if (!Disabling)
            {
                string strModFolderPath = Path.Combine(VirtualModActivator.VirtualPath, Path.GetFileNameWithoutExtension(Mod.Filename));

                if (Directory.Exists(strModFolderPath))
                {
                    string[] strFiles = Directory.GetFiles(strModFolderPath, "*", SearchOption.AllDirectories);

                    if (strFiles.Length <= 1000)
                    {
                        ItemProgressMaximum  = strFiles.Length;
                        ItemProgressStepSize = 1;
                    }
                    else
                    {
                        ItemProgressMaximum = 1000;
                        booLotsOfLinks      = true;
                        dblRatio            = 1000 / strFiles.Length;
                    }

                    if (strFiles.Length > 0)
                    {
                        IModLinkInstaller ModLinkInstaller = VirtualModActivator.GetModLinkInstaller();

                        foreach (string File in strFiles)
                        {
                            //if (m_booCancel)
                            //	break;
                            ItemMessage = String.Format("{0}: {1}", Disabling ? "Disabling" : "Activating", File);

                            string strFile = File.Replace((strModFolderPath + Path.DirectorySeparatorChar), String.Empty);

                            string strFileLink = ModLinkInstaller.AddFileLink(Mod, strFile, null, false);

                            if (!string.IsNullOrEmpty(strFileLink))
                            {
                                if (PluginManager != null)
                                {
                                    if (PluginManager.IsActivatiblePluginFile(strFileLink))
                                    {
                                        PluginManager.AddPlugin(strFileLink);
                                        PluginManager.ActivatePlugin(strFileLink);
                                    }
                                }
                            }

                            if (ItemProgress < ItemProgressMaximum)
                            {
                                if (booLotsOfLinks)
                                {
                                    ItemProgress = (int)Math.Floor(++intProgress * dblRatio);
                                }
                                else
                                {
                                    StepItemProgress();
                                }
                            }
                        }

                        VirtualModActivator.FinalizeModActivation(Mod);
                    }
                }
            }
            else
            {
                if (Mod != null)
                {
                    List <IVirtualModLink> ivlLinks = VirtualModActivator.VirtualLinks.Where(x => (x.ModInfo != null) && (x.ModInfo.ModFileName.ToLowerInvariant() == Path.GetFileName(Mod.Filename).ToLowerInvariant())).ToList();
                    if ((ivlLinks != null) && (ivlLinks.Count > 0))
                    {
                        if (ivlLinks.Count <= 1000)
                        {
                            ItemProgressMaximum  = ivlLinks.Count;
                            ItemProgressStepSize = 1;
                        }
                        else
                        {
                            ItemProgressMaximum = 1000;
                            booLotsOfLinks      = true;
                            dblRatio            = 1000 / ivlLinks.Count;
                        }

                        foreach (IVirtualModLink Link in ivlLinks)
                        {
                            ItemMessage = String.Format("{0}: {1}", Disabling ? "Disabling" : "Activating", Link.VirtualModPath);
                            VirtualModActivator.RemoveFileLink(Link, Mod);

                            if (ItemProgress < ItemProgressMaximum)
                            {
                                if (booLotsOfLinks)
                                {
                                    ItemProgress = (int)Math.Floor(++intProgress * dblRatio);
                                }
                                else
                                {
                                    StepItemProgress();
                                }
                            }
                        }
                    }

                    VirtualModActivator.FinalizeModDeactivation(Mod);
                }
            }


            if (OverallProgress < OverallProgressMaximum)
            {
                StepOverallProgress();
            }

            return(null);
        }
Example #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);
                    }
                }
            }
        }
        /// <summary>
        /// The method that is called to start the background task.
        /// </summary>
        /// <param name="args">Arguments to for the task execution.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override object DoWork(object[] args)
        {
            var    lotsOfLinks = false;
            var    intProgress = 0;
            double dblRatio    = 0;

            OverallMessage          = $"{(Disabling ? "Disabling" : "Activating")} Mod Links: {Mod.ModName}";
            ItemMessage             = $"{(Disabling ? "Disabling" : "Activating")}...";
            OverallProgress         = 0;
            OverallProgressStepSize = 1;
            OverallProgressMaximum  = 1;
            ShowItemProgress        = true;
            ItemProgress            = 0;

            if (!Disabling)
            {
                var modFilenamePath    = Path.Combine(VirtualModActivator.VirtualPath, Path.GetFileNameWithoutExtension(Mod.Filename).Trim());
                var linkFilenamePath   = MultiHDMode ? Path.Combine(VirtualModActivator.HDLinkFolder, Path.GetFileNameWithoutExtension(Mod.Filename).Trim()) : string.Empty;
                var modDownloadIdPath  = string.IsNullOrWhiteSpace(Mod.DownloadId) || Mod.DownloadId.Length <= 1 || Mod.DownloadId.Equals("-1", StringComparison.OrdinalIgnoreCase) ? string.Empty : Path.Combine(VirtualModActivator.VirtualPath, Mod.DownloadId);
                var linkDownloadIdPath = MultiHDMode ? string.IsNullOrWhiteSpace(Mod.DownloadId) || Mod.DownloadId.Length <= 1 || Mod.DownloadId.Equals("-1", StringComparison.OrdinalIgnoreCase) ? string.Empty : Path.Combine(VirtualModActivator.HDLinkFolder, Mod.DownloadId) : string.Empty;
                var modFolderPath      = modFilenamePath;
                var linkFolderPath     = linkFilenamePath;

                if (!string.IsNullOrWhiteSpace(modDownloadIdPath) && Directory.Exists(modDownloadIdPath))
                {
                    modFolderPath = modDownloadIdPath;
                }

                if (MultiHDMode && !string.IsNullOrWhiteSpace(linkDownloadIdPath) && Directory.Exists(linkDownloadIdPath))
                {
                    linkFolderPath = linkDownloadIdPath;
                }

                if (Directory.Exists(modFolderPath) || MultiHDMode && Directory.Exists(linkFolderPath))
                {
                    string[] files;

                    try
                    {
                        if (MultiHDMode && Directory.Exists(linkFolderPath))
                        {
                            files = Directory.Exists(modFolderPath) ?
                                    Directory.GetFiles(linkFolderPath, "*", SearchOption.AllDirectories).Concat(Directory.GetFiles(modFolderPath, "*", SearchOption.AllDirectories)).ToArray() :
                                    Directory.GetFiles(linkFolderPath, "*", SearchOption.AllDirectories);
                        }
                        else
                        {
                            files = Directory.GetFiles(modFolderPath, "*", SearchOption.AllDirectories);
                        }
                    }
                    catch (Exception ex)
                    {
                        TraceUtil.TraceException(ex);
                        OverallMessage = $"{nameof(LinkActivationTask)} failed: {ex.Message}";
                        Status         = TaskStatus.Error;

                        return(null);
                    }

                    if (files.Length <= 1000)
                    {
                        ItemProgressMaximum  = files.Length;
                        ItemProgressStepSize = 1;
                    }
                    else
                    {
                        ItemProgressMaximum = 1000;
                        lotsOfLinks         = true;
                        dblRatio            = 1000 / files.Length;
                    }

                    if (files.Length > 0)
                    {
                        var modLinkInstaller = VirtualModActivator.GetModLinkInstaller();

                        foreach (var file in files)
                        {
                            ItemMessage = $"{(Disabling ? "Disabling" : "Activating")}: {file}";

                            var strFile = MultiHDMode && file.Contains(linkFolderPath)
                                ? file.Replace(linkFolderPath + Path.DirectorySeparatorChar, string.Empty)
                                : file.Replace(modFolderPath + Path.DirectorySeparatorChar, string.Empty);

                            var fileLink = string.Empty;

                            try
                            {
                                fileLink = modLinkInstaller.AddFileLink(Mod, strFile, null, false);
                            }
                            catch (Exception ex)
                            {
                                TraceUtil.TraceException(ex);
                                OverallMessage = $"{nameof(LinkActivationTask)} failed: {ex.Message}";
                                Status         = TaskStatus.Error;

                                return(null);
                            }

                            if (!string.IsNullOrEmpty(fileLink) && PluginManager != null)
                            {
                                if (PluginManager.IsActivatiblePluginFile(fileLink))
                                {
                                    PluginManager.AddPlugin(fileLink);
                                    PluginManager.ActivatePlugin(fileLink);
                                }
                            }

                            if (ItemProgress < ItemProgressMaximum)
                            {
                                if (lotsOfLinks)
                                {
                                    ItemProgress = (int)Math.Floor(++intProgress * dblRatio);
                                }
                                else
                                {
                                    StepItemProgress();
                                }
                            }
                        }

                        VirtualModActivator.FinalizeModActivation(Mod);
                    }
                }
            }
            else
            {
                if (Mod != null)
                {
                    var ivlLinks = VirtualModActivator.VirtualLinks
                                   .Where(x => x.ModInfo != null && string.Equals(x.ModInfo.ModFileName, Path.GetFileName(Mod.Filename), StringComparison.OrdinalIgnoreCase))
                                   .ToList();

                    if (ivlLinks.Count > 0)
                    {
                        if (ivlLinks.Count <= 1000)
                        {
                            ItemProgressMaximum  = ivlLinks.Count;
                            ItemProgressStepSize = 1;
                        }
                        else
                        {
                            ItemProgressMaximum = 1000;
                            lotsOfLinks         = true;
                            dblRatio            = 1000 / ivlLinks.Count;
                        }

                        foreach (var link in ivlLinks)
                        {
                            ItemMessage = $"{(Disabling ? "Disabling" : "Activating")}: {link.VirtualModPath}";
                            VirtualModActivator.RemoveFileLink(link, Mod);

                            if (ItemProgress < ItemProgressMaximum)
                            {
                                if (lotsOfLinks)
                                {
                                    ItemProgress = (int)Math.Floor(++intProgress * dblRatio);
                                }
                                else
                                {
                                    StepItemProgress();
                                }
                            }
                        }
                    }

                    VirtualModActivator.FinalizeModDeactivation(Mod);
                }
            }


            if (OverallProgress < OverallProgressMaximum)
            {
                StepOverallProgress();
            }

            return(null);
        }