Files
elwig/Elwig/Dialogs/UpdateDialog.xaml.cs
Lorenz Stechauner 62f63ef63d
All checks were successful
Test / Run tests (push) Successful in 2m0s
UpdateDialog: Add Link to Changelog
2024-07-01 11:07:21 +02:00

56 lines
1.7 KiB
C#

using Elwig.Helpers;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Navigation;
namespace Elwig.Dialogs {
public partial class UpdateDialog : Window {
public string Version { get; private set; }
public string Url { get; private set; }
public UpdateDialog(string version, string url, long size) {
Version = version;
Url = url;
InitializeComponent();
VersionText.Text = version;
SizeText.Text = $"{size / 1024 / 1024}";
}
private async void InstallButton_Click(object sender, RoutedEventArgs evt) {
Description.Visibility = Visibility.Hidden;
ProgressBar.Visibility = Visibility.Visible;
InstallButton.IsEnabled = false;
await Install();
DialogResult = true;
Close();
}
public async Task Install() {
var fileName = Path.Combine(App.TempPath, $"Elwig-{Version}.exe");
{
using var stream = new FileStream(fileName, FileMode.Create);
using var client = new HttpClient() {
Timeout = TimeSpan.FromSeconds(5),
};
await client.DownloadAsync(Url, stream, new Progress<double>(p => {
ProgressBar.Value = p * 100.0;
}));
}
Process.Start(fileName);
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo {
FileName = e.Uri.ToString(),
UseShellExecute = true,
});
}
}
}