diff --git a/Program.cs b/Program.cs index 3abdce2..128db22 100644 --- a/Program.cs +++ b/Program.cs @@ -1,12 +1,16 @@ 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) { @@ -24,4 +28,8 @@ 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 920a087..3c5fbeb 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,10 +19,10 @@ namespace WorldClockStatusWindow.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { + public class Resources { private static global::System.Resources.ResourceManager resourceMan; @@ -36,7 +36,7 @@ namespace WorldClockStatusWindow.Properties { /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WorldClockStatusWindow.Properties.Resources", typeof(Resources).Assembly); @@ -51,7 +51,7 @@ namespace WorldClockStatusWindow.Properties { /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + public static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -63,11 +63,83 @@ namespace WorldClockStatusWindow.Properties { /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// - internal static System.Drawing.Icon ApplicationIcon { + public static System.Drawing.Icon ApplicationIcon { get { object obj = ResourceManager.GetObject("ApplicationIcon", resourceCulture); return ((System.Drawing.Icon)(obj)); } } + + /// + /// Looks up a localized string similar to World Clock Status Window. + /// + public static string ApplicationName { + get { + return ResourceManager.GetString("ApplicationName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Check for Update. + /// + public static string CheckUpdate { + get { + return ResourceManager.GetString("CheckUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close. + /// + public static string CloseButtonText { + get { + return ResourceManager.GetString("CloseButtonText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About. + /// + public static string optionCategoryAbout { + get { + return ResourceManager.GetString("optionCategoryAbout", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to General. + /// + public static string optionCategoryGeneral { + get { + return ResourceManager.GetString("optionCategoryGeneral", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + public static string SettingsTitle { + get { + return ResourceManager.GetString("SettingsTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Start when Windows starts. + /// + public static string startWithWindowsCheckBox { + get { + return ResourceManager.GetString("startWithWindowsCheckBox", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Version {0}. + /// + public static string Version { + get { + return ResourceManager.GetString("Version", resourceCulture); + } + } } } diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 14ab4ad..be32e6e 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -121,4 +121,28 @@ ..\Resources\Application.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + World Clock Status Window + + + About + + + _Check for Update + + + _Start when Windows starts + + + General + + + Settings + + + Close + + + Version {0} + \ No newline at end of file diff --git a/SettingsWindow/AboutSettingsPanel.xaml b/SettingsWindow/AboutSettingsPanel.xaml new file mode 100644 index 0000000..e3fb541 --- /dev/null +++ b/SettingsWindow/AboutSettingsPanel.xaml @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/SettingsWindow/AboutSettingsPanel.xaml.cs b/SettingsWindow/AboutSettingsPanel.xaml.cs new file mode 100644 index 0000000..c0d8332 --- /dev/null +++ b/SettingsWindow/AboutSettingsPanel.xaml.cs @@ -0,0 +1,12 @@ +namespace WorldClockStatusWindow.SettingsWindow +{ + public partial class AboutSettingsPanel + { + public AboutSettingsPanel() + { + InitializeComponent(); + } + + public override string CategoryName => Properties.Resources.optionCategoryAbout; + } +} \ No newline at end of file diff --git a/SettingsWindow/GeneralSettingsPanel.xaml b/SettingsWindow/GeneralSettingsPanel.xaml new file mode 100644 index 0000000..8f44969 --- /dev/null +++ b/SettingsWindow/GeneralSettingsPanel.xaml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/SettingsWindow/GeneralSettingsPanel.xaml.cs b/SettingsWindow/GeneralSettingsPanel.xaml.cs new file mode 100644 index 0000000..a3d2a8d --- /dev/null +++ b/SettingsWindow/GeneralSettingsPanel.xaml.cs @@ -0,0 +1,36 @@ +using ChrisKaczor.Wpf.Application; +using System.Windows; +using WorldClockStatusWindow.Properties; + +namespace WorldClockStatusWindow.SettingsWindow; + +public partial class GeneralSettingsPanel +{ + public GeneralSettingsPanel() + { + InitializeComponent(); + } + + public override string CategoryName => Properties.Resources.optionCategoryGeneral; + + public override void LoadPanel(Window parentWindow) + { + base.LoadPanel(parentWindow); + + MarkLoaded(); + } + + private void OnSaveSettings(object sender, RoutedEventArgs e) + { + SaveSettings(); + } + + private void SaveSettings() + { + if (!HasLoaded) return; + + Settings.Default.Save(); + + Application.Current.SetStartWithWindows(Settings.Default.AutoStart); + } +} \ No newline at end of file diff --git a/WindowSource.cs b/WindowSource.cs index de91b73..af94144 100644 --- a/WindowSource.cs +++ b/WindowSource.cs @@ -9,8 +9,8 @@ using System.Text.Json; using System.Threading.Tasks; using System.Timers; using System.Windows.Threading; -using Velopack; -using Velopack.Sources; +using ChrisKaczor.Wpf.Windows; +using WorldClockStatusWindow.SettingsWindow; namespace WorldClockStatusWindow; @@ -20,8 +20,6 @@ internal class WindowSource : IWindowSource, IDisposable private readonly Timer _timer; private readonly Dispatcher _dispatcher; - private readonly UpdateManager _updateManager; - private List _timeZoneEntries; internal WindowSource() @@ -31,8 +29,6 @@ internal class WindowSource : IWindowSource, IDisposable _dispatcher = Dispatcher.CurrentDispatcher; - _updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false)); - _timer = new Timer(1000); Task.Factory.StartNew(UpdateApp).ContinueWith(task => Start(task.Result.Result)); @@ -42,14 +38,14 @@ internal class WindowSource : IWindowSource, IDisposable { try { - if (!_updateManager.IsInstalled) + if (!Program.UpdateManager.IsInstalled) return false; Log.Logger.Information("Checking for update"); await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update...")); - var newVersion = await _updateManager.CheckForUpdatesAsync(); + var newVersion = await Program.UpdateManager.CheckForUpdatesAsync(); if (newVersion == null) return false; @@ -58,13 +54,13 @@ internal class WindowSource : IWindowSource, IDisposable await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update...")); - await _updateManager.DownloadUpdatesAsync(newVersion); + await Program.UpdateManager.DownloadUpdatesAsync(newVersion); Log.Logger.Information("Installing update"); await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update...")); - _updateManager.ApplyUpdatesAndRestart(newVersion); + Program.UpdateManager.ApplyUpdatesAndRestart(newVersion); } catch (Exception e) { @@ -130,10 +126,6 @@ internal class WindowSource : IWindowSource, IDisposable text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Properties.Settings.Default.TimeFormat)}"); } - text.AppendLine(); - text.AppendLine(); - text.Append(_updateManager.CurrentVersion); - _dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString())); } @@ -163,6 +155,18 @@ internal class WindowSource : IWindowSource, IDisposable public void ShowSettings() { + var categoryPanels = new List + { + new GeneralSettingsPanel(), + new AboutSettingsPanel() + }; + + var settingsWindow = new CategoryWindow(categoryPanels, Properties.Resources.SettingsTitle, Properties.Resources.CloseButtonText); + + var dialogResult = settingsWindow.ShowDialog(); + + if (!dialogResult.GetValueOrDefault(false)) + return; Save(); } diff --git a/WorldClockStatusWindow.csproj b/WorldClockStatusWindow.csproj index 4ebaf1b..681de2b 100644 --- a/WorldClockStatusWindow.csproj +++ b/WorldClockStatusWindow.csproj @@ -1,44 +1,56 @@  - - net8.0-windows7.0 - WinExe - false - true - true - WorldClockStatusWindow.Program - Resources\Application.ico - - - - - - - - - - - - - - - - - - - - - True - True - Settings.settings - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - + + net8.0-windows7.0 + WinExe + false + true + true + WorldClockStatusWindow.Program + Resources\Application.ico + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + \ No newline at end of file