diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 606d2ab..7b0b639 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -79,6 +79,15 @@ namespace WorldClockStatusWindow.Properties { } } + /// + /// Looks up a localized string similar to Checking for update.... + /// + public static string CheckingForUpdate { + get { + return ResourceManager.GetString("CheckingForUpdate", resourceCulture); + } + } + /// /// Looks up a localized string similar to _Check for Update. /// @@ -115,6 +124,33 @@ namespace WorldClockStatusWindow.Properties { } } + /// + /// Looks up a localized string similar to Downloading update.... + /// + public static string DownloadingUpdate { + get { + return ResourceManager.GetString("DownloadingUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Installing update.... + /// + public static string InstallingUpdate { + get { + return ResourceManager.GetString("InstallingUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Loading.... + /// + public static string Loading { + get { + return ResourceManager.GetString("Loading", resourceCulture); + } + } + /// /// Looks up a localized string similar to About. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 0b023e5..de940b8 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -163,8 +163,20 @@ No updates are available at this time. - Version {1} of {0} is now available. + Version {0} is now available. Would you like to download and install it now? + + Loading... + + + Checking for update... + + + Downloading update... + + + Installing update... + \ No newline at end of file diff --git a/UpdateCheck.cs b/UpdateCheck.cs index 9c1997d..ca6c93e 100644 --- a/UpdateCheck.cs +++ b/UpdateCheck.cs @@ -5,57 +5,46 @@ using System.Windows; using Velopack; using Velopack.Sources; -namespace WorldClockStatusWindow +namespace WorldClockStatusWindow; + +internal static class UpdateCheck { - internal static class UpdateCheck + private static UpdateManager _updateManager; + + public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", 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) { - private static UpdateManager _updateManager; + var newVersion = IsInstalled ? await UpdateManager.CheckForUpdatesAsync() : null; - public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", 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) + if (newVersion != null) { - UpdateInfo newVersion = null; + var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName); - if (IsInstalled) - { - newVersion = await UpdateManager.CheckForUpdatesAsync(); - } + var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckNewVersion, newVersion.TargetFullRelease.Version); - if (newVersion != null) - { - // Format the check title - var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName); + if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) + return; - // Format the message - var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckNewVersion, Properties.Resources.ApplicationName, newVersion.TargetFullRelease.Version); + Log.Logger.Information("Downloading update"); - // Ask the user to update - if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) - return; + await UpdateManager.DownloadUpdatesAsync(newVersion); - Log.Logger.Information("Downloading update"); + Log.Logger.Information("Installing update"); - await UpdateManager.DownloadUpdatesAsync(newVersion); + UpdateManager.ApplyUpdatesAndRestart(newVersion); + } + else if (showIfCurrent) + { + var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName); - Log.Logger.Information("Installing update"); + var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckCurrent, Properties.Resources.ApplicationName); - UpdateManager.ApplyUpdatesAndRestart(newVersion); - } - else if (showIfCurrent) - { - // Format the check title - var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName); - - // Format the message - var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckCurrent, Properties.Resources.ApplicationName); - - MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information); - } + MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information); } } -} +} \ No newline at end of file diff --git a/WindowSource.cs b/WindowSource.cs index 13ef4c9..49ad02c 100644 --- a/WindowSource.cs +++ b/WindowSource.cs @@ -4,12 +4,12 @@ using Serilog; using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Text; using System.Text.Json; using System.Threading.Tasks; using System.Timers; using System.Windows.Threading; +using WorldClockStatusWindow.Properties; using WorldClockStatusWindow.SettingsWindow; namespace WorldClockStatusWindow; @@ -25,7 +25,7 @@ internal class WindowSource : IWindowSource, IDisposable internal WindowSource() { _floatingStatusWindow = new FloatingStatusWindow(this); - _floatingStatusWindow.SetText("Loading..."); + _floatingStatusWindow.SetText(Resources.Loading); _dispatcher = Dispatcher.CurrentDispatcher; @@ -41,12 +41,12 @@ internal class WindowSource : IWindowSource, IDisposable if (!UpdateCheck.IsInstalled) return false; - if (!Properties.Settings.Default.CheckVersionAtStartup) + if (!Settings.Default.CheckVersionAtStartup) return false; Log.Logger.Information("Checking for update"); - await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.CheckingForUpdate)); var newVersion = await UpdateCheck.UpdateManager.CheckForUpdatesAsync(); @@ -55,13 +55,13 @@ internal class WindowSource : IWindowSource, IDisposable Log.Logger.Information("Downloading update"); - await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.DownloadingUpdate)); await UpdateCheck.UpdateManager.DownloadUpdatesAsync(newVersion); Log.Logger.Information("Installing update"); - await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update...")); + await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.InstallingUpdate)); UpdateCheck.UpdateManager.ApplyUpdatesAndRestart(newVersion); } @@ -92,7 +92,7 @@ internal class WindowSource : IWindowSource, IDisposable private void Load() { - _timeZoneEntries = JsonSerializer.Deserialize>(Properties.Settings.Default.TimeZones); + _timeZoneEntries = JsonSerializer.Deserialize>(Settings.Default.TimeZones); if (_timeZoneEntries.Any()) return; @@ -107,8 +107,8 @@ internal class WindowSource : IWindowSource, IDisposable private void Save() { - Properties.Settings.Default.TimeZones = JsonSerializer.Serialize(_timeZoneEntries); - Properties.Settings.Default.Save(); + Settings.Default.TimeZones = JsonSerializer.Serialize(_timeZoneEntries); + Settings.Default.Save(); } private void HandleTimerElapsed(object sender, ElapsedEventArgs e) @@ -126,7 +126,7 @@ internal class WindowSource : IWindowSource, IDisposable if (text.Length > 0) text.AppendLine(); - text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Properties.Settings.Default.TimeFormat)}"); + text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Settings.Default.TimeFormat)}"); } _dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString())); @@ -143,9 +143,9 @@ internal class WindowSource : IWindowSource, IDisposable public Guid Id => Guid.Parse("29DF6CFD-6783-406F-AE12-4723EB7741EA"); - public string Name => "World Clock"; + public string Name => Resources.ApplicationName; - public System.Drawing.Icon Icon => Properties.Resources.ApplicationIcon; + public System.Drawing.Icon Icon => Resources.ApplicationIcon; public bool HasSettingsMenu => true; @@ -153,7 +153,6 @@ internal class WindowSource : IWindowSource, IDisposable public void ShowAbout() { - _floatingStatusWindow.SetText(Assembly.GetEntryAssembly()!.GetName().Version!.ToString()); } public void ShowSettings() @@ -165,7 +164,7 @@ internal class WindowSource : IWindowSource, IDisposable new AboutSettingsPanel() }; - var settingsWindow = new CategoryWindow(categoryPanels, Properties.Resources.SettingsTitle, Properties.Resources.CloseButtonText); + var settingsWindow = new CategoryWindow(categoryPanels, Resources.SettingsTitle, Resources.CloseButtonText); var dialogResult = settingsWindow.ShowDialog(); @@ -183,11 +182,11 @@ internal class WindowSource : IWindowSource, IDisposable public string WindowSettings { - get => Properties.Settings.Default.WindowSettings; + get => Settings.Default.WindowSettings; set { - Properties.Settings.Default.WindowSettings = value; - Properties.Settings.Default.Save(); + Settings.Default.WindowSettings = value; + Settings.Default.Save(); } } } \ No newline at end of file