From fae4add130f5d987b80e648dcab9026a278dd11e Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 17 Nov 2023 16:39:21 -0500 Subject: [PATCH] Add update handling for zip files --- StabilityMatrix.Core/Updater/UpdateHelper.cs | 42 +++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/StabilityMatrix.Core/Updater/UpdateHelper.cs b/StabilityMatrix.Core/Updater/UpdateHelper.cs index f990a81c..a9751348 100644 --- a/StabilityMatrix.Core/Updater/UpdateHelper.cs +++ b/StabilityMatrix.Core/Updater/UpdateHelper.cs @@ -61,15 +61,39 @@ public class UpdateHelper : IUpdateHelper UpdateFolder.Create(); UpdateFolder.Info.Attributes |= FileAttributes.Hidden; - // download the file from URL - await downloadService - .DownloadToFileAsync( - updateInfo.Url.ToString(), - ExecutablePath, - progress: progress, - httpClientName: "UpdateClient" - ) - .ConfigureAwait(false); + var downloadFile = UpdateFolder.JoinFile(Path.GetFileName(updateInfo.Url.ToString())); + + try + { + // download the file from URL + await downloadService + .DownloadToFileAsync( + updateInfo.Url.ToString(), + downloadFile, + progress: progress, + httpClientName: "UpdateClient" + ) + .ConfigureAwait(false); + + // Unzip if needed + if (downloadFile.Extension == ".zip") + { + await ArchiveHelper + .Extract(downloadFile, UpdateFolder, progress) + .ConfigureAwait(false); + await downloadFile.DeleteAsync().ConfigureAwait(false); + } + // Otherwise just rename + else + { + downloadFile.Rename(ExecutablePath.Name); + } + } + finally + { + // Clean up original download + await downloadFile.DeleteAsync().ConfigureAwait(false); + } } private async Task CheckForUpdate()