From cc490c71125b600c152c269d7f6cf1011f5be6a5 Mon Sep 17 00:00:00 2001 From: FrigaT Date: Tue, 25 Nov 2025 09:50:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D0=B6=D0=B8=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReleaseUpdater/ReleaseUpdaterFacade.cs | 7 +++++++ Updater/Core/Options.cs | 12 ++++++++---- Updater/Program.cs | 20 +++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) 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);