diff --git a/Elwig/Dialogs/UpdateDialog.xaml b/Elwig/Dialogs/UpdateDialog.xaml
index 570c656..58ea9f7 100644
--- a/Elwig/Dialogs/UpdateDialog.xaml
+++ b/Elwig/Dialogs/UpdateDialog.xaml
@@ -5,9 +5,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
WindowStartupLocation="CenterOwner"
- Title="Neues Update verfügbar - Elwig" Height="180" Width="400">
+ Title="Neues Update verfügbar - Elwig" Height="190" Width="400"
+ Closed="OnClosed">
-
Version 0.0.0 von Elwig ist verfügbar!
(Änderungen)
@@ -20,12 +21,12 @@
HorizontalAlignment="Center" VerticalAlignment="Center"
Height="27" Width="300" SnapsToDevicePixels="True"/>
-
-
diff --git a/Elwig/Dialogs/UpdateDialog.xaml.cs b/Elwig/Dialogs/UpdateDialog.xaml.cs
index 84d22c9..e8f498a 100644
--- a/Elwig/Dialogs/UpdateDialog.xaml.cs
+++ b/Elwig/Dialogs/UpdateDialog.xaml.cs
@@ -3,6 +3,7 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Navigation;
@@ -13,36 +14,47 @@ namespace Elwig.Dialogs {
public string Version { get; private set; }
public string Url { get; private set; }
+ private readonly CancellationTokenSource Cancellation;
+
public UpdateDialog(string version, string url, long size) {
Version = version;
Url = url;
+ Cancellation = new();
InitializeComponent();
VersionText.Text = version;
SizeText.Text = $"{size / 1024 / 1024}";
}
+ private void OnClosed(object sender, EventArgs evt) {
+ Cancellation.Cancel();
+ }
+
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");
- {
+ try {
using var stream = new FileStream(fileName, FileMode.Create);
using var client = new HttpClient() {
Timeout = TimeSpan.FromSeconds(5),
};
await client.DownloadAsync(Url, stream, new Progress(p => {
ProgressBar.Value = p * 100.0;
- }));
+ }), Cancellation.Token);
+ } catch (OperationCanceledException) {
+ File.Delete(fileName);
+ return;
+ } catch (Exception exc) {
+ MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
-
Process.Start(fileName);
+ DialogResult = true;
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {