Added a WMI provider, documentation to follow.
1.1 --- a/GUI/MainForm.Designer.cs Thu Oct 14 17:30:51 2010 +0000
1.2 +++ b/GUI/MainForm.Designer.cs Sat Oct 16 13:29:06 2010 +0000
1.3 @@ -100,6 +100,8 @@
1.4 this.fahrenheitMenuItem = new System.Windows.Forms.MenuItem();
1.5 this.MenuItem4 = new System.Windows.Forms.MenuItem();
1.6 this.hddMenuItem = new System.Windows.Forms.MenuItem();
1.7 + this.menuItem5 = new System.Windows.Forms.MenuItem();
1.8 + this.wmiMenuItem = new System.Windows.Forms.MenuItem();
1.9 this.helpMenuItem = new System.Windows.Forms.MenuItem();
1.10 this.aboutMenuItem = new System.Windows.Forms.MenuItem();
1.11 this.sensorContextMenu = new System.Windows.Forms.ContextMenu();
1.12 @@ -308,7 +310,9 @@
1.13 this.separatorMenuItem,
1.14 this.temperatureUnitsMenuItem,
1.15 this.MenuItem4,
1.16 - this.hddMenuItem});
1.17 + this.hddMenuItem,
1.18 + this.menuItem5,
1.19 + this.wmiMenuItem});
1.20 this.optionsMenuItem.Text = "Options";
1.21 //
1.22 // startMinMenuItem
1.23 @@ -366,6 +370,16 @@
1.24 this.hddMenuItem.Index = 7;
1.25 this.hddMenuItem.Text = "Read HDD sensors";
1.26 //
1.27 + // menuItem5
1.28 + //
1.29 + this.menuItem5.Index = 8;
1.30 + this.menuItem5.Text = "-";
1.31 + //
1.32 + // wmiMenuItem
1.33 + //
1.34 + this.wmiMenuItem.Index = 9;
1.35 + this.wmiMenuItem.Text = "Enable WMI Provider";
1.36 + //
1.37 // helpMenuItem
1.38 //
1.39 this.helpMenuItem.Index = 3;
1.40 @@ -522,6 +536,8 @@
1.41 private System.Windows.Forms.MenuItem MenuItem3;
1.42 private System.Windows.Forms.MenuItem gadgetMenuItem;
1.43 private System.Windows.Forms.MenuItem minCloseMenuItem;
1.44 + private System.Windows.Forms.MenuItem menuItem5;
1.45 + private System.Windows.Forms.MenuItem wmiMenuItem;
1.46 }
1.47 }
1.48
2.1 --- a/GUI/MainForm.cs Thu Oct 14 17:30:51 2010 +0000
2.2 +++ b/GUI/MainForm.cs Sat Oct 16 13:29:06 2010 +0000
2.3 @@ -19,7 +19,7 @@
2.4 Portions created by the Initial Developer are Copyright (C) 2009-2010
2.5 the Initial Developer. All Rights Reserved.
2.6
2.7 - Contributor(s):
2.8 + Contributor(s): Paul Werelds
2.9
2.10 Alternatively, the contents of this file may be used under the terms of
2.11 either the GNU General Public License Version 2 or later (the "GPL"), or
2.12 @@ -38,15 +38,13 @@
2.13 using System;
2.14 using System.Collections.Generic;
2.15 using System.ComponentModel;
2.16 -using System.Configuration;
2.17 using System.Drawing;
2.18 using System.IO;
2.19 -using System.Text;
2.20 using System.Windows.Forms;
2.21 using Aga.Controls.Tree;
2.22 using Aga.Controls.Tree.NodeControls;
2.23 using OpenHardwareMonitor.Hardware;
2.24 -using OpenHardwareMonitor.Utilities;
2.25 +using OpenHardwareMonitor.WMIProvider;
2.26
2.27 namespace OpenHardwareMonitor.GUI {
2.28 public partial class MainForm : Form {
2.29 @@ -75,6 +73,9 @@
2.30 private UserOption autoStart;
2.31 private UserOption readHddSensors;
2.32 private UserOption showGadget;
2.33 + private UserOption enableWmiProvider;
2.34 +
2.35 + private WmiProvider wmiProvider;
2.36
2.37 public MainForm() {
2.38 InitializeComponent();
2.39 @@ -133,6 +134,10 @@
2.40
2.41 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.42 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.43 +
2.44 + if (settings.GetValue("enableWmiProvider", false))
2.45 + wmiProvider = new WmiProvider(computer);
2.46 +
2.47 computer.Open();
2.48
2.49 timer.Enabled = true;
2.50 @@ -152,7 +157,8 @@
2.51 plotColorPalette[11] = Color.Olive;
2.52 plotColorPalette[12] = Color.Firebrick;
2.53
2.54 - showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, settings);
2.55 + showHiddenSensors = new UserOption("hiddenMenuItem", false,
2.56 + hiddenMenuItem, settings);
2.57 showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
2.58 treeModel.ForceVisible = showHiddenSensors.Value;
2.59 };
2.60 @@ -163,7 +169,8 @@
2.61 treeView.Invalidate();
2.62 };
2.63
2.64 - showValue = new UserOption("valueMenuItem", true, valueMenuItem, settings);
2.65 + showValue = new UserOption("valueMenuItem", true, valueMenuItem,
2.66 + settings);
2.67 showValue.Changed += delegate(object sender, EventArgs e) {
2.68 treeView.Columns[1].IsVisible = showValue.Value;
2.69 };
2.70 @@ -178,16 +185,20 @@
2.71 treeView.Columns[3].IsVisible = showMax.Value;
2.72 };
2.73
2.74 - startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem, settings);
2.75 + startMinimized = new UserOption("startMinMenuItem", false,
2.76 + startMinMenuItem, settings);
2.77
2.78 - minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem, settings);
2.79 + minimizeToTray = new UserOption("minTrayMenuItem", true,
2.80 + minTrayMenuItem, settings);
2.81 minimizeToTray.Changed += delegate(object sender, EventArgs e) {
2.82 systemTray.IsMainIconEnabled = minimizeToTray.Value;
2.83 };
2.84
2.85 - minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, settings);
2.86 + minimizeOnClose = new UserOption("minCloseMenuItem", false,
2.87 + minCloseMenuItem, settings);
2.88
2.89 - autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings);
2.90 + autoStart = new UserOption(null, startupManager.Startup,
2.91 + startupMenuItem, settings);
2.92 autoStart.Changed += delegate(object sender, EventArgs e) {
2.93 try {
2.94 startupManager.Startup = autoStart.Value;
2.95 @@ -198,18 +209,31 @@
2.96 }
2.97 };
2.98
2.99 - readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem, settings);
2.100 + readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
2.101 + settings);
2.102 readHddSensors.Changed += delegate(object sender, EventArgs e) {
2.103 computer.HDDEnabled = readHddSensors.Value;
2.104 UpdatePlotSelection(null, null);
2.105 };
2.106
2.107 - showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem, settings);
2.108 + showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
2.109 + settings);
2.110 showGadget.Changed += delegate(object sender, EventArgs e) {
2.111 if (gadget != null)
2.112 gadget.Visible = showGadget.Value;
2.113 };
2.114
2.115 + enableWmiProvider = new UserOption("enableWmiProvider", false,
2.116 + wmiMenuItem, settings);
2.117 + enableWmiProvider.Changed += delegate {
2.118 + if (enableWmiProvider.Value && wmiProvider == null)
2.119 + wmiProvider = new WmiProvider(computer);
2.120 + else if (!enableWmiProvider.Value && wmiProvider != null) {
2.121 + wmiProvider.Dispose();
2.122 + wmiProvider = null;
2.123 + }
2.124 + };
2.125 +
2.126 celciusMenuItem.Checked =
2.127 unitManager.TemperatureUnit == TemperatureUnit.Celcius;
2.128 fahrenheitMenuItem.Checked = !celciusMenuItem.Checked;
2.129 @@ -229,10 +253,9 @@
2.130 IntPtr handle = Handle;
2.131
2.132 // Make sure the settings are saved when the user logs off
2.133 - Microsoft.Win32.SystemEvents.SessionEnded +=
2.134 - delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
2.135 - SaveConfiguration();
2.136 - };
2.137 + Microsoft.Win32.SystemEvents.SessionEnded += delegate {
2.138 + SaveConfiguration();
2.139 + };
2.140 }
2.141
2.142 private void SubHardwareAdded(IHardware hardware, Node node) {
2.143 @@ -297,7 +320,8 @@
2.144 plotPanel.SetSensors(selected, colors);
2.145 }
2.146
2.147 - private void nodeTextBoxText_EditorShowing(object sender, CancelEventArgs e)
2.148 + private void nodeTextBoxText_EditorShowing(object sender,
2.149 + CancelEventArgs e)
2.150 {
2.151 e.Cancel = !(treeView.CurrentNode != null &&
2.152 treeView.CurrentNode.Tag is SensorNode);
2.153 @@ -319,9 +343,12 @@
2.154 computer.Accept(updateVisitor);
2.155 treeView.Invalidate();
2.156 plotPanel.Invalidate();
2.157 - systemTray.Redraw();
2.158 + systemTray.Redraw();
2.159 if (gadget != null)
2.160 gadget.Redraw();
2.161 +
2.162 + if (wmiProvider != null)
2.163 + wmiProvider.Update();
2.164 }
2.165
2.166 private void SaveConfiguration() {
2.167 @@ -355,13 +382,13 @@
2.168 Height = settings.GetValue("mainForm.Height", 640)
2.169 };
2.170
2.171 - Rectangle totalWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
2.172 + Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
2.173 int.MinValue, int.MinValue);
2.174
2.175 foreach (Screen screen in Screen.AllScreens)
2.176 - totalWorkingArea = Rectangle.Union(totalWorkingArea, screen.Bounds);
2.177 + fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
2.178
2.179 - Rectangle intersection = Rectangle.Intersect(totalWorkingArea, newBounds);
2.180 + Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
2.181 if (intersection.Width < 20 || intersection.Height < 20 ||
2.182 !settings.Contains("mainForm.Location.X")
2.183 ) {
2.184 @@ -394,7 +421,9 @@
2.185 if (m == null || m.Button != MouseButtons.Right)
2.186 return;
2.187
2.188 - NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
2.189 + NodeControlInfo info = treeView.GetNodeControlInfoAt(
2.190 + new Point(m.X, m.Y)
2.191 + );
2.192 treeView.SelectedNode = info.Node;
2.193 if (info.Node != null) {
2.194 SensorNode node = info.Node.Tag as SensorNode;
3.1 --- a/OpenHardwareMonitor.csproj Thu Oct 14 17:30:51 2010 +0000
3.2 +++ b/OpenHardwareMonitor.csproj Sat Oct 16 13:29:06 2010 +0000
3.3 @@ -58,7 +58,9 @@
3.4 </PropertyGroup>
3.5 <ItemGroup>
3.6 <Reference Include="System" />
3.7 + <Reference Include="System.Configuration.Install" />
3.8 <Reference Include="System.Drawing" />
3.9 + <Reference Include="System.Management" />
3.10 <Reference Include="System.Windows.Forms" />
3.11 <Reference Include="System.Xml" />
3.12 <Reference Include="Aga.Controls, Version=1.7.0.0, Culture=neutral, PublicKeyToken=fcc90fbf924463a3">
3.13 @@ -126,6 +128,12 @@
3.14 <Compile Include="GUI\SensorNode.cs" />
3.15 <Compile Include="Utilities\EmbeddedResources.cs" />
3.16 <Compile Include="Utilities\IconFactory.cs" />
3.17 + <Compile Include="WMIProvider\Hardware.cs" />
3.18 + <Compile Include="WMIProvider\IWmiClass.cs" />
3.19 + <Compile Include="WMIProvider\Sensor.cs" />
3.20 + <Compile Include="WMIProvider\WMIProvider.cs">
3.21 + <SubType>Component</SubType>
3.22 + </Compile>
3.23 </ItemGroup>
3.24 <ItemGroup>
3.25 <EmbeddedResource Include="GUI\AboutBox.resx">
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/WMIProvider/Hardware.cs Sat Oct 16 13:29:06 2010 +0000
4.3 @@ -0,0 +1,19 @@
4.4 +using System.Management.Instrumentation;
4.5 +using OpenHardwareMonitor.Hardware;
4.6 +
4.7 +namespace OpenHardwareMonitor.WMIProvider {
4.8 + [InstrumentationClass(InstrumentationType.Instance)]
4.9 + public class Hardware : IWmiClass {
4.10 + public string HardwareType { get; private set; }
4.11 + public string Identifier { get; private set; }
4.12 + public string Name { get; private set; }
4.13 +
4.14 + public Hardware(IHardware hardware) {
4.15 + Name = hardware.Name;
4.16 + Identifier = hardware.Identifier.ToString();
4.17 + HardwareType = hardware.HardwareType.ToString();
4.18 + }
4.19 +
4.20 + public void Update() { }
4.21 + }
4.22 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/WMIProvider/IWmiClass.cs Sat Oct 16 13:29:06 2010 +0000
5.3 @@ -0,0 +1,8 @@
5.4 +namespace OpenHardwareMonitor.WMIProvider {
5.5 + interface IWmiClass {
5.6 + string Name { get; }
5.7 + string Identifier { get; }
5.8 +
5.9 + void Update();
5.10 + }
5.11 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/WMIProvider/Sensor.cs Sat Oct 16 13:29:06 2010 +0000
6.3 @@ -0,0 +1,40 @@
6.4 +using System.Management.Instrumentation;
6.5 +using OpenHardwareMonitor.Hardware;
6.6 +
6.7 +namespace OpenHardwareMonitor.WMIProvider {
6.8 + [InstrumentationClass(InstrumentationType.Instance)]
6.9 + public class Sensor : IWmiClass {
6.10 +
6.11 + private ISensor _sensor;
6.12 +
6.13 + public string SensorType { get; private set; }
6.14 + public string Identifier { get; private set; }
6.15 + public string Parent { get; private set; }
6.16 + public string Name { get; private set; }
6.17 + public float Value { get; private set; }
6.18 + public float Min { get; private set; }
6.19 + public float Max { get; private set; }
6.20 + public int Index { get; private set; }
6.21 +
6.22 + public Sensor(ISensor sensor) {
6.23 + Name = sensor.Name;
6.24 + Index = sensor.Index;
6.25 +
6.26 + SensorType = sensor.SensorType.ToString();
6.27 + Identifier = sensor.Identifier.ToString();
6.28 + Parent = sensor.Hardware.Identifier.ToString();
6.29 +
6.30 + _sensor = sensor;
6.31 + }
6.32 +
6.33 + public void Update() {
6.34 + Value = (_sensor.Value != null) ? (float)_sensor.Value : 0;
6.35 +
6.36 + if (_sensor.Min != null)
6.37 + Min = (float)_sensor.Min;
6.38 +
6.39 + if (_sensor.Max != null)
6.40 + Max = (float)_sensor.Max;
6.41 + }
6.42 + }
6.43 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/WMIProvider/WMIProvider.cs Sat Oct 16 13:29:06 2010 +0000
7.3 @@ -0,0 +1,100 @@
7.4 +using System;
7.5 +using System.Collections.Generic;
7.6 +using System.Management.Instrumentation;
7.7 +using OpenHardwareMonitor.Hardware;
7.8 +
7.9 +[assembly: Instrumented("root/OpenHardwareMonitor")]
7.10 +
7.11 +[System.ComponentModel.RunInstaller(true)]
7.12 +public class InstanceInstaller : DefaultManagementProjectInstaller { }
7.13 +
7.14 +namespace OpenHardwareMonitor.WMIProvider {
7.15 + public class WmiProvider : IDisposable {
7.16 + private List<IWmiClass> _activeInstances;
7.17 +
7.18 + public WmiProvider(IComputer computer) {
7.19 + _activeInstances = new List<IWmiClass>();
7.20 +
7.21 + foreach (IHardware hardware in computer.Hardware)
7.22 + ComputerHardwareAdded(hardware);
7.23 +
7.24 + computer.HardwareAdded += ComputerHardwareAdded;
7.25 + computer.HardwareRemoved += ComputerHardwareRemoved;
7.26 + }
7.27 +
7.28 + public void Update() {
7.29 + foreach (IWmiClass instance in _activeInstances)
7.30 + instance.Update();
7.31 + }
7.32 +
7.33 + #region Eventhandlers
7.34 +
7.35 + private void ComputerHardwareAdded(IHardware hardware) {
7.36 + if (!Exists(hardware.Identifier.ToString())) {
7.37 + foreach (ISensor sensor in hardware.Sensors)
7.38 + HardwareSensorAdded(sensor);
7.39 +
7.40 + hardware.SensorAdded += HardwareSensorAdded;
7.41 + hardware.SensorRemoved += HardwareSensorRemoved;
7.42 +
7.43 + Hardware hw = new Hardware(hardware);
7.44 + _activeInstances.Add(hw);
7.45 +
7.46 + Instrumentation.Publish(hw);
7.47 + }
7.48 +
7.49 + foreach (IHardware subHardware in hardware.SubHardware)
7.50 + ComputerHardwareAdded(subHardware);
7.51 + }
7.52 +
7.53 + private void HardwareSensorAdded(ISensor data) {
7.54 + Sensor sensor = new Sensor(data);
7.55 + _activeInstances.Add(sensor);
7.56 +
7.57 + Instrumentation.Publish(sensor);
7.58 + }
7.59 +
7.60 + private void ComputerHardwareRemoved(IHardware hardware) {
7.61 + hardware.SensorAdded -= HardwareSensorAdded;
7.62 + hardware.SensorRemoved -= HardwareSensorRemoved;
7.63 +
7.64 + foreach (ISensor sensor in hardware.Sensors)
7.65 + HardwareSensorRemoved(sensor);
7.66 +
7.67 + foreach (IHardware subHardware in hardware.SubHardware)
7.68 + ComputerHardwareRemoved(subHardware);
7.69 +
7.70 + RevokeInstance(hardware.Identifier.ToString());
7.71 + }
7.72 +
7.73 + private void HardwareSensorRemoved(ISensor sensor) {
7.74 + RevokeInstance(sensor.Identifier.ToString());
7.75 + }
7.76 +
7.77 + #endregion
7.78 +
7.79 + #region Helpers
7.80 +
7.81 + private bool Exists(string identifier) {
7.82 + return _activeInstances.Exists(h => h.Identifier == identifier);
7.83 + }
7.84 +
7.85 + private void RevokeInstance(string identifier) {
7.86 + int instanceIndex = _activeInstances.FindIndex(
7.87 + item => item.Identifier == identifier.ToString()
7.88 + );
7.89 +
7.90 + Instrumentation.Revoke(_activeInstances[instanceIndex]);
7.91 +
7.92 + _activeInstances.RemoveAt(instanceIndex);
7.93 + }
7.94 +
7.95 + #endregion
7.96 +
7.97 + public void Dispose() {
7.98 + foreach (IWmiClass instance in _activeInstances)
7.99 + Instrumentation.Revoke(instance);
7.100 + _activeInstances = null;
7.101 + }
7.102 + }
7.103 +}