Add UpdateStarted event to signal when update download begins

This commit is contained in:
Stone_Red
2026-02-20 20:42:25 +01:00
parent 16d2f8ced4
commit 1dd95c7b10
3 changed files with 24 additions and 0 deletions
+6
View File
@@ -11,6 +11,7 @@ internal class Program
{ {
updater.ProgressChanged += Updater_ProgressChanged; updater.ProgressChanged += Updater_ProgressChanged;
updater.UpdateAvailable += Updater_UpdateAvailable; updater.UpdateAvailable += Updater_UpdateAvailable;
updater.UpdateStarted += Updater_UpdateStarted;
updater.NoUpdateAvailable += Updater_NoUpdateAvailable; updater.NoUpdateAvailable += Updater_NoUpdateAvailable;
updater.OnException += Updater_OnException; updater.OnException += Updater_OnException;
updater.Start(); updater.Start();
@@ -42,6 +43,11 @@ internal class Program
Console.WriteLine($"[{step}] {itemsProcessed}/{totalItems} {progressPercentage}%"); Console.WriteLine($"[{step}] {itemsProcessed}/{totalItems} {progressPercentage}%");
} }
private static void Updater_UpdateStarted(string version)
{
Console.WriteLine($"Starting update to version {version}...");
}
private static void Updater_NoUpdateAvailable() private static void Updater_NoUpdateAvailable()
{ {
Console.WriteLine("You are up to date!"); Console.WriteLine("You are up to date!");
+13
View File
@@ -66,6 +66,17 @@ namespace AlwaysUpToDate
/// </summary> /// </summary>
public event ExceptionHandler OnException; public event ExceptionHandler OnException;
/// <summary>
/// Represents the method that will handle notifications when the update process begins.
/// </summary>
/// <param name="version">The version string of the update being installed.</param>
public delegate void UpdateStartedHandler(string version);
/// <summary>
/// Occurs once when the update download begins, before the first <see cref="ProgressChanged"/> event.
/// </summary>
public event UpdateStartedHandler UpdateStarted;
private static readonly XmlSerializer manifestSerializer = new XmlSerializer(typeof(UpdateManifest)); private static readonly XmlSerializer manifestSerializer = new XmlSerializer(typeof(UpdateManifest));
private readonly HttpClient httpClient = new HttpClient(); private readonly HttpClient httpClient = new HttpClient();
private readonly System.Timers.Timer updateTimer = new System.Timers.Timer(); private readonly System.Timers.Timer updateTimer = new System.Timers.Timer();
@@ -242,6 +253,8 @@ namespace AlwaysUpToDate
updateTimer.Stop(); updateTimer.Stop();
_ = Interlocked.Exchange(ref updating, 1); _ = Interlocked.Exchange(ref updating, 1);
UpdateStarted?.Invoke(pendingUpdateItem?.Version);
using HttpResponseMessage response = await httpClient.GetAsync(updateUrl); using HttpResponseMessage response = await httpClient.GetAsync(updateUrl);
_ = response.EnsureSuccessStatusCode(); _ = response.EnsureSuccessStatusCode();
+5
View File
@@ -51,12 +51,17 @@ updater.Start();
... ...
updater.ProgressChanged += Updater_ProgressChanged; updater.ProgressChanged += Updater_ProgressChanged;
updater.UpdateAvailible += Updater_UpdateAvailible; updater.UpdateAvailible += Updater_UpdateAvailible;
updater.UpdateStarted += Updater_UpdateStarted;
} }
private static void Updater_UpdateAvailible(string version, string additionalInformationUrl) private static void Updater_UpdateAvailible(string version, string additionalInformationUrl)
{ {
} }
private static void Updater_UpdateStarted(string version)
{
}
private static void Updater_ProgressChanged(UpdateStep step, long? totalItems, long itemsProcessed, double? progressPercentage) private static void Updater_ProgressChanged(UpdateStep step, long? totalItems, long itemsProcessed, double? progressPercentage)
{ {
} }