Files
pamhagen-sysctrl/PamhagenSysCtrl/Dialogs/UpdateDialog.xaml.cs
T
2026-08-08 00:09:06 +02:00

50 lines
2.0 KiB
C#

using PamhagenSysCtrl.Helpers;
using System.Windows;
namespace PamhagenSysCtrl.Dialogs {
public partial class UpdateDialog : Window {
private readonly UpdateInstaller Installer;
private readonly CancellationTokenSource Cancellation = new();
public UpdateDialog(UpdateInstaller installer) {
Installer = installer;
InitializeComponent();
VersionText.Text = installer.Version.ToString();
SizeText.Text = Math.Ceiling(installer.Size / 1024d / 1024d).ToString("N0");
}
private void OnClosed(object? sender, EventArgs evt) {
Cancellation.Cancel();
Cancellation.Dispose();
}
private async void InstallButton_Click(object sender, RoutedEventArgs evt) {
Description.Visibility = Visibility.Collapsed;
DownloadPanel.Visibility = Visibility.Visible;
InstallButton.IsEnabled = false;
try {
var progress = new Progress<double>(value => DownloadProgress.Value = value * 100);
var fileName = await UpdateService.DownloadInstallerAsync(Installer, App.TempPath, progress, Cancellation.Token);
StatusText.Text = "Installer wird gestartet...";
UpdateService.StartInstaller(fileName);
DialogResult = true;
} catch (OperationCanceledException) {
// Closing the dialog cancels an active download.
} catch (Exception exc) {
MessageBox.Show(
this,
$"Das Update konnte nicht installiert werden:\n\n{exc.Message}",
"Update installieren",
MessageBoxButton.OK,
MessageBoxImage.Error
);
Description.Visibility = Visibility.Visible;
DownloadPanel.Visibility = Visibility.Collapsed;
InstallButton.IsEnabled = true;
}
}
}
}