Browse Source

Add update handling for zip files

pull/269/head
Ionite 1 year ago
parent
commit
fae4add130
No known key found for this signature in database
  1. 42
      StabilityMatrix.Core/Updater/UpdateHelper.cs

42
StabilityMatrix.Core/Updater/UpdateHelper.cs

@ -61,15 +61,39 @@ public class UpdateHelper : IUpdateHelper
UpdateFolder.Create(); UpdateFolder.Create();
UpdateFolder.Info.Attributes |= FileAttributes.Hidden; UpdateFolder.Info.Attributes |= FileAttributes.Hidden;
// download the file from URL var downloadFile = UpdateFolder.JoinFile(Path.GetFileName(updateInfo.Url.ToString()));
await downloadService
.DownloadToFileAsync( try
updateInfo.Url.ToString(), {
ExecutablePath, // download the file from URL
progress: progress, await downloadService
httpClientName: "UpdateClient" .DownloadToFileAsync(
) updateInfo.Url.ToString(),
.ConfigureAwait(false); 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() private async Task CheckForUpdate()

Loading…
Cancel
Save