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@437
|
62 |
//Start our SoundGraph server
|
StephaneLenclud@437
|
63 |
iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
|
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@437
|
106 |
Quit();
|
StephaneLenclud@436
|
107 |
iServer.Stop();
|
StephaneLenclud@433
|
108 |
|
StephaneLenclud@433
|
109 |
}
|
StephaneLenclud@433
|
110 |
|
StephaneLenclud@433
|
111 |
public void Redraw()
|
StephaneLenclud@433
|
112 |
{
|
StephaneLenclud@433
|
113 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
114 |
icon.Update();
|
StephaneLenclud@433
|
115 |
}
|
StephaneLenclud@433
|
116 |
|
StephaneLenclud@433
|
117 |
public bool Contains(ISensor sensor)
|
StephaneLenclud@433
|
118 |
{
|
StephaneLenclud@433
|
119 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
120 |
if (icon.Sensor == sensor)
|
StephaneLenclud@433
|
121 |
return true;
|
StephaneLenclud@433
|
122 |
return false;
|
StephaneLenclud@433
|
123 |
}
|
StephaneLenclud@433
|
124 |
|
StephaneLenclud@433
|
125 |
public void Add(ISensor sensor, bool balloonTip)
|
StephaneLenclud@433
|
126 |
{
|
StephaneLenclud@433
|
127 |
if (Contains(sensor))
|
StephaneLenclud@433
|
128 |
{
|
StephaneLenclud@433
|
129 |
return;
|
StephaneLenclud@433
|
130 |
}
|
StephaneLenclud@433
|
131 |
else
|
StephaneLenclud@433
|
132 |
{
|
StephaneLenclud@433
|
133 |
//SL:
|
StephaneLenclud@433
|
134 |
//list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
|
StephaneLenclud@433
|
135 |
//UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
136 |
//settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
|
StephaneLenclud@433
|
137 |
}
|
StephaneLenclud@433
|
138 |
}
|
StephaneLenclud@433
|
139 |
|
StephaneLenclud@433
|
140 |
public void Remove(ISensor sensor)
|
StephaneLenclud@433
|
141 |
{
|
StephaneLenclud@433
|
142 |
Remove(sensor, true);
|
StephaneLenclud@433
|
143 |
}
|
StephaneLenclud@433
|
144 |
|
StephaneLenclud@433
|
145 |
private void Remove(ISensor sensor, bool deleteConfig)
|
StephaneLenclud@433
|
146 |
{
|
StephaneLenclud@433
|
147 |
if (deleteConfig)
|
StephaneLenclud@433
|
148 |
{
|
StephaneLenclud@433
|
149 |
settings.Remove(
|
StephaneLenclud@433
|
150 |
new Identifier(sensor.Identifier, "tray").ToString());
|
StephaneLenclud@433
|
151 |
settings.Remove(
|
StephaneLenclud@433
|
152 |
new Identifier(sensor.Identifier, "traycolor").ToString());
|
StephaneLenclud@433
|
153 |
}
|
StephaneLenclud@433
|
154 |
SensorFrontView instance = null;
|
StephaneLenclud@433
|
155 |
foreach (SensorFrontView icon in list)
|
StephaneLenclud@433
|
156 |
if (icon.Sensor == sensor)
|
StephaneLenclud@433
|
157 |
instance = icon;
|
StephaneLenclud@433
|
158 |
if (instance != null)
|
StephaneLenclud@433
|
159 |
{
|
StephaneLenclud@433
|
160 |
list.Remove(instance);
|
StephaneLenclud@433
|
161 |
UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
162 |
instance.Dispose();
|
StephaneLenclud@433
|
163 |
}
|
StephaneLenclud@433
|
164 |
}
|
StephaneLenclud@433
|
165 |
|
StephaneLenclud@433
|
166 |
|
StephaneLenclud@433
|
167 |
|
StephaneLenclud@433
|
168 |
private void UpdateMainIconVisibilty()
|
StephaneLenclud@433
|
169 |
{
|
StephaneLenclud@433
|
170 |
/*
|
StephaneLenclud@433
|
171 |
if (mainIconEnabled)
|
StephaneLenclud@433
|
172 |
{
|
StephaneLenclud@433
|
173 |
mainIcon.Visible = list.Count == 0;
|
StephaneLenclud@433
|
174 |
}
|
StephaneLenclud@433
|
175 |
else
|
StephaneLenclud@433
|
176 |
{
|
StephaneLenclud@433
|
177 |
mainIcon.Visible = false;
|
StephaneLenclud@433
|
178 |
}
|
StephaneLenclud@433
|
179 |
*/
|
StephaneLenclud@433
|
180 |
}
|
StephaneLenclud@433
|
181 |
|
StephaneLenclud@436
|
182 |
public void Init()
|
StephaneLenclud@434
|
183 |
{
|
StephaneLenclud@436
|
184 |
iServer.SendMessage("init:");
|
StephaneLenclud@434
|
185 |
}
|
StephaneLenclud@434
|
186 |
|
StephaneLenclud@435
|
187 |
public void Uninit()
|
StephaneLenclud@434
|
188 |
{
|
StephaneLenclud@436
|
189 |
iServer.SendMessage("uninit:");
|
StephaneLenclud@434
|
190 |
}
|
StephaneLenclud@434
|
191 |
|
StephaneLenclud@435
|
192 |
public void SetText(string aUpperLine, string aLowerLine)
|
StephaneLenclud@434
|
193 |
{
|
StephaneLenclud@436
|
194 |
iServer.SendMessage("set-vfd-text:" + aUpperLine);
|
StephaneLenclud@434
|
195 |
}
|
StephaneLenclud@434
|
196 |
|
StephaneLenclud@437
|
197 |
public void Quit()
|
StephaneLenclud@437
|
198 |
{
|
StephaneLenclud@437
|
199 |
iServer.SendMessage("quit:");
|
StephaneLenclud@437
|
200 |
}
|
StephaneLenclud@437
|
201 |
|
StephaneLenclud@433
|
202 |
/*
|
StephaneLenclud@433
|
203 |
public bool IsMainIconEnabled
|
StephaneLenclud@433
|
204 |
{
|
StephaneLenclud@433
|
205 |
get { return mainIconEnabled; }
|
StephaneLenclud@433
|
206 |
set
|
StephaneLenclud@433
|
207 |
{
|
StephaneLenclud@433
|
208 |
if (mainIconEnabled != value)
|
StephaneLenclud@433
|
209 |
{
|
StephaneLenclud@433
|
210 |
mainIconEnabled = value;
|
StephaneLenclud@433
|
211 |
UpdateMainIconVisibilty();
|
StephaneLenclud@433
|
212 |
}
|
StephaneLenclud@433
|
213 |
}
|
StephaneLenclud@433
|
214 |
}*/
|
StephaneLenclud@434
|
215 |
|
StephaneLenclud@435
|
216 |
|
StephaneLenclud@433
|
217 |
}
|
StephaneLenclud@433
|
218 |
}
|