Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Dec 30, 2024
2 parents 8ecdcad + 102256d commit f63618f
Show file tree
Hide file tree
Showing 51 changed files with 870 additions and 374 deletions.
7 changes: 1 addition & 6 deletions WPF/CpuSingleton.cs → Common/CpuSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZenStates.Core;
using ZenStates.Core;

namespace ZenTimings
{
Expand Down
2 changes: 1 addition & 1 deletion Common/UpdaterPersistenceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ZenTimings
{
public sealed class UpdaterPersistenceProvider : IPersistenceProvider
{
internal readonly AppSettings appSettings = (Application.Current as App)?.settings;
internal readonly AppSettings appSettings = AppSettings.Instance;
public UpdaterPersistenceProvider() { }

/// <summary>
Expand Down
Binary file modified Common/ZenStates-Core.dll
Binary file not shown.
8 changes: 7 additions & 1 deletion WPF-no-themes/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Markup;
using ZenStates.Core;
using ZenTimings.Windows;

Expand All @@ -14,7 +16,6 @@ public partial class App
internal const string mutexName = "Local\\ZenTimings";
internal static Mutex instanceMutex;
internal bool createdNew;
public readonly AppSettings settings = new AppSettings().Load();
public Updater updater;

protected override void OnStartup(StartupEventArgs e)
Expand All @@ -30,6 +31,11 @@ protected override void OnStartup(StartupEventArgs e)
Environment.Exit(0);
}

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

updater = new Updater();

GC.KeepAlive(instanceMutex);
Expand Down
105 changes: 58 additions & 47 deletions WPF-no-themes/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Windows;
using System.Xml.Serialization;
Expand All @@ -8,37 +8,49 @@ namespace ZenTimings
[Serializable]
public sealed class AppSettings
{
private const int VERSION_MAJOR = 1;
private const int VERSION_MINOR = 1;
public const int VersionMajor = 1;
public const int VersionMinor = 4;

private const string filename = "settings.xml";
private static readonly string Filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.xml");

public enum THEME : int
private static AppSettings _instance = null;

private AppSettings() { }

public static AppSettings Instance
{
get
{
if (_instance == null)
{
_instance = new AppSettings().Load();
}

return _instance;
}
}

public enum Theme : int
{
LIGHT,
DARK,
DARK_MINT,
Light,
Dark,
DarkMint,
DarkMintGradient,
DarkRed,
Dracula,
RetroWave,
BurntOrange,
}

public AppSettings Create()
public enum ScreenshotType : int
{
Version = $"{VERSION_MAJOR}.{VERSION_MINOR}";
AppTheme = THEME.LIGHT;
AutoRefresh = true;
AutoRefreshInterval = 2000;
AdvancedMode = true;
// DarkMode = false;
CheckForUpdates = true;
SaveWindowPosition = false;
WindowLeft = 0;
WindowTop = 0;
SysInfoWindowLeft = 0;
SysInfoWindowHeight = 0;
SysInfoWindowWidth = 0;
NotifiedChangelog = "";
NotifiedRembrandt = "";
Window,
Desktop,
}

Save();
public AppSettings Create(bool save = true)
{
if (save) Save();

return this;
}
Expand All @@ -47,46 +59,44 @@ public AppSettings Create()

public AppSettings Load()
{
if (File.Exists(filename))
try
{
using (StreamReader sr = new StreamReader(filename))
if (File.Exists(Filename))
{
try
using (StreamReader sr = new StreamReader(Filename))
{
XmlSerializer xmls = new XmlSerializer(typeof(AppSettings));
return xmls.Deserialize(sr) as AppSettings;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
sr.Close();
MessageBox.Show(
"Invalid settings file!\nSettings will be reset to defaults.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
return Create();
}
}
}
else
catch (Exception ex)
{
return Create();
Console.WriteLine(ex.Message);
MessageBox.Show(
"Invalid or outdated settings file!\nSettings will be reset to defaults.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
}

return Create();
}

public void Save()
{
try
{
using (StreamWriter sw = new StreamWriter(filename))
Version = $"{VersionMajor}.{VersionMinor}";
using (StreamWriter sw = new StreamWriter(Filename))
{
XmlSerializer xmls = new XmlSerializer(typeof(AppSettings));
xmls.Serialize(sw, this);
}
}
catch (Exception)
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(
"Could not save settings to file!",
"Error",
Expand All @@ -95,17 +105,18 @@ public void Save()
}
}

public string Version { get; set; } = $"{VERSION_MAJOR}.{VERSION_MINOR}";
public string Version { get; set; } = $"{VersionMajor}.{VersionMinor}";
public bool AutoRefresh { get; set; } = true;
public int AutoRefreshInterval { get; set; } = 2000;
public bool AdvancedMode { get; set; } = true;
// public bool DarkMode { get; set; }
public THEME AppTheme { get; set; } = THEME.LIGHT;
public Theme AppTheme { get; set; } = Theme.DarkMintGradient;
public ScreenshotType ScreenshotMode { get; set; } = ScreenshotType.Window;
public bool CheckForUpdates { get; set; } = true;
public string UpdaterSkippedVersion { get; set; } = "";
public string UpdaterRemindLaterAt { get; set; } = "";
public bool MinimizeToTray { get; set; }
public bool SaveWindowPosition { get; set; }
public bool AutoUninstallDriver { get; set; } = true;
public double WindowLeft { get; set; }
public double WindowTop { get; set; }
public double SysInfoWindowLeft { get; set; }
Expand All @@ -115,4 +126,4 @@ public void Save()
public string NotifiedChangelog { get; set; } = "";
public string NotifiedRembrandt { get; set; } = "";
}
}
}
Loading

0 comments on commit f63618f

Please sign in to comment.