diff --git a/App.config b/App.config
index 24584f9..e134e5c 100644
--- a/App.config
+++ b/App.config
@@ -22,6 +22,9 @@
[]
+
+ True
+
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 128db22..3abdce2 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,16 +1,12 @@
using Microsoft.Extensions.Logging;
-using NuGet.Versioning;
using Serilog;
using System;
using Velopack;
-using Velopack.Sources;
namespace WorldClockStatusWindow;
internal class Program
{
- private static UpdateManager _updateManager;
-
[STAThread]
public static void Main(string[] args)
{
@@ -28,8 +24,4 @@ internal class Program
Log.Logger.Information("End");
}
-
- 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();
}
\ No newline at end of file
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
index 3c5fbeb..606d2ab 100644
--- a/Properties/Resources.Designer.cs
+++ b/Properties/Resources.Designer.cs
@@ -88,6 +88,24 @@ namespace WorldClockStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Check _Now.
+ ///
+ public static string checkVersionNowButton {
+ get {
+ return ResourceManager.GetString("checkVersionNowButton", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to _Check for a new version on startup.
+ ///
+ public static string checkVersionOnStartupCheckBox {
+ get {
+ return ResourceManager.GetString("checkVersionOnStartupCheckBox", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Close.
///
@@ -115,6 +133,15 @@ namespace WorldClockStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Update.
+ ///
+ public static string optionCategoryUpdate {
+ get {
+ return ResourceManager.GetString("optionCategoryUpdate", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Settings.
///
@@ -133,6 +160,37 @@ namespace WorldClockStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to You are already running the most recent version.
+ ///
+ ///No updates are available at this time..
+ ///
+ public static string UpdateCheckCurrent {
+ get {
+ return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Version {1} of {0} is now available.
+ ///
+ ///Would you like to download and install it now?.
+ ///
+ public static string UpdateCheckNewVersion {
+ get {
+ return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to {0} Update.
+ ///
+ public static string UpdateCheckTitle {
+ get {
+ return ResourceManager.GetString("UpdateCheckTitle", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Version {0}.
///
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index be32e6e..0b023e5 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -145,4 +145,26 @@
Version {0}
+
+ Update
+
+
+ _Check for a new version on startup
+
+
+ Check _Now
+
+
+ {0} Update
+
+
+ You are already running the most recent version.
+
+No updates are available at this time.
+
+
+ Version {1} of {0} is now available.
+
+Would you like to download and install it now?
+
\ No newline at end of file
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
index 8f5d4c5..bf9081a 100644
--- a/Properties/Settings.Designer.cs
+++ b/Properties/Settings.Designer.cs
@@ -70,5 +70,17 @@ namespace WorldClockStatusWindow.Properties {
this["TimeZones"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
+ public bool CheckVersionAtStartup {
+ get {
+ return ((bool)(this["CheckVersionAtStartup"]));
+ }
+ set {
+ this["CheckVersionAtStartup"] = value;
+ }
+ }
}
}
diff --git a/Properties/Settings.settings b/Properties/Settings.settings
index dd70d6c..ee3bfb2 100644
--- a/Properties/Settings.settings
+++ b/Properties/Settings.settings
@@ -14,5 +14,8 @@
[]
+
+ True
+
\ No newline at end of file
diff --git a/SettingsWindow/AboutSettingsPanel.xaml b/SettingsWindow/AboutSettingsPanel.xaml
index e3fb541..70de048 100644
--- a/SettingsWindow/AboutSettingsPanel.xaml
+++ b/SettingsWindow/AboutSettingsPanel.xaml
@@ -13,7 +13,7 @@
-
diff --git a/SettingsWindow/UpdateSettingsPanel.xaml b/SettingsWindow/UpdateSettingsPanel.xaml
new file mode 100644
index 0000000..5a48289
--- /dev/null
+++ b/SettingsWindow/UpdateSettingsPanel.xaml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SettingsWindow/UpdateSettingsPanel.xaml.cs b/SettingsWindow/UpdateSettingsPanel.xaml.cs
new file mode 100644
index 0000000..6849706
--- /dev/null
+++ b/SettingsWindow/UpdateSettingsPanel.xaml.cs
@@ -0,0 +1,31 @@
+using System.Windows;
+using WorldClockStatusWindow.Properties;
+
+namespace WorldClockStatusWindow.SettingsWindow;
+
+public partial class UpdateSettingsPanel
+{
+ public UpdateSettingsPanel()
+ {
+ InitializeComponent();
+ }
+
+ public override string CategoryName => Properties.Resources.optionCategoryUpdate;
+
+ private void HandleCheckVersionNowButtonClick(object sender, RoutedEventArgs e)
+ {
+ UpdateCheck.DisplayUpdateInformation(true);
+ }
+
+ private void OnSaveSettings(object sender, RoutedEventArgs e)
+ {
+ SaveSettings();
+ }
+
+ private void SaveSettings()
+ {
+ if (!HasLoaded) return;
+
+ Settings.Default.Save();
+ }
+}
\ No newline at end of file
diff --git a/UpdateCheck.cs b/UpdateCheck.cs
new file mode 100644
index 0000000..cc28fe6
--- /dev/null
+++ b/UpdateCheck.cs
@@ -0,0 +1,60 @@
+using NuGet.Versioning;
+using Serilog;
+using System.Windows;
+using Velopack;
+using Velopack.Sources;
+
+namespace WorldClockStatusWindow
+{
+ 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 void DisplayUpdateInformation(bool showIfCurrent)
+ {
+ UpdateInfo newVersion = null;
+
+ if (IsInstalled)
+ {
+ newVersion = await UpdateManager.CheckForUpdatesAsync();
+ }
+
+ if (newVersion != null)
+ {
+ // Format the check title
+ var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName);
+
+ // Format the message
+ var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckNewVersion, Properties.Resources.ApplicationName, newVersion.TargetFullRelease.Version);
+
+ // Ask the user to update
+ if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
+ return;
+
+ Log.Logger.Information("Downloading update");
+
+ await UpdateManager.DownloadUpdatesAsync(newVersion);
+
+ Log.Logger.Information("Installing update");
+
+ 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);
+ }
+ }
+ }
+}
diff --git a/WindowSource.cs b/WindowSource.cs
index af94144..13ef4c9 100644
--- a/WindowSource.cs
+++ b/WindowSource.cs
@@ -1,4 +1,5 @@
-using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
+using ChrisKaczor.Wpf.Windows;
+using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
using Serilog;
using System;
using System.Collections.Generic;
@@ -9,7 +10,6 @@ using System.Text.Json;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Threading;
-using ChrisKaczor.Wpf.Windows;
using WorldClockStatusWindow.SettingsWindow;
namespace WorldClockStatusWindow;
@@ -38,14 +38,17 @@ internal class WindowSource : IWindowSource, IDisposable
{
try
{
- if (!Program.UpdateManager.IsInstalled)
+ if (!UpdateCheck.IsInstalled)
+ return false;
+
+ if (!Properties.Settings.Default.CheckVersionAtStartup)
return false;
Log.Logger.Information("Checking for update");
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update..."));
- var newVersion = await Program.UpdateManager.CheckForUpdatesAsync();
+ var newVersion = await UpdateCheck.UpdateManager.CheckForUpdatesAsync();
if (newVersion == null)
return false;
@@ -54,13 +57,13 @@ internal class WindowSource : IWindowSource, IDisposable
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update..."));
- await Program.UpdateManager.DownloadUpdatesAsync(newVersion);
+ await UpdateCheck.UpdateManager.DownloadUpdatesAsync(newVersion);
Log.Logger.Information("Installing update");
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update..."));
- Program.UpdateManager.ApplyUpdatesAndRestart(newVersion);
+ UpdateCheck.UpdateManager.ApplyUpdatesAndRestart(newVersion);
}
catch (Exception e)
{
@@ -158,6 +161,7 @@ internal class WindowSource : IWindowSource, IDisposable
var categoryPanels = new List
{
new GeneralSettingsPanel(),
+ new UpdateSettingsPanel(),
new AboutSettingsPanel()
};
diff --git a/WorldClockStatusWindow.sln.DotSettings b/WorldClockStatusWindow.sln.DotSettings
new file mode 100644
index 0000000..c960585
--- /dev/null
+++ b/WorldClockStatusWindow.sln.DotSettings
@@ -0,0 +1,2 @@
+
+ True
\ No newline at end of file