/// <summary> /// Runs the uninstall tasks. /// </summary> protected void RunTasks() { //the install process modifies INI and config files. // if multiple sources (i.e., installs) try to modify // these files simultaneously the outcome is not well known // (e.g., one install changes SETTING1 in a config file to valueA // while simultaneously another install changes SETTING1 in the // file to value2 - after each install commits its changes it is // not clear what the value of SETTING1 will be). // as a result, we only allow one mod to be installed at a time, // hence the lock. bool booSuccess = false; string strErrorMessage = String.Empty; lock (objUninstallLock) { using (TransactionScope tsTransaction = new TransactionScope()) { TxFileManager tfmFileManager = new TxFileManager(); booSuccess = RunBasicUninstallScript(tfmFileManager, out strErrorMessage); if (booSuccess) { Mod.InstallDate = null; ModInstallLog.RemoveMod(Mod); tsTransaction.Complete(); GC.GetTotalMemory(true); } } } if (booSuccess) { OnTaskSetCompleted(booSuccess, "The mod was successfully deactivated." + Environment.NewLine + strErrorMessage, Mod); } else { OnTaskSetCompleted(false, "The mod was not deactivated." + Environment.NewLine + strErrorMessage, Mod); } }
/// <summary> /// Registers the mod being upgraded with the install log. /// </summary> protected override void RegisterMod() { ModInstallLog.ReplaceActiveMod(OldMod, Mod); }
/// <summary> /// Registers the mod being installed with the install log. /// </summary> protected virtual void RegisterMod() { ModInstallLog.AddActiveMod(Mod); }
/// <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); }