# HG changeset patch # User moel.mich # Date 1281275846 0 # Node ID 813d8bc3192f4b854a114256d670c14f9657b5b3 # Parent cc1e116d0f2c8e991cefb87ffefdeaecea44c75c Refactored the hardware monitoring code into a library (Issue 101). diff -r cc1e116d0f2c -r 813d8bc3192f Collections/IReadOnlyArray.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Collections/IReadOnlyArray.cs Sun Aug 08 13:57:26 2010 +0000 @@ -0,0 +1,50 @@ +/* + + 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.Collections { + + public interface IReadOnlyArray : IEnumerable { + + T this[int index] { get; } + + int Length { get; } + + } +} diff -r cc1e116d0f2c -r 813d8bc3192f Collections/ListSet.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Collections/ListSet.cs Sun Aug 08 13:57:26 2010 +0000 @@ -0,0 +1,82 @@ +/* + + 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; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Collections { + public class ListSet : IEnumerable { + + private List list = new List(); + + public ListSet() { } + + public bool Add(T item) { + if (list.Contains(item)) + return false; + + list.Add(item); + return true; + } + + public bool Remove(T item) { + if (!list.Contains(item)) + return false; + + list.Remove(item); + return true; + } + + public bool Contains(T item) { + return list.Contains(item); + } + + public T[] ToArray() { + return list.ToArray(); + } + + public IEnumerator GetEnumerator() { + return list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() { + return list.GetEnumerator(); + } + } +} diff -r cc1e116d0f2c -r 813d8bc3192f Collections/ReadOnlyArray.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Collections/ReadOnlyArray.cs Sun Aug 08 13:57:26 2010 +0000 @@ -0,0 +1,70 @@ +/* + + 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; +using System.Collections.Generic; + +namespace OpenHardwareMonitor.Collections { + + public class ReadOnlyArray : IReadOnlyArray { + + private T[] array; + + public ReadOnlyArray(T[] array) { + this.array = array; + } + + public T this[int index] { + get { return array[index]; } + } + + public int Length { get { return array.Length; } } + + public IEnumerator GetEnumerator() { + return ((IEnumerable)array).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() { + return array.GetEnumerator(); + } + + public static implicit operator ReadOnlyArray(T[] array) { + return new ReadOnlyArray(array); + } + } +} diff -r cc1e116d0f2c -r 813d8bc3192f GUI/HardwareNode.cs --- a/GUI/HardwareNode.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/HardwareNode.cs Sun Aug 08 13:57:26 2010 +0000 @@ -43,14 +43,41 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/MainForm.cs --- a/GUI/MainForm.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/MainForm.cs Sun Aug 08 13:57:26 2010 +0000 @@ -51,7 +51,9 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/ParameterForm.cs --- a/GUI/ParameterForm.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/ParameterForm.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,7 +41,7 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/SensorNode.cs --- a/GUI/SensorNode.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/SensorNode.cs Sun Aug 08 13:57:26 2010 +0000 @@ -44,13 +44,15 @@ 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 @@ 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 @@ 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 @@ get { return base.IsVisible; } set { base.IsVisible = value; - Config.Set(new Identifier(sensor.Identifier, + settings.Set(new Identifier(sensor.Identifier, "hidden").ToString(), !value); } } diff -r cc1e116d0f2c -r 813d8bc3192f GUI/SensorNotifyIcon.cs --- a/GUI/SensorNotifyIcon.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/SensorNotifyIcon.cs Sun Aug 08 13:57:26 2010 +0000 @@ -62,7 +62,7 @@ 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/SystemTray.cs --- a/GUI/SystemTray.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/SystemTray.cs Sun Aug 08 13:57:26 2010 +0000 @@ -46,12 +46,14 @@ 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 @@ } 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/UnitManager.cs --- a/GUI/UnitManager.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/UnitManager.cs Sun Aug 08 13:57:26 2010 +0000 @@ -37,7 +37,6 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.GUI { @@ -48,18 +47,20 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f GUI/UserOption.cs --- a/GUI/UserOption.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/GUI/UserOption.cs Sun Aug 08 13:57:26 2010 +0000 @@ -46,13 +46,15 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/ATI/ADL.cs --- a/Hardware/ATI/ADL.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/ATI/ADL.cs Sun Aug 08 13:57:26 2010 +0000 @@ -42,7 +42,7 @@ 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 @@ } [StructLayout(LayoutKind.Sequential)] - public struct ADLPMActivity { + internal struct ADLPMActivity { public int Size; public int EngineClock; public int MemoryClock; @@ -81,13 +81,13 @@ } [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 @@ } [StructLayout(LayoutKind.Sequential)] - public struct ADLFanSpeedInfo { + internal struct ADLFanSpeedInfo { public int Size; public int Flags; public int MinPercent; @@ -104,7 +104,7 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/ATI/ATIGPU.cs --- a/Hardware/ATI/ATIGPU.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/ATI/ATIGPU.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/ATI/ATIGroup.cs --- a/Hardware/ATI/ATIGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/ATI/ATIGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -40,12 +40,12 @@ 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 @@ adapterInfo[i].AdapterName.Trim(), adapterInfo[i].AdapterIndex, adapterInfo[i].BusNumber, - adapterInfo[i].DeviceNumber)); + adapterInfo[i].DeviceNumber, settings)); } report.AppendLine(); diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/AMD10CPU.cs --- a/Hardware/CPU/AMD10CPU.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/AMD10CPU.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ "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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/CPUGroup.cs --- a/Hardware/CPU/CPUGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/CPUGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -42,7 +42,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { - public class CPUGroup : IGroup { + internal class CPUGroup : IGroup { private List hardware = new List(); private CPUID[][][] threads; @@ -100,7 +100,7 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/CPUID.cs --- a/Hardware/CPU/CPUID.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/CPUID.cs Sun Aug 08 13:57:26 2010 +0000 @@ -40,14 +40,14 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/CPULoad.cs --- a/Hardware/CPU/CPULoad.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/CPULoad.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,7 +41,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.CPU { - public class CPULoad { + internal class CPULoad { [StructLayout(LayoutKind.Sequential)] private struct SystemProcessorPerformanceInformation { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/CPU/IntelCPU.cs --- a/Hardware/CPU/IntelCPU.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/CPU/IntelCPU.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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.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 @@ 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 @@ "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 @@ } 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/Computer.cs --- a/Hardware/Computer.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Computer.cs Sun Aug 08 13:57:26 2010 +0000 @@ -50,8 +50,19 @@ 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 @@ 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/HDD/HDD.cs --- a/Hardware/HDD/HDD.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/HDD/HDD.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ get { return new Identifier("hdd", drive.ToString()); } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.HDD; } } public IHardware[] SubHardware { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/HDD/HDDGroup.cs --- a/Hardware/HDD/HDDGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/HDD/HDDGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -39,13 +39,13 @@ 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 @@ } if (attribute >= 0) { - hardware.Add(new HDD(name, handle, drive, attribute)); + hardware.Add(new HDD(name, handle, drive, attribute, settings)); continue; } } diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/HDD/SMART.cs --- a/Hardware/HDD/SMART.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/HDD/SMART.cs Sun Aug 08 13:57:26 2010 +0000 @@ -40,8 +40,8 @@ using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware.HDD { - - public class SMART { + + internal class SMART { [Flags] public enum Status : ushort { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Hardware.cs --- a/Hardware/Hardware.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Hardware.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/HexStringArray.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/HexStringArray.cs Sun Aug 08 13:57:26 2010 +0000 @@ -0,0 +1,61 @@ +/* + + 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.Text; + +namespace OpenHardwareMonitor.Hardware { + internal class HexStringArray { + + private byte[] array; + + public HexStringArray(string input) { + List list = new List(); + foreach (string str in input.Split(' ')) { + string s = str.Trim(); + if (s.Length > 0) + list.Add(Convert.ToByte(s, 16)); + } + array = list.ToArray(); + } + + public byte this[int i] { + get { return array[i]; } + } + } +} diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/IGroup.cs --- a/Hardware/IGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/IGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -40,7 +40,7 @@ namespace OpenHardwareMonitor.Hardware { - public interface IGroup { + internal interface IGroup { IHardware[] Hardware { get; } diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/IHardware.cs --- a/Hardware/IHardware.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/IHardware.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/ISensor.cs --- a/Hardware/ISensor.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/ISensor.cs Sun Aug 08 13:57:26 2010 +0000 @@ -37,7 +37,7 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Utilities; +using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/ISettings.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/ISettings.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/Chip.cs --- a/Hardware/LPC/Chip.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/Chip.cs Sun Aug 08 13:57:26 2010 +0000 @@ -5,7 +5,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { - public enum Chip : ushort { + internal enum Chip : ushort { Unknown = 0, IT8712F = 0x8712, IT8716F = 0x8716, diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/F718XX.cs --- a/Hardware/LPC/F718XX.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/F718XX.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/ISuperIO.cs --- a/Hardware/LPC/ISuperIO.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/ISuperIO.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/IT87XX.cs --- a/Hardware/LPC/IT87XX.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/IT87XX.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/LMSensors.cs --- a/Hardware/LPC/LMSensors.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/LMSensors.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,7 +41,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { - public class LMSensors { + internal class LMSensors { private List lmChips = new List(); diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/LPCIO.cs --- a/Hardware/LPC/LPCIO.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/LPCIO.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,7 +41,7 @@ using System.Threading; namespace OpenHardwareMonitor.Hardware.LPC { - public class LPCIO { + internal class LPCIO { private List superIOs = new List(); private StringBuilder report = new StringBuilder(); diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/LPC/W836XX.cs --- a/Hardware/LPC/W836XX.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/LPC/W836XX.cs Sun Aug 08 13:57:26 2010 +0000 @@ -40,7 +40,7 @@ using System.Text; namespace OpenHardwareMonitor.Hardware.LPC { - public class W836XX : ISuperIO { + internal class W836XX : ISuperIO { private ushort address; private byte revision; diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/Mainboard.cs --- a/Hardware/Mainboard/Mainboard.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/Mainboard.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ 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 @@ get { return new Identifier("mainboard"); } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.Mainboard; } } public string GetReport() { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/MainboardGroup.cs --- a/Hardware/Mainboard/MainboardGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/MainboardGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -39,13 +39,13 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/Manufacturer.cs --- a/Hardware/Mainboard/Manufacturer.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/Manufacturer.cs Sun Aug 08 13:57:26 2010 +0000 @@ -36,8 +36,8 @@ */ namespace OpenHardwareMonitor.Hardware.Mainboard { - - public enum Manufacturer { + + internal enum Manufacturer { ASRock, ASUS, Dell, diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/Model.cs --- a/Hardware/Mainboard/Model.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/Model.cs Sun Aug 08 13:57:26 2010 +0000 @@ -37,7 +37,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { - public enum Model { + internal enum Model { // ASRock _880GMH_USB3, diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/SMBIOS.cs --- a/Hardware/Mainboard/SMBIOS.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/SMBIOS.cs Sun Aug 08 13:57:26 2010 +0000 @@ -43,7 +43,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { - public class SMBIOS { + internal class SMBIOS { private byte[] raw; private Structure[] table; diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Mainboard/SuperIOHardware.cs --- a/Hardware/Mainboard/SuperIOHardware.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Mainboard/SuperIOHardware.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ formula, voltage.Rf), new ParameterDescription("Vf [V]", "Reference voltage.\n" + formula, voltage.Vf) - }); + }, settings); voltages.Add(sensor); } @@ -583,14 +580,14 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/Nvidia/NVAPI.cs --- a/Hardware/Nvidia/NVAPI.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Nvidia/NVAPI.cs Sun Aug 08 13:57:26 2010 +0000 @@ -42,7 +42,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { - public enum NvStatus { + internal enum NvStatus { OK = 0, ERROR = -1, LIBRARY_NOT_FOUND = -2, @@ -94,9 +94,9 @@ 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 @@ VBIOSEVT, OS, UNKNOWN = -1, - } + } - public enum NvThermalTarget { + internal enum NvThermalTarget { NONE = 0, GPU = 1, MEMORY = 2, @@ -123,7 +123,7 @@ }; [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvSensor { + internal struct NvSensor { public NvThermalController Controller; public uint DefaultMinTemp; public uint DefaultMaxTemp; @@ -132,7 +132,7 @@ } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvGPUThermalSettings { + internal struct NvGPUThermalSettings { public uint Version; public uint Count; [MarshalAs(UnmanagedType.ByValArray, @@ -141,30 +141,30 @@ } [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 @@ } [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 @@ } [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 @@ } [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 @@ } [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct NvDisplayDriverVersion { + internal struct NvDisplayDriverVersion { public uint Version; public uint DriverVersion; public uint BldChangeListNum; @@ -219,9 +219,9 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/Nvidia/NvidiaGPU.cs --- a/Hardware/Nvidia/NvidiaGPU.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Nvidia/NvidiaGPU.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/Nvidia/NvidiaGroup.cs --- a/Hardware/Nvidia/NvidiaGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Nvidia/NvidiaGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,12 +41,12 @@ 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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f Hardware/PInvokeDelegateFactory.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/PInvokeDelegateFactory.cs Sun Aug 08 13:57:26 2010 +0000 @@ -0,0 +1,118 @@ +/* + + 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.Reflection; +using System.Reflection.Emit; +using System.Runtime.InteropServices; + +namespace OpenHardwareMonitor.Hardware { + + internal sealed class PInvokeDelegateFactory { + + private static AssemblyBuilder assemblyBuilder; + private static ModuleBuilder moduleBuilder; + + private static IDictionary wrapperTypes = + new Dictionary(); + + static PInvokeDelegateFactory() { + + AssemblyName assemblyName = new AssemblyName(); + assemblyName.Name = "PInvokeDelegateFactoryInternalAssembly"; + + assemblyBuilder = + AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, + AssemblyBuilderAccess.Run); + + moduleBuilder = assemblyBuilder.DefineDynamicModule( + "PInvokeDelegateFactoryInternalModule"); + } + + private PInvokeDelegateFactory() { } + + public static void CreateDelegate(DllImportAttribute dllImportAttribute, + out T newDelegate) where T : class + { + Type wrapperType; + wrapperTypes.TryGetValue(dllImportAttribute, out wrapperType); + + if (wrapperType == null) { + wrapperType = CreateWrapperType(typeof(T), dllImportAttribute); + wrapperTypes.Add(dllImportAttribute, wrapperType); + } + + newDelegate = Delegate.CreateDelegate(typeof(T), wrapperType, + dllImportAttribute.EntryPoint) as T; + } + + + private static Type CreateWrapperType(Type delegateType, + DllImportAttribute dllImportAttribute) { + + TypeBuilder typeBuilder = moduleBuilder.DefineType( + "PInvokeDelegateFactoryInternalWrapperType" + wrapperTypes.Count); + + MethodInfo methodInfo = delegateType.GetMethod("Invoke"); + + ParameterInfo[] parameterInfos = methodInfo.GetParameters(); + int parameterCount = parameterInfos.GetLength(0); + + Type[] parameterTypes = new Type[parameterCount]; + for (int i = 0; i < parameterCount; i++) + parameterTypes[i] = parameterInfos[i].ParameterType; + + MethodBuilder methodBuilder = typeBuilder.DefinePInvokeMethod( + dllImportAttribute.EntryPoint, dllImportAttribute.Value, + MethodAttributes.Public | MethodAttributes.Static | + MethodAttributes.PinvokeImpl, CallingConventions.Standard, + methodInfo.ReturnType, parameterTypes, + dllImportAttribute.CallingConvention, + dllImportAttribute.CharSet); + + foreach (ParameterInfo parameterInfo in parameterInfos) + methodBuilder.DefineParameter(parameterInfo.Position + 1, + parameterInfo.Attributes, parameterInfo.Name); + + if (dllImportAttribute.PreserveSig) + methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig); + + return typeBuilder.CreateType(); + } + } +} diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Parameter.cs --- a/Hardware/Parameter.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Parameter.cs Sun Aug 08 13:57:26 2010 +0000 @@ -64,13 +64,23 @@ 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 @@ } 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 @@ this.isDefault = value; if (value) { this.value = description.DefaultValue; - Utilities.Config.Remove(Identifier.ToString()); + this.settings.Remove(Identifier.ToString()); } } } diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/Sensor.cs --- a/Hardware/Sensor.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/Sensor.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ 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 @@ 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 @@ name = value; else name = defaultName; - Config.Settings[new Identifier(Identifier, "name").ToString()] = name; + settings.Set(new Identifier(Identifier, "name").ToString(), name); } } diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/TBalancer/FTD2XX.cs --- a/Hardware/TBalancer/FTD2XX.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/TBalancer/FTD2XX.cs Sun Aug 08 13:57:26 2010 +0000 @@ -41,7 +41,7 @@ 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 @@ FT_DEVICE_4232H } - public enum FT_STATUS { + internal enum FT_STATUS { FT_OK, FT_INVALID_HANDLE, FT_DEVICE_NOT_FOUND, @@ -73,26 +73,26 @@ 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 @@ public FT_HANDLE Handle; } - public class FTD2XX { + internal class FTD2XX { public delegate FT_STATUS FT_CreateDeviceInfoListDelegate( out uint numDevices); diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/TBalancer/TBalancer.cs --- a/Hardware/TBalancer/TBalancer.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/TBalancer/TBalancer.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } } - public Image Icon { - get { return icon; } + public HardwareType HardwareType { + get { return HardwareType.TBalancer; } } public string Name { diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/TBalancer/TBalancerGroup.cs --- a/Hardware/TBalancer/TBalancerGroup.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/TBalancer/TBalancerGroup.cs Sun Aug 08 13:57:26 2010 +0000 @@ -43,12 +43,12 @@ 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 @@ if (isValid) { report.AppendLine("Status: OK"); - hardware.Add(new TBalancer(i, protocolVersion)); + hardware.Add(new TBalancer(i, protocolVersion, settings)); return; } report.AppendLine(); diff -r cc1e116d0f2c -r 813d8bc3192f Hardware/WinRing0.cs --- a/Hardware/WinRing0.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Hardware/WinRing0.cs Sun Aug 08 13:57:26 2010 +0000 @@ -43,7 +43,7 @@ namespace OpenHardwareMonitor.Hardware { - public class WinRing0 { + internal class WinRing0 { public enum OlsDllStatus{ OLS_DLL_NO_ERROR = 0, diff -r cc1e116d0f2c -r 813d8bc3192f OpenHardwareMonitor.csproj --- a/OpenHardwareMonitor.csproj Thu Aug 05 19:28:50 2010 +0000 +++ b/OpenHardwareMonitor.csproj Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f OpenHardwareMonitor.sln --- a/OpenHardwareMonitor.sln Thu Aug 05 19:28:50 2010 +0000 +++ b/OpenHardwareMonitor.sln Sun Aug 08 13:57:26 2010 +0000 @@ -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 @@ 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 -r cc1e116d0f2c -r 813d8bc3192f OpenHardwareMonitorLib.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OpenHardwareMonitorLib.csproj Sun Aug 08 13:57:26 2010 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Properties/AssemblyInfo.cs --- a/Properties/AssemblyInfo.cs Thu Aug 05 19:28:50 2010 +0000 +++ b/Properties/AssemblyInfo.cs Sun Aug 08 13:57:26 2010 +0000 @@ -69,5 +69,5 @@ // 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 -r cc1e116d0f2c -r 813d8bc3192f Utilities/Config.cs --- a/Utilities/Config.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r cc1e116d0f2c -r 813d8bc3192f Utilities/HexStringArray.cs --- a/Utilities/HexStringArray.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +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.Text; - -namespace OpenHardwareMonitor.Utilities { - public class HexStringArray { - - private byte[] array; - - public HexStringArray(string input) { - List list = new List(); - foreach (string str in input.Split(' ')) { - string s = str.Trim(); - if (s.Length > 0) - list.Add(Convert.ToByte(s, 16)); - } - array = list.ToArray(); - } - - public byte this[int i] { - get { return array[i]; } - } - } -} diff -r cc1e116d0f2c -r 813d8bc3192f Utilities/IReadOnlyArray.cs --- a/Utilities/IReadOnlyArray.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +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; - -namespace OpenHardwareMonitor.Utilities { - - public interface IReadOnlyArray : IEnumerable { - - T this[int index] { get; } - - int Length { get; } - - } -} diff -r cc1e116d0f2c -r 813d8bc3192f Utilities/ListSet.cs --- a/Utilities/ListSet.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +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; -using System.Collections.Generic; -using System.Text; - -namespace OpenHardwareMonitor.Utilities { - public class ListSet : IEnumerable { - - private List list = new List(); - - public ListSet() { } - - public bool Add(T item) { - if (list.Contains(item)) - return false; - - list.Add(item); - return true; - } - - public bool Remove(T item) { - if (!list.Contains(item)) - return false; - - list.Remove(item); - return true; - } - - public bool Contains(T item) { - return list.Contains(item); - } - - public T[] ToArray() { - return list.ToArray(); - } - - public IEnumerator GetEnumerator() { - return list.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() { - return list.GetEnumerator(); - } - } -} diff -r cc1e116d0f2c -r 813d8bc3192f Utilities/PInvokeDelegateFactory.cs --- a/Utilities/PInvokeDelegateFactory.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +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.Reflection; -using System.Reflection.Emit; -using System.Runtime.InteropServices; - -namespace OpenHardwareMonitor.Hardware { - - public sealed class PInvokeDelegateFactory { - - private static AssemblyBuilder assemblyBuilder; - private static ModuleBuilder moduleBuilder; - - private static IDictionary wrapperTypes = - new Dictionary(); - - static PInvokeDelegateFactory() { - - AssemblyName assemblyName = new AssemblyName(); - assemblyName.Name = "PInvokeDelegateFactoryInternalAssembly"; - - assemblyBuilder = - AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, - AssemblyBuilderAccess.Run); - - moduleBuilder = assemblyBuilder.DefineDynamicModule( - "PInvokeDelegateFactoryInternalModule"); - } - - private PInvokeDelegateFactory() { } - - public static void CreateDelegate(DllImportAttribute dllImportAttribute, - out T newDelegate) where T : class - { - Type wrapperType; - wrapperTypes.TryGetValue(dllImportAttribute, out wrapperType); - - if (wrapperType == null) { - wrapperType = CreateWrapperType(typeof(T), dllImportAttribute); - wrapperTypes.Add(dllImportAttribute, wrapperType); - } - - newDelegate = Delegate.CreateDelegate(typeof(T), wrapperType, - dllImportAttribute.EntryPoint) as T; - } - - - private static Type CreateWrapperType(Type delegateType, - DllImportAttribute dllImportAttribute) { - - TypeBuilder typeBuilder = moduleBuilder.DefineType( - "PInvokeDelegateFactoryInternalWrapperType" + wrapperTypes.Count); - - MethodInfo methodInfo = delegateType.GetMethod("Invoke"); - - ParameterInfo[] parameterInfos = methodInfo.GetParameters(); - int parameterCount = parameterInfos.GetLength(0); - - Type[] parameterTypes = new Type[parameterCount]; - for (int i = 0; i < parameterCount; i++) - parameterTypes[i] = parameterInfos[i].ParameterType; - - MethodBuilder methodBuilder = typeBuilder.DefinePInvokeMethod( - dllImportAttribute.EntryPoint, dllImportAttribute.Value, - MethodAttributes.Public | MethodAttributes.Static | - MethodAttributes.PinvokeImpl, CallingConventions.Standard, - methodInfo.ReturnType, parameterTypes, - dllImportAttribute.CallingConvention, - dllImportAttribute.CharSet); - - foreach (ParameterInfo parameterInfo in parameterInfos) - methodBuilder.DefineParameter(parameterInfo.Position + 1, - parameterInfo.Attributes, parameterInfo.Name); - - if (dllImportAttribute.PreserveSig) - methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig); - - return typeBuilder.CreateType(); - } - } -} diff -r cc1e116d0f2c -r 813d8bc3192f Utilities/PersistentSettings.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utilities/PersistentSettings.cs Sun Aug 08 13:57:26 2010 +0000 @@ -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; + } + } + } +} diff -r cc1e116d0f2c -r 813d8bc3192f Utilities/ReadOnlyArray.cs --- a/Utilities/ReadOnlyArray.cs Thu Aug 05 19:28:50 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +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; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Utilities { - - public class ReadOnlyArray : IReadOnlyArray { - - private T[] array; - - public ReadOnlyArray(T[] array) { - this.array = array; - } - - public T this[int index] { - get { return array[index]; } - } - - public int Length { get { return array.Length; } } - - public IEnumerator GetEnumerator() { - return ((IEnumerable)array).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() { - return array.GetEnumerator(); - } - - public static implicit operator ReadOnlyArray(T[] array) { - return new ReadOnlyArray(array); - } - } -}