mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-30 13:57:38 +00:00
Refactoring: New class Computer manages all the hardware and creates events.
This commit is contained in:
parent
15162a2a12
commit
31adbedc3c
36
GUI/MainForm.Designer.cs
generated
36
GUI/MainForm.Designer.cs
generated
@ -94,6 +94,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
|
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.plotMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.plotMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.minTrayMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.hddMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.hddMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
@ -409,16 +411,32 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
// optionsToolStripMenuItem
|
// optionsToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.minTrayMenuItem,
|
||||||
|
this.toolStripMenuItem3,
|
||||||
this.hddMenuItem});
|
this.hddMenuItem});
|
||||||
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
|
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
|
||||||
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
|
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
|
||||||
this.optionsToolStripMenuItem.Text = "Options";
|
this.optionsToolStripMenuItem.Text = "Options";
|
||||||
//
|
//
|
||||||
|
// minTrayMenuItem
|
||||||
|
//
|
||||||
|
this.minTrayMenuItem.Checked = true;
|
||||||
|
this.minTrayMenuItem.CheckOnClick = true;
|
||||||
|
this.minTrayMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
|
this.minTrayMenuItem.Name = "minTrayMenuItem";
|
||||||
|
this.minTrayMenuItem.Size = new System.Drawing.Size(166, 22);
|
||||||
|
this.minTrayMenuItem.Text = "Minimize To Tray";
|
||||||
|
//
|
||||||
|
// toolStripMenuItem3
|
||||||
|
//
|
||||||
|
this.toolStripMenuItem3.Name = "toolStripMenuItem3";
|
||||||
|
this.toolStripMenuItem3.Size = new System.Drawing.Size(163, 6);
|
||||||
|
//
|
||||||
// hddMenuItem
|
// hddMenuItem
|
||||||
//
|
//
|
||||||
this.hddMenuItem.CheckOnClick = true;
|
this.hddMenuItem.CheckOnClick = true;
|
||||||
this.hddMenuItem.Name = "hddMenuItem";
|
this.hddMenuItem.Name = "hddMenuItem";
|
||||||
this.hddMenuItem.Size = new System.Drawing.Size(141, 22);
|
this.hddMenuItem.Size = new System.Drawing.Size(166, 22);
|
||||||
this.hddMenuItem.Text = "HDD sensors";
|
this.hddMenuItem.Text = "HDD sensors";
|
||||||
this.hddMenuItem.CheckedChanged += new System.EventHandler(this.hddsensorsToolStripMenuItem_CheckedChanged);
|
this.hddMenuItem.CheckedChanged += new System.EventHandler(this.hddsensorsToolStripMenuItem_CheckedChanged);
|
||||||
//
|
//
|
||||||
@ -477,7 +495,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
|
this.notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
|
||||||
this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
|
this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
|
||||||
this.notifyIcon.Text = "Open Hardware Monitor";
|
this.notifyIcon.Text = "Open Hardware Monitor";
|
||||||
this.notifyIcon.Click += new System.EventHandler(this.notifyIcon_Click);
|
this.notifyIcon.DoubleClick += new System.EventHandler(this.restoreClick);
|
||||||
//
|
//
|
||||||
// notifyContextMenuStrip
|
// notifyContextMenuStrip
|
||||||
//
|
//
|
||||||
@ -486,25 +504,25 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.toolStripMenuItem2,
|
this.toolStripMenuItem2,
|
||||||
this.exitToolStripMenuItem1});
|
this.exitToolStripMenuItem1});
|
||||||
this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
|
this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
|
||||||
this.notifyContextMenuStrip.Size = new System.Drawing.Size(153, 76);
|
this.notifyContextMenuStrip.Size = new System.Drawing.Size(119, 54);
|
||||||
//
|
//
|
||||||
// restoreToolStripMenuItem
|
// restoreToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.restoreToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F);
|
this.restoreToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
|
||||||
this.restoreToolStripMenuItem.Name = "restoreToolStripMenuItem";
|
this.restoreToolStripMenuItem.Name = "restoreToolStripMenuItem";
|
||||||
this.restoreToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
this.restoreToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
|
||||||
this.restoreToolStripMenuItem.Text = "Restore";
|
this.restoreToolStripMenuItem.Text = "Restore";
|
||||||
this.restoreToolStripMenuItem.Click += new System.EventHandler(this.restoreToolStripMenuItem_Click);
|
this.restoreToolStripMenuItem.Click += new System.EventHandler(this.restoreClick);
|
||||||
//
|
//
|
||||||
// toolStripMenuItem2
|
// toolStripMenuItem2
|
||||||
//
|
//
|
||||||
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
|
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
|
||||||
this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
|
this.toolStripMenuItem2.Size = new System.Drawing.Size(115, 6);
|
||||||
//
|
//
|
||||||
// exitToolStripMenuItem1
|
// exitToolStripMenuItem1
|
||||||
//
|
//
|
||||||
this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
|
this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
|
||||||
this.exitToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
|
this.exitToolStripMenuItem1.Size = new System.Drawing.Size(118, 22);
|
||||||
this.exitToolStripMenuItem1.Text = "Exit";
|
this.exitToolStripMenuItem1.Text = "Exit";
|
||||||
this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@ -579,6 +597,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private System.Windows.Forms.ToolStripMenuItem restoreToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem restoreToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
|
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
|
||||||
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem1;
|
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem1;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem minTrayMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
138
GUI/MainForm.cs
138
GUI/MainForm.cs
@ -45,19 +45,19 @@ using System.Windows.Forms;
|
|||||||
using Aga.Controls.Tree;
|
using Aga.Controls.Tree;
|
||||||
using Aga.Controls.Tree.NodeControls;
|
using Aga.Controls.Tree.NodeControls;
|
||||||
using OpenHardwareMonitor.Hardware;
|
using OpenHardwareMonitor.Hardware;
|
||||||
|
using OpenHardwareMonitor.Utilities;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.GUI {
|
namespace OpenHardwareMonitor.GUI {
|
||||||
public partial class MainForm : Form {
|
public partial class MainForm : Form {
|
||||||
|
|
||||||
|
private Computer computer = new Computer();
|
||||||
private Node root;
|
private Node root;
|
||||||
private List<IGroup> groupList = new List<IGroup>();
|
|
||||||
private TreeModel treeModel;
|
private TreeModel treeModel;
|
||||||
private IDictionary<ISensor, Color> sensorPlotColors =
|
private IDictionary<ISensor, Color> sensorPlotColors =
|
||||||
new Dictionary<ISensor, Color>();
|
new Dictionary<ISensor, Color>();
|
||||||
private Color[] plotColorPalette;
|
private Color[] plotColorPalette;
|
||||||
|
|
||||||
public MainForm() {
|
public MainForm() {
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Font = SystemFonts.MessageBoxFont;
|
this.Font = SystemFonts.MessageBoxFont;
|
||||||
treeView.Font = SystemFonts.MessageBoxFont;
|
treeView.Font = SystemFonts.MessageBoxFont;
|
||||||
@ -99,13 +99,10 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
treeModel.Nodes.Add(root);
|
treeModel.Nodes.Add(root);
|
||||||
treeView.Model = treeModel;
|
treeView.Model = treeModel;
|
||||||
|
|
||||||
AddGroup(new Hardware.SMBIOS.SMBIOSGroup());
|
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
|
||||||
AddGroup(new Hardware.LPC.LPCGroup());
|
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
|
||||||
AddGroup(new Hardware.CPU.CPUGroup());
|
computer.Open();
|
||||||
AddGroup(new Hardware.ATI.ATIGroup());
|
|
||||||
AddGroup(new Hardware.Nvidia.NvidiaGroup());
|
|
||||||
AddGroup(new Hardware.TBalancer.TBalancerGroup());
|
|
||||||
|
|
||||||
plotColorPalette = new Color[14];
|
plotColorPalette = new Color[14];
|
||||||
plotColorPalette[0] = Color.Blue;
|
plotColorPalette[0] = Color.Blue;
|
||||||
plotColorPalette[1] = Color.OrangeRed;
|
plotColorPalette[1] = Color.OrangeRed;
|
||||||
@ -122,38 +119,36 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
plotColorPalette[12] = Color.Olive;
|
plotColorPalette[12] = Color.Olive;
|
||||||
plotColorPalette[13] = Color.Firebrick;
|
plotColorPalette[13] = Color.Firebrick;
|
||||||
|
|
||||||
plotMenuItem.Checked = Utilities.Config.Get(plotMenuItem.Name, false);
|
plotMenuItem.Checked = Config.Get(plotMenuItem.Name, false);
|
||||||
minMenuItem.Checked = Utilities.Config.Get(minMenuItem.Name, false);
|
minMenuItem.Checked = Config.Get(minMenuItem.Name, false);
|
||||||
maxMenuItem.Checked = Utilities.Config.Get(maxMenuItem.Name, true);
|
maxMenuItem.Checked = Config.Get(maxMenuItem.Name, true);
|
||||||
limitMenuItem.Checked = Utilities.Config.Get(limitMenuItem.Name, false);
|
limitMenuItem.Checked = Config.Get(limitMenuItem.Name, false);
|
||||||
hddMenuItem.Checked = Utilities.Config.Get(hddMenuItem.Name, true);
|
|
||||||
|
|
||||||
voltMenuItem.Checked = Utilities.Config.Get(voltMenuItem.Name, true);
|
minTrayMenuItem.Checked = Config.Get(minTrayMenuItem.Name, true);
|
||||||
clocksMenuItem.Checked = Utilities.Config.Get(clocksMenuItem.Name, true);
|
hddMenuItem.Checked = Config.Get(hddMenuItem.Name, true);
|
||||||
loadMenuItem.Checked = Utilities.Config.Get(loadMenuItem.Name, true);
|
|
||||||
tempMenuItem.Checked = Utilities.Config.Get(tempMenuItem.Name, true);
|
|
||||||
fansMenuItem.Checked = Utilities.Config.Get(fansMenuItem.Name, true);
|
|
||||||
|
|
||||||
timer.Enabled = true;
|
voltMenuItem.Checked = Config.Get(voltMenuItem.Name, true);
|
||||||
|
clocksMenuItem.Checked = Config.Get(clocksMenuItem.Name, true);
|
||||||
|
loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
|
||||||
|
tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
|
||||||
|
fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
|
||||||
|
|
||||||
|
timer.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddGroup(IGroup group) {
|
private void HardwareAdded(IHardware hardware) {
|
||||||
groupList.Add(group);
|
root.Nodes.Add(new HardwareNode(hardware));
|
||||||
foreach (IHardware hardware in group.Hardware)
|
|
||||||
root.Nodes.Add(new HardwareNode(hardware));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveGroup(IGroup group) {
|
private void HardwareRemoved(IHardware hardware) {
|
||||||
List<Node> nodesToRemove = new List<Node>();
|
List<Node> nodesToRemove = new List<Node>();
|
||||||
foreach (IHardware hardware in group.Hardware)
|
foreach (Node node in root.Nodes) {
|
||||||
foreach (Node node in root.Nodes) {
|
HardwareNode hardwareNode = node as HardwareNode;
|
||||||
HardwareNode hardwareNode = node as HardwareNode;
|
if (hardwareNode != null && hardwareNode.Hardware == hardware)
|
||||||
if (hardwareNode != null && hardwareNode.Hardware == hardware)
|
nodesToRemove.Add(node);
|
||||||
nodesToRemove.Add(node);
|
}
|
||||||
}
|
|
||||||
foreach (Node node in nodesToRemove)
|
foreach (Node node in nodesToRemove)
|
||||||
root.Nodes.Remove(node);
|
root.Nodes.Remove(node);
|
||||||
groupList.Remove(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
|
private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
|
||||||
@ -213,12 +208,10 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
try {
|
try {
|
||||||
#endif
|
#endif
|
||||||
foreach (IGroup group in groupList)
|
computer.Update();
|
||||||
foreach (IHardware hardware in group.Hardware)
|
|
||||||
hardware.Update();
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
Utilities.CrashReport.Save(exception);
|
CrashReport.Save(exception);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -228,27 +221,29 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
|
||||||
Utilities.Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
|
|
||||||
Utilities.Config.Set(minMenuItem.Name, minMenuItem.Checked);
|
Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
|
||||||
Utilities.Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
|
Config.Set(minMenuItem.Name, minMenuItem.Checked);
|
||||||
Utilities.Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
|
Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
|
||||||
Utilities.Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
|
Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
|
||||||
|
|
||||||
Utilities.Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
|
Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
|
||||||
Utilities.Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
|
Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
|
||||||
Utilities.Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
|
|
||||||
Utilities.Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
|
Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
|
||||||
Utilities.Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
|
Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
|
||||||
|
Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
|
||||||
|
Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
|
||||||
|
Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
|
||||||
|
|
||||||
if (WindowState != FormWindowState.Minimized) {
|
if (WindowState != FormWindowState.Minimized) {
|
||||||
Utilities.Config.Set("mainForm.Location.X", Location.X);
|
Config.Set("mainForm.Location.X", Location.X);
|
||||||
Utilities.Config.Set("mainForm.Location.Y", Location.Y);
|
Config.Set("mainForm.Location.Y", Location.Y);
|
||||||
Utilities.Config.Set("mainForm.Width", Width);
|
Config.Set("mainForm.Width", Width);
|
||||||
Utilities.Config.Set("mainForm.Height", Height);
|
Config.Set("mainForm.Height", Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (IGroup group in groupList)
|
computer.Close();
|
||||||
group.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||||
@ -290,31 +285,21 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
|
NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
|
||||||
if (info.Control == null)
|
if (info.Control == null) {
|
||||||
columnsContextMenuStrip.Show(treeView, m.X, m.Y);
|
columnsContextMenuStrip.Show(treeView, m.X, m.Y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||||
ReportWriter.Save(groupList, new Version(Application.ProductVersion));
|
computer.SaveReport(new Version(Application.ProductVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
|
private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
|
||||||
EventArgs e)
|
EventArgs e)
|
||||||
{
|
{
|
||||||
if (hddMenuItem.Checked) {
|
computer.HDDEnabled = hddMenuItem.Checked;
|
||||||
AddGroup(new Hardware.HDD.HDDGroup());
|
UpdateSensorTypeChecked(null, null);
|
||||||
UpdateSensorTypeChecked(null, null);
|
UpdatePlotSelection(null, null);
|
||||||
} else {
|
|
||||||
List<IGroup> groupsToRemove = new List<IGroup>();
|
|
||||||
foreach (IGroup group in groupList)
|
|
||||||
if (group is Hardware.HDD.HDDGroup)
|
|
||||||
groupsToRemove.Add(group);
|
|
||||||
foreach (IGroup group in groupsToRemove) {
|
|
||||||
group.Close();
|
|
||||||
RemoveGroup(group);
|
|
||||||
}
|
|
||||||
UpdatePlotSelection(null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSensorTypeChecked(object sender, EventArgs e) {
|
private void UpdateSensorTypeChecked(object sender, EventArgs e) {
|
||||||
@ -334,29 +319,24 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
} else {
|
} else {
|
||||||
Visible = true;
|
Visible = true;
|
||||||
notifyIcon.Visible = false;
|
notifyIcon.Visible = false;
|
||||||
|
BringToFront();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void WndProc(ref Message m) {
|
protected override void WndProc(ref Message m) {
|
||||||
const int WM_SYSCOMMAND = 0x112;
|
const int WM_SYSCOMMAND = 0x112;
|
||||||
const int SC_MINIMIZE = 0xF020;
|
const int SC_MINIMIZE = 0xF020;
|
||||||
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
|
if (minTrayMenuItem.Checked &&
|
||||||
|
m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
|
||||||
ToggleSysTray();
|
ToggleSysTray();
|
||||||
} else {
|
} else {
|
||||||
base.WndProc(ref m);
|
base.WndProc(ref m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyIcon_Click(object sender, EventArgs e) {
|
private void restoreClick(object sender, EventArgs e) {
|
||||||
MouseEventArgs m = e as MouseEventArgs;
|
ToggleSysTray();
|
||||||
if (m == null || m.Button != MouseButtons.Left)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ToggleSysTray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
||||||
ToggleSysTray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
197
Hardware/Computer.cs
Normal file
197
Hardware/Computer.cs
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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 <m.moeller@gmx.ch>.
|
||||||
|
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.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenHardwareMonitor.Hardware {
|
||||||
|
|
||||||
|
public delegate void HardwareEventHandler(IHardware hardware);
|
||||||
|
|
||||||
|
public class Computer {
|
||||||
|
|
||||||
|
private List<IGroup> groups = new List<IGroup>();
|
||||||
|
|
||||||
|
private bool open = false;
|
||||||
|
private bool hddEnabled = false;
|
||||||
|
|
||||||
|
public Computer() { }
|
||||||
|
|
||||||
|
private void Add(IGroup group) {
|
||||||
|
if (groups.Contains(group))
|
||||||
|
return;
|
||||||
|
|
||||||
|
groups.Add(group);
|
||||||
|
|
||||||
|
if (HardwareAdded != null)
|
||||||
|
foreach (IHardware hardware in group.Hardware)
|
||||||
|
HardwareAdded(hardware);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Remove(IGroup group) {
|
||||||
|
if (!groups.Contains(group))
|
||||||
|
return;
|
||||||
|
|
||||||
|
groups.Remove(group);
|
||||||
|
|
||||||
|
if (HardwareRemoved != null)
|
||||||
|
foreach (IHardware hardware in group.Hardware)
|
||||||
|
HardwareRemoved(hardware);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open() {
|
||||||
|
if (open)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Add(new SMBIOS.SMBIOSGroup());
|
||||||
|
Add(new LPC.LPCGroup());
|
||||||
|
Add(new CPU.CPUGroup());
|
||||||
|
Add(new ATI.ATIGroup());
|
||||||
|
Add(new Nvidia.NvidiaGroup());
|
||||||
|
Add(new TBalancer.TBalancerGroup());
|
||||||
|
|
||||||
|
if (hddEnabled)
|
||||||
|
Add(new HDD.HDDGroup());
|
||||||
|
|
||||||
|
open = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update() {
|
||||||
|
foreach (IGroup group in groups)
|
||||||
|
foreach (IHardware hardware in group.Hardware)
|
||||||
|
hardware.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HDDEnabled {
|
||||||
|
get { return hddEnabled; }
|
||||||
|
set {
|
||||||
|
if (open && value && !hddEnabled) {
|
||||||
|
Add(new HDD.HDDGroup());
|
||||||
|
} else if (open && !value && hddEnabled) {
|
||||||
|
List<IGroup> list = new List<IGroup>();
|
||||||
|
foreach (IGroup group in groups)
|
||||||
|
if (group is HDD.HDDGroup)
|
||||||
|
list.Add(group);
|
||||||
|
foreach (IGroup group in list)
|
||||||
|
Remove(group);
|
||||||
|
}
|
||||||
|
hddEnabled = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IHardware> Hardware {
|
||||||
|
get {
|
||||||
|
foreach (IGroup group in groups)
|
||||||
|
foreach (IHardware hardware in group.Hardware)
|
||||||
|
yield return hardware;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NewSection(TextWriter writer) {
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
writer.Write("----------");
|
||||||
|
writer.WriteLine();
|
||||||
|
writer.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveReport(Version version) {
|
||||||
|
|
||||||
|
using (TextWriter w =
|
||||||
|
new StreamWriter("OpenHardwareMonitor.Report.txt")) {
|
||||||
|
|
||||||
|
w.WriteLine();
|
||||||
|
w.WriteLine("Open Hardware Monitor Report");
|
||||||
|
w.WriteLine();
|
||||||
|
|
||||||
|
NewSection(w);
|
||||||
|
w.Write("Version: "); w.WriteLine(version.ToString());
|
||||||
|
w.WriteLine();
|
||||||
|
|
||||||
|
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}",
|
||||||
|
new object[] { sensor.SensorType, sensor.Index, sensor.Name,
|
||||||
|
sensor.Value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.WriteLine();
|
||||||
|
|
||||||
|
foreach (IGroup group in groups) {
|
||||||
|
string report = group.GetReport();
|
||||||
|
if (report != null) {
|
||||||
|
NewSection(w);
|
||||||
|
w.Write(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
IHardware[] hardwareArray = group.Hardware;
|
||||||
|
foreach (IHardware hardware in hardwareArray) {
|
||||||
|
string hardwareReport = hardware.GetReport();
|
||||||
|
if (hardwareReport != null) {
|
||||||
|
NewSection(w);
|
||||||
|
w.Write(hardwareReport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close() {
|
||||||
|
if (!open)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (IGroup group in groups)
|
||||||
|
group.Close();
|
||||||
|
groups.Clear();
|
||||||
|
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event HardwareEventHandler HardwareAdded;
|
||||||
|
public event HardwareEventHandler HardwareRemoved;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -54,7 +54,9 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface ISensor {
|
public interface ISensor {
|
||||||
|
IHardware Hardware { get; }
|
||||||
SensorType SensorType { get; }
|
SensorType SensorType { get; }
|
||||||
|
string Identifier { get; }
|
||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
int Index { get; }
|
int Index { get; }
|
||||||
float? Value { get; }
|
float? Value { get; }
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware {
|
|
||||||
public class ReportWriter {
|
|
||||||
|
|
||||||
private static void NewSection(TextWriter writer) {
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
writer.Write("----------");
|
|
||||||
writer.WriteLine();
|
|
||||||
writer.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Save(List<IGroup> groupList, Version version) {
|
|
||||||
|
|
||||||
using (TextWriter w =
|
|
||||||
new StreamWriter("OpenHardwareMonitor.Report.txt")) {
|
|
||||||
|
|
||||||
w.WriteLine();
|
|
||||||
w.WriteLine("Open Hardware Monitor Report");
|
|
||||||
w.WriteLine();
|
|
||||||
|
|
||||||
NewSection(w);
|
|
||||||
w.Write("Version: "); w.WriteLine(version.ToString());
|
|
||||||
w.WriteLine();
|
|
||||||
|
|
||||||
NewSection(w);
|
|
||||||
foreach (IGroup group in groupList) {
|
|
||||||
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}",
|
|
||||||
new object[] { sensor.SensorType, sensor.Index, sensor.Name,
|
|
||||||
sensor.Value });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.WriteLine();
|
|
||||||
|
|
||||||
foreach (IGroup group in groupList) {
|
|
||||||
string report = group.GetReport();
|
|
||||||
if (report != null) {
|
|
||||||
NewSection(w);
|
|
||||||
w.Write(report);
|
|
||||||
}
|
|
||||||
|
|
||||||
IHardware[] hardwareArray = group.Hardware;
|
|
||||||
foreach (IHardware hardware in hardwareArray) {
|
|
||||||
string hardwareReport = hardware.GetReport();
|
|
||||||
if (hardwareReport != null) {
|
|
||||||
NewSection(w);
|
|
||||||
w.Write(hardwareReport);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -59,12 +59,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
private const int MAX_MINUTES = 120;
|
private const int MAX_MINUTES = 120;
|
||||||
|
|
||||||
private string GetIdentifier() {
|
|
||||||
return hardware.Identifier + "/" + sensorType.ToString().ToLower() +
|
|
||||||
"/" + index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sensor(string name, int index, SensorType sensorType,
|
public Sensor(string name, int index, SensorType sensorType,
|
||||||
IHardware hardware)
|
IHardware hardware)
|
||||||
: this(name, index, null, sensorType, hardware) { }
|
: this(name, index, null, sensorType, hardware) { }
|
||||||
@ -77,24 +72,35 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
this.defaultLimit = limit;
|
this.defaultLimit = limit;
|
||||||
this.sensorType = sensorType;
|
this.sensorType = sensorType;
|
||||||
this.hardware = hardware;
|
this.hardware = hardware;
|
||||||
string configName =
|
string configName =
|
||||||
Utilities.Config.Settings[GetIdentifier() + "/name"];
|
Utilities.Config.Settings[Identifier + "/name"];
|
||||||
if (configName != null)
|
if (configName != null)
|
||||||
this.name = configName;
|
this.name = configName;
|
||||||
else
|
else
|
||||||
this.name = name;
|
this.name = name;
|
||||||
string configLimit =
|
string configLimit =
|
||||||
Utilities.Config.Settings[GetIdentifier() + "/limit"];
|
Utilities.Config.Settings[Identifier + "/limit"];
|
||||||
if (configLimit != null && configLimit != "")
|
if (configLimit != null && configLimit != "")
|
||||||
this.limit = float.Parse(configLimit);
|
this.limit = float.Parse(configLimit);
|
||||||
else
|
else
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IHardware Hardware {
|
||||||
|
get { return hardware; }
|
||||||
|
}
|
||||||
|
|
||||||
public SensorType SensorType {
|
public SensorType SensorType {
|
||||||
get { return sensorType; }
|
get { return sensorType; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Identifier {
|
||||||
|
get {
|
||||||
|
return hardware.Identifier + "/" + sensorType.ToString().ToLower() +
|
||||||
|
"/" + index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Name {
|
public string Name {
|
||||||
get {
|
get {
|
||||||
return name;
|
return name;
|
||||||
@ -104,7 +110,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
name = value;
|
name = value;
|
||||||
else
|
else
|
||||||
name = defaultName;
|
name = defaultName;
|
||||||
Utilities.Config.Settings[GetIdentifier() + "/name"] = name;
|
Utilities.Config.Settings[Identifier + "/name"] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,11 +156,11 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
set {
|
set {
|
||||||
if (value.HasValue) {
|
if (value.HasValue) {
|
||||||
limit = value;
|
limit = value;
|
||||||
Utilities.Config.Settings[GetIdentifier() + "/limit"] =
|
Utilities.Config.Settings[Identifier + "/limit"] =
|
||||||
limit.ToString();
|
limit.ToString();
|
||||||
} else {
|
} else {
|
||||||
limit = defaultLimit;
|
limit = defaultLimit;
|
||||||
Utilities.Config.Settings[GetIdentifier() + "/limit"] = "";
|
Utilities.Config.Settings[Identifier + "/limit"] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<Compile Include="Hardware\LPC\F718XX.cs" />
|
<Compile Include="Hardware\LPC\F718XX.cs" />
|
||||||
<Compile Include="Hardware\SMBIOS\SMBIOSGroup.cs" />
|
<Compile Include="Hardware\SMBIOS\SMBIOSGroup.cs" />
|
||||||
<Compile Include="Hardware\LPC\W83627DHG.cs" />
|
<Compile Include="Hardware\LPC\W83627DHG.cs" />
|
||||||
<Compile Include="Hardware\ReportWriter.cs" />
|
<Compile Include="Hardware\Computer.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="GUI\AboutBox.cs">
|
<Compile Include="GUI\AboutBox.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@ -80,6 +80,7 @@
|
|||||||
<Compile Include="Hardware\ATI\ADL.cs" />
|
<Compile Include="Hardware\ATI\ADL.cs" />
|
||||||
<Compile Include="Hardware\ATI\ATIGroup.cs" />
|
<Compile Include="Hardware\ATI\ATIGroup.cs" />
|
||||||
<Compile Include="Hardware\ATI\ATIGPU.cs" />
|
<Compile Include="Hardware\ATI\ATIGPU.cs" />
|
||||||
|
<Compile Include="Utilities\IconFactory.cs" />
|
||||||
<Compile Include="Utilities\Configuration.cs" />
|
<Compile Include="Utilities\Configuration.cs" />
|
||||||
<Compile Include="Utilities\CrashReport.cs" />
|
<Compile Include="Utilities\CrashReport.cs" />
|
||||||
<Compile Include="Utilities\EmbeddedResources.cs" />
|
<Compile Include="Utilities\EmbeddedResources.cs" />
|
||||||
@ -137,7 +138,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources\chip.png" />
|
<EmbeddedResource Include="Resources\chip.png" />
|
||||||
<EmbeddedResource Include="Resources\hdd.png" />
|
<EmbeddedResource Include="Resources\hdd.png" />
|
||||||
<Content Include="Resources\icon.ico" />
|
<None Include="Resources\icon.ico" />
|
||||||
<EmbeddedResource Include="Resources\load.png" />
|
<EmbeddedResource Include="Resources\load.png" />
|
||||||
<EmbeddedResource Include="Resources\voltage.png" />
|
<EmbeddedResource Include="Resources\voltage.png" />
|
||||||
<EmbeddedResource Include="Resources\nvidia.png" />
|
<EmbeddedResource Include="Resources\nvidia.png" />
|
||||||
|
@ -99,6 +99,10 @@ namespace OpenHardwareMonitor.Utilities {
|
|||||||
return element != null;
|
return element != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Remove(string name) {
|
||||||
|
instance.config.AppSettings.Settings.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Set(string name, bool value) {
|
public static void Set(string name, bool value) {
|
||||||
instance[name] = value ? "true" : "false";
|
instance[name] = value ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,20 @@ namespace OpenHardwareMonitor.Utilities {
|
|||||||
|
|
||||||
return new Bitmap(1, 1);
|
return new Bitmap(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Icon GetIcon(string name) {
|
||||||
|
name = "OpenHardwareMonitor.Resources." + name;
|
||||||
|
|
||||||
|
string[] names =
|
||||||
|
Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
||||||
|
for (int i = 0; i < names.Length; i++) {
|
||||||
|
if (names[i].Replace('\\', '.') == name)
|
||||||
|
return new Icon(Assembly.GetExecutingAssembly().
|
||||||
|
GetManifestResourceStream(names[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user