From 2c804375feeb10fe4e28e92ffb93c3e18d1fcd22 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Thu, 3 Oct 2024 23:40:55 -0500 Subject: [PATCH] Apply same refactoring to launcher --- .../UpdateService.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/LANCommander.Launcher.Services/UpdateService.cs b/LANCommander.Launcher.Services/UpdateService.cs index 129f2985..c86d19ed 100644 --- a/LANCommander.Launcher.Services/UpdateService.cs +++ b/LANCommander.Launcher.Services/UpdateService.cs @@ -4,6 +4,7 @@ using Semver; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO.Compression; using System.Linq; using System.Reflection; using System.Text; @@ -32,9 +33,15 @@ namespace LANCommander.Launcher.Services { var settings = SettingService.GetSettings(); - Logger?.LogInformation("Updating launcher to v{Version}", version); + Logger?.LogInformation("Downloading launcher v{Version}", version); - await Client.Launcher.DownloadAsync(Path.Combine(settings.Updates.StoragePath, $"{version}.zip")); + string path = Path.Combine(settings.Updates.StoragePath, $"{version}.zip"); + + await Client.Launcher.DownloadAsync(path); + + Logger?.LogInformation("Update version {Version} has been downloaded", version); + + Logger?.LogInformation("New autoupdater is being extracted"); string processExecutable = String.Empty; @@ -43,6 +50,14 @@ namespace LANCommander.Launcher.Services else if (File.Exists("LANCommander.AutoUpdater")) processExecutable = "LANCommander.AutoUpdater"; + using (ZipArchive archive = ZipFile.OpenRead(path)) + { + foreach (ZipArchiveEntry entry in archive.Entries.Where(e => e.FullName == processExecutable)) + { + entry.ExtractToFile(Path.Combine(processExecutable, entry.FullName)); + } + } + var process = new ProcessStartInfo(); process.FileName = processExecutable;