Nexus.Client.ModManagement.ModInstaller.RunTasks C# (CSharp) Method

RunTasks() protected method

Runs the install tasks.
protected RunTasks ( ) : void
return void
		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);
		}