Beispiel #1
0
        /// <summary>
        /// Performs the actual uninstallation.
        /// </summary>
        /// <returns><c>true</c> if the uninstall was successful;
        /// <c>false</c> otherwise.</returns>
        protected bool UninstallFiles()
        {
            bool   booSecondaryInstall = false;
            string strCheckedFile      = string.Empty;

            OverallMessage          = "Uninstalling Mod...";
            ShowItemProgress        = true;
            OverallProgressStepSize = 1;
            ItemProgressStepSize    = 1;

            IList <string>  lstFiles    = ModInstallLog.GetInstalledModFiles(Mod);
            IList <IniEdit> lstIniEdits = ModInstallLog.GetInstalledIniEdits(Mod);
            IList <string>  lstGameSpecificValueEdits = ModInstallLog.GetInstalledGameSpecificValueEdits(Mod);

            OverallProgressMaximum = 3;

            ItemProgressMaximum = lstFiles.Count;
            ItemProgress        = 0;
            ItemMessage         = "Uninstalling Files...";

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

            foreach (string strFile in lstFiles)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                if (GameMode.HasSecondaryInstallPath)
                {
                    if (GameMode.CheckSecondaryUninstall(strFile))
                    {
                        return(false);
                    }
                }

                if (Path.IsPathRooted(strFile))
                {
                    string strCompatibilityPath = Path.Combine(Path.Combine(GameMode.GameModeEnvironmentInfo.ModDirectory, "VirtualInstall"), Path.GetFileNameWithoutExtension(Mod.Filename));
                    strCheckedFile = strFile.Replace(strCompatibilityPath, "");
                    strCheckedFile = strCheckedFile.TrimStart(Path.DirectorySeparatorChar);
                }
                else
                {
                    strCheckedFile = strFile;
                }

                try
                {
                    Installers.FileInstaller.UninstallDataFile(strCheckedFile, booSecondaryInstall);
                }
                catch (UnauthorizedAccessException)
                {
                    string strDetails = "Access to the path: " + Environment.NewLine + strFile + " is denied." + Environment.NewLine +
                                        "This error commonly occurs when Antivirus programs (even if disabled) prevents NMM from interacting with game/mod files." + Environment.NewLine +
                                        "Please add NMM and its folders to the antivirus' exception list.";
                    Installers.FileInstaller.InstallErrors.Add(strDetails);
                    return(false);
                }
                catch (NullReferenceException ex)
                {
                    string strDetails = ex.Message;
                    Installers.FileInstaller.InstallErrors.Add(strDetails);
                    return(false);
                }
                StepItemProgress();
            }
            StepOverallProgress();

            ItemProgressMaximum = lstIniEdits.Count;
            ItemProgress        = 0;
            ItemMessage         = "Undoing Ini Edits...";
            foreach (IniEdit iniEdit in lstIniEdits)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                Installers.IniInstaller.UneditIni(iniEdit.File, iniEdit.Section, iniEdit.Key);
                StepItemProgress();
            }
            StepOverallProgress();

            ItemProgressMaximum = lstGameSpecificValueEdits.Count;
            ItemProgress        = 0;
            ItemMessage         = "Undoing Game Specific Value Edits...";
            foreach (string strEdit in lstGameSpecificValueEdits)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                Installers.GameSpecificValueInstaller.UnEditGameSpecificValue(strEdit);
                StepItemProgress();
            }
            StepOverallProgress();

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

            return(true);
        }
        /// <summary>
        /// Performs the actual uninstallation.
        /// </summary>
        /// <returns><c>true</c> if the uninstall was successful;
        /// <c>false</c> otherwise.</returns>
        protected bool UninstallFiles()
        {
            bool   booSecondaryInstall = false;
            string strCheckedFile      = string.Empty;

            OverallMessage          = "Uninstalling Mod...";
            ShowItemProgress        = true;
            OverallProgressStepSize = 1;
            ItemProgressStepSize    = 1;

            IList <string>  lstFiles    = ModInstallLog.GetInstalledModFiles(Mod);
            IList <IniEdit> lstIniEdits = ModInstallLog.GetInstalledIniEdits(Mod);
            IList <string>  lstGameSpecificValueEdits = ModInstallLog.GetInstalledGameSpecificValueEdits(Mod);

            OverallProgressMaximum = 3;

            ItemProgressMaximum = lstFiles.Count;
            ItemProgress        = 0;
            ItemMessage         = "Uninstalling Files...";

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

            foreach (string strFile in lstFiles)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                if (GameMode.HasSecondaryInstallPath)
                {
                    if (GameMode.CheckSecondaryUninstall(strFile))
                    {
                        return(false);
                    }
                }

                if (Path.IsPathRooted(strFile))
                {
                    string strCompatibilityPath = Path.Combine(Path.Combine(GameMode.GameModeEnvironmentInfo.ModDirectory, "VirtualInstall"), Path.GetFileNameWithoutExtension(Mod.Filename));
                    strCheckedFile = strFile.Replace(strCompatibilityPath, "");
                    strCheckedFile = strCheckedFile.TrimStart(Path.DirectorySeparatorChar);
                }
                else
                {
                    strCheckedFile = strFile;
                }

                try
                {
                    Installers.FileInstaller.UninstallDataFile(strCheckedFile, booSecondaryInstall);
                }
                catch (UnauthorizedAccessException)
                {
                    string strDetails = "Access to the path: " + Environment.NewLine + strFile + " is denied." + Environment.NewLine +
                                        "This error commonly occurs when Antivirus programs (even if disabled) prevents NMM from interacting with game/mod files." + Environment.NewLine +
                                        "Please add NMM and its folders to the antivirus' exception list.";
                    Installers.FileInstaller.InstallErrors.Add(strDetails);
                    strPopupErrorMessageType = "Error";
                    return(false);
                }
                catch (Nexus.Client.ModManagement.Scripting.IllegalFilePathException)
                {
                    string strDetails = Environment.NewLine +
                                        "The mod has been deleted with success, but the manager was unable to remove one or more files. " + Environment.NewLine +
                                        "An IllegalFilePathException was thrown, a path is safe to be written to if it contains no charaters disallowed by the operating system and if it is in the Data directory or one of its sub-directories." + Environment.NewLine;
                    if (!boo_CheckUninstallError)
                    {
                        Installers.FileInstaller.InstallErrors.Add(strDetails);
                        boo_CheckUninstallError = true;
                    }
                    strPopupErrorMessageType = "Warning";
                }
                catch (NullReferenceException ex)
                {
                    string strDetails = ex.Message;
                    Installers.FileInstaller.InstallErrors.Add(strDetails);
                    strPopupErrorMessageType = "Error";
                    return(false);
                }
                StepItemProgress();
            }
            StepOverallProgress();

            if (Installers.FileInstaller.InstallErrors.Count > 0)
            {
                if (!boo_CheckUninstallError)
                {
                    string strDetails = Environment.NewLine + "The mod has been deleted with success, but the manager was unable to remove one or more files. " + Environment.NewLine;
                    Installers.FileInstaller.InstallErrors.Add(strDetails);
                    boo_CheckUninstallError = true;
                }
                strPopupErrorMessageType = "Warning";
            }

            ItemProgressMaximum = lstIniEdits.Count;
            ItemProgress        = 0;
            ItemMessage         = "Undoing Ini Edits...";
            foreach (IniEdit iniEdit in lstIniEdits)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                if (File.Exists(iniEdit.File))
                {
                    Installers.IniInstaller.UneditIni(iniEdit.File, iniEdit.Section, iniEdit.Key);
                }
                StepItemProgress();
            }
            StepOverallProgress();

            ItemProgressMaximum = lstGameSpecificValueEdits.Count;
            ItemProgress        = 0;
            ItemMessage         = "Undoing Game Specific Value Edits...";
            foreach (string strEdit in lstGameSpecificValueEdits)
            {
                if (Status == TaskStatus.Cancelling)
                {
                    return(false);
                }
                Installers.GameSpecificValueInstaller.UnEditGameSpecificValue(strEdit);
                StepItemProgress();
            }
            StepOverallProgress();

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

            return(true);
        }