/// <summary> /// Called to perform the upgrade. /// </summary> /// <remarks> /// Sets up the resources required to upgrade the install log. /// </remarks> /// <param name="p_mdrManagedModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> public void Upgrade(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mdrManagedModRegistry) { Trace.WriteLine("Beginning Install Log Upgrade."); m_tfmFileManager = new TxFileManager(); using (TransactionScope tsTransaction = new TransactionScope()) { m_tfmFileManager.Snapshot(p_strLogPath); Start(p_strLogPath, p_strModInstallDirectory, p_mdrManagedModRegistry); tsTransaction.Complete(); m_tfmFileManager = null; } }
/// <summary> /// Runs the install 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 strMessage = "The mod was not activated."; try { lock (objUninstallLock) { using (TransactionScope tsTransaction = new TransactionScope()) { if (!File.Exists(Mod.Filename)) throw new Exception("The selected file was not found: " + Mod.Filename); TxFileManager tfmFileManager = new TxFileManager(); if (!BeginModReadOnlyTransaction()) return; RegisterMod(); booSuccess = RunScript(tfmFileManager); if (booSuccess) { Mod.InstallDate = DateTime.Now.ToString(); tsTransaction.Complete(); strMessage = "The mod was successfully activated."; GC.GetTotalMemory(true); } } } } catch (TransactionException) { throw; } catch (SecurityException) { throw; } catch (ObjectDisposedException) { throw; } //this blobck used to be conditionally excluded from debug builds, // presumably so that the debugger would break on the source of the // exception, however that prevents the full mod install flow from // happening, which lead to missed bugs catch (Exception e) { StringBuilder stbError = new StringBuilder(e.Message); if (e is FileNotFoundException) stbError.Append(" (" + ((FileNotFoundException)e).FileName + ")"); if (e is IllegalFilePathException) stbError.Append(" (" + ((IllegalFilePathException)e).Path + ")"); if (e.InnerException != null) stbError.AppendLine().AppendLine(e.InnerException.Message); if (e is RollbackException) foreach (RollbackException.ExceptedResourceManager erm in ((RollbackException)e).ExceptedResourceManagers) { stbError.AppendLine(erm.ResourceManager.ToString()); stbError.AppendLine(erm.Exception.Message); if (erm.Exception.InnerException != null) stbError.AppendLine(erm.Exception.InnerException.Message); } string strExceptionMessageFormat = "A problem occurred during install: " + Environment.NewLine + "{0}" + Environment.NewLine + "The mod was not installed."; ; strMessage = String.Format(strExceptionMessageFormat, stbError.ToString()); PopupErrorMessage = strMessage; PopupErrorMessageType = "Error"; } finally { Mod.EndReadOnlyTransaction(); } OnTaskSetCompleted(booSuccess, strMessage, Mod); }
/// <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); }