mirror of
				https://github.com/velopack/velopack.git
				synced 2025-10-25 15:19:22 +00:00 
			
		
		
		
	Introduces IProcessImpl.Exit and uses it
Adds IProcessImpl.Exit for controlled process termination, replaces Environment.Exit with IProcessImpl.Exit calls, and adds a test implementation for IProcessImpl.
This commit is contained in:
		| @@ -75,5 +75,7 @@ namespace Velopack.Locators | ||||
|                 _logger.Error($"Process {p.Id} has already exited."); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void Exit(int exitCode) => Environment.Exit(exitCode); | ||||
|     } | ||||
| } | ||||
| @@ -9,5 +9,11 @@ namespace Velopack.Locators | ||||
|         string GetCurrentProcessPath(); | ||||
|         uint GetCurrentProcessId(); | ||||
|         void StartProcess(string exePath, IEnumerable<string> args, string workDir, bool showWindow); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Exit the current process with the given exit code. | ||||
|         /// </summary> | ||||
|         /// <param name="exitCode">The exit code</param> | ||||
|         void Exit(int exitCode); | ||||
|     } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| using System; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
| using NuGet.Versioning; | ||||
| @@ -86,6 +86,8 @@ namespace Velopack.Locators | ||||
| 
 | ||||
|         public override IProcessImpl Process => this; | ||||
| 
 | ||||
|         public int? ExitCode { get; private set; } | ||||
| 
 | ||||
|         public override VelopackAsset? GetLatestLocalFullPackage() | ||||
|         { | ||||
|             if (_asset != null) { | ||||
| @@ -142,5 +144,13 @@ namespace Velopack.Locators | ||||
|         { | ||||
|             new DefaultProcessImpl(Log).StartProcess(exePath, args, workDir, showWindow); | ||||
|         } | ||||
| 
 | ||||
|         public void Exit(int exitCode) | ||||
|         { | ||||
|             if (ExitCode is not null) { | ||||
|                 throw new InvalidOperationException("Exit has already been called on this instance."); | ||||
|             } | ||||
|             ExitCode = exitCode; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -16,7 +16,7 @@ namespace Velopack | ||||
|         public void ApplyUpdatesAndRestart(VelopackAsset? toApply, string[]? restartArgs = null) | ||||
|         { | ||||
|             WaitExitThenApplyUpdates(toApply, silent: false, restart: true, restartArgs); | ||||
|             Environment.Exit(0); | ||||
|             Locator.Process.Exit(0); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -29,7 +29,7 @@ namespace Velopack | ||||
|         public void ApplyUpdatesAndExit(VelopackAsset? toApply) | ||||
|         { | ||||
|             WaitExitThenApplyUpdates(toApply, silent: true, restart: false); | ||||
|             Environment.Exit(0); | ||||
|             Locator.Process.Exit(0); | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|   | ||||
| @@ -276,9 +276,7 @@ namespace Velopack | ||||
| 
 | ||||
|         private static void Exit(int code) | ||||
|         { | ||||
|             if (!VelopackRuntimeInfo.InUnitTestRunner) { | ||||
|                 Environment.Exit(code); | ||||
|             } | ||||
|             VelopackLocator.GetCurrentOrCreateDefault().Process.Exit(code); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user