Files
Chris Kaczor fe3941d8bd
All checks were successful
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 54s
Fix update source
2026-01-27 20:40:39 -05:00

50 lines
1.8 KiB
C#

using System.Threading.Tasks;
using System.Windows;
using NuGet.Versioning;
using Serilog;
using Velopack;
using Velopack.Sources;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal static class UpdateCheck
{
private static UpdateManager? _updateManager;
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GiteaSource("https://gitea.kaczorzoo.net/ckaczor/HardwareMonitorStatusWindow", null, false));
public static string LocalVersion => (UpdateManager.CurrentVersion ?? new SemanticVersion(0, 0, 0)).ToString();
public static bool IsInstalled => UpdateManager.IsInstalled;
public static async Task DisplayUpdateInformation(bool showIfCurrent)
{
var newVersion = IsInstalled ? await UpdateManager.CheckForUpdatesAsync() : null;
if (newVersion != null)
{
var updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationName);
var updateCheckMessage = string.Format(Resources.UpdateCheckNewVersion, newVersion.TargetFullRelease.Version);
if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return;
Log.Information("Downloading update");
await UpdateManager.DownloadUpdatesAsync(newVersion);
Log.Information("Installing update");
UpdateManager.ApplyUpdatesAndRestart(newVersion);
}
else if (showIfCurrent)
{
var updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationName);
var updateCheckMessage = string.Format(Resources.UpdateCheckCurrent, Resources.ApplicationName);
MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}