Reverting client/server communication around our pipes to fix access denied err.
Now simply opening files for pipes created by SoundGraphAccess server.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
15 using System.Diagnostics;
16 using System.Windows.Forms;
18 using OpenHardwareMonitor.Hardware;
19 using OpenHardwareMonitor.Utilities;
20 using System.Runtime.InteropServices;
29 namespace OpenHardwareMonitor.GUI
31 public class SoundGraphDisplay : IDisposable
33 private IComputer computer;
34 private PersistentSettings settings;
35 private UnitManager unitManager;
36 private List<SensorFrontView> list = new List<SensorFrontView>();
37 private SoundGraph.Server iServer;
40 public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
41 UnitManager unitManager)
43 this.computer = computer;
44 this.settings = settings;
45 this.unitManager = unitManager;
46 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
47 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
49 //Start our client if needed
50 Process[] processes = Process.GetProcessesByName("SoundGraphAccess");
51 if (!(processes.Length > 0))
54 //Process client = UserAccountControl.CreateProcessAsStandardUser(@"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe","");
56 Process client = new Process();
57 client.StartInfo.FileName = @"D:\Dev\SoundGraphAccess\Debug\SoundGraphAccess.exe";
58 client.StartInfo.WorkingDirectory = @"D:\Dev\SoundGraphAccess";
62 //Start our SoundGraph server
63 iServer = new SoundGraph.Server(@"\\.\pipe\sga-inbound", @"\\.\pipe\sga-outbound");
65 //iServer.SendMessage("init:");
68 private void HardwareRemoved(IHardware hardware)
70 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
71 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
72 foreach (ISensor sensor in hardware.Sensors)
73 SensorRemoved(sensor);
74 foreach (IHardware subHardware in hardware.SubHardware)
75 HardwareRemoved(subHardware);
78 private void HardwareAdded(IHardware hardware)
80 foreach (ISensor sensor in hardware.Sensors)
82 hardware.SensorAdded += new SensorEventHandler(SensorAdded);
83 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
84 foreach (IHardware subHardware in hardware.SubHardware)
85 HardwareAdded(subHardware);
88 private void SensorAdded(ISensor sensor)
90 if (settings.GetValue(new Identifier(sensor.Identifier,
91 "tray").ToString(), false))
95 private void SensorRemoved(ISensor sensor)
98 Remove(sensor, false);
101 public void Dispose()
103 foreach (SensorFrontView icon in list)
113 foreach (SensorFrontView icon in list)
117 public bool Contains(ISensor sensor)
119 foreach (SensorFrontView icon in list)
120 if (icon.Sensor == sensor)
125 public void Add(ISensor sensor, bool balloonTip)
127 if (Contains(sensor))
134 //list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager));
135 //UpdateMainIconVisibilty();
136 //settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
140 public void Remove(ISensor sensor)
142 Remove(sensor, true);
145 private void Remove(ISensor sensor, bool deleteConfig)
150 new Identifier(sensor.Identifier, "tray").ToString());
152 new Identifier(sensor.Identifier, "traycolor").ToString());
154 SensorFrontView instance = null;
155 foreach (SensorFrontView icon in list)
156 if (icon.Sensor == sensor)
158 if (instance != null)
160 list.Remove(instance);
161 UpdateMainIconVisibilty();
168 private void UpdateMainIconVisibilty()
173 mainIcon.Visible = list.Count == 0;
177 mainIcon.Visible = false;
184 iServer.SendMessage("init:");
189 iServer.SendMessage("uninit:");
192 public void SetText(string aUpperLine, string aLowerLine)
194 iServer.SendMessage("set-vfd-text:" + aUpperLine);
199 iServer.SendMessage("quit:");
203 public bool IsMainIconEnabled
205 get { return mainIconEnabled; }
208 if (mainIconEnabled != value)
210 mainIconEnabled = value;
211 UpdateMainIconVisibilty();