diff --git a/AlwaysUpToDate.Test/Program.cs b/AlwaysUpToDate.Test/Program.cs index d72c1a3..4a6c43d 100644 --- a/AlwaysUpToDate.Test/Program.cs +++ b/AlwaysUpToDate.Test/Program.cs @@ -11,6 +11,7 @@ internal class Program { updater.ProgressChanged += Updater_ProgressChanged; updater.UpdateAvailable += Updater_UpdateAvailable; + updater.UpdateStarted += Updater_UpdateStarted; updater.NoUpdateAvailable += Updater_NoUpdateAvailable; updater.OnException += Updater_OnException; updater.Start(); @@ -42,6 +43,11 @@ internal class Program 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() { Console.WriteLine("You are up to date!"); diff --git a/AlwaysUpToDate/DownloadManager.cs b/AlwaysUpToDate/DownloadManager.cs index 5e54ed9..5ffadec 100644 --- a/AlwaysUpToDate/DownloadManager.cs +++ b/AlwaysUpToDate/DownloadManager.cs @@ -66,6 +66,17 @@ namespace AlwaysUpToDate /// public event ExceptionHandler OnException; + /// + /// Represents the method that will handle notifications when the update process begins. + /// + /// The version string of the update being installed. + public delegate void UpdateStartedHandler(string version); + + /// + /// Occurs once when the update download begins, before the first event. + /// + public event UpdateStartedHandler UpdateStarted; + private static readonly XmlSerializer manifestSerializer = new XmlSerializer(typeof(UpdateManifest)); private readonly HttpClient httpClient = new HttpClient(); private readonly System.Timers.Timer updateTimer = new System.Timers.Timer(); @@ -242,6 +253,8 @@ namespace AlwaysUpToDate updateTimer.Stop(); _ = Interlocked.Exchange(ref updating, 1); + UpdateStarted?.Invoke(pendingUpdateItem?.Version); + using HttpResponseMessage response = await httpClient.GetAsync(updateUrl); _ = response.EnsureSuccessStatusCode(); diff --git a/README.md b/README.md index 66f0aa5..4b9bd4f 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,17 @@ updater.Start(); ... updater.ProgressChanged += Updater_ProgressChanged; updater.UpdateAvailible += Updater_UpdateAvailible; + updater.UpdateStarted += Updater_UpdateStarted; } 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) { }