StephaneLenclud@433
|
1 |
/*
|
StephaneLenclud@433
|
2 |
|
StephaneLenclud@433
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
StephaneLenclud@433
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
StephaneLenclud@433
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
StephaneLenclud@433
|
6 |
|
StephaneLenclud@433
|
7 |
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
StephaneLenclud@433
|
8 |
|
StephaneLenclud@433
|
9 |
*/
|
StephaneLenclud@433
|
10 |
|
StephaneLenclud@433
|
11 |
using System;
|
StephaneLenclud@433
|
12 |
using System.Collections.Generic;
|
StephaneLenclud@433
|
13 |
using System.Drawing;
|
StephaneLenclud@433
|
14 |
using System.Text;
|
StephaneLenclud@436
|
15 |
using System.Diagnostics;
|
StephaneLenclud@433
|
16 |
using System.Windows.Forms;
|
StephaneLenclud@435
|
17 |
using System.Windows;
|
StephaneLenclud@433
|
18 |
using OpenHardwareMonitor.Hardware;
|
StephaneLenclud@433
|
19 |
using OpenHardwareMonitor.Utilities;
|
StephaneLenclud@433
|
20 |
using System.Runtime.InteropServices;
|
StephaneLenclud@436
|
21 |
using UacHelpers;
|
StephaneLenclud@433
|
22 |
|
StephaneLenclud@433
|
23 |
|
StephaneLenclud@433
|
24 |
|
StephaneLenclud@433
|
25 |
|
StephaneLenclud@433
|
26 |
|
StephaneLenclud@434
|
27 |
|
StephaneLenclud@433
|
28 |
|
StephaneLenclud@433
|
29 |
namespace OpenHardwareMonitor.GUI
|
StephaneLenclud@433
|
30 |
{
|
StephaneLenclud@433
|
31 |
public class SoundGraphDisplay : IDisposable
|
StephaneLenclud@433
|
32 |
{
|
StephaneLenclud@433
|
33 |
private IComputer computer;
|
StephaneLenclud@433
|
34 |
private PersistentSettings settings;
|
StephaneLenclud@433
|
35 |
private UnitManager unitManager;
|
StephaneLenclud@433
|
36 |
private List<SensorFrontView> list = new List<SensorFrontView>();
|
StephaneLenclud@436
|
37 |
private SoundGraph.Server iServer;
|
StephaneLenclud@436
|
38 |
|
StephaneLenclud@433
|
39 |
|
StephaneLenclud@433
|
40 |
public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
|
StephaneLenclud@433
|
41 |
UnitManager unitManager)
|
StephaneLenclud@433
|
42 |
{
|
StephaneLenclud@433
|
43 |
this.computer = computer;
|
StephaneLenclud@433
|
44 |
this.settings = settings;
|
StephaneLenclud@433
|
45 |
this.unitManager = unitManager;
|
StephaneLenclud@433
|
46 |
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
|
StephaneLenclud@433
|
47 |
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
|
StephaneLenclud@433
|
48 |
|
StephaneLenclud@436
|
49 |
//Start our client if needed
|
StephaneLenclud@436
|
50 |
Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
|
StephaneLenclud@436
|
51 |
if (!(processes.Length > 0))
|
StephaneLenclud@436
|
52 |
{
|
StephaneLenclud@436
|
53 |
|
StephaneLenclud@436
|
54 |
//Process client = UserAccountControl.CreateProcessAsStandardUser(@"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe","");
|
StephaneLenclud@436
|
55 |
/*
|
StephaneLenclud@436
|
56 |
Process client = new Process();
|
StephaneLenclud@436
|
57 |
client.StartInfo.FileName = @"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe";
|
StephaneLenclud@436
|
58 |
client.StartInfo.WorkingDirectory = @"D:\Dev\SoundGraphAccess";
|
StephaneLenclud@436
|
59 |
client.Start();*/
|
StephaneLenclud@436
|
60 |
}
|
StephaneLenclud@436
|
61 |
|
StephaneLenclud@433
|
62 |
//Try loading SoundGraph iMON Disaply DLL
|
StephaneLenclud@436
|
63 |
iServer = new SoundGraph.Server(@"\\.\pipe\sga-receiver", @"\\.\pipe\sga-sender");
|
StephaneLenclud@436
|
64 |
iServer.Start();
|
StephaneLenclud@436
|
65 |
//iServer.SendMessage("init:");
|
StephaneLenclud@433
|
66 |
}
|
StephaneLenclud@433
|
67 |
|
StephaneLenclud@433
|
68 |
private void HardwareRemoved(IHardware hardware)
|
StephaneLenclud@433
|
69 |
{
|
StephaneLenclud@433
|
70 |
hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
|
StephaneLenclud@433
|
71 |
hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
|
StephaneLenclud@433
|
72 |
foreach (ISensor sensor in hardware.Sensors)
|
StephaneLenclud@433
|
73 |
SensorRemoved(sensor);
|
StephaneLenclud@433
|
74 |
foreach (IHardware subHardware in hardware.SubHardware)
|
StephaneLenclud@433
|
75 |
HardwareRemoved(subHardware);
|
StephaneLenclud@433
|
76 |
}
|
StephaneLenclud@433
|
77 |
|
StephaneLenclud@433
|
78 |
private void HardwareAdded(IHardware hardware)
|
StephaneLenclud@433
|
79 |
{
|
StephaneLenclud@433
|
80 |
foreach (ISensor sensor in hardware.Sensors)
|
StephaneLenclud@433
|
81 |
SensorAdded(sensor);
|
StephaneLenclud@433
|
82 |
hardware.SensorAdded += new SensorEventHandler(SensorAdded);
|
StephaneLenclud@433
|
83 |
hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
|
StephaneLenclud@433
|
84 |
foreach (IHardware subHardware in hardware.SubHardware)
|
StephaneLenclud@433
|
85 |
HardwareAdded(subHardware);
|
StephaneLenclud@433
|
86 |
}
|
StephaneLenclud@433
|
87 |
|
StephaneLenclud@433
|
88 |
private void SensorAdded(ISensor sensor)
|
StephaneLenclud@433
|
89 |
{
|
StephaneLenclud@433
|
90 |
if (settings.GetValue(new Identifier(sensor.Identifier,
|
StephaneLenclud@433
|
91 |
"tray").ToString(), false))
|
StephaneLenclud@433
|
92 |
Add(sensor, false);
|
StephaneLenclud@433
|
93 |
}
|
StephaneLenclud@433
|
94 |
|
StephaneLenclud@433
|
95 |
private void SensorRemoved(ISensor sensor)
|
StephaneLenclud@433
|
96 |
{
|
StephaneLenclud@433
|
97 |
if (Contains(sensor))
|
StephaneLenclud@433
|
98 |
Remove(sensor, false);
|
StephaneLenclud@433
|
99 |
}
|
StephaneLenclud@433
|
100 |
|
StephaneLenclud@433
|
101 |
public void Dispose()
|
StephaneLenclud@433
|
102 |
{
|
StephaneLenclud@433
|
103 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
104 |
icon.Dispose();
|
StephaneLenclud@433
|
105 |
|
StephaneLenclud@436
|
106 |
iServer.Stop();
|
StephaneLenclud@433
|
107 |
|
StephaneLenclud@433
|
108 |
}
|
StephaneLenclud@433
|
109 |
|
StephaneLenclud@433
|
110 |
public void Redraw()
|
StephaneLenclud@433
|
111 |
{
|
StephaneLenclud@433
|
112 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
113 |
icon.Update();
|
StephaneLenclud@433
|
114 |
}
|
StephaneLenclud@433
|
115 |
|
StephaneLenclud@433
|
116 |
public bool Contains(ISensor sensor)
|
StephaneLenclud@433
|
117 |
{
|
StephaneLenclud@433
|
118 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
119 |
if (icon.Sensor == sensor)
|
StephaneLenclud@433
|
120 |
return true;
|
StephaneLenclud@433
|
121 |
return false;
|
StephaneLenclud@433
|
122 |
}
|
StephaneLenclud@433
|
123 |
|
StephaneLenclud@433
|
124 |
public void Add(ISensor sensor, bool balloonTip)
|
StephaneLenclud@433
|
125 |
{
|
StephaneLenclud@433
|
126 |
if (Contains(sensor))
|
StephaneLenclud@433
|
127 |
{
|
StephaneLenclud@433
|
128 |
return;
|
StephaneLenclud@433
|
129 |
}
|
StephaneLenclud@433
|
130 |
else
|
StephaneLenclud@433
|
131 |
{
|
StephaneLenclud@433
|
132 |
//SL:
|
StephaneLenclud@433
|
133 |
//list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
|
StephaneLenclud@433
|
134 |
//UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
135 |
//settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
|
StephaneLenclud@433
|
136 |
}
|
StephaneLenclud@433
|
137 |
}
|
StephaneLenclud@433
|
138 |
|
StephaneLenclud@433
|
139 |
public void Remove(ISensor sensor)
|
StephaneLenclud@433
|
140 |
{
|
StephaneLenclud@433
|
141 |
Remove(sensor, true);
|
StephaneLenclud@433
|
142 |
}
|
StephaneLenclud@433
|
143 |
|
StephaneLenclud@433
|
144 |
private void Remove(ISensor sensor, bool deleteConfig)
|
StephaneLenclud@433
|
145 |
{
|
StephaneLenclud@433
|
146 |
if (deleteConfig)
|
StephaneLenclud@433
|
147 |
{
|
StephaneLenclud@433
|
148 |
settings.Remove(
|
StephaneLenclud@433
|
149 |
new Identifier(sensor.Identifier, "tray").ToString());
|
StephaneLenclud@433
|
150 |
settings.Remove(
|
StephaneLenclud@433
|
151 |
new Identifier(sensor.Identifier, "traycolor").ToString());
|
StephaneLenclud@433
|
152 |
}
|
StephaneLenclud@433
|
153 |
SensorFrontView instance = null;
|
StephaneLenclud@433
|
154 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
155 |
if (icon.Sensor == sensor)
|
StephaneLenclud@433
|
156 |
instance = icon;
|
StephaneLenclud@433
|
157 |
if (instance != null)
|
StephaneLenclud@433
|
158 |
{
|
StephaneLenclud@433
|
159 |
list.Remove(instance);
|
StephaneLenclud@433
|
160 |
UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
161 |
instance.Dispose();
|
StephaneLenclud@433
|
162 |
}
|
StephaneLenclud@433
|
163 |
}
|
StephaneLenclud@433
|
164 |
|
StephaneLenclud@433
|
165 |
|
StephaneLenclud@433
|
166 |
|
StephaneLenclud@433
|
167 |
private void UpdateMainIconVisibilty()
|
StephaneLenclud@433
|
168 |
{
|
StephaneLenclud@433
|
169 |
/*
|
StephaneLenclud@433
|
170 |
if (mainIconEnabled)
|
StephaneLenclud@433
|
171 |
{
|
StephaneLenclud@433
|
172 |
mainIcon.Visible = list.Count == 0;
|
StephaneLenclud@433
|
173 |
}
|
StephaneLenclud@433
|
174 |
else
|
StephaneLenclud@433
|
175 |
{
|
StephaneLenclud@433
|
176 |
mainIcon.Visible = false;
|
StephaneLenclud@433
|
177 |
}
|
StephaneLenclud@433
|
178 |
*/
|
StephaneLenclud@433
|
179 |
}
|
StephaneLenclud@433
|
180 |
|
StephaneLenclud@436
|
181 |
public void Init()
|
StephaneLenclud@434
|
182 |
{
|
StephaneLenclud@436
|
183 |
iServer.SendMessage("init:");
|
StephaneLenclud@434
|
184 |
}
|
StephaneLenclud@434
|
185 |
|
StephaneLenclud@435
|
186 |
public void Uninit()
|
StephaneLenclud@434
|
187 |
{
|
StephaneLenclud@436
|
188 |
iServer.SendMessage("uninit:");
|
StephaneLenclud@434
|
189 |
}
|
StephaneLenclud@434
|
190 |
|
StephaneLenclud@435
|
191 |
public void SetText(string aUpperLine, string aLowerLine)
|
StephaneLenclud@434
|
192 |
{
|
StephaneLenclud@436
|
193 |
iServer.SendMessage("set-vfd-text:" + aUpperLine);
|
StephaneLenclud@434
|
194 |
}
|
StephaneLenclud@434
|
195 |
|
StephaneLenclud@433
|
196 |
/*
|
StephaneLenclud@433
|
197 |
public bool IsMainIconEnabled
|
StephaneLenclud@433
|
198 |
{
|
StephaneLenclud@433
|
199 |
get { return mainIconEnabled; }
|
StephaneLenclud@433
|
200 |
set
|
StephaneLenclud@433
|
201 |
{
|
StephaneLenclud@433
|
202 |
if (mainIconEnabled != value)
|
StephaneLenclud@433
|
203 |
{
|
StephaneLenclud@433
|
204 |
mainIconEnabled = value;
|
StephaneLenclud@433
|
205 |
UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
206 |
}
|
StephaneLenclud@433
|
207 |
}
|
StephaneLenclud@433
|
208 |
}*/
|
StephaneLenclud@434
|
209 |
|
StephaneLenclud@436
|
210 |
/*
|
StephaneLenclud@434
|
211 |
public bool IsDllLoaded
|
StephaneLenclud@434
|
212 |
{
|
StephaneLenclud@434
|
213 |
get { return iSoundGraphDll!=IntPtr.Zero; }
|
StephaneLenclud@434
|
214 |
}
|
StephaneLenclud@436
|
215 |
*/
|
StephaneLenclud@435
|
216 |
|
StephaneLenclud@435
|
217 |
|
StephaneLenclud@433
|
218 |
}
|
StephaneLenclud@433
|
219 |
}
|