SHOW:
|
|
- or go back to the newest paste.
1 | - | // Decompiled with JetBrains decompiler |
1 | + | |
2 | - | // Type: MSI.CommandCenter.RemoteServer.MCCRSListener |
2 | + | |
3 | - | // Assembly: MSICCRS, Version=1.1.5.0, Culture=neutral, PublicKeyToken=null |
3 | + | |
4 | - | // MVID: 377F300C-14C2-4EBB-961E-9E3C5432C07F |
4 | + | |
5 | - | // Assembly location: C:\Program Files (x86)\MSI\Command Center\MSICCRS.exe |
5 | + | |
6 | using System.Collections.Specialized; | |
7 | using System.Diagnostics; | |
8 | using System.Drawing; | |
9 | using System.Globalization; | |
10 | using System.IO; | |
11 | using System.Net; | |
12 | using System.Runtime.InteropServices; | |
13 | using System.Text; | |
14 | using System.Threading; | |
15 | using System.Web; | |
16 | using System.Windows.Forms; | |
17 | using System.Xml; | |
18 | using System.Xml.Serialization; | |
19 | ||
20 | namespace MSI.CommandCenter.RemoteServer | |
21 | { | |
22 | internal class MCCRSListener | |
23 | { | |
24 | private volatile bool shouldListen = true; | |
25 | private string FN_NAME = "BACKSPACE TAB ENTER SHIFT CTRL ALT ESC SPACEBAR PAGEUP PAGEDOWN END HOME LEFT UP RIGHT DOWN INSERT DELETE 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z WINDOW * + - . / F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 "; | |
26 | private string FN_ID = "8 9 13 16 17 18 27 32 33 34 35 36 37 38 39 40 45 46 48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 106 107 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123"; | |
27 | private const int RequestThreadAbortedException = 995; | |
28 | private const string DEFAULT = "default"; | |
29 | private const string AUTO = "auto"; | |
30 | private const string ERR_INVALID_ARGS = "Invalid Arguments"; | |
31 | private const string ERR_EMPTY_POST_REQUEST = "The server request is empty, no actions will be performed"; | |
32 | private const string ERR_UNKNOWN_COMMAND = "Unknown Command"; | |
33 | private const string ERR_ACCESS_DENIED = "Access denied"; | |
34 | private const string SETTINGS_SUCCESSFUL = "Successfully applied new settings"; | |
35 | private const string SETTINGS_FAILED = "Failed to apply new settings on host"; | |
36 | private const string SETTINGS_SUCCESSFUL_RESTART = "Successfully applied new settings - Restart Required"; | |
37 | private const string PROCESS_ABORTED = "Command could not complete successfully. Process aborted."; | |
38 | private const string UNKNOWN_STATE = "Press Refresh to get the latest values."; | |
39 | private const string COMMAND_PROCESSED = "Command successfully sent to host"; | |
40 | private const string RESET_APPLIED = "Values successfully reset"; | |
41 | private const string CONTROLCENTER_RUNNING = "Control Center is already running"; | |
42 | private const string CONTROLCENTER_STARTING = "Starting Control Center on host PC"; | |
43 | private const string CONTROLCENTER_ERROR_STARTING = "Could not start Control Center on host PC"; | |
44 | private const string COMMANDCENTER_RUNNING = "Command Center is already running"; | |
45 | private const string COMMANDCENTER_STARTING = "Starting Command Center on host PC"; | |
46 | private const string COMMANDCENTER_ERROR_STARTING = "Could not start Command Center on host PC"; | |
47 | private const string MUTE_TRUE = "Mute true"; | |
48 | private const string MUTE_FALSE = "Mute false"; | |
49 | private const string NO_AUDIO_DEVICE = "No Audio Device"; | |
50 | private const string KBMOUSE_SUCCESSFUL = "Send Successfully"; | |
51 | private const int WM_KEYDOWN = 256; | |
52 | private const int WM_KEYUP = 257; | |
53 | private const int WM_SETTEXT = 12; | |
54 | private const int MOUSEEVENTF_MOVE = 1; | |
55 | private const int MOUSEEVENTF_LEFTDOWN = 2; | |
56 | private const int MOUSEEVENTF_LEFTUP = 4; | |
57 | private const int MOUSEEVENTF_RIGHTDOWN = 8; | |
58 | private const int MOUSEEVENTF_RIGHTUP = 16; | |
59 | private const int MOUSEEVENTF_MIDDLEDOWN = 32; | |
60 | private const int MOUSEEVENTF_MIDDLEUP = 64; | |
61 | private const int MOUSEEVENTF_ABSOLUTE = 32768; | |
62 | private const uint KEYEVENTF_EXTENDEDKEY = 1; | |
63 | private const uint KEYEVENTF_KEYUP = 2; | |
64 | private MSICommandCenterRemoteServer systray; | |
65 | private HttpListener server; | |
66 | private int port; | |
67 | private bool iTunes_Repeat; | |
68 | private string[] FN_NAME_Array; | |
69 | private string[] FN_ID_Array; | |
70 | ||
71 | public int Port | |
72 | { | |
73 | get | |
74 | { | |
75 | return this.port; | |
76 | } | |
77 | } | |
78 | ||
79 | public MCCRSListener(MSICommandCenterRemoteServer mainForm) | |
80 | { | |
81 | this.systray = mainForm; | |
82 | this.FN_NAME_Array = this.FN_NAME.Split(' '); | |
83 | this.FN_ID_Array = this.FN_ID.Split(' '); | |
84 | } | |
85 | ||
86 | [DllImport("user32.dll")] | |
87 | private static extern int GetForegroundWindow(); | |
88 | ||
89 | [DllImport("user32.dll")] | |
90 | private static extern int GetWindowText(int hWnd, StringBuilder lpsb, int count); | |
91 | ||
92 | [DllImport("User32.dll")] | |
93 | private static extern int SendMessage(int hWnd, int Msg, int wParam, string lParam); | |
94 | ||
95 | [DllImport("user32")] | |
96 | private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); | |
97 | ||
98 | [DllImport("user32")] | |
99 | private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); | |
100 | ||
101 | [DllImport("User32")] | |
102 | public static extern void SetCursorPos(int x, int y); | |
103 | ||
104 | [DllImport("User32")] | |
105 | public static extern bool GetCursorPos(out Point p); | |
106 | ||
107 | public void StartListening() | |
108 | { | |
109 | string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; | |
110 | string ipAddress = Settings.Default.IPAddress; | |
111 | if (ipAddress != "*") | |
112 | { | |
113 | try | |
114 | { | |
115 | ipAddress = IPAddress.Parse(Settings.Default.IPAddress).ToString(); | |
116 | MCCRSLogger.LogMessage("localaddress: " + ipAddress); | |
117 | } | |
118 | catch (FormatException ex) | |
119 | { | |
120 | this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error starting server: " + ex.Message, ToolTipIcon.Error); | |
121 | MCCRSLogger.LogError((Exception) ex, "Error starting server"); | |
122 | return; | |
123 | } | |
124 | catch (Exception ex) | |
125 | { | |
126 | this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "An error occured: " + ex.Message, ToolTipIcon.Error); | |
127 | MCCRSLogger.LogError(ex, "An error occured"); | |
128 | return; | |
129 | } | |
130 | } | |
131 | else | |
132 | MCCRSLogger.LogMessage("localaddress: *"); | |
133 | try | |
134 | { | |
135 | this.port = Settings.Default.Port; | |
136 | } | |
137 | catch | |
138 | { | |
139 | this.port = 80; | |
140 | } | |
141 | MCCRSLogger.LogMessage("Checking Windows firewall for an exception for port: " + this.port.ToString()); | |
142 | this.OpenFirewall(this.port); | |
143 | this.server = new HttpListener(); | |
144 | this.server.Prefixes.Add("http://" + ipAddress + ":" + this.port.ToString() + "/"); | |
145 | try | |
146 | { | |
147 | this.server.Start(); | |
148 | this.server.AuthenticationSchemes = AuthenticationSchemes.Basic; | |
149 | this.server.IgnoreWriteExceptions = true; | |
150 | } | |
151 | catch (Exception ex) | |
152 | { | |
153 | this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error starting server: " + ex.Message, ToolTipIcon.Error); | |
154 | MCCRSLogger.LogError(ex, "Error starting server"); | |
155 | this.shouldListen = false; | |
156 | return; | |
157 | } | |
158 | while (this.shouldListen) | |
159 | { | |
160 | try | |
161 | { | |
162 | HttpListenerContext context = this.server.GetContext(); | |
163 | try | |
164 | { | |
165 | HttpListenerRequest request = context.Request; | |
166 | HttpListenerResponse response = context.Response; | |
167 | HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity) context.User.Identity; | |
168 | if (identity.Name == "MSICommandCenter" && identity.Password == Settings.Default.Key) | |
169 | { | |
170 | this.ProcessRequestData(request, response); | |
171 | } | |
172 | else | |
173 | { | |
174 | string str = this.sendError("Access denied"); | |
175 | this.setResponseStatus(response, HttpStatusCode.Unauthorized, str); | |
176 | byte[] bytes = Encoding.UTF8.GetBytes(str); | |
177 | response.ContentLength64 = (long) bytes.Length; | |
178 | Stream outputStream = response.OutputStream; | |
179 | outputStream.Write(bytes, 0, bytes.Length); | |
180 | outputStream.Close(); | |
181 | } | |
182 | try | |
183 | { | |
184 | context.Response.Close(); | |
185 | } | |
186 | catch | |
187 | { | |
188 | } | |
189 | } | |
190 | catch (HttpListenerException ex) | |
191 | { | |
192 | if (ex.ErrorCode != 995) | |
193 | MCCRSLogger.LogError((Exception) ex, "Error processing request"); | |
194 | } | |
195 | catch (ThreadAbortException ex) | |
196 | { | |
197 | } | |
198 | catch (ArgumentException ex) | |
199 | { | |
200 | } | |
201 | catch (Exception ex) | |
202 | { | |
203 | this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error processing request: " + ex.Message, ToolTipIcon.Error); | |
204 | MCCRSLogger.LogError(ex, "Error processing request"); | |
205 | HttpListenerResponse response = context.Response; | |
206 | string str = this.sendError(ex); | |
207 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str); | |
208 | byte[] bytes = Encoding.UTF8.GetBytes(str); | |
209 | response.ContentLength64 = (long) bytes.Length; | |
210 | Stream outputStream = response.OutputStream; | |
211 | outputStream.Write(bytes, 0, bytes.Length); | |
212 | outputStream.Close(); | |
213 | } | |
214 | } | |
215 | catch (HttpListenerException ex) | |
216 | { | |
217 | if (ex.ErrorCode == 995) | |
218 | this.shouldListen = false; | |
219 | else | |
220 | MCCRSLogger.LogError((Exception) ex); | |
221 | } | |
222 | catch (ThreadAbortException ex) | |
223 | { | |
224 | } | |
225 | catch (Exception ex) | |
226 | { | |
227 | this.shouldListen = false; | |
228 | MCCRSLogger.LogError(ex); | |
229 | } | |
230 | } | |
231 | } | |
232 | ||
233 | public void Restart() | |
234 | { | |
235 | this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Restarting server", ToolTipIcon.Info); | |
236 | if (this.server != null) | |
237 | { | |
238 | this.server.Stop(); | |
239 | this.server = (HttpListener) null; | |
240 | } | |
241 | this.shouldListen = true; | |
242 | this.StartListening(); | |
243 | } | |
244 | ||
245 | public void StopListening() | |
246 | { | |
247 | this.shouldListen = false; | |
248 | if (this.server == null) | |
249 | return; | |
250 | try | |
251 | { | |
252 | this.server.Stop(); | |
253 | this.server.Abort(); | |
254 | this.server.Close(); | |
255 | } | |
256 | finally | |
257 | { | |
258 | this.server = (HttpListener) null; | |
259 | } | |
260 | } | |
261 | ||
262 | public string GetPrefixes() | |
263 | { | |
264 | if (this.server == null) | |
265 | return "Not Available"; | |
266 | string str = ""; | |
267 | foreach (string prefix in this.server.Prefixes) | |
268 | str += prefix; | |
269 | return str; | |
270 | } | |
271 | ||
272 | private void ProcessRequestData(HttpListenerRequest request, HttpListenerResponse response) | |
273 | { | |
274 | string str1 = ""; | |
275 | MCCHM mcchm = (MCCHM) null; | |
276 | MCCOCSharedMemory mccocSharedMemory = (MCCOCSharedMemory) null; | |
277 | NameValueCollection queryString1 = request.QueryString; | |
278 | string localPath = request.Url.LocalPath; | |
279 | if (localPath.IndexOf("@@") > 0) | |
280 | { | |
281 | int num = localPath.IndexOf("@@", 3); | |
282 | string str2 = localPath.Substring(3, num - 3); | |
283 | string keys = localPath.Substring(num + 2, localPath.Length - 2 - num); | |
284 | switch (str2) | |
285 | { | |
286 | case "STR": | |
287 | SendKeys.SendWait(keys); | |
288 | break; | |
289 | case "FNKEY": | |
290 | int int32_1 = Convert.ToInt32(keys.Substring(0, 1)); | |
291 | int int32_2 = Convert.ToInt32(keys.Substring(1, 1)); | |
292 | int int32_3 = Convert.ToInt32(keys.Substring(2, 1)); | |
293 | int int32_4 = Convert.ToInt32(keys.Substring(3, 1)); | |
294 | string upper = keys.Substring(5, keys.Length - 5).ToUpper(); | |
295 | for (int index = 0; index < this.FN_NAME.Length; ++index) | |
296 | { | |
297 | if (upper.Equals(this.FN_NAME_Array[index])) | |
298 | { | |
299 | if (int32_1 == 1) | |
300 | MCCRSListener.keybd_event((byte) 10, (byte) 0, 0U, 0U); | |
301 | if (int32_2 == 1) | |
302 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U); | |
303 | if (int32_3 == 1) | |
304 | MCCRSListener.keybd_event((byte) 91, (byte) 0, 0U, 0U); | |
305 | if (int32_4 == 1) | |
306 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U); | |
307 | MCCRSListener.keybd_event(byte.Parse(this.FN_ID_Array[index]), (byte) 0, 0U, 0U); | |
308 | if (int32_1 == 1) | |
309 | MCCRSListener.keybd_event((byte) 10, (byte) 0, 2U, 0U); | |
310 | if (int32_2 == 1) | |
311 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U); | |
312 | if (int32_3 == 1) | |
313 | MCCRSListener.keybd_event((byte) 91, (byte) 0, 2U, 0U); | |
314 | if (int32_4 == 1) | |
315 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U); | |
316 | MCCRSListener.keybd_event(byte.Parse(this.FN_ID_Array[index]), (byte) 0, 2U, 0U); | |
317 | break; | |
318 | } | |
319 | } | |
320 | break; | |
321 | case "SCROLL": | |
322 | if (keys.Equals("UP")) | |
323 | { | |
324 | MCCRSListener.keybd_event((byte) 38, (byte) 0, 0U, 0U); | |
325 | MCCRSListener.keybd_event((byte) 38, (byte) 0, 2U, 0U); | |
326 | break; | |
327 | } | |
328 | if (keys.Equals("DOWN")) | |
329 | { | |
330 | MCCRSListener.keybd_event((byte) 40, (byte) 0, 0U, 0U); | |
331 | MCCRSListener.keybd_event((byte) 40, (byte) 0, 2U, 0U); | |
332 | break; | |
333 | } | |
334 | break; | |
335 | } | |
336 | str1 = this.sendMessage("Send Successfully"); | |
337 | } | |
338 | else | |
339 | { | |
340 | StringBuilder lpsb = new StringBuilder(256); | |
341 | int foregroundWindow = MCCRSListener.GetForegroundWindow(); | |
342 | Process process1 = new Process(); | |
343 | string path1 = Environment.GetEnvironmentVariable("WinDir") + "\\ehome\\ehshell.exe"; | |
344 | string path2 = !Environment.Is64BitOperatingSystem ? Environment.GetEnvironmentVariable("ProgramFiles") + "\\Windows Media Player\\wmplayer.exe" : Environment.GetEnvironmentVariable("ProgramFiles(x86)") + "\\Windows Media Player\\wmplayer.exe"; | |
345 | switch (localPath) | |
346 | { | |
347 | case "/detect": | |
348 | str1 = "Online."; | |
349 | break; | |
350 | case "/mcchm": | |
351 | try | |
352 | { | |
353 | mcchm = new MCCHM(); | |
354 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHM)); | |
355 | MemoryStream memoryStream = new MemoryStream(); | |
356 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
357 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchm); | |
358 | xmlTextWriter.Close(); | |
359 | memoryStream.Close(); | |
360 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
361 | break; | |
362 | } | |
363 | catch (SharedMemoryNotFound ex) | |
364 | { | |
365 | str1 = this.sendError((Exception) ex); | |
366 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
367 | break; | |
368 | } | |
369 | catch (Exception ex) | |
370 | { | |
371 | str1 = this.sendError(ex); | |
372 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
373 | break; | |
374 | } | |
375 | case "/mcchmheader": | |
376 | try | |
377 | { | |
378 | mcchm = new MCCHM(); | |
379 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMHeader)); | |
380 | MemoryStream memoryStream = new MemoryStream(); | |
381 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
382 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchm.Header); | |
383 | xmlTextWriter.Close(); | |
384 | memoryStream.Close(); | |
385 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
386 | break; | |
387 | } | |
388 | catch (SharedMemoryNotFound ex) | |
389 | { | |
390 | str1 = this.sendError((Exception) ex); | |
391 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
392 | break; | |
393 | } | |
394 | catch (Exception ex) | |
395 | { | |
396 | str1 = this.sendError(ex); | |
397 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
398 | break; | |
399 | } | |
400 | case "/ocov": | |
401 | try | |
402 | { | |
403 | if (Settings.Default.MonitorOnly) | |
404 | { | |
405 | str1 = this.sendError("Access denied"); | |
406 | this.setResponseStatus(response, HttpStatusCode.Forbidden, str1); | |
407 | break; | |
408 | } | |
409 | mcchm = new MCCHM(); | |
410 | MCCHMOCOVEntries mcchmocovEntries = new MCCHMOCOVEntries(); | |
411 | mcchmocovEntries.OCOVEntries = mcchm.OCOVEntries; | |
412 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMOCOVEntries)); | |
413 | MemoryStream memoryStream = new MemoryStream(); | |
414 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
415 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmocovEntries); | |
416 | xmlTextWriter.Close(); | |
417 | memoryStream.Close(); | |
418 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
419 | break; | |
420 | } | |
421 | catch (SharedMemoryNotFound ex) | |
422 | { | |
423 | str1 = this.sendError((Exception) ex); | |
424 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
425 | break; | |
426 | } | |
427 | catch (Exception ex) | |
428 | { | |
429 | MCCRSLogger.LogMessage(ex.ToString()); | |
430 | str1 = this.sendError(ex); | |
431 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
432 | break; | |
433 | } | |
434 | case "/monitor": | |
435 | try | |
436 | { | |
437 | mcchm = new MCCHM(); | |
438 | MCCHMMonitorEntries mcchmMonitorEntries = new MCCHMMonitorEntries(); | |
439 | mcchmMonitorEntries.MonitorEntries = mcchm.MonitorEntries; | |
440 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMMonitorEntries)); | |
441 | MemoryStream memoryStream = new MemoryStream(); | |
442 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
443 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmMonitorEntries); | |
444 | xmlTextWriter.Close(); | |
445 | memoryStream.Close(); | |
446 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
447 | break; | |
448 | } | |
449 | catch (SharedMemoryNotFound ex) | |
450 | { | |
451 | str1 = this.sendError((Exception) ex); | |
452 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
453 | break; | |
454 | } | |
455 | catch (Exception ex) | |
456 | { | |
457 | MCCRSLogger.LogMessage(ex.ToString()); | |
458 | str1 = this.sendError(ex); | |
459 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
460 | break; | |
461 | } | |
462 | case "/info": | |
463 | try | |
464 | { | |
465 | mcchm = new MCCHM(); | |
466 | MCCHMInfoEntries mcchmInfoEntries = new MCCHMInfoEntries(); | |
467 | mcchmInfoEntries.InfoEntries = mcchm.InfoEntries; | |
468 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMInfoEntries)); | |
469 | MemoryStream memoryStream = new MemoryStream(); | |
470 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
471 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmInfoEntries); | |
472 | xmlTextWriter.Close(); | |
473 | memoryStream.Close(); | |
474 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
475 | break; | |
476 | } | |
477 | catch (SharedMemoryNotFound ex) | |
478 | { | |
479 | str1 = this.sendError((Exception) ex); | |
480 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
481 | break; | |
482 | } | |
483 | catch (Exception ex) | |
484 | { | |
485 | MCCRSLogger.LogMessage(ex.ToString()); | |
486 | str1 = this.sendError(ex); | |
487 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
488 | break; | |
489 | } | |
490 | case "/draminfo": | |
491 | try | |
492 | { | |
493 | mcchm = new MCCHM(); | |
494 | MCCHMDRAMEntries mcchmdramEntries = new MCCHMDRAMEntries(); | |
495 | mcchmdramEntries.DRAMEntries = mcchm.DRAMEntries; | |
496 | XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMDRAMEntries)); | |
497 | MemoryStream memoryStream = new MemoryStream(); | |
498 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
499 | xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmdramEntries); | |
500 | xmlTextWriter.Close(); | |
501 | memoryStream.Close(); | |
502 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
503 | break; | |
504 | } | |
505 | catch (SharedMemoryNotFound ex) | |
506 | { | |
507 | str1 = this.sendError((Exception) ex); | |
508 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
509 | break; | |
510 | } | |
511 | catch (Exception ex) | |
512 | { | |
513 | MCCRSLogger.LogMessage(ex.ToString()); | |
514 | str1 = this.sendError(ex); | |
515 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
516 | break; | |
517 | } | |
518 | case "/allinfo": | |
519 | try | |
520 | { | |
521 | mcchm = new MCCHM(); | |
522 | MemoryStream memoryStream = new MemoryStream(); | |
523 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
524 | xmlTextWriter.WriteStartDocument(); | |
525 | xmlTextWriter.WriteStartElement("AllInfoEntries"); | |
526 | new XmlSerializer(typeof (MCCHMInfoEntries)).Serialize((XmlWriter) xmlTextWriter, (object) new MCCHMInfoEntries() | |
527 | { | |
528 | InfoEntries = mcchm.InfoEntries | |
529 | }); | |
530 | new XmlSerializer(typeof (MCCHMDRAMEntries)).Serialize((XmlWriter) xmlTextWriter, (object) new MCCHMDRAMEntries() | |
531 | { | |
532 | DRAMEntries = mcchm.DRAMEntries | |
533 | }); | |
534 | xmlTextWriter.WriteEndElement(); | |
535 | xmlTextWriter.Close(); | |
536 | memoryStream.Close(); | |
537 | str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer())); | |
538 | break; | |
539 | } | |
540 | catch (SharedMemoryNotFound ex) | |
541 | { | |
542 | str1 = this.sendError((Exception) ex); | |
543 | this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1); | |
544 | break; | |
545 | } | |
546 | catch (Exception ex) | |
547 | { | |
548 | MCCRSLogger.LogMessage(ex.ToString()); | |
549 | str1 = this.sendError(ex); | |
550 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
551 | break; | |
552 | } | |
553 | case "/startcchost": | |
554 | try | |
555 | { | |
556 | mcchm = new MCCHM(); | |
557 | str1 = !this.systray.ControlCenter ? "Command Center is already running" : "Control Center is already running"; | |
558 | break; | |
559 | } | |
560 | catch (SharedMemoryNotFound ex) | |
561 | { | |
562 | if (this.launchControlCenter()) | |
563 | { | |
564 | str1 = !this.systray.ControlCenter ? "Starting Command Center on host PC" : "Starting Control Center on host PC"; | |
565 | break; | |
566 | } | |
567 | str1 = !this.systray.ControlCenter ? "Could not start Command Center on host PC" : "Could not start Control Center on host PC"; | |
568 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
569 | break; | |
570 | } | |
571 | catch (Exception ex) | |
572 | { | |
573 | str1 = this.sendError(ex); | |
574 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
575 | break; | |
576 | } | |
577 | case "/applyOCOV": | |
578 | if (Settings.Default.MonitorOnly) | |
579 | { | |
580 | str1 = this.sendError("Access denied"); | |
581 | this.setResponseStatus(response, HttpStatusCode.Forbidden, str1); | |
582 | } | |
583 | else | |
584 | { | |
585 | try | |
586 | { | |
587 | mccocSharedMemory = new MCCOCSharedMemory(); | |
588 | if (mccocSharedMemory == null) | |
589 | { | |
590 | str1 = this.sendMessage("Command could not complete successfully. Process aborted."); | |
591 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
592 | } | |
593 | else | |
594 | { | |
595 | bool flag = false; | |
596 | string end = new StreamReader(request.InputStream).ReadToEnd(); | |
597 | MCCRSLogger.LogMessage(request.RemoteEndPoint.ToString() + " Apply OC/OV: " + end); | |
598 | NameValueCollection queryString2 = HttpUtility.ParseQueryString(end); | |
599 | if (queryString2.Count < 1) | |
600 | { | |
601 | str1 = this.sendMessage("The server request is empty, no actions will be performed"); | |
602 | this.setResponseStatus(response, HttpStatusCode.BadRequest, str1); | |
603 | break; | |
604 | } | |
605 | for (int index = 0; index < queryString2.Count; ++index) | |
606 | { | |
607 | string key = queryString2.GetKey(index); | |
608 | string s = key.Substring(2, key.Length - 2); | |
609 | if (int.Parse(s) == 35) | |
610 | flag = true; | |
611 | mccocSharedMemory.SetEntryValue(int.Parse(s), float.Parse(queryString2.GetValues(index)[0], (IFormatProvider) CultureInfo.InvariantCulture)); | |
612 | } | |
613 | mccocSharedMemory.CommitChanges(); | |
614 | mccocSharedMemory.LoadSharedMemory(); | |
615 | str1 = this.sendMessage("Press Refresh to get the latest values."); | |
616 | int num = 0; | |
617 | while (num < 8) | |
618 | { | |
619 | try | |
620 | { | |
621 | uint updatedStatus = mccocSharedMemory.getUpdatedStatus(); | |
622 | mccocSharedMemory.LoadSharedMemory(); | |
623 | switch (updatedStatus) | |
624 | { | |
625 | case 1: | |
626 | str1 = !flag ? this.sendMessage("Successfully applied new settings") : ""; | |
627 | num = 99; | |
628 | continue; | |
629 | case 2: | |
630 | str1 = this.sendMessage("Failed to apply new settings on host"); | |
631 | num = 99; | |
632 | continue; | |
633 | case 3: | |
634 | str1 = this.sendMessage("Successfully applied new settings - Restart Required"); | |
635 | num = 99; | |
636 | continue; | |
637 | default: | |
638 | continue; | |
639 | } | |
640 | } | |
641 | catch (Exception ex) | |
642 | { | |
643 | str1 = this.sendMessage(ex.Message); | |
644 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
645 | } | |
646 | finally | |
647 | { | |
648 | Thread.Sleep(1000); | |
649 | ++num; | |
650 | } | |
651 | } | |
652 | } | |
653 | } | |
654 | catch (Exception ex) | |
655 | { | |
656 | MCCRSLogger.LogMessage(ex.ToString()); | |
657 | str1 = this.sendError(ex); | |
658 | this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1); | |
659 | } | |
660 | } | |
661 | if (mccocSharedMemory != null) | |
662 | { | |
663 | mccocSharedMemory.clearStatus(); | |
664 | break; | |
665 | } | |
666 | break; | |
667 | case "/PLAY": | |
668 | MCCRSListener.keybd_event((byte) 179, (byte) 0, 0U, 0U); | |
669 | MCCRSListener.keybd_event((byte) 179, (byte) 0, 2U, 0U); | |
670 | str1 = this.sendMessage("Successfully applied new settings"); | |
671 | break; | |
672 | case "/STOP": | |
673 | MCCRSListener.keybd_event((byte) 178, (byte) 0, 0U, 0U); | |
674 | MCCRSListener.keybd_event((byte) 178, (byte) 0, 2U, 0U); | |
675 | str1 = this.sendMessage("Successfully applied new settings"); | |
676 | break; | |
677 | case "/PAUSE": | |
678 | MCCRSListener.keybd_event((byte) 179, (byte) 0, 0U, 0U); | |
679 | MCCRSListener.keybd_event((byte) 179, (byte) 0, 2U, 0U); | |
680 | str1 = this.sendMessage("Successfully applied new settings"); | |
681 | break; | |
682 | case "/PREVIOUSSECTION": | |
683 | MCCRSListener.keybd_event((byte) 177, (byte) 0, 0U, 0U); | |
684 | MCCRSListener.keybd_event((byte) 177, (byte) 0, 2U, 0U); | |
685 | str1 = this.sendMessage("Successfully applied new settings"); | |
686 | break; | |
687 | case "/NEXTSECTION": | |
688 | MCCRSListener.keybd_event((byte) 176, (byte) 0, 0U, 0U); | |
689 | MCCRSListener.keybd_event((byte) 176, (byte) 0, 2U, 0U); | |
690 | str1 = this.sendMessage("Successfully applied new settings"); | |
691 | break; | |
692 | case "/VOLUMEUP": | |
693 | MCCRSListener.keybd_event((byte) 175, (byte) 0, 0U, 0U); | |
694 | MCCRSListener.keybd_event((byte) 175, (byte) 0, 2U, 0U); | |
695 | str1 = this.sendMessage("Successfully applied new settings"); | |
696 | break; | |
697 | case "/VOLUMEDOWN": | |
698 | MCCRSListener.keybd_event((byte) 174, (byte) 0, 0U, 0U); | |
699 | MCCRSListener.keybd_event((byte) 174, (byte) 0, 2U, 0U); | |
700 | str1 = this.sendMessage("Successfully applied new settings"); | |
701 | break; | |
702 | case "/GETMUTESTATUS": | |
703 | try | |
704 | { | |
705 | str1 = !new MMDeviceEnumerator().GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).AudioEndpointVolume.Mute ? this.sendMessage("Mute false") : this.sendMessage("Mute true"); | |
706 | break; | |
707 | } | |
708 | catch (Exception ex) | |
709 | { | |
710 | str1 = this.sendMessage("No Audio Device"); | |
711 | break; | |
712 | } | |
713 | case "/MUTE": | |
714 | MCCRSListener.keybd_event((byte) 173, (byte) 0, 0U, 0U); | |
715 | MCCRSListener.keybd_event((byte) 173, (byte) 0, 2U, 0U); | |
716 | str1 = this.sendMessage("Successfully applied new settings"); | |
717 | break; | |
718 | case "/REPEAT": | |
719 | MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity); | |
720 | string str2 = lpsb.ToString(); | |
721 | if (str2.Equals("iTunes")) | |
722 | { | |
723 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U); | |
724 | MCCRSListener.keybd_event((byte) 67, (byte) 0, 0U, 0U); | |
725 | MCCRSListener.keybd_event((byte) 67, (byte) 0, 2U, 0U); | |
726 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U); | |
727 | MCCRSListener.keybd_event((byte) 82, (byte) 0, 0U, 0U); | |
728 | MCCRSListener.keybd_event((byte) 82, (byte) 0, 2U, 0U); | |
729 | if (this.iTunes_Repeat) | |
730 | { | |
731 | this.iTunes_Repeat = false; | |
732 | MCCRSListener.keybd_event((byte) 65, (byte) 0, 0U, 0U); | |
733 | MCCRSListener.keybd_event((byte) 65, (byte) 0, 2U, 0U); | |
734 | } | |
735 | else | |
736 | { | |
737 | this.iTunes_Repeat = true; | |
738 | MCCRSListener.keybd_event((byte) 79, (byte) 0, 0U, 0U); | |
739 | MCCRSListener.keybd_event((byte) 79, (byte) 0, 2U, 0U); | |
740 | } | |
741 | } | |
742 | else if (str2.Equals("Windows Media Player")) | |
743 | { | |
744 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U); | |
745 | MCCRSListener.keybd_event((byte) 84, (byte) 0, 0U, 0U); | |
746 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U); | |
747 | MCCRSListener.keybd_event((byte) 84, (byte) 0, 2U, 0U); | |
748 | } | |
749 | str1 = this.sendMessage("Successfully applied new settings"); | |
750 | break; | |
751 | case "/SHUFFLE": | |
752 | MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity); | |
753 | string str3 = lpsb.ToString(); | |
754 | if (str3.Equals("iTunes")) | |
755 | { | |
756 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U); | |
757 | MCCRSListener.keybd_event((byte) 67, (byte) 0, 0U, 0U); | |
758 | MCCRSListener.keybd_event((byte) 67, (byte) 0, 2U, 0U); | |
759 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U); | |
760 | MCCRSListener.keybd_event((byte) 83, (byte) 0, 0U, 0U); | |
761 | MCCRSListener.keybd_event((byte) 83, (byte) 0, 2U, 0U); | |
762 | MCCRSListener.keybd_event((byte) 84, (byte) 0, 0U, 0U); | |
763 | MCCRSListener.keybd_event((byte) 84, (byte) 0, 2U, 0U); | |
764 | } | |
765 | else if (str3.Equals("Windows Media Player")) | |
766 | { | |
767 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U); | |
768 | MCCRSListener.keybd_event((byte) 72, (byte) 0, 0U, 0U); | |
769 | MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U); | |
770 | MCCRSListener.keybd_event((byte) 72, (byte) 0, 2U, 0U); | |
771 | } | |
772 | str1 = this.sendMessage("Successfully applied new settings"); | |
773 | break; | |
774 | case "/UP": | |
775 | MCCRSListener.keybd_event((byte) 38, (byte) 0, 0U, 0U); | |
776 | MCCRSListener.keybd_event((byte) 38, (byte) 0, 2U, 0U); | |
777 | str1 = this.sendMessage("Successfully applied new settings"); | |
778 | break; | |
779 | case "/DOWN": | |
780 | MCCRSListener.keybd_event((byte) 40, (byte) 0, 0U, 0U); | |
781 | MCCRSListener.keybd_event((byte) 40, (byte) 0, 2U, 0U); | |
782 | str1 = this.sendMessage("Successfully applied new settings"); | |
783 | break; | |
784 | case "/LEFT": | |
785 | MCCRSListener.keybd_event((byte) 37, (byte) 0, 0U, 0U); | |
786 | MCCRSListener.keybd_event((byte) 37, (byte) 0, 2U, 0U); | |
787 | str1 = this.sendMessage("Successfully applied new settings"); | |
788 | break; | |
789 | case "/RIGHT": | |
790 | MCCRSListener.keybd_event((byte) 39, (byte) 0, 0U, 0U); | |
791 | MCCRSListener.keybd_event((byte) 39, (byte) 0, 2U, 0U); | |
792 | str1 = this.sendMessage("Successfully applied new settings"); | |
793 | break; | |
794 | case "/ENTER": | |
795 | MCCRSListener.keybd_event((byte) 13, (byte) 0, 0U, 0U); | |
796 | MCCRSListener.keybd_event((byte) 13, (byte) 0, 2U, 0U); | |
797 | str1 = this.sendMessage("Successfully applied new settings"); | |
798 | break; | |
799 | case "/BACK": | |
800 | MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity); | |
801 | string str4 = lpsb.ToString(); | |
802 | if (str4.Equals("Windows Media Center")) | |
803 | { | |
804 | MCCRSListener.keybd_event((byte) 8, (byte) 0, 0U, 0U); | |
805 | MCCRSListener.keybd_event((byte) 8, (byte) 0, 2U, 0U); | |
806 | } | |
807 | else if (str4.Equals("Windows Media Player")) | |
808 | { | |
809 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U); | |
810 | MCCRSListener.keybd_event((byte) 37, (byte) 0, 0U, 0U); | |
811 | MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U); | |
812 | MCCRSListener.keybd_event((byte) 37, (byte) 0, 2U, 0U); | |
813 | } | |
814 | str1 = this.sendMessage("Successfully applied new settings"); | |
815 | break; | |
816 | case "/OPENMEDIACENTER": | |
817 | bool flag1 = false; | |
818 | ProcessStartInfo processStartInfo = new ProcessStartInfo(); | |
819 | string str5; | |
820 | if (System.IO.File.Exists(path1)) | |
821 | { | |
822 | foreach (Process process2 in Process.GetProcessesByName("ehshell")) | |
823 | { | |
824 | try | |
825 | { | |
826 | flag1 = true; | |
827 | process2.Kill(); | |
828 | } | |
829 | catch (Exception ex) | |
830 | { | |
831 | } | |
832 | } | |
833 | if (!flag1) | |
834 | { | |
835 | if (this.systray.ControlCenter) | |
836 | str5 = this.processMediaCommand(this.systray.CurrentWorkDirectory, "/OPENMEDIACENTER"); | |
837 | else | |
838 | this.StartMedia(); | |
839 | } | |
840 | } | |
841 | else if (System.IO.File.Exists(path2)) | |
842 | { | |
843 | bool flag2 = false; | |
844 | foreach (Process process2 in Process.GetProcessesByName("wmplayer")) | |
845 | { | |
846 | try | |
847 | { | |
848 | flag2 = true; | |
849 | process2.Kill(); | |
850 | } | |
851 | catch (Exception ex) | |
852 | { | |
853 | } | |
854 | } | |
855 | if (!flag2) | |
856 | { | |
857 | if (this.systray.ControlCenter) | |
858 | str5 = this.processMediaCommand(this.systray.CurrentWorkDirectory, "/OPENMEDIACENTER"); | |
859 | else | |
860 | this.StartMedia(); | |
861 | } | |
862 | } | |
863 | str1 = this.sendMessage("Successfully applied new settings"); | |
864 | break; | |
865 | case "/SHUTDOWN": | |
866 | try | |
867 | { | |
868 | new Process() | |
869 | { | |
870 | StartInfo = { | |
871 | FileName = "shutdown.exe", | |
872 | Arguments = "-s -f -t 0" | |
873 | } | |
874 | }.Start(); | |
875 | } | |
876 | catch (Exception ex) | |
877 | { | |
878 | } | |
879 | str1 = this.sendMessage("Successfully applied new settings"); | |
880 | break; | |
881 | case "/REBOOT": | |
882 | try | |
883 | { | |
884 | new Process() | |
885 | { | |
886 | StartInfo = { | |
887 | FileName = "shutdown.exe", | |
888 | Arguments = "-r -f -t 0" | |
889 | } | |
890 | }.Start(); | |
891 | } | |
892 | catch (Exception ex) | |
893 | { | |
894 | } | |
895 | str1 = this.sendMessage("Successfully applied new settings"); | |
896 | break; | |
897 | case "/CLEARCMOS": | |
898 | str1 = !this.systray.ControlCenter ? this.processMediaCommand("", "/CLEARCMOS") : this.processMediaCommand(this.systray.CurrentWorkDirectory, "/CLEARCMOS"); | |
899 | break; | |
900 | case "/CTRLALTDELETE": | |
901 | this.CTRLALTDELETE(); | |
902 | break; | |
903 | default: | |
904 | str1 = this.sendError("Unknown Command"); | |
905 | this.setResponseStatus(response, HttpStatusCode.NotFound, str1); | |
906 | break; | |
907 | } | |
908 | } | |
909 | byte[] bytes = Encoding.UTF8.GetBytes(str1); | |
910 | response.ContentLength64 = (long) bytes.Length; | |
911 | Stream outputStream = response.OutputStream; | |
912 | outputStream.Write(bytes, 0, bytes.Length); | |
913 | outputStream.Close(); | |
914 | response.Close(); | |
915 | if (mcchm == null) | |
916 | return; | |
917 | mcchm.Disconnect(); | |
918 | } | |
919 | ||
920 | private void OpenFirewall(int port) | |
921 | { | |
922 | string str1 = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\"; | |
923 | string str2 = !this.systray.ControlCenter ? "MSI Command Center Remote Server" : "MSI Command Center Remote Server"; | |
924 | Process process = new Process(); | |
925 | process.StartInfo.FileName = str1 + "netsh.exe"; | |
926 | process.StartInfo.Arguments = "advfirewall firewall del rule name=\"" + str2 + "\""; | |
927 | process.StartInfo.UseShellExecute = false; | |
928 | process.StartInfo.CreateNoWindow = true; | |
929 | process.Start(); | |
930 | process.WaitForExit(); | |
931 | process.StartInfo.Arguments = "advfirewall firewall add rule name=\"" + str2 + "\" dir=in protocol=tcp localport=" + port.ToString() + " action=allow"; | |
932 | process.StartInfo.UseShellExecute = false; | |
933 | process.StartInfo.CreateNoWindow = true; | |
934 | process.Start(); | |
935 | process.WaitForExit(); | |
936 | process.StartInfo.Arguments = "advfirewall firewall add rule name=\"" + str2 + "\" dir=in protocol=udp localport=26820 action=allow"; | |
937 | process.StartInfo.UseShellExecute = false; | |
938 | process.StartInfo.CreateNoWindow = true; | |
939 | process.Start(); | |
940 | process.WaitForExit(); | |
941 | } | |
942 | ||
943 | private string formatResponse(string responseString) | |
944 | { | |
945 | responseString = responseString.Substring(responseString.IndexOf(Convert.ToChar(60))); | |
946 | return responseString.Substring(0, responseString.LastIndexOf(Convert.ToChar(62)) + 1); | |
947 | } | |
948 | ||
949 | private void setResponseStatus(HttpListenerResponse response, HttpStatusCode statusCode, string description) | |
950 | { | |
951 | response.StatusCode = (int) statusCode; | |
952 | switch (statusCode) | |
953 | { | |
954 | case HttpStatusCode.Unauthorized: | |
955 | response.StatusDescription = "401 Unauthorized"; | |
956 | break; | |
957 | case HttpStatusCode.Forbidden: | |
958 | response.StatusDescription = "403 Forbidden"; | |
959 | break; | |
960 | case HttpStatusCode.ServiceUnavailable: | |
961 | response.StatusDescription = "503 Service unavailable"; | |
962 | break; | |
963 | default: | |
964 | response.StatusDescription = ((int) statusCode).ToString() + " Unknown Error"; | |
965 | break; | |
966 | } | |
967 | } | |
968 | ||
969 | private string sendError(Exception ex) | |
970 | { | |
971 | MemoryStream memoryStream = new MemoryStream(); | |
972 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
973 | xmlTextWriter.WriteStartDocument(); | |
974 | xmlTextWriter.WriteStartElement("error"); | |
975 | if (this.systray.ControlCenter) | |
976 | xmlTextWriter.WriteElementString("message", "ControlCenter : " + ex.Message); | |
977 | else | |
978 | xmlTextWriter.WriteElementString("message", "CommandCenter : " + ex.Message); | |
979 | if (ex.InnerException != null) | |
980 | xmlTextWriter.WriteElementString("innerMessage", ex.InnerException.Message); | |
981 | xmlTextWriter.WriteEndElement(); | |
982 | xmlTextWriter.Flush(); | |
983 | StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true); | |
984 | memoryStream.Seek(0L, SeekOrigin.Begin); | |
985 | return streamReader.ReadToEnd(); | |
986 | } | |
987 | ||
988 | private string sendError(string errorMessage) | |
989 | { | |
990 | MemoryStream memoryStream = new MemoryStream(); | |
991 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
992 | xmlTextWriter.WriteStartDocument(); | |
993 | xmlTextWriter.WriteStartElement("error"); | |
994 | xmlTextWriter.WriteElementString("message", errorMessage); | |
995 | xmlTextWriter.WriteEndElement(); | |
996 | xmlTextWriter.Flush(); | |
997 | StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true); | |
998 | memoryStream.Seek(0L, SeekOrigin.Begin); | |
999 | return streamReader.ReadToEnd(); | |
1000 | } | |
1001 | ||
1002 | private string sendMessage(string message) | |
1003 | { | |
1004 | MemoryStream memoryStream = new MemoryStream(); | |
1005 | XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8); | |
1006 | xmlTextWriter.WriteStartDocument(); | |
1007 | xmlTextWriter.WriteStartElement("info"); | |
1008 | xmlTextWriter.WriteElementString("message", message); | |
1009 | xmlTextWriter.WriteEndElement(); | |
1010 | xmlTextWriter.Flush(); | |
1011 | StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true); | |
1012 | memoryStream.Seek(0L, SeekOrigin.Begin); | |
1013 | return streamReader.ReadToEnd(); | |
1014 | } | |
1015 | ||
1016 | private string normalizeXML(string XML) | |
1017 | { | |
1018 | try | |
1019 | { | |
1020 | XmlDocument xmlDocument = new XmlDocument(); | |
1021 | xmlDocument.LoadXml(XML); | |
1022 | this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/srcUnits"), "°C", "C"); | |
1023 | this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/localizedSrcUnits"), "°C", "C"); | |
1024 | this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/data"), ",", "."); | |
1025 | return xmlDocument.OuterXml; | |
1026 | } | |
1027 | catch | |
1028 | { | |
1029 | return XML; | |
1030 | } | |
1031 | } | |
1032 | ||
1033 | private void replaceInnerXMLText(XmlNodeList nodes, string find, string replace) | |
1034 | { | |
1035 | foreach (XmlNode node in nodes) | |
1036 | { | |
1037 | if (node.InnerText.Contains(find)) | |
1038 | node.InnerText = node.InnerText.Replace(find, replace); | |
1039 | } | |
1040 | } | |
1041 | ||
1042 | private string processMediaCommand(string Path, string command) | |
1043 | { | |
1044 | try | |
1045 | { | |
1046 | if (Path.Equals("")) | |
1047 | Process.Start("C:\\MSIServiceCfg_CC\\function.exe", command); | |
1048 | else | |
1049 | Process.Start(Path + "function.exe", command); | |
1050 | return this.sendMessage("Command successfully sent to host"); | |
1051 | } | |
1052 | catch (Exception ex) | |
1053 | { | |
1054 | return this.sendError(ex); | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | private bool launchControlCenter() | |
1059 | { | |
1060 | if (this.systray.ControlCenter) | |
1061 | { | |
1062 | try | |
1063 | { | |
1064 | Process process = new Process(); | |
1065 | process.StartInfo.CreateNoWindow = true; | |
1066 | process.StartInfo.FileName = this.systray.CurrentWorkDirectory + "controlcenter.exe"; | |
1067 | process.StartInfo.UseShellExecute = true; | |
1068 | bool flag = process.Start(); | |
1069 | process.WaitForExit(); | |
1070 | return flag; | |
1071 | } | |
1072 | catch (Exception ex) | |
1073 | { | |
1074 | MCCRSLogger.LogError(ex); | |
1075 | return false; | |
1076 | } | |
1077 | } | |
1078 | else | |
1079 | { | |
1080 | try | |
1081 | { | |
1082 | Process process = new Process(); | |
1083 | process.StartInfo.CreateNoWindow = true; | |
1084 | process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SC.exe"; | |
1085 | process.StartInfo.Arguments = "control MSICTL_CC 151"; | |
1086 | process.StartInfo.UseShellExecute = false; | |
1087 | bool flag = process.Start(); | |
1088 | process.WaitForExit(); | |
1089 | return flag; | |
1090 | } | |
1091 | catch (Exception ex) | |
1092 | { | |
1093 | MCCRSLogger.LogError(ex); | |
1094 | return false; | |
1095 | } | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | private void CTRLALTDELETE() | |
1100 | { | |
1101 | try | |
1102 | { | |
1103 | Process process = new Process(); | |
1104 | process.StartInfo.CreateNoWindow = true; | |
1105 | process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SC.exe"; | |
1106 | process.StartInfo.Arguments = "control MSICTL_CC 152"; | |
1107 | process.StartInfo.UseShellExecute = false; | |
1108 | process.Start(); | |
1109 | process.WaitForExit(); | |
1110 | } | |
1111 | catch (Exception ex) | |
1112 | { | |
1113 | MCCRSLogger.LogError(ex); | |
1114 | } | |
1115 | } | |
1116 | ||
1117 | private void StartMedia() | |
1118 | { | |
1119 | if (Registry.LocalMachine.OpenSubKey("SOFTWARE\\MSI\\CommandCenter") == null) | |
1120 | Registry.LocalMachine.CreateSubKey("SOFTWARE\\MSI\\CommandCenter"); | |
1121 | RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MSI\\CommandCenter", true); | |
1122 | try | |
1123 | { | |
1124 | registryKey.SetValue("DateTime", (object) DateTime.Now.ToString()); | |
1125 | } | |
1126 | catch (Exception ex) | |
1127 | { | |
1128 | } | |
1129 | registryKey.Close(); | |
1130 | } | |
1131 | } | |
1132 | } |