diff --git a/Utilities/IReadOnlyArray.cs b/Collections/IReadOnlyArray.cs similarity index 95% rename from Utilities/IReadOnlyArray.cs rename to Collections/IReadOnlyArray.cs index b540edc..d5e78e4 100644 --- a/Utilities/IReadOnlyArray.cs +++ b/Collections/IReadOnlyArray.cs @@ -38,7 +38,7 @@ using System; using System.Collections.Generic; -namespace OpenHardwareMonitor.Utilities { +namespace OpenHardwareMonitor.Collections { public interface IReadOnlyArray : IEnumerable { diff --git a/Utilities/ListSet.cs b/Collections/ListSet.cs similarity index 95% rename from Utilities/ListSet.cs rename to Collections/ListSet.cs index 8548fc7..af3fb37 100644 --- a/Utilities/ListSet.cs +++ b/Collections/ListSet.cs @@ -40,7 +40,7 @@ using System.Collections; using System.Collections.Generic; using System.Text; -namespace OpenHardwareMonitor.Utilities { +namespace OpenHardwareMonitor.Collections { public class ListSet : IEnumerable { private List list = new List(); diff --git a/Utilities/ReadOnlyArray.cs b/Collections/ReadOnlyArray.cs similarity index 95% rename from Utilities/ReadOnlyArray.cs rename to Collections/ReadOnlyArray.cs index 6b3cde9..df937c8 100644 --- a/Utilities/ReadOnlyArray.cs +++ b/Collections/ReadOnlyArray.cs @@ -39,7 +39,7 @@ using System; using System.Collections; using System.Collections.Generic; -namespace OpenHardwareMonitor.Utilities { +namespace OpenHardwareMonitor.Collections { public class ReadOnlyArray : IReadOnlyArray { diff --git a/GUI/HardwareNode.cs b/GUI/HardwareNode.cs index ca93f6a..1a816bd 100644 --- a/GUI/HardwareNode.cs +++ b/GUI/HardwareNode.cs @@ -43,14 +43,41 @@ using OpenHardwareMonitor.Hardware; namespace OpenHardwareMonitor.GUI { public class HardwareNode : Node { + private PersistentSettings settings; + private UnitManager unitManager; private IHardware hardware; private List typeNodes = new List(); - public HardwareNode(IHardware hardware) : base(hardware.Name) { - + public HardwareNode(IHardware hardware, PersistentSettings settings, + UnitManager unitManager) : base(hardware.Name) + { + this.settings = settings; + this.unitManager = unitManager; this.hardware = hardware; - this.Image = hardware.Icon; + switch (hardware.HardwareType) { + case HardwareType.CPU: + this.Image = Utilities.EmbeddedResources.GetImage("cpu.png"); + break; + case HardwareType.GPU: + if (hardware.Identifier.ToString().Contains("nvidia")) + this.Image = Utilities.EmbeddedResources.GetImage("nvidia.png"); + else + this.Image = Utilities.EmbeddedResources.GetImage("ati.png"); + break; + case HardwareType.HDD: + this.Image = Utilities.EmbeddedResources.GetImage("hdd.png"); + break; + case HardwareType.Mainboard: + this.Image = Utilities.EmbeddedResources.GetImage("mainboard.png"); + break; + case HardwareType.SuperIO: + this.Image = Utilities.EmbeddedResources.GetImage("chip.png"); + break; + case HardwareType.TBalancer: + this.Image = Utilities.EmbeddedResources.GetImage("bigng.png"); + break; + } typeNodes.Add(new TypeNode(SensorType.Voltage)); typeNodes.Add(new TypeNode(SensorType.Clock)); @@ -105,7 +132,7 @@ namespace OpenHardwareMonitor.GUI { while (i < node.Nodes.Count && ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index) i++; - SensorNode sensorNode = new SensorNode(sensor); + SensorNode sensorNode = new SensorNode(sensor, settings, unitManager); node.Nodes.Insert(i, sensorNode); } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 117fba8..e4cd064 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -51,7 +51,9 @@ using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.GUI { public partial class MainForm : Form { - private Computer computer = new Computer(); + private PersistentSettings settings; + private UnitManager unitManager; + private Computer computer; private Node root; private TreeModel treeModel; private IDictionary sensorPlotColors = @@ -74,6 +76,12 @@ namespace OpenHardwareMonitor.GUI { public MainForm() { InitializeComponent(); + this.settings = new PersistentSettings(); + this.settings.Load(Path.ChangeExtension( + System.Windows.Forms.Application.ExecutablePath, ".config")); + + this.unitManager = new UnitManager(settings); + // set the DockStyle here, to avoid conflicts with the MainMenu this.splitContainer.Dock = DockStyle.Fill; @@ -98,10 +106,10 @@ namespace OpenHardwareMonitor.GUI { nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText; nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing; - if (Utilities.Config.Contains("mainForm.Location.X")) { - int x = Utilities.Config.Get("mainForm.Location.X", Location.X); + if (settings.Contains("mainForm.Location.X")) { + int x = settings.Get("mainForm.Location.X", Location.X); x = x < 0 ? 0 : x; - int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y); + int y = settings.Get("mainForm.Location.Y", Location.Y); y = y < 0 ? 0 : y; this.Location = new Point(x, y); } else { @@ -109,12 +117,12 @@ namespace OpenHardwareMonitor.GUI { } ClientSize = new Size( - Utilities.Config.Get("mainForm.Width", 470), - Utilities.Config.Get("mainForm.Height", 640)); + settings.Get("mainForm.Width", 470), + settings.Get("mainForm.Height", 640)); foreach (TreeColumn column in treeView.Columns) - column.Width = Math.Max(20, Math.Min(400, - Config.Get("treeView.Columns." + column.Header + ".Width", + column.Width = Math.Max(20, Math.Min(400, + settings.Get("treeView.Columns." + column.Header + ".Width", column.Width))); treeModel = new TreeModel(); @@ -122,9 +130,11 @@ namespace OpenHardwareMonitor.GUI { root.Image = Utilities.EmbeddedResources.GetImage("computer.png"); treeModel.Nodes.Add(root); - treeView.Model = treeModel; + treeView.Model = treeModel; - systemTray = new SystemTray(computer); + this.computer = new Computer(settings); + + systemTray = new SystemTray(computer, settings); systemTray.HideShowCommand += hideShowClick; systemTray.ExitCommand += exitClick; @@ -149,52 +159,52 @@ namespace OpenHardwareMonitor.GUI { plotColorPalette[11] = Color.Olive; plotColorPalette[12] = Color.Firebrick; - showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem); + showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, settings); showHiddenSensors.Changed += delegate(object sender, EventArgs e) { treeModel.ForceVisible = showHiddenSensors.Value; }; - showPlot = new UserOption("plotMenuItem", false, plotMenuItem); + showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings); showPlot.Changed += delegate(object sender, EventArgs e) { splitContainer.Panel2Collapsed = !showPlot.Value; treeView.Invalidate(); }; - showValue = new UserOption("valueMenuItem", true, valueMenuItem); + showValue = new UserOption("valueMenuItem", true, valueMenuItem, settings); showValue.Changed += delegate(object sender, EventArgs e) { treeView.Columns[1].IsVisible = showValue.Value; }; - showMin = new UserOption("minMenuItem", false, minMenuItem); + showMin = new UserOption("minMenuItem", false, minMenuItem, settings); showMin.Changed += delegate(object sender, EventArgs e) { treeView.Columns[2].IsVisible = showMin.Value; }; - showMax = new UserOption("maxMenuItem", true, maxMenuItem); + showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings); showMax.Changed += delegate(object sender, EventArgs e) { treeView.Columns[3].IsVisible = showMax.Value; }; - startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem); + startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem, settings); - minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem); + minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem, settings); minimizeToTray.Changed += delegate(object sender, EventArgs e) { systemTray.IsMainIconEnabled = minimizeToTray.Value; }; - autoStart = new UserOption(null, startupManager.Startup, startupMenuItem); + autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings); autoStart.Changed += delegate(object sender, EventArgs e) { startupManager.Startup = autoStart.Value; ; }; - readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem); + readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem, settings); readHddSensors.Changed += delegate(object sender, EventArgs e) { computer.HDDEnabled = readHddSensors.Value; UpdatePlotSelection(null, null); }; celciusMenuItem.Checked = - UnitManager.TemperatureUnit == TemperatureUnit.Celcius; + unitManager.TemperatureUnit == TemperatureUnit.Celcius; fahrenheitMenuItem.Checked = !celciusMenuItem.Checked; startupMenuItem.Visible = startupManager.IsAvailable; @@ -219,14 +229,14 @@ namespace OpenHardwareMonitor.GUI { } private void SubHardwareAdded(IHardware hardware, Node node) { - Node hardwareNode = new HardwareNode(hardware); + Node hardwareNode = new HardwareNode(hardware, settings, unitManager); node.Nodes.Add(hardwareNode); foreach (IHardware subHardware in hardware.SubHardware) SubHardwareAdded(subHardware, hardwareNode); } private void HardwareAdded(IHardware hardware) { - Node hardwareNode = new HardwareNode(hardware); + Node hardwareNode = new HardwareNode(hardware, settings, unitManager); root.Nodes.Add(hardwareNode); foreach (IHardware subHardware in hardware.SubHardware) SubHardwareAdded(subHardware, hardwareNode); @@ -307,17 +317,18 @@ namespace OpenHardwareMonitor.GUI { private void SaveConfiguration() { if (WindowState != FormWindowState.Minimized) { - Config.Set("mainForm.Location.X", Location.X); - Config.Set("mainForm.Location.Y", Location.Y); - Config.Set("mainForm.Width", ClientSize.Width); - Config.Set("mainForm.Height", ClientSize.Height); + settings.Set("mainForm.Location.X", Location.X); + settings.Set("mainForm.Location.Y", Location.Y); + settings.Set("mainForm.Width", ClientSize.Width); + settings.Set("mainForm.Height", ClientSize.Height); } foreach (TreeColumn column in treeView.Columns) - Config.Set("treeView.Columns." + column.Header + ".Width", + settings.Set("treeView.Columns." + column.Header + ".Width", column.Width); - Config.Save(); + settings.Save(Path.ChangeExtension( + System.Windows.Forms.Application.ExecutablePath, ".config")); } private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { @@ -451,13 +462,13 @@ namespace OpenHardwareMonitor.GUI { private void celciusMenuItem_Click(object sender, EventArgs e) { celciusMenuItem.Checked = true; fahrenheitMenuItem.Checked = false; - UnitManager.TemperatureUnit = TemperatureUnit.Celcius; + unitManager.TemperatureUnit = TemperatureUnit.Celcius; } private void fahrenheitMenuItem_Click(object sender, EventArgs e) { celciusMenuItem.Checked = false; fahrenheitMenuItem.Checked = true; - UnitManager.TemperatureUnit = TemperatureUnit.Fahrenheit; + unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit; } private void sumbitReportMenuItem_Click(object sender, EventArgs e) diff --git a/GUI/ParameterForm.cs b/GUI/ParameterForm.cs index 6ec0ad5..e004558 100644 --- a/GUI/ParameterForm.cs +++ b/GUI/ParameterForm.cs @@ -41,7 +41,7 @@ using System.ComponentModel; using System.Text; using System.Windows.Forms; using OpenHardwareMonitor.Hardware; -using OpenHardwareMonitor.Utilities; +using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.GUI { public partial class ParameterForm : Form { diff --git a/GUI/SensorNode.cs b/GUI/SensorNode.cs index c85e82d..3a21c8f 100644 --- a/GUI/SensorNode.cs +++ b/GUI/SensorNode.cs @@ -44,13 +44,15 @@ namespace OpenHardwareMonitor.GUI { public class SensorNode : Node { private ISensor sensor; + private PersistentSettings settings; + private UnitManager unitManager; private string format; - private bool plot = false; + private bool plot = false; public string ValueToString(float? value) { if (value.HasValue) { if (sensor.SensorType == SensorType.Temperature && - UnitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) { + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) { return string.Format("{0:F1} °F", value * 1.8 + 32); } else { return string.Format(format, value); @@ -59,8 +61,11 @@ namespace OpenHardwareMonitor.GUI { return "-"; } - public SensorNode(ISensor sensor) : base() { + public SensorNode(ISensor sensor, PersistentSettings settings, + UnitManager unitManager) : base() { this.sensor = sensor; + this.settings = settings; + this.unitManager = unitManager; switch (sensor.SensorType) { case SensorType.Voltage: format = "{0:F2} V"; break; case SensorType.Clock: format = "{0:F0} MHz"; break; @@ -71,7 +76,7 @@ namespace OpenHardwareMonitor.GUI { case SensorType.Control: format = "{0:F1} %"; break; } - bool hidden = Config.Get(new Identifier(sensor.Identifier, + bool hidden = settings.Get(new Identifier(sensor.Identifier, "hidden").ToString(), sensor.IsDefaultHidden); base.IsVisible = !hidden; } @@ -85,7 +90,7 @@ namespace OpenHardwareMonitor.GUI { get { return base.IsVisible; } set { base.IsVisible = value; - Config.Set(new Identifier(sensor.Identifier, + settings.Set(new Identifier(sensor.Identifier, "hidden").ToString(), !value); } } diff --git a/GUI/SensorNotifyIcon.cs b/GUI/SensorNotifyIcon.cs index a371f3a..3d0ddbf 100644 --- a/GUI/SensorNotifyIcon.cs +++ b/GUI/SensorNotifyIcon.cs @@ -62,7 +62,7 @@ namespace OpenHardwareMonitor.GUI { private Font font; public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, - bool balloonTip) + bool balloonTip, PersistentSettings settings) { this.sensor = sensor; this.notifyIcon = new NotifyIcon(); @@ -71,7 +71,7 @@ namespace OpenHardwareMonitor.GUI { if (sensor.SensorType == SensorType.Load) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } - Color = Config.Get(new Identifier(sensor.Identifier, + Color = settings.Get(new Identifier(sensor.Identifier, "traycolor").ToString(), defaultColor); this.pen = new Pen(Color.FromArgb(96, Color.Black)); @@ -95,7 +95,7 @@ namespace OpenHardwareMonitor.GUI { dialog.Color = Color; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; - Config.Set(new Identifier(sensor.Identifier, + settings.Set(new Identifier(sensor.Identifier, "traycolor").ToString(), Color); } }; diff --git a/GUI/SystemTray.cs b/GUI/SystemTray.cs index be62ce6..3bd8df8 100644 --- a/GUI/SystemTray.cs +++ b/GUI/SystemTray.cs @@ -46,12 +46,14 @@ using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.GUI { public class SystemTray : IDisposable { private IComputer computer; + private PersistentSettings settings; private List list = new List(); private bool mainIconEnabled = false; private NotifyIcon mainIcon; - public SystemTray(IComputer computer) { + public SystemTray(IComputer computer, PersistentSettings settings) { this.computer = computer; + this.settings = settings; computer.HardwareAdded += new HardwareEventHandler(HardwareAdded); computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved); @@ -95,7 +97,7 @@ namespace OpenHardwareMonitor.GUI { } private void SensorAdded(ISensor sensor) { - if (Config.Get(new Identifier(sensor.Identifier, + if (settings.Get(new Identifier(sensor.Identifier, "tray").ToString(), false)) Add(sensor, false); } @@ -127,9 +129,9 @@ namespace OpenHardwareMonitor.GUI { if (Contains(sensor)) { return; } else { - list.Add(new SensorNotifyIcon(this, sensor, balloonTip)); + list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings)); UpdateMainIconVisibilty(); - Config.Set(new Identifier(sensor.Identifier, "tray").ToString(), true); + settings.Set(new Identifier(sensor.Identifier, "tray").ToString(), true); } } @@ -139,9 +141,9 @@ namespace OpenHardwareMonitor.GUI { private void Remove(ISensor sensor, bool deleteConfig) { if (deleteConfig) { - Config.Remove( + settings.Remove( new Identifier(sensor.Identifier, "tray").ToString()); - Config.Remove( + settings.Remove( new Identifier(sensor.Identifier, "traycolor").ToString()); } SensorNotifyIcon instance = null; diff --git a/GUI/UnitManager.cs b/GUI/UnitManager.cs index 382d474..d50b301 100644 --- a/GUI/UnitManager.cs +++ b/GUI/UnitManager.cs @@ -37,7 +37,6 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.GUI { @@ -48,18 +47,20 @@ namespace OpenHardwareMonitor.GUI { public class UnitManager { - private static TemperatureUnit temperatureUnit; + private PersistentSettings settings; + private TemperatureUnit temperatureUnit; - static UnitManager () { - temperatureUnit = (TemperatureUnit)Config.Get("TemperatureUnit", + public UnitManager(PersistentSettings settings) { + this.settings = settings; + this.temperatureUnit = (TemperatureUnit)settings.Get("TemperatureUnit", (int)TemperatureUnit.Celcius); } - public static TemperatureUnit TemperatureUnit { + public TemperatureUnit TemperatureUnit { get { return temperatureUnit; } set { - temperatureUnit = value; - Config.Set("TemperatureUnit", (int)temperatureUnit); + this.temperatureUnit = value; + this.settings.Set("TemperatureUnit", (int)temperatureUnit); } } } diff --git a/GUI/UserOption.cs b/GUI/UserOption.cs index d6266f9..43c31c7 100644 --- a/GUI/UserOption.cs +++ b/GUI/UserOption.cs @@ -46,13 +46,15 @@ namespace OpenHardwareMonitor.GUI { private bool value; private MenuItem menuItem; private event EventHandler changed; + private PersistentSettings settings; public UserOption(string name, bool value, - MenuItem menuItem) { + MenuItem menuItem, PersistentSettings settings) { + this.settings = settings; this.name = name; if (name != null) - this.value = Config.Get(name, value); + this.value = settings.Get(name, value); else this.value = value; this.menuItem = menuItem; @@ -70,7 +72,7 @@ namespace OpenHardwareMonitor.GUI { if (this.value != value) { this.value = value; if (this.name != null) - Config.Set(name, value); + settings.Set(name, value); this.menuItem.Checked = value; if (changed != null) changed(this, null); diff --git a/Hardware/ATI/ADL.cs b/Hardware/ATI/ADL.cs index f71b462..878f780 100644 --- a/Hardware/ATI/ADL.cs +++ b/Hardware/ATI/ADL.cs @@ -42,7 +42,7 @@ using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware.ATI { [StructLayout(LayoutKind.Sequential)] - public struct ADLAdapterInfo { + internal struct ADLAdapterInfo { public int Size; public int AdapterIndex; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL.ADL_MAX_PATH)] @@ -67,7 +67,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { } [StructLayout(LayoutKind.Sequential)] - public struct ADLPMActivity { + internal struct ADLPMActivity { public int Size; public int EngineClock; public int MemoryClock; @@ -81,13 +81,13 @@ namespace OpenHardwareMonitor.Hardware.ATI { } [StructLayout(LayoutKind.Sequential)] - public struct ADLTemperature { + internal struct ADLTemperature { public int Size; public int Temperature; } [StructLayout(LayoutKind.Sequential)] - public struct ADLFanSpeedValue { + internal struct ADLFanSpeedValue { public int Size; public int SpeedType; public int FanSpeed; @@ -95,7 +95,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { } [StructLayout(LayoutKind.Sequential)] - public struct ADLFanSpeedInfo { + internal struct ADLFanSpeedInfo { public int Size; public int Flags; public int MinPercent; @@ -104,7 +104,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { public int MaxRPM; } - public class ADL { + internal class ADL { public const int ADL_MAX_PATH = 256; public const int ADL_MAX_ADAPTERS = 40; public const int ADL_MAX_DISPLAYS = 40; diff --git a/Hardware/ATI/ATIGPU.cs b/Hardware/ATI/ATIGPU.cs index 5698234..41301f5 100644 --- a/Hardware/ATI/ATIGPU.cs +++ b/Hardware/ATI/ATIGPU.cs @@ -37,13 +37,11 @@ using System; using System.Collections.Generic; -using System.Drawing; namespace OpenHardwareMonitor.Hardware.ATI { - public class ATIGPU : Hardware { + internal class ATIGPU : Hardware { private string name; - private Image icon; private int adapterIndex; private int busNumber; private int deviceNumber; @@ -56,22 +54,20 @@ namespace OpenHardwareMonitor.Hardware.ATI { private Sensor fanControl; public ATIGPU(string name, int adapterIndex, int busNumber, - int deviceNumber) + int deviceNumber, ISettings settings) { this.name = name; - this.icon = Utilities.EmbeddedResources.GetImage("ati.png"); this.adapterIndex = adapterIndex; this.busNumber = busNumber; this.deviceNumber = deviceNumber; - this.temperature = - new Sensor("GPU Core", 0, SensorType.Temperature, this); - this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, null); - this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this); - this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this); - this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this); - this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this); - this.fanControl = new Sensor("GPU Fan", 0, SensorType.Control, this); + this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings); + this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings); + this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings); + this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings); + this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings); + this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings); + this.fanControl = new Sensor("GPU Fan", 0, SensorType.Control, this, settings); Update(); } @@ -87,8 +83,8 @@ namespace OpenHardwareMonitor.Hardware.ATI { get { return new Identifier("atigpu", adapterIndex.ToString()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.GPU; } } public override void Update() { diff --git a/Hardware/ATI/ATIGroup.cs b/Hardware/ATI/ATIGroup.cs index 46b09cb..76fa796 100644 --- a/Hardware/ATI/ATIGroup.cs +++ b/Hardware/ATI/ATIGroup.cs @@ -40,12 +40,12 @@ using System.Collections.Generic; using System.Text; namespace OpenHardwareMonitor.Hardware.ATI { - public class ATIGroup : IGroup { + internal class ATIGroup : IGroup { private List hardware = new List(); private StringBuilder report = new StringBuilder(); - public ATIGroup() { + public ATIGroup(ISettings settings) { try { int status = ADL.ADL_Main_Control_Create(1); @@ -113,7 +113,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { adapterInfo[i].AdapterName.Trim(), adapterInfo[i].AdapterIndex, adapterInfo[i].BusNumber, - adapterInfo[i].DeviceNumber)); + adapterInfo[i].DeviceNumber, settings)); } report.AppendLine(); diff --git a/Hardware/CPU/AMD0FCPU.cs b/Hardware/CPU/AMD0FCPU.cs index 0a9ba55..61b798e 100644 --- a/Hardware/CPU/AMD0FCPU.cs +++ b/Hardware/CPU/AMD0FCPU.cs @@ -37,16 +37,12 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Diagnostics; using System.Text; - namespace OpenHardwareMonitor.Hardware.CPU { - public class AMD0FCPU : Hardware, IHardware { + internal class AMD0FCPU : Hardware, IHardware { private string name; - private Image icon; private int processorIndex; private uint pciAddress; @@ -64,15 +60,14 @@ namespace OpenHardwareMonitor.Hardware.CPU { private const byte THERM_SENSE_CORE_SEL_CPU0 = 0x4; private const byte THERM_SENSE_CORE_SEL_CPU1 = 0x0; - public AMD0FCPU(int processorIndex, CPUID[][] cpuid) { + public AMD0FCPU(int processorIndex, CPUID[][] cpuid, ISettings settings) { this.processorIndex = processorIndex; this.name = cpuid[0][0].Name; - this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); - int coreCount = cpuid.Length; + int coreCount = cpuid.Length; - totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); + totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this, settings); float offset = -49.0f; @@ -93,7 +88,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\n" + "Temperature = Value + Offset.", offset) - }); + }, settings); } } else { coreTemperatures = new Sensor[0]; @@ -102,7 +97,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreCount; i++) coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, - SensorType.Load, this); + SensorType.Load, this, settings); cpuLoad = new CPULoad(cpuid); if (cpuLoad.IsAvailable) { @@ -125,8 +120,8 @@ namespace OpenHardwareMonitor.Hardware.CPU { get { return new Identifier("amdcpu", processorIndex.ToString()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.CPU; } } public override void Update() { diff --git a/Hardware/CPU/AMD10CPU.cs b/Hardware/CPU/AMD10CPU.cs index 9cddfee..14e3967 100644 --- a/Hardware/CPU/AMD10CPU.cs +++ b/Hardware/CPU/AMD10CPU.cs @@ -37,15 +37,13 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Diagnostics; using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - - public class AMD10CPU : Hardware, IHardware { + + internal class AMD10CPU : Hardware, IHardware { private string name; - private Image icon; private int processorIndex; private uint pciAddress; @@ -61,20 +59,19 @@ namespace OpenHardwareMonitor.Hardware.CPU { private const ushort PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID = 0x1303; private const uint REPORTED_TEMPERATURE_CONTROL_REGISTER = 0xA4; - public AMD10CPU(int processorIndex, CPUID[][] cpuid) { + public AMD10CPU(int processorIndex, CPUID[][] cpuid, ISettings settings) { this.processorIndex = processorIndex; this.name = cpuid[0][0].Name; - this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); int coreCount = cpuid.Length; - totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); + totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this, settings); coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreCount; i++) coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, - SensorType.Load, this); + SensorType.Load, this, settings); cpuLoad = new CPULoad(cpuid); if (cpuLoad.IsAvailable) { @@ -88,7 +85,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { "Core" + (coreCount > 1 ? " #1 - #" + coreCount : ""), 0, SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription("Offset [°C]", "Temperature offset.", 0) - }); + }, settings); pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID, (byte)processorIndex); @@ -107,8 +104,8 @@ namespace OpenHardwareMonitor.Hardware.CPU { get { return new Identifier("amdcpu", processorIndex.ToString()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.CPU; } } public override void Update() { diff --git a/Hardware/CPU/CPUGroup.cs b/Hardware/CPU/CPUGroup.cs index cea3524..19d2499 100644 --- a/Hardware/CPU/CPUGroup.cs +++ b/Hardware/CPU/CPUGroup.cs @@ -42,7 +42,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - public class CPUGroup : IGroup { + internal class CPUGroup : IGroup { private List hardware = new List(); private CPUID[][][] threads; @@ -100,7 +100,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { return coreThreads; } - public CPUGroup() { + public CPUGroup(ISettings settings) { // No implementation for cpuid on Unix systems int p = (int)System.Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) @@ -123,15 +123,15 @@ namespace OpenHardwareMonitor.Hardware.CPU { switch (threads[0].Vendor) { case Vendor.Intel: - hardware.Add(new IntelCPU(index, coreThreads)); + hardware.Add(new IntelCPU(index, coreThreads, settings)); break; case Vendor.AMD: switch (threads[0].Family) { case 0x0F: - hardware.Add(new AMD0FCPU(index, coreThreads)); + hardware.Add(new AMD0FCPU(index, coreThreads, settings)); break; case 0x10: - hardware.Add(new AMD10CPU(index, coreThreads)); + hardware.Add(new AMD10CPU(index, coreThreads, settings)); break; default: break; diff --git a/Hardware/CPU/CPUID.cs b/Hardware/CPU/CPUID.cs index 94ac883..942bea7 100644 --- a/Hardware/CPU/CPUID.cs +++ b/Hardware/CPU/CPUID.cs @@ -40,14 +40,14 @@ using System.Collections.Generic; using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - - public enum Vendor { + + internal enum Vendor { Unknown, Intel, AMD, } - - public class CPUID { + + internal class CPUID { private int thread; diff --git a/Hardware/CPU/CPULoad.cs b/Hardware/CPU/CPULoad.cs index d491593..4bd2311 100644 --- a/Hardware/CPU/CPULoad.cs +++ b/Hardware/CPU/CPULoad.cs @@ -41,7 +41,7 @@ using System.Runtime.InteropServices; using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - public class CPULoad { + internal class CPULoad { [StructLayout(LayoutKind.Sequential)] private struct SystemProcessorPerformanceInformation { diff --git a/Hardware/CPU/IntelCPU.cs b/Hardware/CPU/IntelCPU.cs index 2c0c1c0..135eec1 100644 --- a/Hardware/CPU/IntelCPU.cs +++ b/Hardware/CPU/IntelCPU.cs @@ -37,7 +37,6 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Diagnostics; using System.Globalization; using System.Reflection; @@ -46,14 +45,13 @@ using System.Threading; using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - public class IntelCPU : Hardware, IHardware { + internal class IntelCPU : Hardware, IHardware { private int processorIndex; private CPUID[][] cpuid; private int coreCount; private string name; - private Image icon; private uint family; private uint model; @@ -94,13 +92,12 @@ namespace OpenHardwareMonitor.Hardware.CPU { return result; } - public IntelCPU(int processorIndex, CPUID[][] cpuid) { + public IntelCPU(int processorIndex, CPUID[][] cpuid, ISettings settings) { this.processorIndex = processorIndex; this.cpuid = cpuid; this.coreCount = cpuid.Length; this.name = cpuid[0][0].Name; - this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = cpuid[0][0].Family; this.model = cpuid[0][0].Model; @@ -179,7 +176,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { "Temperature = TjMax - TSlope * Value.", tjMax[i]), new ParameterDescription("TSlope [°C]", "Temperature slope of the digital thermal sensor.\n" + - "Temperature = TjMax - TSlope * Value.", 1)}); + "Temperature = TjMax - TSlope * Value.", 1)}, settings); ActivateSensor(coreTemperatures[i]); } } else { @@ -187,13 +184,13 @@ namespace OpenHardwareMonitor.Hardware.CPU { } if (coreCount > 1) - totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); + totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this, settings); else totalLoad = null; coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) coreLoads[i] = new Sensor(CoreString(i), i + 1, - SensorType.Load, this); + SensorType.Load, this, settings); cpuLoad = new CPULoad(cpuid); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) @@ -229,11 +226,11 @@ namespace OpenHardwareMonitor.Hardware.CPU { lastTimeStampCount = 0; lastTime = 0; - busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); + busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this, settings); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = - new Sensor(CoreString(i), i + 1, SensorType.Clock, this); + new Sensor(CoreString(i), i + 1, SensorType.Clock, this, settings); if (hasTSC) ActivateSensor(coreClocks[i]); } @@ -249,8 +246,8 @@ namespace OpenHardwareMonitor.Hardware.CPU { get { return new Identifier("intelcpu", processorIndex.ToString()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.CPU; } } private void AppendMSRData(StringBuilder r, uint msr, int thread) { diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index a123b9b..b6154f2 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -50,8 +50,19 @@ namespace OpenHardwareMonitor.Hardware { private bool open = false; private bool hddEnabled = false; + private ISettings settings; - public Computer() { } + public Computer() { + this.settings = new Settings(); + } + + public Computer(ISettings settings) { + if (settings != null) + this.settings = settings; + else { + this.settings = new Settings(); + } + } private void Add(IGroup group) { if (groups.Contains(group)) @@ -79,14 +90,14 @@ namespace OpenHardwareMonitor.Hardware { if (open) return; - Add(new Mainboard.MainboardGroup()); - Add(new CPU.CPUGroup()); - Add(new ATI.ATIGroup()); - Add(new Nvidia.NvidiaGroup()); - Add(new TBalancer.TBalancerGroup()); + Add(new Mainboard.MainboardGroup(settings)); + Add(new CPU.CPUGroup(settings)); + Add(new ATI.ATIGroup(settings)); + Add(new Nvidia.NvidiaGroup(settings)); + Add(new TBalancer.TBalancerGroup(settings)); if (hddEnabled) - Add(new HDD.HDDGroup()); + Add(new HDD.HDDGroup(settings)); open = true; } @@ -95,7 +106,7 @@ namespace OpenHardwareMonitor.Hardware { get { return hddEnabled; } set { if (open && value && !hddEnabled) { - Add(new HDD.HDDGroup()); + Add(new HDD.HDDGroup(settings)); } else if (open && !value && hddEnabled) { List list = new List(); foreach (IGroup group in groups) @@ -263,5 +274,20 @@ namespace OpenHardwareMonitor.Hardware { foreach (IHardware hardware in group.Hardware) hardware.Accept(visitor); } + + private class Settings : ISettings { + + public bool Contains(string name) { + return false; + } + + public void Set(string name, string value) { } + + public string Get(string name, string value) { + return value; + } + + public void Remove(string name) { } + } } } diff --git a/Hardware/HDD/HDD.cs b/Hardware/HDD/HDD.cs index 171ddac..68dda66 100644 --- a/Hardware/HDD/HDD.cs +++ b/Hardware/HDD/HDD.cs @@ -37,10 +37,9 @@ using System; using System.Collections.Generic; -using System.Drawing; namespace OpenHardwareMonitor.Hardware.HDD { - public class HDD : IHardware { + internal class HDD : IHardware { private const int UPDATE_DIVIDER = 30; // update only every 30s @@ -48,19 +47,20 @@ namespace OpenHardwareMonitor.Hardware.HDD { private IntPtr handle; private int drive; private int attribute; - private Image icon; private Sensor temperature; private int count; - public HDD(string name, IntPtr handle, int drive, int attribute) { + public HDD(string name, IntPtr handle, int drive, int attribute, + ISettings settings) + { this.name = name; this.handle = handle; this.drive = drive; this.attribute = attribute; this.count = 0; - this.icon = Utilities.EmbeddedResources.GetImage("hdd.png"); - this.temperature = new Sensor("HDD", 0, SensorType.Temperature, this); + this.temperature = new Sensor("HDD", 0, SensorType.Temperature, this, + settings); Update(); } @@ -73,8 +73,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { get { return new Identifier("hdd", drive.ToString()); } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.HDD; } } public IHardware[] SubHardware { diff --git a/Hardware/HDD/HDDGroup.cs b/Hardware/HDD/HDDGroup.cs index fab5a3c..86e017d 100644 --- a/Hardware/HDD/HDDGroup.cs +++ b/Hardware/HDD/HDDGroup.cs @@ -39,13 +39,13 @@ using System; using System.Collections.Generic; namespace OpenHardwareMonitor.Hardware.HDD { - public class HDDGroup : IGroup { + internal class HDDGroup : IGroup { private const int MAX_DRIVES = 32; private List hardware = new List(); - public HDDGroup() { + public HDDGroup(ISettings settings) { int p = (int)System.Environment.OSVersion.Platform; if ((p != 4) && (p != 128)) { @@ -87,7 +87,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { } if (attribute >= 0) { - hardware.Add(new HDD(name, handle, drive, attribute)); + hardware.Add(new HDD(name, handle, drive, attribute, settings)); continue; } } diff --git a/Hardware/HDD/SMART.cs b/Hardware/HDD/SMART.cs index 77e0946..3c58a64 100644 --- a/Hardware/HDD/SMART.cs +++ b/Hardware/HDD/SMART.cs @@ -40,8 +40,8 @@ using System.Collections.Generic; using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware.HDD { - - public class SMART { + + internal class SMART { [Flags] public enum Status : ushort { diff --git a/Hardware/Hardware.cs b/Hardware/Hardware.cs index 8d8b956..05b621f 100644 --- a/Hardware/Hardware.cs +++ b/Hardware/Hardware.cs @@ -37,11 +37,10 @@ using System; using System.Collections.Generic; -using System.Drawing; -using OpenHardwareMonitor.Utilities; +using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware { - public abstract class Hardware : IHardware { + internal abstract class Hardware : IHardware { private ListSet active = new ListSet(); @@ -72,7 +71,7 @@ namespace OpenHardwareMonitor.Hardware { public abstract string Name { get; } public abstract Identifier Identifier { get; } - public abstract Image Icon { get; } + public abstract HardwareType HardwareType { get; } public virtual string GetReport() { return null; diff --git a/Utilities/HexStringArray.cs b/Hardware/HexStringArray.cs similarity index 93% rename from Utilities/HexStringArray.cs rename to Hardware/HexStringArray.cs index 6d338e8..0facce6 100644 --- a/Utilities/HexStringArray.cs +++ b/Hardware/HexStringArray.cs @@ -39,8 +39,8 @@ using System; using System.Collections.Generic; using System.Text; -namespace OpenHardwareMonitor.Utilities { - public class HexStringArray { +namespace OpenHardwareMonitor.Hardware { + internal class HexStringArray { private byte[] array; diff --git a/Hardware/IGroup.cs b/Hardware/IGroup.cs index e00ddf7..3f6e3f2 100644 --- a/Hardware/IGroup.cs +++ b/Hardware/IGroup.cs @@ -40,7 +40,7 @@ using System.Collections.Generic; namespace OpenHardwareMonitor.Hardware { - public interface IGroup { + internal interface IGroup { IHardware[] Hardware { get; } diff --git a/Hardware/IHardware.cs b/Hardware/IHardware.cs index 5a46e81..59ed614 100644 --- a/Hardware/IHardware.cs +++ b/Hardware/IHardware.cs @@ -37,18 +37,26 @@ using System; using System.Collections.Generic; -using System.Drawing; namespace OpenHardwareMonitor.Hardware { public delegate void SensorEventHandler(ISensor sensor); + public enum HardwareType { + CPU, + GPU, + HDD, + Mainboard, + SuperIO, + TBalancer + } + public interface IHardware : IElement { string Name { get; } Identifier Identifier { get; } - Image Icon { get; } + HardwareType HardwareType { get; } string GetReport(); diff --git a/Hardware/ISensor.cs b/Hardware/ISensor.cs index 61172f9..8166cc4 100644 --- a/Hardware/ISensor.cs +++ b/Hardware/ISensor.cs @@ -37,7 +37,7 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; +using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware { diff --git a/Hardware/ISettings.cs b/Hardware/ISettings.cs new file mode 100644 index 0000000..31465f9 --- /dev/null +++ b/Hardware/ISettings.cs @@ -0,0 +1,52 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; + +namespace OpenHardwareMonitor.Hardware { + public interface ISettings { + + bool Contains(string name); + + void Set(string name, string value); + + string Get(string name, string value); + + void Remove(string name); + } +} diff --git a/Hardware/LPC/Chip.cs b/Hardware/LPC/Chip.cs index f625300..83f3a99 100644 --- a/Hardware/LPC/Chip.cs +++ b/Hardware/LPC/Chip.cs @@ -5,7 +5,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.LPC { - public enum Chip : ushort { + internal enum Chip : ushort { Unknown = 0, IT8712F = 0x8712, IT8716F = 0x8716, diff --git a/Hardware/LPC/F718XX.cs b/Hardware/LPC/F718XX.cs index 08fef7d..b010b75 100644 --- a/Hardware/LPC/F718XX.cs +++ b/Hardware/LPC/F718XX.cs @@ -38,10 +38,9 @@ using System; using System.Collections.Generic; using System.Text; -using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.Hardware.LPC { - public class F718XX : ISuperIO { + internal class F718XX : ISuperIO { private ushort address; private Chip chip; diff --git a/Hardware/LPC/ISuperIO.cs b/Hardware/LPC/ISuperIO.cs index aabfbdc..146146f 100644 --- a/Hardware/LPC/ISuperIO.cs +++ b/Hardware/LPC/ISuperIO.cs @@ -37,10 +37,9 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.Hardware.LPC { - public interface ISuperIO { + internal interface ISuperIO { Chip Chip { get; } diff --git a/Hardware/LPC/IT87XX.cs b/Hardware/LPC/IT87XX.cs index 0c954a6..7382539 100644 --- a/Hardware/LPC/IT87XX.cs +++ b/Hardware/LPC/IT87XX.cs @@ -37,11 +37,10 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Text; namespace OpenHardwareMonitor.Hardware.LPC { - public class IT87XX : ISuperIO { + internal class IT87XX : ISuperIO { private ushort address; private Chip chip; diff --git a/Hardware/LPC/LMSensors.cs b/Hardware/LPC/LMSensors.cs index 61de0f4..b8ee360 100755 --- a/Hardware/LPC/LMSensors.cs +++ b/Hardware/LPC/LMSensors.cs @@ -41,7 +41,7 @@ using System.IO; namespace OpenHardwareMonitor.Hardware.LPC { - public class LMSensors { + internal class LMSensors { private List lmChips = new List(); diff --git a/Hardware/LPC/LPCIO.cs b/Hardware/LPC/LPCIO.cs index b48d6f6..ff6d662 100644 --- a/Hardware/LPC/LPCIO.cs +++ b/Hardware/LPC/LPCIO.cs @@ -41,7 +41,7 @@ using System.Text; using System.Threading; namespace OpenHardwareMonitor.Hardware.LPC { - public class LPCIO { + internal class LPCIO { private List superIOs = new List(); private StringBuilder report = new StringBuilder(); diff --git a/Hardware/LPC/W836XX.cs b/Hardware/LPC/W836XX.cs index a134b6f..1553b84 100644 --- a/Hardware/LPC/W836XX.cs +++ b/Hardware/LPC/W836XX.cs @@ -40,7 +40,7 @@ using System.Collections.Generic; using System.Text; namespace OpenHardwareMonitor.Hardware.LPC { - public class W836XX : ISuperIO { + internal class W836XX : ISuperIO { private ushort address; private byte revision; diff --git a/Hardware/Mainboard/Mainboard.cs b/Hardware/Mainboard/Mainboard.cs index 97ad918..9bcaf0e 100644 --- a/Hardware/Mainboard/Mainboard.cs +++ b/Hardware/Mainboard/Mainboard.cs @@ -37,21 +37,19 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Text; using OpenHardwareMonitor.Hardware.LPC; namespace OpenHardwareMonitor.Hardware.Mainboard { - public class Mainboard : IHardware { + internal class Mainboard : IHardware { private SMBIOS smbios; private string name; - private Image icon; private LPCIO lpcio; private LMSensors lmSensors; private IHardware[] superIOHardware; - public Mainboard() { + public Mainboard(ISettings settings) { this.smbios = new SMBIOS(); if (smbios.Board != null) { @@ -69,7 +67,6 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { this.name = Manufacturer.Unknown.ToString(); } - this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png"); ISuperIO[] superIO; int p = (int)System.Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { @@ -84,8 +81,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { for (int i = 0; i < superIO.Length; i++) superIOHardware[i] = new SuperIOHardware(superIO[i], smbios.Board != null ? smbios.Board.Manufacturer : - Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model : - Model.Unknown); + Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model : + Model.Unknown, settings); } public string Name { @@ -96,8 +93,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { get { return new Identifier("mainboard"); } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.Mainboard; } } public string GetReport() { diff --git a/Hardware/Mainboard/MainboardGroup.cs b/Hardware/Mainboard/MainboardGroup.cs index acb7e29..53ae715 100644 --- a/Hardware/Mainboard/MainboardGroup.cs +++ b/Hardware/Mainboard/MainboardGroup.cs @@ -39,13 +39,13 @@ using System; using System.Collections.Generic; namespace OpenHardwareMonitor.Hardware.Mainboard { - public class MainboardGroup : IGroup { + internal class MainboardGroup : IGroup { private Mainboard[] mainboards; - public MainboardGroup() { + public MainboardGroup(ISettings settings) { mainboards = new Mainboard[1]; - mainboards[0] = new Mainboard(); + mainboards[0] = new Mainboard(settings); } public void Close() { diff --git a/Hardware/Mainboard/Manufacturer.cs b/Hardware/Mainboard/Manufacturer.cs index 9277b31..c82d26f 100644 --- a/Hardware/Mainboard/Manufacturer.cs +++ b/Hardware/Mainboard/Manufacturer.cs @@ -36,8 +36,8 @@ */ namespace OpenHardwareMonitor.Hardware.Mainboard { - - public enum Manufacturer { + + internal enum Manufacturer { ASRock, ASUS, Dell, diff --git a/Hardware/Mainboard/Model.cs b/Hardware/Mainboard/Model.cs index 787a7c7..009d52b 100644 --- a/Hardware/Mainboard/Model.cs +++ b/Hardware/Mainboard/Model.cs @@ -37,7 +37,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { - public enum Model { + internal enum Model { // ASRock _880GMH_USB3, diff --git a/Hardware/Mainboard/SMBIOS.cs b/Hardware/Mainboard/SMBIOS.cs index 6bff20f..d914a57 100644 --- a/Hardware/Mainboard/SMBIOS.cs +++ b/Hardware/Mainboard/SMBIOS.cs @@ -43,7 +43,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.Mainboard { - public class SMBIOS { + internal class SMBIOS { private byte[] raw; private Structure[] table; diff --git a/Hardware/Mainboard/SuperIOHardware.cs b/Hardware/Mainboard/SuperIOHardware.cs index 470dbf1..04af3eb 100644 --- a/Hardware/Mainboard/SuperIOHardware.cs +++ b/Hardware/Mainboard/SuperIOHardware.cs @@ -37,25 +37,22 @@ using System; using System.Collections.Generic; -using System.Drawing; using OpenHardwareMonitor.Hardware.LPC; namespace OpenHardwareMonitor.Hardware.Mainboard { - public class SuperIOHardware : Hardware { + internal class SuperIOHardware : Hardware { private ISuperIO superIO; - private Image icon; protected readonly string name; private List voltages = new List(); private List temperatures = new List(); private List fans = new List(); - public SuperIOHardware(ISuperIO superIO, Manufacturer manufacturer, - Model model) + public SuperIOHardware(ISuperIO superIO, Manufacturer manufacturer, + Model model, ISettings settings) { this.superIO = superIO; - this.icon = Utilities.EmbeddedResources.GetImage("chip.png"); switch (superIO.Chip) { case Chip.F71858: name = "Fintek F71858"; break; @@ -574,7 +571,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { formula, voltage.Rf), new ParameterDescription("Vf [V]", "Reference voltage.\n" + formula, voltage.Vf) - }); + }, settings); voltages.Add(sensor); } @@ -583,14 +580,14 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { Sensor sensor = new Sensor(temperature.Name, temperature.Index, SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription("Offset [°C]", "Temperature offset.", 0) - }); + }, settings); temperatures.Add(sensor); } foreach (Fan fan in f) if (fan.Index < superIO.Fans.Length) { Sensor sensor = new Sensor(fan.Name, fan.Index, SensorType.Fan, - this, null); + this, settings); fans.Add(sensor); } } @@ -599,8 +596,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { get { return new Identifier("lpc", superIO.Chip.ToString().ToLower()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.SuperIO; } } public override string Name { diff --git a/Hardware/Nvidia/NVAPI.cs b/Hardware/Nvidia/NVAPI.cs index 01b650d..41277a6 100644 --- a/Hardware/Nvidia/NVAPI.cs +++ b/Hardware/Nvidia/NVAPI.cs @@ -42,7 +42,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.Nvidia { - public enum NvStatus { + internal enum NvStatus { OK = 0, ERROR = -1, LIBRARY_NOT_FOUND = -2, @@ -94,9 +94,9 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { INVALID_CALL = -134, D3D10_1_LIBRARY_NOT_FOUND = -135, FUNCTION_NOT_FOUND = -136 - } + } - public enum NvThermalController { + internal enum NvThermalController { NONE = 0, GPU_INTERNAL, ADM1032, @@ -110,9 +110,9 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { VBIOSEVT, OS, UNKNOWN = -1, - } + } - public enum NvThermalTarget { + internal enum NvThermalTarget { NONE = 0, GPU = 1, MEMORY = 2, @@ -123,7 +123,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { }; [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvSensor { + internal struct NvSensor { public NvThermalController Controller; public uint DefaultMinTemp; public uint DefaultMaxTemp; @@ -132,7 +132,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvGPUThermalSettings { + internal struct NvGPUThermalSettings { public uint Version; public uint Count; [MarshalAs(UnmanagedType.ByValArray, @@ -141,30 +141,30 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential)] - public struct NvDisplayHandle { + internal struct NvDisplayHandle { private IntPtr ptr; } [StructLayout(LayoutKind.Sequential)] - public struct NvPhysicalGpuHandle { + internal struct NvPhysicalGpuHandle { private IntPtr ptr; } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvClocks { + internal struct NvClocks { public uint Version; [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_CLOCKS_PER_GPU)] public uint[] Clock; } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvPState { + internal struct NvPState { public bool Present; public int Percentage; } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvPStates { + internal struct NvPStates { public uint Version; public uint Flags; [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_PSTATES_PER_GPU)] @@ -172,14 +172,14 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvUsages { + internal struct NvUsages { public uint Version; [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_USAGES_PER_GPU)] public uint[] Usage; } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvCooler { + internal struct NvCooler { public int Type; public int Controller; public int DefaultMin; @@ -195,7 +195,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvGPUCoolerSettings { + internal struct NvGPUCoolerSettings { public uint Version; public uint Count; [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_COOLER_PER_GPU)] @@ -203,7 +203,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvMemoryInfo { + internal struct NvMemoryInfo { public uint Version; [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_MEMORY_VALUES_PER_GPU)] @@ -211,7 +211,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvDisplayDriverVersion { + internal struct NvDisplayDriverVersion { public uint Version; public uint DriverVersion; public uint BldChangeListNum; @@ -219,9 +219,9 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { public string BuildBranch; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NVAPI.SHORT_STRING_MAX)] public string Adapter; - } + } - public class NVAPI { + internal class NVAPI { public const int MAX_PHYSICAL_GPUS = 64; public const int SHORT_STRING_MAX = 64; diff --git a/Hardware/Nvidia/NvidiaGPU.cs b/Hardware/Nvidia/NvidiaGPU.cs index 0192994..cd9a82d 100644 --- a/Hardware/Nvidia/NvidiaGPU.cs +++ b/Hardware/Nvidia/NvidiaGPU.cs @@ -37,14 +37,12 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Text; namespace OpenHardwareMonitor.Hardware.Nvidia { - public class NvidiaGPU : Hardware, IHardware { + internal class NvidiaGPU : Hardware, IHardware { private string name; - private Image icon; private int adapterIndex; private NvPhysicalGpuHandle handle; private NvDisplayHandle? displayHandle; @@ -57,7 +55,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { private Sensor memoryLoad; public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle, - NvDisplayHandle? displayHandle) + NvDisplayHandle? displayHandle, ISettings settings) { string gpuName; if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK) { @@ -65,15 +63,14 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } else { this.name = "NVIDIA"; } - this.icon = Utilities.EmbeddedResources.GetImage("nvidia.png"); this.adapterIndex = adapterIndex; this.handle = handle; this.displayHandle = displayHandle; - NvGPUThermalSettings settings = GetThermalSettings(); - temperatures = new Sensor[settings.Count]; + NvGPUThermalSettings thermalSettings = GetThermalSettings(); + temperatures = new Sensor[thermalSettings.Count]; for (int i = 0; i < temperatures.Length; i++) { - NvSensor sensor = settings.Sensor[i]; + NvSensor sensor = thermalSettings.Sensor[i]; string name; switch (sensor.Target) { case NvThermalTarget.BOARD: name = "GPU Board"; break; @@ -83,8 +80,8 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break; default: name = "GPU"; break; } - temperatures[i] = new Sensor(name, i, SensorType.Temperature, this, - new ParameterDescription[0]); + temperatures[i] = new Sensor(name, i, SensorType.Temperature, this, + new ParameterDescription[0], settings); ActivateSensor(temperatures[i]); } @@ -92,25 +89,25 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { if (NVAPI.NvAPI_GPU_GetTachReading != null && NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK) { if (value > 0) { - fan = new Sensor("GPU", 0, SensorType.Fan, this); + fan = new Sensor("GPU", 0, SensorType.Fan, this, settings); ActivateSensor(fan); } } clocks = new Sensor[3]; - clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this); - clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this); - clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this); + clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings); + clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings); + clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings); for (int i = 0; i < clocks.Length; i++) ActivateSensor(clocks[i]); loads = new Sensor[3]; - loads[0] = new Sensor("GPU Core", 0, SensorType.Load, this); - loads[1] = new Sensor("GPU Memory Controller", 1, SensorType.Load, this); - loads[2] = new Sensor("GPU Video Engine", 2, SensorType.Load, this); - memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this); + loads[0] = new Sensor("GPU Core", 0, SensorType.Load, this, settings); + loads[1] = new Sensor("GPU Memory Controller", 1, SensorType.Load, this, settings); + loads[2] = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings); + memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this, settings); - control = new Sensor("GPU Fan", 0, SensorType.Control, this); + control = new Sensor("GPU Fan", 0, SensorType.Control, this, settings); } public override string Name { @@ -121,8 +118,8 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { get { return new Identifier("nvidiagpu", adapterIndex.ToString()); } } - public override Image Icon { - get { return icon; } + public override HardwareType HardwareType { + get { return HardwareType.GPU; } } private NvGPUThermalSettings GetThermalSettings() { diff --git a/Hardware/Nvidia/NvidiaGroup.cs b/Hardware/Nvidia/NvidiaGroup.cs index cf07481..96cc1d7 100644 --- a/Hardware/Nvidia/NvidiaGroup.cs +++ b/Hardware/Nvidia/NvidiaGroup.cs @@ -41,12 +41,12 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.Nvidia { - public class NvidiaGroup : IGroup { + internal class NvidiaGroup : IGroup { private List hardware = new List(); private StringBuilder report = new StringBuilder(); - public NvidiaGroup() { + public NvidiaGroup(ISettings settings) { if (!NVAPI.IsAvailable) return; @@ -109,9 +109,9 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { for (int i = 0; i < count; i++) { NvDisplayHandle displayHandle; if (displayHandles.TryGetValue(handles[i], out displayHandle)) - hardware.Add(new NvidiaGPU(i, handles[i], displayHandle)); + hardware.Add(new NvidiaGPU(i, handles[i], displayHandle, settings)); else - hardware.Add(new NvidiaGPU(i, handles[i], null)); + hardware.Add(new NvidiaGPU(i, handles[i], null, settings)); } report.AppendLine(); diff --git a/Utilities/PInvokeDelegateFactory.cs b/Hardware/PInvokeDelegateFactory.cs similarity index 96% rename from Utilities/PInvokeDelegateFactory.cs rename to Hardware/PInvokeDelegateFactory.cs index 10caa8e..92aae5c 100644 --- a/Utilities/PInvokeDelegateFactory.cs +++ b/Hardware/PInvokeDelegateFactory.cs @@ -43,7 +43,7 @@ using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware { - public sealed class PInvokeDelegateFactory { + internal sealed class PInvokeDelegateFactory { private static AssemblyBuilder assemblyBuilder; private static ModuleBuilder moduleBuilder; diff --git a/Hardware/Parameter.cs b/Hardware/Parameter.cs index 114a388..8753b66 100644 --- a/Hardware/Parameter.cs +++ b/Hardware/Parameter.cs @@ -64,13 +64,23 @@ namespace OpenHardwareMonitor.Hardware { private ParameterDescription description; private float value; private bool isDefault; + private ISettings settings; - public Parameter(ParameterDescription description, ISensor sensor) { + public Parameter(ParameterDescription description, ISensor sensor, + ISettings settings) + { this.sensor = sensor; this.description = description; - this.value = Utilities.Config.Get(Identifier.ToString(), - description.DefaultValue); - this.isDefault = !Utilities.Config.Contains(Identifier.ToString()); + this.settings = settings; + this.isDefault = !settings.Contains(Identifier.ToString()); + this.value = description.DefaultValue; + if (!this.isDefault) { + if (!float.TryParse(settings.Get(Identifier.ToString(), "0"), + System.Globalization.NumberStyles.Float, + System.Globalization.CultureInfo.InvariantCulture, + out this.value)) + this.value = description.DefaultValue; + } } public ISensor Sensor { @@ -96,8 +106,9 @@ namespace OpenHardwareMonitor.Hardware { } set { this.isDefault = false; - this.value = value; - Utilities.Config.Set(Identifier.ToString(), value); + this.value = value; + this.settings.Set(Identifier.ToString(), value.ToString( + System.Globalization.CultureInfo.InvariantCulture.NumberFormat)); } } @@ -111,7 +122,7 @@ namespace OpenHardwareMonitor.Hardware { this.isDefault = value; if (value) { this.value = description.DefaultValue; - Utilities.Config.Remove(Identifier.ToString()); + this.settings.Remove(Identifier.ToString()); } } } diff --git a/Hardware/Sensor.cs b/Hardware/Sensor.cs index 2407623..a0adc12 100644 --- a/Hardware/Sensor.cs +++ b/Hardware/Sensor.cs @@ -37,11 +37,11 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; +using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware { - public class Sensor : ISensor { + internal class Sensor : ISensor { private string defaultName; private string name; @@ -55,6 +55,7 @@ namespace OpenHardwareMonitor.Hardware { private float? max; private Queue values = new Queue(MAX_MINUTES * 15); + private ISettings settings; private float sum = 0; private int count = 0; @@ -62,19 +63,19 @@ namespace OpenHardwareMonitor.Hardware { private const int MAX_MINUTES = 120; public Sensor(string name, int index, SensorType sensorType, - IHardware hardware) : this(name, index, sensorType, hardware, - null) { } + IHardware hardware, ISettings settings) : + this(name, index, sensorType, hardware, null, settings) { } public Sensor(string name, int index, SensorType sensorType, - IHardware hardware, ParameterDescription[] parameterDescriptions) : + IHardware hardware, ParameterDescription[] parameterDescriptions, + ISettings settings) : this(name, index, false, sensorType, hardware, - parameterDescriptions) { } + parameterDescriptions, settings) { } public Sensor(string name, int index, bool defaultHidden, SensorType sensorType, IHardware hardware, - ParameterDescription[] parameterDescriptions) - { - this.defaultName = name; + ParameterDescription[] parameterDescriptions, ISettings settings) + { this.index = index; this.defaultHidden = defaultHidden; this.sensorType = sensorType; @@ -82,15 +83,13 @@ namespace OpenHardwareMonitor.Hardware { Parameter[] parameters = new Parameter[parameterDescriptions == null ? 0 : parameterDescriptions.Length]; for (int i = 0; i < parameters.Length; i++ ) - parameters[i] = new Parameter(parameterDescriptions[i], this); + parameters[i] = new Parameter(parameterDescriptions[i], this, settings); this.parameters = parameters; - string configName = Config.Settings[ - new Identifier(Identifier, "name").ToString()]; - if (configName != null) - this.name = configName; - else - this.name = name; + this.settings = settings; + this.defaultName = name; + this.name = settings.Get( + new Identifier(Identifier, "name").ToString(), name); } public IHardware Hardware { @@ -117,7 +116,7 @@ namespace OpenHardwareMonitor.Hardware { name = value; else name = defaultName; - Config.Settings[new Identifier(Identifier, "name").ToString()] = name; + settings.Set(new Identifier(Identifier, "name").ToString(), name); } } diff --git a/Hardware/TBalancer/FTD2XX.cs b/Hardware/TBalancer/FTD2XX.cs index e93b85c..de0ef3f 100644 --- a/Hardware/TBalancer/FTD2XX.cs +++ b/Hardware/TBalancer/FTD2XX.cs @@ -41,7 +41,7 @@ using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware.TBalancer { - public enum FT_DEVICE : uint { + internal enum FT_DEVICE : uint { FT_DEVICE_BM, FT_DEVICE_AM, FT_DEVICE_100AX, @@ -52,7 +52,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { FT_DEVICE_4232H } - public enum FT_STATUS { + internal enum FT_STATUS { FT_OK, FT_INVALID_HANDLE, FT_DEVICE_NOT_FOUND, @@ -73,26 +73,26 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { FT_OTHER_ERROR } - public enum FT_FLOW_CONTROL : ushort { + internal enum FT_FLOW_CONTROL : ushort { FT_FLOW_DTR_DSR = 512, FT_FLOW_NONE = 0, FT_FLOW_RTS_CTS = 256, FT_FLOW_XON_XOFF = 1024, } - public enum FT_PURGE : uint { + internal enum FT_PURGE : uint { FT_PURGE_RX = 1, FT_PURGE_TX = 2, FT_PURGE_ALL = 3, } [StructLayout(LayoutKind.Sequential)] - public struct FT_HANDLE { + internal struct FT_HANDLE { private uint handle; } [StructLayout(LayoutKind.Sequential)] - public struct FT_DEVICE_INFO_NODE { + internal struct FT_DEVICE_INFO_NODE { public uint Flags; public FT_DEVICE Type; public uint ID; @@ -104,7 +104,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { public FT_HANDLE Handle; } - public class FTD2XX { + internal class FTD2XX { public delegate FT_STATUS FT_CreateDeviceInfoListDelegate( out uint numDevices); diff --git a/Hardware/TBalancer/TBalancer.cs b/Hardware/TBalancer/TBalancer.cs index d6751d0..d1539ac 100644 --- a/Hardware/TBalancer/TBalancer.cs +++ b/Hardware/TBalancer/TBalancer.cs @@ -38,15 +38,14 @@ using System; using System.Collections.Generic; using System.Configuration; -using System.Drawing; using System.Text; namespace OpenHardwareMonitor.Hardware.TBalancer { - public class TBalancer : IHardware { + internal class TBalancer : IHardware { + private ISettings settings; private int portIndex; private FT_HANDLE handle; - private Image icon; private byte protocolVersion; private Sensor[] digitalTemperatures = new Sensor[8]; private Sensor[] analogTemperatures = new Sensor[4]; @@ -68,9 +67,10 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { private delegate void MethodDelegate(); private MethodDelegate alternativeRequest; - public TBalancer(int portIndex, byte protocolVersion) { + public TBalancer(int portIndex, byte protocolVersion, ISettings settings) { + this.settings = settings; + this.portIndex = portIndex; - this.icon = Utilities.EmbeddedResources.GetImage("bigng.png"); this.protocolVersion = protocolVersion; ParameterDescription[] parameter = new ParameterDescription[] { @@ -79,23 +79,23 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { int offset = 0; for (int i = 0; i < digitalTemperatures.Length; i++) digitalTemperatures[i] = new Sensor("Digital Sensor " + i, - offset + i, SensorType.Temperature, this, parameter); + offset + i, SensorType.Temperature, this, parameter, settings); offset += digitalTemperatures.Length; for (int i = 0; i < analogTemperatures.Length; i++) analogTemperatures[i] = new Sensor("Analog Sensor " + (i + 1), - offset + i, SensorType.Temperature, this, parameter); + offset + i, SensorType.Temperature, this, parameter, settings); offset += analogTemperatures.Length; for (int i = 0; i < sensorhubTemperatures.Length; i++) sensorhubTemperatures[i] = new Sensor("Sensorhub Sensor " + i, - offset + i, SensorType.Temperature, this, parameter); + offset + i, SensorType.Temperature, this, parameter, settings); offset += sensorhubTemperatures.Length; for (int i = 0; i < miniNGTemperatures.Length; i++) miniNGTemperatures[i] = new Sensor("miniNG #" + (i / 2 + 1) + - " Sensor " + (i % 2 + 1), offset + i, SensorType.Temperature, - this, parameter); + " Sensor " + (i % 2 + 1), offset + i, SensorType.Temperature, + this, parameter, settings); offset += miniNGTemperatures.Length; for (int i = 0; i < sensorhubFlows.Length; i++) @@ -103,16 +103,17 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { i, SensorType.Flow, this, new ParameterDescription[] { new ParameterDescription("Impulse Rate", "The impulse rate of the flowmeter in pulses/L", 509) - }); + }, settings); for (int i = 0; i < controls.Length; i++) { controls[i] = new Sensor("Fan Channel " + i, i, SensorType.Control, - this, null); + this, settings); } for (int i = 0; i < miniNGControls.Length; i++) { miniNGControls[i] = new Sensor("miniNG #" + (i / 2 + 1) + - " Fan Channel " + (i % 2 + 1), 4 + i, SensorType.Control, this, null); + " Fan Channel " + (i % 2 + 1), 4 + i, SensorType.Control, this, + settings); } alternativeRequest = new MethodDelegate(DelayedAlternativeRequest); @@ -164,7 +165,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { if (miniNGFans[number * 2 + i] == null) miniNGFans[number * 2 + i] = new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1), - 4 + number * 2 + i, SensorType.Fan, this, null); + 4 + number * 2 + i, SensorType.Fan, this, settings); Sensor sensor = miniNGFans[number * 2 + i]; @@ -241,7 +242,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { this, new ParameterDescription[] { new ParameterDescription("MaxRPM", "Maximum revolutions per minute (RPM) of the fan.", maxRPM) - }); + }, settings); float value; if ((data[136] & (1 << i)) == 0) // pwm mode @@ -266,8 +267,8 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.TBalancer; } } public string Name { diff --git a/Hardware/TBalancer/TBalancerGroup.cs b/Hardware/TBalancer/TBalancerGroup.cs index 56e0cbf..0c1f133 100644 --- a/Hardware/TBalancer/TBalancerGroup.cs +++ b/Hardware/TBalancer/TBalancerGroup.cs @@ -43,12 +43,12 @@ using System.Text; using System.Threading; namespace OpenHardwareMonitor.Hardware.TBalancer { - public class TBalancerGroup : IGroup { + internal class TBalancerGroup : IGroup { private List hardware = new List(); private StringBuilder report = new StringBuilder(); - public TBalancerGroup() { + public TBalancerGroup(ISettings settings) { uint numDevices; try { @@ -129,7 +129,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { if (isValid) { report.AppendLine("Status: OK"); - hardware.Add(new TBalancer(i, protocolVersion)); + hardware.Add(new TBalancer(i, protocolVersion, settings)); return; } report.AppendLine(); diff --git a/Hardware/WinRing0.cs b/Hardware/WinRing0.cs index 346a851..f577863 100644 --- a/Hardware/WinRing0.cs +++ b/Hardware/WinRing0.cs @@ -43,7 +43,7 @@ using System.Threading; namespace OpenHardwareMonitor.Hardware { - public class WinRing0 { + internal class WinRing0 { public enum OlsDllStatus{ OLS_DLL_NO_ERROR = 0, diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 937caa4..de695eb 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -48,7 +48,6 @@ - @@ -83,7 +82,6 @@ ParameterForm.cs - Component @@ -96,32 +94,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + Form @@ -129,41 +102,17 @@ AboutBox.cs - - - - - - - - - - Form MainForm.cs - - - - - - - - - - - - - - - - + + @@ -214,6 +163,12 @@ + + + {B0397530-545A-471D-BB74-027AE456DF1A} + OpenHardwareMonitorLib + + diff --git a/OpenHardwareMonitor.sln b/OpenHardwareMonitor.sln index 9a14b10..d3b96d0 100644 --- a/OpenHardwareMonitor.sln +++ b/OpenHardwareMonitor.sln @@ -1,7 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitor", "OpenHardwareMonitor.csproj", "{F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}" + ProjectSection(ProjectDependencies) = postProject + {B0397530-545A-471D-BB74-027AE456DF1A} = {B0397530-545A-471D-BB74-027AE456DF1A} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -9,6 +14,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Debug|Any CPU.Build.0 = Debug|Any CPU {F5E0C1F7-9E9B-46F2-AC88-8C9C1C923880}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/OpenHardwareMonitorLib.csproj b/OpenHardwareMonitorLib.csproj new file mode 100644 index 0000000..f67dc5c --- /dev/null +++ b/OpenHardwareMonitorLib.csproj @@ -0,0 +1,101 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {B0397530-545A-471D-BB74-027AE456DF1A} + Library + Properties + OpenHardwareMonitor + OpenHardwareMonitorLib + v2.0 + 512 + + + + + true + full + false + Bin\Debug\ + TRACE;DEBUG + prompt + 4 + + + none + true + Bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b1ce373..4802442 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -69,5 +69,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.37.2")] -[assembly: AssemblyFileVersion("0.1.37.2")] +[assembly: AssemblyVersion("0.1.37.3")] +[assembly: AssemblyFileVersion("0.1.37.3")] diff --git a/Utilities/Config.cs b/Utilities/Config.cs deleted file mode 100644 index 989550b..0000000 --- a/Utilities/Config.cs +++ /dev/null @@ -1,195 +0,0 @@ -/* - - Version: MPL 1.1/GPL 2.0/LGPL 2.1 - - The contents of this file are subject to the Mozilla Public License Version - 1.1 (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS IS" basis, - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - for the specific language governing rights and limitations under the License. - - The Original Code is the Open Hardware Monitor code. - - The Initial Developer of the Original Code is - Michael Möller . - Portions created by the Initial Developer are Copyright (C) 2009-2010 - the Initial Developer. All Rights Reserved. - - Contributor(s): - - Alternatively, the contents of this file may be used under the terms of - either the GNU General Public License Version 2 or later (the "GPL"), or - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - in which case the provisions of the GPL or the LGPL are applicable instead - of those above. If you wish to allow use of your version of this file only - under the terms of either the GPL or the LGPL, and not to allow others to - use your version of this file under the terms of the MPL, indicate your - decision by deleting the provisions above and replace them with the notice - and other provisions required by the GPL or the LGPL. If you do not delete - the provisions above, a recipient may use your version of this file under - the terms of any one of the MPL, the GPL or the LGPL. - -*/ - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; - -namespace OpenHardwareMonitor.Utilities { - - public sealed class Config { - private static readonly Config instance = new Config(); - - private string fileName; - - private System.Configuration.Configuration config; - - private Config() { - this.fileName = Path.ChangeExtension( - System.Windows.Forms.Application.ExecutablePath, ".config"); - System.Configuration.ExeConfigurationFileMap fileMap = - new System.Configuration.ExeConfigurationFileMap(); - fileMap.ExeConfigFilename = fileName; - config = System.Configuration.ConfigurationManager. - OpenMappedExeConfiguration(fileMap, - System.Configuration.ConfigurationUserLevel.None); - try { - // try to load the settings - System.Configuration.KeyValueConfigurationCollection collection = - config.AppSettings.Settings; - } catch { - // if an exception is thrown, start with a new config file - if (File.Exists(fileName)) - File.Delete(fileName); - config = System.Configuration.ConfigurationManager. - OpenMappedExeConfiguration(fileMap, - System.Configuration.ConfigurationUserLevel.None); - } - } - - private void SaveConfig() { - string tempName = Path.ChangeExtension(fileName, ".tmp"); - - if (File.Exists(tempName)) - File.Delete(tempName); - try { - config.SaveAs(tempName); - if (File.Exists(fileName) && File.Exists(tempName)) - File.Delete(fileName); - File.Move(tempName, fileName); - } catch (System.Configuration.ConfigurationErrorsException) { } - } - - public static void Save() { - instance.SaveConfig(); - } - - public static Config Settings { - get { - return instance; - } - } - - public string this[string name] { - get { - System.Configuration.KeyValueConfigurationElement element = - config.AppSettings.Settings[name]; - if (element != null) - return element.Value; - else - return null; - } - set { - config.AppSettings.Settings.Remove(name); - config.AppSettings.Settings.Add(name, value); - } - } - - public static bool Contains(string name) { - System.Configuration.KeyValueConfigurationElement element = - instance.config.AppSettings.Settings[name]; - return element != null; - } - - public static void Remove(string name) { - instance.config.AppSettings.Settings.Remove(name); - } - - public static void Set(string name, bool value) { - instance[name] = value ? "true" : "false"; - } - - public static bool Get(string name, bool value) { - System.Configuration.KeyValueConfigurationElement element = - instance.config.AppSettings.Settings[name]; - if (element == null) - return value; - else - return element.Value == "true"; - } - - public static void Set(string name, int value) { - instance[name] = value.ToString(); - } - - public static int Get(string name, int value) { - System.Configuration.KeyValueConfigurationElement element = - instance.config.AppSettings.Settings[name]; - if (element == null) - return value; - else { - int parsedValue; - if (int.TryParse(element.Value, out parsedValue)) - return parsedValue; - else - return value; - } - } - - public static void Set(string name, Color color) { - instance[name] = color.ToArgb().ToString("X8"); - } - - public static Color Get(string name, Color value) { - System.Configuration.KeyValueConfigurationElement element = - instance.config.AppSettings.Settings[name]; - if (element == null) - return value; - else { - int parsedValue; - if (int.TryParse(element.Value, - System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out parsedValue)) - return Color.FromArgb(parsedValue); - else - return value; - } - } - - public static void Set(string name, float value) { - instance[name] = value.ToString( - System.Globalization.CultureInfo.InvariantCulture.NumberFormat); - } - - public static float Get(string name, float value) { - System.Configuration.KeyValueConfigurationElement element = - instance.config.AppSettings.Settings[name]; - if (element == null) - return value; - else { - float parsedValue; - if (float.TryParse(element.Value, - System.Globalization.NumberStyles.Float, - System.Globalization.CultureInfo.InvariantCulture, out parsedValue)) - return parsedValue; - else - return value; - } - } - } -} diff --git a/Utilities/PersistentSettings.cs b/Utilities/PersistentSettings.cs new file mode 100644 index 0000000..b7c3bf9 --- /dev/null +++ b/Utilities/PersistentSettings.cs @@ -0,0 +1,163 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using System.Xml; +using OpenHardwareMonitor.Hardware; + +namespace OpenHardwareMonitor { + public class PersistentSettings : ISettings { + + private IDictionary settings = + new Dictionary(); + + public void Load(string fileName) { + XmlDocument doc = new XmlDocument(); + try { + doc.Load(fileName); + } catch { + return; + } + XmlNodeList list = doc.GetElementsByTagName("appSettings"); + foreach (XmlNode node in list) { + XmlNode parent = node.ParentNode; + if (parent != null && parent.Name == "configuration" && + parent.ParentNode is XmlDocument) { + foreach (XmlNode child in node.ChildNodes) { + if (child.Name == "add") { + XmlAttributeCollection attributes = child.Attributes; + XmlAttribute keyAttribute = attributes["key"]; + XmlAttribute valueAttribute = attributes["value"]; + if (keyAttribute != null && valueAttribute != null && + keyAttribute.Value != null) { + settings.Add(keyAttribute.Value, valueAttribute.Value); + } + } + } + } + } + } + + public void Save(string fileName) { + XmlDocument doc = new XmlDocument(); + doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); + XmlElement configuration = doc.CreateElement("configuration"); + doc.AppendChild(configuration); + XmlElement appSettings = doc.CreateElement("appSettings"); + configuration.AppendChild(appSettings); + foreach (KeyValuePair keyValuePair in settings) { + XmlElement add = doc.CreateElement("add"); + add.SetAttribute("key", keyValuePair.Key); + add.SetAttribute("value", keyValuePair.Value); + appSettings.AppendChild(add); + } + doc.Save(fileName); + } + + public bool Contains(string name) { + return settings.ContainsKey(name); + } + + public void Set(string name, string value) { + settings[name] = value; + } + + public string Get(string name, string value) { + string result; + if (settings.TryGetValue(name, out result)) + return result; + else + return value; + } + + public void Remove(string name) { + settings.Remove(name); + } + + public void Set(string name, int value) { + settings[name] = value.ToString(); + } + + public int Get(string name, int value) { + string str; + if (settings.TryGetValue(name, out str)) { + int parsedValue; + if (int.TryParse(str, out parsedValue)) + return parsedValue; + else + return value; + } else { + return value; + } + } + + public void Set(string name, bool value) { + settings[name] = value ? "true" : "false"; + } + + public bool Get(string name, bool value) { + string str; + if (settings.TryGetValue(name, out str)) { + return str == "true"; + } else { + return value; + } + } + + public void Set(string name, Color color) { + settings[name] = color.ToArgb().ToString("X8"); + } + + public Color Get(string name, Color value) { + string str; + if (settings.TryGetValue(name, out str)) { + int parsedValue; + if (int.TryParse(str, + System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out parsedValue)) + return Color.FromArgb(parsedValue); + else + return value; + } else { + return value; + } + } + } +}