diff --git a/Common/ZenStates-Core.dll b/Common/ZenStates-Core.dll index 11d8516..fe5ae85 100644 Binary files a/Common/ZenStates-Core.dll and b/Common/ZenStates-Core.dll differ diff --git a/WPF-no-themes/Properties/BuildNumberTemplate.cs b/WPF-no-themes/Properties/BuildNumberTemplate.cs index 5e66a86..29d08da 100644 --- a/WPF-no-themes/Properties/BuildNumberTemplate.cs +++ b/WPF-no-themes/Properties/BuildNumberTemplate.cs @@ -5,5 +5,5 @@ using System.Reflection; -[assembly: AssemblyVersion("1.30.1177")] -[assembly: AssemblyFileVersion("1.30.1177")] +[assembly: AssemblyVersion("1.30.1178")] +[assembly: AssemblyFileVersion("1.30.1178")] diff --git a/WPF/AppSettings.cs b/WPF/AppSettings.cs index 0db8309..6b324fc 100644 --- a/WPF/AppSettings.cs +++ b/WPF/AppSettings.cs @@ -9,26 +9,25 @@ 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 = 2; - private const string filename = "settings.xml"; + private static readonly string Filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.xml"); - public enum THEME : int + public enum Theme : int { - LIGHT, - DARK, - DARK_MINT, + Light, + Dark, + DarkMint, } public AppSettings Create() { - Version = $"{VERSION_MAJOR}.{VERSION_MINOR}"; - AppTheme = THEME.LIGHT; + Version = $"{VersionMajor}.{VersionMinor}"; + AppTheme = Theme.Light; AutoRefresh = true; AutoRefreshInterval = 2000; AdvancedMode = true; - // DarkMode = false; CheckForUpdates = true; SaveWindowPosition = false; WindowLeft = 0; @@ -48,46 +47,43 @@ 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)) + 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); AdonisUI.Controls.MessageBox.Show( "Could not save settings to file!", "Error", @@ -98,29 +94,21 @@ public void Save() public void ChangeTheme() { - Uri[] ThemeUri = new Uri[] + Uri[] themeUri = new Uri[] { + new Uri("pack://application:,,,/ZenTimings;component/Themes/Light.xaml", UriKind.Absolute), new Uri("pack://application:,,,/ZenTimings;component/Themes/Dark.xaml", UriKind.Absolute), new Uri("pack://application:,,,/ZenTimings;component/Themes/DarkMint.xaml", UriKind.Absolute), - new Uri("pack://application:,,,/ZenTimings;component/Themes/Light.xaml", UriKind.Absolute), }; - if (AppTheme == THEME.DARK) - ResourceLocator.SetColorScheme(Application.Current.Resources, ThemeUri[0]); - else if (AppTheme == THEME.DARK_MINT) - ResourceLocator.SetColorScheme(Application.Current.Resources, ThemeUri[1]); - else - ResourceLocator.SetColorScheme(Application.Current.Resources, ThemeUri[ThemeUri.Length - 1]); - - //DarkMode = !DarkMode; + ResourceLocator.SetColorScheme(Application.Current.Resources, themeUri[(int)AppTheme]); } - 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.Light; public bool CheckForUpdates { get; set; } = true; public string UpdaterSkippedVersion { get; set; } = ""; public string UpdaterRemindLaterAt { get; set; } = ""; @@ -135,4 +123,4 @@ public void ChangeTheme() public string NotifiedChangelog { get; set; } = ""; public string NotifiedRembrandt { get; set; } = ""; } -} \ No newline at end of file +} diff --git a/WPF/MainWindow.xaml.cs b/WPF/MainWindow.xaml.cs index 05601b7..4f1ed26 100644 --- a/WPF/MainWindow.xaml.cs +++ b/WPF/MainWindow.xaml.cs @@ -929,8 +929,25 @@ private void Window_Initialized(object sender, EventArgs e) if (settings.SaveWindowPosition) { WindowStartupLocation = WindowStartupLocation.Manual; - Left = settings.WindowLeft; - Top = settings.WindowTop; + + // Get the current screen bounds + System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + System.Drawing.Rectangle screenBounds = screen.Bounds; + + // Check if the saved window position is outside the screen bounds + if (settings.WindowLeft < screenBounds.Left || settings.WindowLeft + Width > screenBounds.Right || + settings.WindowTop < screenBounds.Top || settings.WindowTop + Height > screenBounds.Bottom) + { + // Reset the window position to a default value + Left = (screenBounds.Width - Width) / 2 + screenBounds.Left; + Top = (screenBounds.Height - Height) / 2 + screenBounds.Top; + } + else + { + // Set the window position to the saved values + Left = settings.WindowLeft; + Top = settings.WindowTop; + } } SetWindowTitle(); diff --git a/WPF/Plugin/SVI2Plugin.cs b/WPF/Plugin/SVI2Plugin.cs index a495023..e616a08 100644 --- a/WPF/Plugin/SVI2Plugin.cs +++ b/WPF/Plugin/SVI2Plugin.cs @@ -7,9 +7,8 @@ namespace ZenTimings.Plugin { public class SVI2Plugin : IPlugin { - internal Cpu _cpu; - internal int timeout = 20; - internal const string VERSION = "1.1"; + private int timeout = 20; + private const string VERSION = "1.1"; public string Name => "SVI2 Sensors"; @@ -21,7 +20,14 @@ public class SVI2Plugin : IPlugin public List Sensors { get; private set; } + private Cpu _cpu; + public SVI2Plugin(Cpu cpu) + { + InitializeSensors(cpu); + } + + private void InitializeSensors(Cpu cpu) { if (cpu != null && cpu.Status == IOModule.LibStatus.OK) { @@ -36,27 +42,20 @@ public SVI2Plugin(Cpu cpu) public bool Update() { - if (Sensors?.Count > 0) + if (Sensors?.Count > 0 && _cpu != null) { - uint soc_plane_value; - uint vcore_plane_value; + uint socPlaneValue; + uint vcorePlaneValue; do { - soc_plane_value = _cpu.ReadDword(_cpu.info.svi2.socAddress); - vcore_plane_value = _cpu.ReadDword(_cpu.info.svi2.coreAddress); - } while ((soc_plane_value & 0xFF00) != 0 && (vcore_plane_value & 0xFF00) != 0 && --timeout > 0); + ReadSensorValues(out socPlaneValue, out vcorePlaneValue); + } while ((socPlaneValue & 0xFF00) != 0 && (vcorePlaneValue & 0xFF00) != 0 && --timeout > 0); if (timeout > 0) { - uint socVid = (soc_plane_value >> 16) & 0xFF; - Sensors[0].Value = Convert.ToSingle(Utils.VidToVoltage(socVid)); + UpdateSensorValue(socPlaneValue, Sensors[0]); + UpdateSensorValue(vcorePlaneValue, Sensors[1]); - Console.WriteLine("Vsoc: " + Sensors[0].Min + " " + Sensors[0].Max); - - uint coreVid = (vcore_plane_value >> 16) & 0xFF; - Sensors[1].Value = Convert.ToSingle(Utils.VidToVoltage(coreVid)); - - Console.WriteLine("Vcore: " + Sensors[1].Min + " " + Sensors[1].Max); return true; } } @@ -64,6 +63,20 @@ public bool Update() return false; } + private void ReadSensorValues(out uint socPlaneValue, out uint vcorePlaneValue) + { + socPlaneValue = _cpu.ReadDword(_cpu.info.svi2.socAddress); + vcorePlaneValue = _cpu.ReadDword(_cpu.info.svi2.coreAddress); + } + + private void UpdateSensorValue(uint planeValue, Sensor sensor) + { + uint vid = (planeValue >> 16) & 0xFF; + sensor.Value = Convert.ToSingle(Utils.VidToVoltage(vid)); + + Console.WriteLine($"{sensor.Name}: {sensor.Min} {sensor.Max}"); + } + public void Open() { throw new NotImplementedException(); diff --git a/WPF/Properties/BuildNumberTemplate.cs b/WPF/Properties/BuildNumberTemplate.cs index 5e66a86..29d08da 100644 --- a/WPF/Properties/BuildNumberTemplate.cs +++ b/WPF/Properties/BuildNumberTemplate.cs @@ -5,5 +5,5 @@ using System.Reflection; -[assembly: AssemblyVersion("1.30.1177")] -[assembly: AssemblyFileVersion("1.30.1177")] +[assembly: AssemblyVersion("1.30.1178")] +[assembly: AssemblyFileVersion("1.30.1178")] diff --git a/WPF/Windows/Changelog.xaml b/WPF/Windows/Changelog.xaml index 9b7cacc..037fc15 100644 --- a/WPF/Windows/Changelog.xaml +++ b/WPF/Windows/Changelog.xaml @@ -25,13 +25,14 @@ - + + diff --git a/WPF/Windows/OptionsDialog.xaml.cs b/WPF/Windows/OptionsDialog.xaml.cs index 2ba8e1e..5cb8a3f 100644 --- a/WPF/Windows/OptionsDialog.xaml.cs +++ b/WPF/Windows/OptionsDialog.xaml.cs @@ -15,7 +15,7 @@ public partial class OptionsDialog internal readonly AppSettings appSettings = (Application.Current as App)?.settings; private readonly DispatcherTimer timerInstance; private DispatcherTimer notificationTimer; - private THEME _Theme; + private Theme _Theme; private readonly bool _AdvancedMode; public OptionsDialog(DispatcherTimer timer) @@ -136,7 +136,7 @@ private void OptionsWindow_Closing(object sender, System.ComponentModel.CancelEv private void ComboBoxTheme_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { - appSettings.AppTheme = (THEME)comboBoxTheme.SelectedIndex; + appSettings.AppTheme = (Theme)comboBoxTheme.SelectedIndex; appSettings.ChangeTheme(); } } diff --git a/WPF/Windows/SplashWindow.xaml.cs b/WPF/Windows/SplashWindow.xaml.cs index d38bb4a..3de11bb 100644 --- a/WPF/Windows/SplashWindow.xaml.cs +++ b/WPF/Windows/SplashWindow.xaml.cs @@ -29,7 +29,7 @@ public static void Start() { splash.Show(); - if (appSettings.AppTheme != AppSettings.THEME.LIGHT) + if (appSettings.AppTheme != AppSettings.Theme.Light) appSettings.ChangeTheme(); if (appSettings.CheckForUpdates) updater.CheckForUpdate();