Beispiel #1
0
        /// <summary>
        ///   Installs the given <see cref="OptionsForm.PluginFile" />, and activates any
        ///   esm/esp files it encompasses as requested.
        /// </summary>
        /// <param name="plfFile">The file to install.</param>
        /// <param name="booActivate">Whether or not to activate any esp/esm files.</param>
        /// <returns>
        ///   <lang langref="false" /> if the user cancelled the install;
        ///   <lang langref="true" /> otherwise.
        /// </returns>
        protected bool InstallPluginFile(PluginFile plfFile, bool booActivate)
        {
            var strSource = plfFile.Source;
            var strDest   = plfFile.Destination;

            m_bwdProgress.ItemMessage = "Installing " + (String.IsNullOrEmpty(strDest) ? strSource : strDest);
            if (plfFile.IsFolder)
            {
                CopyDataFolder(strSource, strDest);

                if (m_bwdProgress.Cancelled())
                {
                    return(false);
                }

                //if the destination length is greater than 0, then nothing in
                // this folder is directly in the Data folder as so cannot be
                // activated
                if (strDest.Length == 0)
                {
                    var lstFiles = GetFomodFolderFileList(strSource);
                    m_bwdProgress.ItemMessage         = "Activating " + (String.IsNullOrEmpty(strDest) ? strSource : strDest);
                    m_bwdProgress.ItemProgress        = 0;
                    m_bwdProgress.ItemProgressMaximum = lstFiles.Count;

                    if (!strSource.EndsWith("/"))
                    {
                        strSource += "/";
                    }
                    foreach (var strFile in lstFiles)
                    {
                        if (strFile.ToLowerInvariant().EndsWith(".esm") || strFile.ToLowerInvariant().EndsWith(".esp"))
                        {
                            var strNewFileName = strFile.Substring(strSource.Length, strFile.Length - strSource.Length);
                            m_misInstallScript.SetPluginActivation(strNewFileName, booActivate);
                        }
                        if (m_bwdProgress.Cancelled())
                        {
                            return(false);
                        }
                        m_bwdProgress.StepItemProgress();
                    }
                }
            }
            else
            {
                m_bwdProgress.ItemProgress        = 0;
                m_bwdProgress.ItemProgressMaximum = 2;

                m_misInstallScript.CopyDataFile(strSource, strDest);

                m_bwdProgress.StepItemProgress();

                if (String.IsNullOrEmpty(strDest))
                {
                    if (strSource.ToLowerInvariant().EndsWith(".esm") || strSource.ToLowerInvariant().EndsWith(".esp"))
                    {
                        m_misInstallScript.SetPluginActivation(strSource, booActivate);
                    }
                }
                else if (strDest.ToLowerInvariant().EndsWith(".esm") || strDest.ToLowerInvariant().EndsWith(".esp"))
                {
                    m_misInstallScript.SetPluginActivation(strDest, booActivate);
                }

                m_bwdProgress.StepItemProgress();
            }
            return(true);
        }