From 604a7e5b0b2f07ba2e0c8fa695b9bda04a86ec06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Tue, 15 Nov 2022 23:40:54 +0100 Subject: [PATCH] Move `FanMode` and `OverlayMode` to `GlobalConfig` --- CommonHelpers/GlobalConfig.cs | 24 ++++++++++++++++++++ FanControl/FanControlForm.cs | 17 ++++++++------- FanControl/FanController.cs | 7 ------ FanControl/FanControllerSensors.cs | 3 ++- FanControl/FanSensor.cs | 13 ++++++----- PerformanceOverlay/Controller.cs | 10 ++++----- PerformanceOverlay/Overlays.cs | 35 ++++++++++++------------------ PerformanceOverlay/Settings.cs | 9 ++++---- 8 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 CommonHelpers/GlobalConfig.cs diff --git a/CommonHelpers/GlobalConfig.cs b/CommonHelpers/GlobalConfig.cs new file mode 100644 index 0000000..cef3348 --- /dev/null +++ b/CommonHelpers/GlobalConfig.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace CommonHelpers +{ + public enum FanMode : uint + { + Default = 17374, + SteamOS, + Max + } + + public enum OverlayMode : uint + { + FPS = 10032, + Minimal, + Detail, + Full + } +} diff --git a/FanControl/FanControlForm.cs b/FanControl/FanControlForm.cs index 00b0ca2..afb87b5 100644 --- a/FanControl/FanControlForm.cs +++ b/FanControl/FanControlForm.cs @@ -1,5 +1,6 @@ -using CommonHelpers; +using CommonHelpers; using CommonHelpers.FromLibreHardwareMonitor; +using FanControl.Properties; using System; using System.Collections.Generic; using System.ComponentModel; @@ -40,7 +41,7 @@ namespace FanControl propertyGrid1.SelectedObject = fanControl; propertyGrid1.ExpandAllGridItems(); - foreach (var item in Enum.GetValues(typeof(FanController.FanMode))) + foreach (var item in Enum.GetValues(typeof(FanMode))) { fanModeSelectMenu.Items.Add(item); fanModeSelectNotifyMenu.Items.Add(item); @@ -48,12 +49,12 @@ namespace FanControl try { - var fanMode = Enum.Parse(typeof(FanController.FanMode), Properties.Settings.Default.FanMode); - setFanMode((FanController.FanMode)fanMode); + var fanMode = Enum.Parse(typeof(FanMode), Properties.Settings.Default.FanMode); + setFanMode((FanMode)fanMode); } catch(System.ArgumentException) { - setFanMode(FanController.FanMode.Default); + setFanMode(FanMode.Default); } notifyIcon.ShowBalloonTip(3000, Text, "Fan Control Started", ToolTipIcon.Info); @@ -76,7 +77,7 @@ namespace FanControl } } - private void setFanMode(FanController.FanMode mode) + private void setFanMode(FanMode mode) { fanControl.SetMode(mode); fanModeSelectMenu.SelectedItem = mode; @@ -88,7 +89,7 @@ namespace FanControl private void fanModeSelect_SelectedValueChanged(object sender, EventArgs e) { var comboBox = (ToolStripComboBox)sender; - var selectedMode = (FanController.FanMode)comboBox.SelectedItem; + var selectedMode = (FanMode)comboBox.SelectedItem; setFanMode(selectedMode); } @@ -118,7 +119,7 @@ namespace FanControl private void FanControlForm_FormClosed(object sender, FormClosedEventArgs e) { // Always revert to default on closing - fanControl.SetMode(FanController.FanMode.Default); + fanControl.SetMode(FanMode.Default); } private void fanLoopTimer_Tick(object sender, EventArgs e) diff --git a/FanControl/FanController.cs b/FanControl/FanController.cs index b2d6b63..9de2281 100644 --- a/FanControl/FanController.cs +++ b/FanControl/FanController.cs @@ -16,13 +16,6 @@ namespace FanControl [RefreshProperties(RefreshProperties.Repaint)] internal partial class FanController : IDisposable { - public enum FanMode - { - Default, - SteamOS, - Max - } - [CategoryAttribute("Fan")] public FanMode Mode { get; private set; } diff --git a/FanControl/FanControllerSensors.cs b/FanControl/FanControllerSensors.cs index b473013..d7d823d 100644 --- a/FanControl/FanControllerSensors.cs +++ b/FanControl/FanControllerSensors.cs @@ -1,4 +1,5 @@ -using LibreHardwareMonitor.Hardware; +using CommonHelpers; +using LibreHardwareMonitor.Hardware; using System; using System.Collections.Generic; using System.ComponentModel; diff --git a/FanControl/FanSensor.cs b/FanControl/FanSensor.cs index 3b6bcec..6392187 100644 --- a/FanControl/FanSensor.cs +++ b/FanControl/FanSensor.cs @@ -1,4 +1,5 @@ -using LibreHardwareMonitor.Hardware; +using CommonHelpers; +using LibreHardwareMonitor.Hardware; using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,7 +28,7 @@ namespace FanControl private List AllSamples = new List(); - internal Dictionary Profiles { get; set; } = new Dictionary(); + internal Dictionary Profiles { get; set; } = new Dictionary(); internal class Profile { @@ -136,7 +137,7 @@ namespace FanControl sensor.Name == SensorName; } - public bool Update(ISensor hwSensor, FanController.FanMode mode) + public bool Update(ISensor hwSensor, FanMode mode) { if (!Matches(hwSensor)) return false; @@ -149,7 +150,7 @@ namespace FanControl hwSensor.Value, mode); } - public bool Update(string name, float? newValue, FanController.FanMode mode) + public bool Update(string name, float? newValue, FanMode mode) { if (!newValue.HasValue || newValue <= 0.0) return false; @@ -174,7 +175,7 @@ namespace FanControl return true; } - public bool IsValid(FanController.FanMode mode) + public bool IsValid(FanMode mode) { // If we have profile, but no sensor value to consume it // it is invalid @@ -217,7 +218,7 @@ namespace FanControl return value; } - public ushort? CalculateRPM(FanController.FanMode mode) + public ushort? CalculateRPM(FanMode mode) { if (!Profiles.ContainsKey(mode) || !Value.HasValue) return null; diff --git a/PerformanceOverlay/Controller.cs b/PerformanceOverlay/Controller.cs index 7b4338b..e733184 100644 --- a/PerformanceOverlay/Controller.cs +++ b/PerformanceOverlay/Controller.cs @@ -1,4 +1,4 @@ -using CommonHelpers; +using CommonHelpers; using CommonHelpers.FromLibreHardwareMonitor; using Microsoft.VisualBasic.Logging; using PerformanceOverlay.External; @@ -42,7 +42,7 @@ namespace PerformanceOverlay showItem.Checked = Settings.Default.ShowOSD; contextMenu.Items.Add(showItem); contextMenu.Items.Add(new ToolStripSeparator()); - foreach (var mode in Enum.GetValues()) + foreach (var mode in Enum.GetValues()) { var modeItem = new ToolStripMenuItem(mode.ToString()); modeItem.Tag = mode; @@ -103,7 +103,7 @@ namespace PerformanceOverlay { GlobalHotKey.RegisterHotKey(Settings.Default.CycleOSDShortcut, () => { - var values = Enum.GetValues().ToList(); + var values = Enum.GetValues().ToList(); int index = values.IndexOf(Settings.Default.OSDModeParsed); Settings.Default.OSDModeParsed = values[(index + 1) % values.Count]; @@ -123,8 +123,8 @@ namespace PerformanceOverlay { foreach (ToolStripItem item in contextMenu.Items) { - if (item.Tag is Overlays.Mode) - ((ToolStripMenuItem)item).Checked = ((Overlays.Mode)item.Tag == Settings.Default.OSDModeParsed); + if (item.Tag is OverlayMode) + ((ToolStripMenuItem)item).Checked = ((OverlayMode)item.Tag == Settings.Default.OSDModeParsed); } } diff --git a/PerformanceOverlay/Overlays.cs b/PerformanceOverlay/Overlays.cs index 473d174..7ea9fbf 100644 --- a/PerformanceOverlay/Overlays.cs +++ b/PerformanceOverlay/Overlays.cs @@ -1,4 +1,5 @@ -using System; +using CommonHelpers; +using System; using System.Collections.Generic; using System.Linq; using System.Security.Policy; @@ -11,19 +12,11 @@ namespace PerformanceOverlay { internal class Overlays { - public enum Mode - { - FPS, - Minimal, - Detail, - Full - } - public class Entry { public String? Text { get; set; } - public IList Include { get; set; } = new List(); - public IList Exclude { get; set; } = new List(); + public IList Include { get; set; } = new List(); + public IList Exclude { get; set; } = new List(); public IList Nested { get; set; } = new List(); public String Separator { get; set; } = ""; public bool IgnoreMissing { get; set; } @@ -62,7 +55,7 @@ namespace PerformanceOverlay return output; } - public String? GetValue(Mode mode, Sensors sensors) + public String? GetValue(OverlayMode mode, Sensors sensors) { if (Exclude.Count > 0 && Exclude.Contains(mode)) return null; @@ -97,7 +90,7 @@ namespace PerformanceOverlay { Nested = { // Simple just FPS - new Entry(" FPS") { Include = { Mode.FPS } }, + new Entry(" FPS") { Include = { OverlayMode.FPS } }, // Minimal and Detail new Entry { @@ -110,7 +103,7 @@ namespace PerformanceOverlay { new Entry("{BATT_%} %"), new Entry("{BATT_W} W") { IgnoreMissing = true }, - new Entry("C{BATT_CHARGE_W} W") { IgnoreMissing = true, Include = { Mode.Detail } } + new Entry("C{BATT_CHARGE_W} W") { IgnoreMissing = true, Include = { OverlayMode.Detail } } } }, new Entry @@ -120,7 +113,7 @@ namespace PerformanceOverlay { new Entry("{GPU_%} %"), new Entry("{GPU_W} W"), - new Entry("{GPU_T} C") { IgnoreMissing = true, Include = { Mode.Detail } } + new Entry("{GPU_T} C") { IgnoreMissing = true, Include = { OverlayMode.Detail } } } }, new Entry @@ -130,7 +123,7 @@ namespace PerformanceOverlay { new Entry("{CPU_%} %"), new Entry("{CPU_W} W"), - new Entry("{CPU_T} C") { IgnoreMissing = true, Include = { Mode.Detail } } + new Entry("{CPU_T} C") { IgnoreMissing = true, Include = { OverlayMode.Detail } } } }, new Entry @@ -142,7 +135,7 @@ namespace PerformanceOverlay { Text = "FAN", Nested = { new Entry("{FAN_RPM} RPM") }, - Include = { Mode.Detail } + Include = { OverlayMode.Detail } }, new Entry { @@ -152,11 +145,11 @@ namespace PerformanceOverlay new Entry { Text = "[OBJ_FT_SMALL] ms", - Include = { Mode.Detail } + Include = { OverlayMode.Detail } } }, Separator = "| ", - Include = { Mode.Minimal, Mode.Detail } + Include = { OverlayMode.Minimal, OverlayMode.Detail } }, new Entry { @@ -178,12 +171,12 @@ namespace PerformanceOverlay new Entry("[OBJ_FT_LARGE] ms"), }, Separator = "\r\n", - Include = { Mode.Full } + Include = { OverlayMode.Full } } } }; - public static String GetOSD(Mode mode, Sensors sensors) + public static String GetOSD(OverlayMode mode, Sensors sensors) { var sb = new StringBuilder(); diff --git a/PerformanceOverlay/Settings.cs b/PerformanceOverlay/Settings.cs index 76da60c..c502500 100644 --- a/PerformanceOverlay/Settings.cs +++ b/PerformanceOverlay/Settings.cs @@ -1,4 +1,5 @@ -using System; +using CommonHelpers; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,17 +10,17 @@ namespace PerformanceOverlay { internal partial class Settings { - public Overlays.Mode OSDModeParsed + public OverlayMode OSDModeParsed { get { try { - return (Mode)Enum.Parse(OSDMode); + return (OverlayMode)Enum.Parse(OSDMode); } catch (ArgumentException) { - return Mode.FPS; + return OverlayMode.FPS; } } set