Skip to content

Commit

Permalink
Refactor UpdateManager, download file in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Oct 28, 2024
1 parent c72b275 commit 6f00d5f
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/PicView.Avalonia/Update/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class UpdateManager
{
public static async Task UpdateCurrentVersion(MainViewModel vm)
{
// TODO Add support for other OS
// TODO add UI
var currentDirectory = new DirectoryInfo(Environment.ProcessPath);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down Expand Up @@ -53,8 +55,8 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)

// ReSharper disable once RedundantAssignment
var currentVersion = VersionHelper.GetAssemblyVersion();
var url = "https://picview.org/update.json";
var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + "PicView");
const string url = "https://picview.org/update.json";
var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
var tempJsonFileDestination = Path.Combine(tempPath, "update.json");

Expand Down Expand Up @@ -134,18 +136,23 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
{
StartInfo = new ProcessStartInfo
{
Verb = "runas",
UseShellExecute = true,
FileName = tempFileDownloadPath
}
};
process.Start();
return;
case InstalledArchitecture.Arm64Portable:
fileName = Path.GetFileName(updateInfo.X64Portable);
tempFileDownloadPath = Path.Combine(tempPath, fileName);
await StartFileDownloader(vm, updateInfo.Arm64Portable, tempFileDownloadPath);
vm.PlatformService.LocateOnDisk(tempFileDownloadPath);
process = new Process
{
StartInfo = new ProcessStartInfo(updateInfo.Arm64Portable)
{
UseShellExecute = true,
Verb = "open"
}
};
process.Start();
await process.WaitForExitAsync();
return;
case InstalledArchitecture.X64Install:
fileName = Path.GetFileName(updateInfo.X64Install);
Expand All @@ -162,10 +169,16 @@ public static async Task UpdateCurrentVersion(MainViewModel vm)
process.Start();
return;
case InstalledArchitecture.X64Portable:
fileName = Path.GetFileName(updateInfo.X64Portable);
tempFileDownloadPath = Path.Combine(tempPath, fileName);
await StartFileDownloader(vm, updateInfo.X64Portable, tempFileDownloadPath);
vm.PlatformService.LocateOnDisk(tempFileDownloadPath);
process = new Process
{
StartInfo = new ProcessStartInfo(updateInfo.X64Portable)
{
UseShellExecute = true,
Verb = "open"
}
};
process.Start();
await process.WaitForExitAsync();
return;
}
}
Expand Down

0 comments on commit 6f00d5f

Please sign in to comment.