diff --git a/ReleaseUpdater/ReleaseUpdaterFacade.cs b/ReleaseUpdater/ReleaseUpdaterFacade.cs
index 2701bab..f333cdc 100644
--- a/ReleaseUpdater/ReleaseUpdaterFacade.cs
+++ b/ReleaseUpdater/ReleaseUpdaterFacade.cs
@@ -88,9 +88,16 @@ public static class ReleaseUpdaterFacade
BeforeInstall?.Invoke();
+
if (updaterExePath == null) updaterExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updater.exe");
var args = $"--zip \"{zipPath}\" --installPath \"{installPath}\" --appExe \"{appExe}\"";
+ if (exitCurrentApp)
+ {
+ int pid = Process.GetCurrentProcess().Id;
+ args += $" --waitProcess \"{pid}\"";
+ }
+
var process = Process.Start(new ProcessStartInfo
{
FileName = updaterExePath,
diff --git a/Updater/Core/Options.cs b/Updater/Core/Options.cs
index abec43f..31ced91 100644
--- a/Updater/Core/Options.cs
+++ b/Updater/Core/Options.cs
@@ -18,10 +18,13 @@ public sealed class Options
/// Необязательно: подождите миллисекунды перед запуском обновления.
public int UpdateDelayMs { get; init; } = 500;
- public static string Usage =>
- "Usage: Updater.exe --zip --installPath --appExe [--restartDelayMs ] [--updateDelayMs ]";
+ /// Необязательно: дождаться завершения процесса.
+ public int? WaitProcess { get; init; } = null;
- /// Папрсинг CLI аргументов в Options.
+ public static string Usage =>
+ "Usage: Updater.exe --zip --installPath --appExe [--restartDelayMs ] [--updateDelayMs ] [--waitProcess ]";
+
+ /// Парсинг CLI аргументов в Options.
public static Options Parse(string[] args)
{
var dict = new Dictionary(StringComparer.OrdinalIgnoreCase);
@@ -46,7 +49,8 @@ public sealed class Options
InstallPath = Path.GetFullPath(install),
AppExe = exe,
RestartDelayMs = dict.TryGetValue("restartDelayMs", out var d) && int.TryParse(d, out var n) ? n : 500,
- UpdateDelayMs = dict.TryGetValue("updateDelayMs", out var d2) && int.TryParse(d2, out var n2) ? n2 : 500
+ UpdateDelayMs = dict.TryGetValue("updateDelayMs", out var d2) && int.TryParse(d2, out var n2) ? n2 : 500,
+ WaitProcess = dict.TryGetValue("waitProcess", out var pid) && int.TryParse(pid, out var pid_) ? pid_ : null,
};
}
diff --git a/Updater/Program.cs b/Updater/Program.cs
index 861e88d..cb91585 100644
--- a/Updater/Program.cs
+++ b/Updater/Program.cs
@@ -1,4 +1,6 @@
-using Updater.Core;
+using System.Diagnostics;
+using System.Security.Cryptography;
+using Updater.Core;
namespace Updater;
@@ -22,6 +24,22 @@ internal sealed class Program
Thread.Sleep(options.UpdateDelayMs);
+ if (options.WaitProcess != null)
+ try
+ {
+ using (var proc = Process.GetProcessById(options.WaitProcess.Value))
+ {
+ logger.Info($"Waiting for the process to complete {options.WaitProcess}...");
+ proc.WaitForExit(); // блокирует выполнение до завершения процесса
+ logger.Info("Process is completed.");
+ }
+ }
+ catch (ArgumentException)
+ {
+ logger.Info($"Process with PID {options.WaitProcess} not found.");
+ }
+
+
var extractor = new ZipExtractor(logger);
var installer = new SafeFileInstaller(logger);
var procMgr = new ProcessManager(logger);