This commit is contained in:
+24
-45
@@ -12,7 +12,6 @@ namespace PamhagenSysCtrl {
|
||||
public static Dispatcher? MainDispatcher;
|
||||
|
||||
private readonly DispatcherTimer AutoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||
private bool IsCheckingForUpdates;
|
||||
|
||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Anlagensteuerung Pamhagen");
|
||||
public static readonly string ConfigPath = Path.Combine(DataPath, "config.ini");
|
||||
@@ -50,69 +49,49 @@ namespace PamhagenSysCtrl {
|
||||
|
||||
base.OnStartup(evt);
|
||||
|
||||
if (Config.UpdateAuto && Config.UpdateUrl != null) {
|
||||
AutoUpdateTimer.Tick += async (_, _) => await CheckForUpdates();
|
||||
if (Config.UpdateUrl != null && Config.UpdateAuto) {
|
||||
AutoUpdateTimer.Tick += async (_, _) => {
|
||||
try {
|
||||
await CheckForUpdates();
|
||||
} catch { }
|
||||
};
|
||||
AutoUpdateTimer.Start();
|
||||
_ = Dispatcher.BeginInvoke(async () => {
|
||||
await Dispatcher.BeginInvoke(async () => {
|
||||
await Task.Delay(1500);
|
||||
await CheckForUpdates();
|
||||
try {
|
||||
await CheckForUpdates();
|
||||
} catch { }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CheckForUpdates(bool showResult = false) {
|
||||
if (IsCheckingForUpdates) {
|
||||
if (showResult) {
|
||||
MessageBox.Show("Es wird bereits nach Updates gesucht.", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Config.UpdateUrl == null) {
|
||||
if (showResult) {
|
||||
MessageBox.Show("Die automatische Update-Suche ist deaktiviert.", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
return;
|
||||
}
|
||||
public static async Task CheckForUpdates(bool showResult = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
|
||||
IsCheckingForUpdates = true;
|
||||
try {
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(15));
|
||||
var latest = await UpdateService.GetLatestInstallerAsync(Config.UpdateUrl, timeout.Token);
|
||||
if (latest.Version > Version) {
|
||||
var dialog = new UpdateDialog(latest) {
|
||||
Owner = MainWindow,
|
||||
var latest = await UpdateService.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
if (latest.HasValue && new Version(latest.Value.Version) > Version) {
|
||||
var dialog = new UpdateDialog(latest.Value.Version, latest.Value.Url, latest.Value.Size) {
|
||||
Owner = Current.MainWindow,
|
||||
};
|
||||
if (dialog.ShowDialog() == true) {
|
||||
Shutdown();
|
||||
Current.Shutdown();
|
||||
}
|
||||
} else if (showResult) {
|
||||
MessageBox.Show(
|
||||
$"Die Anlagensteuerung ist auf dem aktuellen Stand. (Version {Version})",
|
||||
"Nach Updates suchen",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information
|
||||
);
|
||||
MessageBox.Show($"Die Anlagensteuerung ist auf dem aktuellen Stand.\n(Version {Version})", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
} catch (OperationCanceledException) {
|
||||
if (showResult) {
|
||||
MessageBox.Show(
|
||||
"Zeitüberschreitung beim Abrufen der Update-Informationen.",
|
||||
"Nach Updates suchen",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
MessageBox.Show("Zeitüberschreitung beim Abrufen der Update-Informationen.", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
if (showResult) {
|
||||
MessageBox.Show(
|
||||
$"Die Update-Informationen konnten nicht abgerufen werden:\n\n{exc.Message}",
|
||||
"Nach Updates suchen",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
MessageBox.Show($"Die Update-Informationen konnten nicht abgerufen werden:\n\n{exc.Message}", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
} finally {
|
||||
IsCheckingForUpdates = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user