- Refactoring
- Resource strings
This commit is contained in:
2024-09-30 20:10:42 -04:00
parent 6d4d33c82f
commit 4751ae476d
4 changed files with 94 additions and 58 deletions

View File

@@ -79,6 +79,15 @@ namespace WorldClockStatusWindow.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Checking for update....
/// </summary>
public static string CheckingForUpdate {
get {
return ResourceManager.GetString("CheckingForUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Check for Update.
/// </summary>
@@ -115,6 +124,33 @@ namespace WorldClockStatusWindow.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Downloading update....
/// </summary>
public static string DownloadingUpdate {
get {
return ResourceManager.GetString("DownloadingUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Installing update....
/// </summary>
public static string InstallingUpdate {
get {
return ResourceManager.GetString("InstallingUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Loading....
/// </summary>
public static string Loading {
get {
return ResourceManager.GetString("Loading", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to About.
/// </summary>

View File

@@ -163,8 +163,20 @@
No updates are available at this time.</value>
</data>
<data name="UpdateCheckNewVersion" xml:space="preserve">
<value>Version {1} of {0} is now available.
<value>Version {0} is now available.
Would you like to download and install it now?</value>
</data>
<data name="Loading" xml:space="preserve">
<value>Loading...</value>
</data>
<data name="CheckingForUpdate" xml:space="preserve">
<value>Checking for update...</value>
</data>
<data name="DownloadingUpdate" xml:space="preserve">
<value>Downloading update...</value>
</data>
<data name="InstallingUpdate" xml:space="preserve">
<value>Installing update...</value>
</data>
</root>

View File

@@ -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);
}
}
}
}

View File

@@ -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<List<TimeZoneEntry>>(Properties.Settings.Default.TimeZones);
_timeZoneEntries = JsonSerializer.Deserialize<List<TimeZoneEntry>>(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();
}
}
}