SettingsHelper.cs 951 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using DesktopClock.Properties;
  3. using Microsoft.Win32;
  4. namespace DesktopClock;
  5. public static class SettingsHelper
  6. {
  7. /// <summary>
  8. /// Gets the time zone selected in settings, or local by default.
  9. /// </summary>
  10. public static TimeZoneInfo GetTimeZone() =>
  11. DateTimeUtil.TryGetTimeZoneById(Settings.Default.TimeZone, out var timeZoneInfo) ? timeZoneInfo : TimeZoneInfo.Local;
  12. /// <summary>
  13. /// Selects a time zone to use.
  14. /// </summary>
  15. public static void SetTimeZone(TimeZoneInfo timeZone) =>
  16. Settings.Default.TimeZone = timeZone.Id;
  17. public static void SetRunOnStartup(bool runOnStartup)
  18. {
  19. using var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
  20. if (runOnStartup)
  21. key?.SetValue("DesktopClock", App.ResourceAssembly.Location);
  22. else
  23. key?.DeleteValue("DesktopClock", false);
  24. }
  25. }