Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc490c7112 |
@@ -88,9 +88,16 @@ public static class ReleaseUpdaterFacade
|
|||||||
|
|
||||||
BeforeInstall?.Invoke();
|
BeforeInstall?.Invoke();
|
||||||
|
|
||||||
|
|
||||||
if (updaterExePath == null) updaterExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updater.exe");
|
if (updaterExePath == null) updaterExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updater.exe");
|
||||||
var args = $"--zip \"{zipPath}\" --installPath \"{installPath}\" --appExe \"{appExe}\"";
|
var args = $"--zip \"{zipPath}\" --installPath \"{installPath}\" --appExe \"{appExe}\"";
|
||||||
|
|
||||||
|
if (exitCurrentApp)
|
||||||
|
{
|
||||||
|
int pid = Process.GetCurrentProcess().Id;
|
||||||
|
args += $" --waitProcess \"{pid}\"";
|
||||||
|
}
|
||||||
|
|
||||||
var process = Process.Start(new ProcessStartInfo
|
var process = Process.Start(new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = updaterExePath,
|
FileName = updaterExePath,
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ public sealed class Options
|
|||||||
/// <summary>Необязательно: подождите миллисекунды перед запуском обновления.</summary>
|
/// <summary>Необязательно: подождите миллисекунды перед запуском обновления.</summary>
|
||||||
public int UpdateDelayMs { get; init; } = 500;
|
public int UpdateDelayMs { get; init; } = 500;
|
||||||
|
|
||||||
public static string Usage =>
|
/// <summary>Необязательно: дождаться завершения процесса.</summary>
|
||||||
"Usage: Updater.exe --zip <path.zip> --installPath <dir> --appExe <file.exe> [--restartDelayMs <int>] [--updateDelayMs <int>]";
|
public int? WaitProcess { get; init; } = null;
|
||||||
|
|
||||||
/// <summary>Папрсинг CLI аргументов в Options.</summary>
|
public static string Usage =>
|
||||||
|
"Usage: Updater.exe --zip <path.zip> --installPath <dir> --appExe <file.exe> [--restartDelayMs <int>] [--updateDelayMs <int>] [--waitProcess <int>]";
|
||||||
|
|
||||||
|
/// <summary>Парсинг CLI аргументов в Options.</summary>
|
||||||
public static Options Parse(string[] args)
|
public static Options Parse(string[] args)
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
@@ -46,7 +49,8 @@ public sealed class Options
|
|||||||
InstallPath = Path.GetFullPath(install),
|
InstallPath = Path.GetFullPath(install),
|
||||||
AppExe = exe,
|
AppExe = exe,
|
||||||
RestartDelayMs = dict.TryGetValue("restartDelayMs", out var d) && int.TryParse(d, out var n) ? n : 500,
|
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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Updater.Core;
|
using System.Diagnostics;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Updater.Core;
|
||||||
|
|
||||||
namespace Updater;
|
namespace Updater;
|
||||||
|
|
||||||
@@ -22,6 +24,22 @@ internal sealed class Program
|
|||||||
|
|
||||||
Thread.Sleep(options.UpdateDelayMs);
|
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 extractor = new ZipExtractor(logger);
|
||||||
var installer = new SafeFileInstaller(logger);
|
var installer = new SafeFileInstaller(logger);
|
||||||
var procMgr = new ProcessManager(logger);
|
var procMgr = new ProcessManager(logger);
|
||||||
|
|||||||
Reference in New Issue
Block a user