51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System.Diagnostics;
|
|
using System.Security.Cryptography;
|
|
using Updater.Core;
|
|
|
|
namespace Updater;
|
|
|
|
internal sealed class Program
|
|
{
|
|
static int Main(string[] args)
|
|
{
|
|
var logger = new ConsoleLogger();
|
|
Options? options;
|
|
try
|
|
{
|
|
options = Options.Parse(args);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error($"Arguments error: {ex.Message}");
|
|
Console.WriteLine(Options.Usage);
|
|
return ExitCodes.InvalidArgs;
|
|
}
|
|
|
|
|
|
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);
|
|
var app = new UpdaterApp(logger, extractor, installer, procMgr);
|
|
|
|
return app.Run(options);
|
|
}
|
|
}
|