diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 15d149d..2228118 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -159,8 +159,18 @@ namespace OpenHardwareMonitor.GUI { } } + private void SubHardwareAdded(IHardware hardware, Node node) { + Node hardwareNode = new HardwareNode(hardware); + node.Nodes.Add(hardwareNode); + foreach (IHardware subHardware in hardware.SubHardware) + SubHardwareAdded(subHardware, hardwareNode); + } + private void HardwareAdded(IHardware hardware) { - root.Nodes.Add(new HardwareNode(hardware)); + Node hardwareNode = new HardwareNode(hardware); + root.Nodes.Add(hardwareNode); + foreach (IHardware subHardware in hardware.SubHardware) + SubHardwareAdded(subHardware, hardwareNode); } private void HardwareRemoved(IHardware hardware) { @@ -357,15 +367,25 @@ namespace OpenHardwareMonitor.GUI { UpdatePlotSelection(null, null); } - private void UpdateSensorTypeChecked(object sender, EventArgs e) { - foreach (HardwareNode node in root.Nodes) { - node.SetVisible(SensorType.Voltage, voltMenuItem.Checked); - node.SetVisible(SensorType.Clock, clocksMenuItem.Checked); - node.SetVisible(SensorType.Load, loadMenuItem.Checked); - node.SetVisible(SensorType.Temperature, tempMenuItem.Checked); - node.SetVisible(SensorType.Fan, fansMenuItem.Checked); - node.SetVisible(SensorType.Flow, flowsMenuItem.Checked); - } + private void UpdateSensorTypeVisible(Node node) { + HardwareNode hardwareNode = node as HardwareNode; + if (hardwareNode == null) + return; + + hardwareNode.SetVisible(SensorType.Voltage, voltMenuItem.Checked); + hardwareNode.SetVisible(SensorType.Clock, clocksMenuItem.Checked); + hardwareNode.SetVisible(SensorType.Load, loadMenuItem.Checked); + hardwareNode.SetVisible(SensorType.Temperature, tempMenuItem.Checked); + hardwareNode.SetVisible(SensorType.Fan, fansMenuItem.Checked); + hardwareNode.SetVisible(SensorType.Flow, flowsMenuItem.Checked); + + foreach (Node n in node.Nodes) + UpdateSensorTypeVisible(n); + } + + private void UpdateSensorTypeChecked(object sender, EventArgs e) { + foreach (HardwareNode node in root.Nodes) + UpdateSensorTypeVisible(node); } private void ToggleSysTray() { diff --git a/GUI/SensorSystemTray.cs b/GUI/SensorSystemTray.cs index 101cb2c..d1a3075 100644 --- a/GUI/SensorSystemTray.cs +++ b/GUI/SensorSystemTray.cs @@ -59,13 +59,17 @@ namespace OpenHardwareMonitor.GUI { hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved); foreach (ISensor sensor in hardware.Sensors) SensorRemoved(sensor); + foreach (IHardware subHardware in hardware.SubHardware) + HardwareRemoved(subHardware); } - + private void HardwareAdded(IHardware hardware) { foreach (ISensor sensor in hardware.Sensors) SensorAdded(sensor); hardware.SensorAdded += new SensorEventHandler(SensorAdded); hardware.SensorRemoved += new SensorEventHandler(SensorRemoved); + foreach (IHardware subHardware in hardware.SubHardware) + HardwareAdded(subHardware); } private void SensorAdded(ISensor sensor) { diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index 6a78dd3..14f15ab 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -61,7 +61,7 @@ namespace OpenHardwareMonitor.Hardware { groups.Add(group); if (HardwareAdded != null) - foreach (IHardware hardware in group.Hardware) + foreach (IHardware hardware in group.Hardware) HardwareAdded(hardware); } @@ -72,7 +72,7 @@ namespace OpenHardwareMonitor.Hardware { groups.Remove(group); if (HardwareRemoved != null) - foreach (IHardware hardware in group.Hardware) + foreach (IHardware hardware in group.Hardware) HardwareRemoved(hardware); } @@ -80,8 +80,7 @@ namespace OpenHardwareMonitor.Hardware { if (open) return; - Add(new SMBIOS.SMBIOSGroup()); - Add(new LPC.LPCGroup()); + Add(new Mainboard.MainboardGroup()); Add(new CPU.CPUGroup()); Add(new ATI.ATIGroup()); Add(new Nvidia.NvidiaGroup()); @@ -93,10 +92,19 @@ namespace OpenHardwareMonitor.Hardware { open = true; } + private void SubHardwareUpdate(IHardware hardware) { + foreach (IHardware subHardware in hardware.SubHardware) { + subHardware.Update(); + SubHardwareUpdate(subHardware); + } + } + public void Update() { foreach (IGroup group in groups) - foreach (IHardware hardware in group.Hardware) + foreach (IHardware hardware in group.Hardware) { hardware.Update(); + SubHardwareUpdate(hardware); + } } public bool HDDEnabled { @@ -131,6 +139,38 @@ namespace OpenHardwareMonitor.Hardware { writer.WriteLine(); } + private void ReportHardwareTree(IHardware hardware, TextWriter w, + string space) + { + w.WriteLine("{0}|", space); + w.WriteLine("{0}+-+ {1} ({2})", + space, hardware.Name, hardware.Identifier); + foreach (ISensor sensor in hardware.Sensors) { + w.WriteLine("{0}| +- {1} : {2} : {3} : {4}", + space, sensor.SensorType, sensor.Index, sensor.Name, + string.Format(CultureInfo.InvariantCulture, "{0} : {1} : {2}", + sensor.Value, sensor.Min, sensor.Max)); + foreach (IParameter parameter in sensor.Parameters) { + w.WriteLine("{0}| +- {1} : {2} : {3}", + space, parameter.Name, parameter.IsDefault, + string.Format(CultureInfo.InvariantCulture, "{0} : {1}", + parameter.DefaultValue, parameter.Value)); + } + } + foreach (IHardware subHardware in hardware.SubHardware) + ReportHardwareTree(subHardware, w, "| "); + } + + private void ReportHardware(IHardware hardware, TextWriter w) { + string hardwareReport = hardware.GetReport(); + if (hardwareReport != null && hardwareReport != "") { + NewSection(w); + w.Write(hardwareReport); + } + foreach (IHardware subHardware in hardware.SubHardware) + ReportHardware(subHardware, w); + } + public void SaveReport(Version version) { using (TextWriter w = @@ -146,23 +186,8 @@ namespace OpenHardwareMonitor.Hardware { NewSection(w); foreach (IGroup group in groups) { - foreach (IHardware hardware in group.Hardware) { - w.WriteLine("|"); - w.WriteLine("+-+ {0} ({1})", - new object[] { hardware.Name, hardware.Identifier }); - foreach (ISensor sensor in hardware.Sensors) { - w.WriteLine("| +- {0} : {1} : {2} : {3}", - sensor.SensorType, sensor.Index, sensor.Name, - string.Format(CultureInfo.InvariantCulture, "{0} : {1} : {2}", - sensor.Value, sensor.Min, sensor.Max) ); - foreach (IParameter parameter in sensor.Parameters) { - w.WriteLine("| +- {0} : {1} : {2}", - parameter.Name, parameter.IsDefault, - string.Format(CultureInfo.InvariantCulture, "{0} : {1}", - parameter.DefaultValue, parameter.Value) ); - } - } - } + foreach (IHardware hardware in group.Hardware) + ReportHardwareTree(hardware, w, ""); } w.WriteLine(); @@ -174,13 +199,9 @@ namespace OpenHardwareMonitor.Hardware { } IHardware[] hardwareArray = group.Hardware; - foreach (IHardware hardware in hardwareArray) { - string hardwareReport = hardware.GetReport(); - if (hardwareReport != null && hardwareReport != "") { - NewSection(w); - w.Write(hardwareReport); - } - } + foreach (IHardware hardware in hardwareArray) + ReportHardware(hardware, w); + } } } @@ -199,7 +220,5 @@ namespace OpenHardwareMonitor.Hardware { public event HardwareEventHandler HardwareAdded; public event HardwareEventHandler HardwareRemoved; - - } } diff --git a/Hardware/HDD/HDD.cs b/Hardware/HDD/HDD.cs index f779868..5f78d58 100644 --- a/Hardware/HDD/HDD.cs +++ b/Hardware/HDD/HDD.cs @@ -77,6 +77,10 @@ namespace OpenHardwareMonitor.Hardware.HDD { get { return icon; } } + public IHardware[] SubHardware { + get { return new IHardware[0]; } + } + public ISensor[] Sensors { get { return new ISensor[] { temperature }; diff --git a/Hardware/Hardware.cs b/Hardware/Hardware.cs index d9285dc..dfbb82f 100644 --- a/Hardware/Hardware.cs +++ b/Hardware/Hardware.cs @@ -43,6 +43,10 @@ namespace OpenHardwareMonitor.Hardware { private List active = new List(); + public IHardware[] SubHardware { + get { return new IHardware[0]; } + } + public ISensor[] Sensors { get { return active.ToArray(); } } @@ -63,7 +67,9 @@ namespace OpenHardwareMonitor.Hardware { } } + #pragma warning disable 67 public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorRemoved; + #pragma warning restore 67 } } diff --git a/Hardware/IHardware.cs b/Hardware/IHardware.cs index b2595c7..61c3221 100644 --- a/Hardware/IHardware.cs +++ b/Hardware/IHardware.cs @@ -54,6 +54,8 @@ namespace OpenHardwareMonitor.Hardware { void Update(); + IHardware[] SubHardware { get; } + ISensor[] Sensors { get; } event SensorEventHandler SensorAdded; diff --git a/Hardware/Mainboard/Mainboard.cs b/Hardware/Mainboard/Mainboard.cs new file mode 100644 index 0000000..7d7b8b6 --- /dev/null +++ b/Hardware/Mainboard/Mainboard.cs @@ -0,0 +1,109 @@ +/* + + 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 OpenHardwareMonitor.Hardware.LPC; + +namespace OpenHardwareMonitor.Hardware.Mainboard { + public class Mainboard : IHardware { + private SMBIOS smbios; + private string name; + private Image icon; + + private LPCGroup lpcGroup; + + public Mainboard() { + this.smbios = new SMBIOS(); + if (smbios.Board != null && smbios.Board.ProductName != null + && smbios.Board.ProductName != "") { + if (smbios.Board.Manufacturer == Manufacturer.Unkown) + this.name = smbios.Board.ProductName; + else + this.name = smbios.Board.Manufacturer + " " + + smbios.Board.ProductName; + } else { + this.name = smbios.Board.Manufacturer.ToString(); + } + this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png"); + this.lpcGroup = new LPCGroup(); + } + + public string Name { + get { return name; } + } + + public string Identifier { + get { return "/mainboard"; } + } + + public Image Icon { + get { return icon; } + } + + public string GetReport() { + StringBuilder r = new StringBuilder(); + + r.AppendLine("Mainboard"); + r.AppendLine(); + r.Append(smbios.GetReport()); + + return r.ToString(); + } + + public void Update() { } + + public void Close() { + lpcGroup.Close(); + } + + public IHardware[] SubHardware { + get { return lpcGroup.Hardware; } + } + + public ISensor[] Sensors { + get { return new ISensor[0]; } + } + + #pragma warning disable 67 + public event SensorEventHandler SensorAdded; + public event SensorEventHandler SensorRemoved; + #pragma warning restore 67 + } +} diff --git a/Hardware/Mainboard/MainboardGroup.cs b/Hardware/Mainboard/MainboardGroup.cs new file mode 100644 index 0000000..acb7e29 --- /dev/null +++ b/Hardware/Mainboard/MainboardGroup.cs @@ -0,0 +1,65 @@ +/* + + 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.Mainboard { + public class MainboardGroup : IGroup { + + private Mainboard[] mainboards; + + public MainboardGroup() { + mainboards = new Mainboard[1]; + mainboards[0] = new Mainboard(); + } + + public void Close() { + foreach (Mainboard mainboard in mainboards) + mainboard.Close(); + } + + public string GetReport() { + return null; + } + + public IHardware[] Hardware { + get { return mainboards; } + + } + } +} diff --git a/Hardware/Mainboard/Manufacturer.cs b/Hardware/Mainboard/Manufacturer.cs new file mode 100644 index 0000000..e306323 --- /dev/null +++ b/Hardware/Mainboard/Manufacturer.cs @@ -0,0 +1,52 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; + +namespace OpenHardwareMonitor.Hardware.Mainboard { + + public enum Manufacturer { + ASUS, + DFI, + EPoX, + Gigabyte, + MSI, + Unkown + } + +} diff --git a/Hardware/SMBIOS/SMBIOSGroup.cs b/Hardware/Mainboard/SMBIOS.cs similarity index 79% rename from Hardware/SMBIOS/SMBIOSGroup.cs rename to Hardware/Mainboard/SMBIOS.cs index 56b3358..0e1ce31 100644 --- a/Hardware/SMBIOS/SMBIOSGroup.cs +++ b/Hardware/Mainboard/SMBIOS.cs @@ -40,17 +40,16 @@ using System.Collections.Generic; using System.Management; using System.Text; -namespace OpenHardwareMonitor.Hardware.SMBIOS { +namespace OpenHardwareMonitor.Hardware.Mainboard { - public class SMBIOSGroup : IGroup { + public class SMBIOS { private Structure[] table; private BIOSInformation biosInformation = null; - private BaseBoardInformation baseBoardInformation = null; - public SMBIOSGroup() { + public SMBIOS() { int p = (int)System.Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) return; @@ -110,13 +109,8 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { table = structureList.ToArray(); } - public IHardware[] Hardware { get { return new IHardware[0]; } } - public string GetReport() { - StringBuilder r = new StringBuilder(); - - r.AppendLine("SMBIOS"); - r.AppendLine(); + StringBuilder r = new StringBuilder(); if (biosInformation != null) { r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor); @@ -126,7 +120,7 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { if (baseBoardInformation != null) { r.Append("Mainboard Manufacturer: "); - r.AppendLine(baseBoardInformation.Manufacturer); + r.AppendLine(baseBoardInformation.ManufacturerName); r.Append("Mainboard Name: "); r.AppendLine(baseBoardInformation.ProductName); r.AppendLine(); @@ -135,7 +129,13 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { return r.ToString(); } - public void Close() { } + public BIOSInformation BIOS { + get { return biosInformation; } + } + + public BaseBoardInformation Board { + get { return baseBoardInformation; } + } public class Structure { private byte type; @@ -185,20 +185,39 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { public class BaseBoardInformation : Structure { - private string manufacturer; + private string manufacturerName; private string productName; + private Manufacturer manufacturer; public BaseBoardInformation(byte type, ushort handle, byte[] data, string[] strings) : base(type, handle, data, strings) { - this.manufacturer = GetString(0x04); - this.productName = GetString(0x05); + this.manufacturerName = GetString(0x04).Trim(); + this.productName = GetString(0x05).Trim(); + + switch (manufacturerName) { + case "ASUSTeK Computer INC.": + manufacturer = Manufacturer.ASUS; break; + case "DFI": + case "DFI Inc.:": + manufacturer = Manufacturer.DFI; break; + case "EPoX COMPUTER CO., LTD": + manufacturer = Manufacturer.EPoX; break; + case "Gigabyte Technology Co., Ltd.": + manufacturer = Manufacturer.Gigabyte; break; + case "MICRO-STAR INTERNATIONAL CO., LTD": + manufacturer = Manufacturer.MSI; break; + default: + manufacturer = Manufacturer.Unkown; break; + } } - public string Manufacturer { get { return manufacturer; } } + public string ManufacturerName { get { return manufacturerName; } } public string ProductName { get { return productName; } } + + public Manufacturer Manufacturer { get { return manufacturer; } } } } } diff --git a/Hardware/TBalancer/TBalancer.cs b/Hardware/TBalancer/TBalancer.cs index b75b5fe..708b62b 100644 --- a/Hardware/TBalancer/TBalancer.cs +++ b/Hardware/TBalancer/TBalancer.cs @@ -262,6 +262,10 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { this.portName.TrimStart(new char[]{'/'}).ToLower(); } } + public IHardware[] SubHardware { + get { return new IHardware[0]; } + } + public ISensor[] Sensors { get { return active.ToArray(); } } diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 4a8bace..80ada31 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -78,8 +78,11 @@ + + + - + @@ -172,6 +175,9 @@ + + +