/[AnywhereTS-MSSQL]/trunk/TSAdminTool/Globals.cs
ViewVC logotype

Contents of /trunk/TSAdminTool/Globals.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (show annotations) (download)
Fri Jul 13 01:35:49 2012 UTC (8 years ago) by william
File size: 43934 byte(s)
+ fix syntax error in UpdateDatabase4.sql (commas cannot come after the last item in an ALTER table statement)

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Reflection; // For path (assembly)
5 using System.IO; // For Path
6 using System.Security; // Security Exception
7 using System.Windows.Forms; // Message Box
8 using System.Text.RegularExpressions; // For validate MAC address
9 using log4net;
10
11 namespace AnywhereTS
12 {
13 public static class ATSGlobals
14 {
15 // Version
16 public const string strDatabaseVersion = "1.0.0.4"; // The version string for the ATS database
17 public const string strDatabaseName = "AnywhereTS"; // THe name of the ATS database
18 //[SerializableAttribute] public struct Color;
19
20 // Registry keys
21 public static string strATSregRoot; // Registry root for AnywhereTS
22 public static string strTFTPD32RegRoot; // Registry root for TFTPD32
23 public const string strRegDHCPconfig = "DHCP"; // DCHP config in registry
24 public const string strRegTFTPconfig = "TFTP"; // TFTP root directory in registry
25 public const string strRegTFTP_root = "TFTP_root"; // TFTP root directory in registry
26 public const string strRegManagedMode = "ManagedMode"; // Reg key for managed mode.
27 public const string strRegConfigured = "Configured"; // Reg key for indicating of ATS is configured.
28 public const string strRegTerminalServer = "TerminalServer"; // Reg key for terinal server config.
29 public const string strRegRunFirstTime = "RunFirstTime"; // Reg key for first time run.
30 public const string strRegAdminVersion = "AdminVersion"; // Reg key for Admin version. Indicates that Admin app is intalled on this computer and the version of the admin app.
31
32 // Help
33 public static string helpFile; // The ATS help file
34
35 // Directories
36 static public string strTFTPdir; // The TFP root directory, including final "\"
37 static public string strExecPath; // The directory for the application exe-file
38 static public string strHelpFilePath; // The path (incl filname) to the application help file
39
40
41 // Other global variables
42 static public int managedMode; // 0=Not definied, 1=Managed, 2=Unmanged
43 static public int configured; // 0=ATS not configured, 1=ATS is configured, 2=Configured for control panel only.
44 static public int dhcpConfig; // 0=Use internal DHCP, 1=Other DHCP
45 static public int tftpConfig; // 0=Use internal TFTP, 1=Other TFTP
46 static public int terminalServerConfig; // 0=Terminal server on this computer, 1=No terminal server on this computer.
47 static public int runFirstTime; // 1=The application (or new version of it) is newly installed and the first time run procedures should be run. 0=The application has already been run.
48
49 static public bool isPro=true; // True = we are running the Pro version. Always true for the open source version.
50 static public bool isEval=true; //True if evalversion of client Non pro feature
51 static public string SelectedGraphicsAdaptersFile; // Name of the file for graphics adapters that corresponds to the users selection of linux kernel
52 static public string SelectedNicAdaptersFile; // Name of the file for network adapters that corresponds to the users selection of linux kernel
53 static public string SelectedSoundAdaptersFile; // Name of the file for sound adapters that corresponds to the users selection of linux kernel
54 static public string ApplicationName; // The name of the application. Used everywhere except for in about box and main window bar. Can be either original or an OEM name.
55 static public string ApplicationTitle = ApplicationName; // The title of the application, used for the main window bar and about box.
56
57 //File names
58 public const string GraphicsAdaptersA = "Graphics30.ats"; //The file containing the list of all graphics adapters
59 public const string NicAdaptersA = "Nic30.ats"; // The file containing the list of all network adapters
60 public const string SoundAdaptersA = "Sound30.ats"; // The file containing the list of all sound adapters
61
62 // Client connect time options
63 public static int[,] ScreenResolutions = new int[,] { { 640, 480 }, { 800, 600 }, { 1024, 600 }, { 1024, 768 }, { 1152, 864 }, { 1280, 768 }, { 1280, 800 }, { 1280, 960 }, { 1280, 1024 }, { 1368, 768 }, { 1400, 1050 }, { 1440, 900 }, { 1440, 1050 }, { 1600, 1000 }, { 1600, 1024 }, { 1600, 1200 }, { 1680, 1050 }, { 1792, 1344 }, { 1856, 1392 }, { 1920, 1080 }, { 1920, 1200 }, { 1920, 1440 } };
64
65 // Constructor
66 static ATSGlobals()
67 {
68 ApplicationName = "Anywhere" + "TS"; // The name of the application. Used everywhere except for in about box and main window bar. Can be either original or an OEM name.
69
70 // Set registry root
71 // This is how we find the OS on run time
72 // on 32 bit OS IntPtr.Size = 4
73 // on 64 bit OS IntPtr.Size = 8
74 if (IntPtr.Size == 8)
75 { // 64 bit OS
76 strATSregRoot = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config";
77 }
78 else
79 { // 32 bit OS
80 strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config";
81 }
82
83
84 // Set registry root for TFTPD32
85 // This is how we find the OS on run time
86 // on 32 bit OS IntPtr.Size = 4
87 // on 64 bit OS IntPtr.Size = 8
88 if (IntPtr.Size == 8)
89 { // 64 bit OS
90 strTFTPD32RegRoot = @"SOFTWARE\Wow6432Node\TFTPD32";
91 }
92 else
93 { // 32 bit OS
94 strTFTPD32RegRoot = @"SOFTWARE\TFTPD32";
95 }
96
97
98 helpFile = "AnywhereTS.chm"; // The ATS help file
99
100 if (GetATSRegValueInt(strRegRunFirstTime) == 1)
101 { // We are runnning this version for the first time, write the needed registry values
102 CreateRegistryValues();
103 }
104
105 strExecPath = Path.GetDirectoryName(Application.ExecutablePath);
106
107 strHelpFilePath = strExecPath + @"\" + helpFile;
108
109 // Get TFTP config
110 tftpConfig = GetATSRegValueInt(strRegTFTPconfig);
111
112 // Get TFTP root
113 strTFTPdir = GetATSRegValueString(strRegTFTP_root);
114
115 // Get DHCP config
116 dhcpConfig = GetATSRegValueInt(strRegDHCPconfig);
117
118 configured = GetATSRegValueInt(strRegConfigured);
119
120 managedMode = GetATSRegValueInt(strRegManagedMode);
121
122 runFirstTime = GetATSRegValueInt(strRegRunFirstTime);
123
124 // Currently only the 3.0 version of the drivers are supported
125 SelectedGraphicsAdaptersFile = GraphicsAdaptersA;
126 SelectedNicAdaptersFile = NicAdaptersA;
127 SelectedSoundAdaptersFile = SoundAdaptersA;
128
129 }
130
131 // Get a registry string
132 public static string GetATSRegValueString(string regValue)
133 {
134 return GetRegValue(strATSregRoot, regValue);
135 }
136
137
138 // Get a registry integer from the application key
139 public static int GetATSRegValueInt(string regValue)
140 {
141 return GetRegValueInt(strATSregRoot, regValue);
142 }
143
144 // Set a registry integer in the the application key
145 public static void SetATSRegValue(string regValue, int value)
146 {
147 SetRegValue(strATSregRoot, regValue, value);
148 }
149
150 // Set a registry string in the the application key
151 public static void SetATSRegValue(string regValue, string value)
152 {
153 SetRegValue(strATSregRoot, regValue, value);
154 }
155
156 // Get a registry string
157 public static string GetRegValue(string regKey, string regValue)
158 {
159 Microsoft.Win32.RegistryKey objRegkey;
160
161 try
162 {
163 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
164 }
165 catch (ArgumentNullException ex)
166 {
167 MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
168 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
169 {
170 using (log4net.NDC.Push("Installation info missing."))
171 {
172 Logging.ATSAdminLog.Error("Error when reading from registry.");
173 }
174 }
175 Application.Exit();
176 return "";
177 }
178 catch (SecurityException ex)
179 {
180 MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: "+ regKey + " Value: " + regValue + " Error details:" + ex.Message);
181 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
182 {
183 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
184 {
185 using (log4net.NDC.Push("Invalid users rights."))
186 {
187 Logging.ATSAdminLog.Error("Error when reading from registry.");
188 }
189 }
190 }
191 Application.Exit();
192 return "";
193 }
194 catch (Exception ex)
195 {
196 MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + ex.Message);
197 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
198 {
199 Logging.ATSAdminLog.Error("Error when reading from registry.");
200 }
201 Application.Exit();
202 return "";
203 }
204
205 if (objRegkey != null)
206 {
207 if (objRegkey.GetValue(regValue) != null)
208 {
209 try
210 {
211 return objRegkey.GetValue(regValue).ToString();
212 }
213 catch (Exception e)
214 {
215 MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
216 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
217 {
218 Logging.ATSAdminLog.Error("Error when reading from registry.");
219 }
220 Application.Exit();
221 return "";
222 }
223 }
224 else
225 {
226 MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
227 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
228 {
229 using (log4net.NDC.Push("Value is missing"))
230 {
231 Logging.ATSAdminLog.Error("Error when reading from registry.");
232 }
233 }
234 Application.Exit();
235 return "";
236 }
237 }
238 else
239 {
240 MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
241 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
242 {
243 using (log4net.NDC.Push("Key is missing"))
244 {
245 Logging.ATSAdminLog.Error("Error when reading from registry.");
246 }
247 }
248 Application.Exit();
249 }
250 return ""; // No value could be retrieved from registry
251 }
252
253 // Get a registry integer
254 public static int GetRegValueInt(string regKey, string regValue)
255 {
256 Microsoft.Win32.RegistryKey objRegkey;
257
258 try
259 {
260 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
261 }
262 catch (ArgumentNullException ex)
263 {
264 MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
265 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
266 {
267 using (log4net.NDC.Push("Installation info missing."))
268 {
269 Logging.ATSAdminLog.Error("Error when reading from registry.");
270 }
271 }
272 Application.Exit();
273 return 0;
274 }
275 catch (SecurityException e)
276 {
277 MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
278 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
279 {
280 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
281 {
282 using (log4net.NDC.Push("Invalid user rights."))
283 {
284 Logging.ATSAdminLog.Error("Error when reading from registry.");
285 }
286 }
287 }
288 Application.Exit();
289 return 0;
290 }
291 catch (Exception e)
292 {
293 MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
294 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
295 {
296 Logging.ATSAdminLog.Error("Error when reading from registry.");
297 }
298 Application.Exit();
299 return 0;
300 }
301
302 if (objRegkey != null)
303 {
304 if (objRegkey.GetValue(regValue) != null)
305 {
306 try
307 {
308 return (int)objRegkey.GetValue(regValue);
309 }
310 catch (Exception e)
311 {
312 MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
313 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
314 {
315 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
316 {
317 Logging.ATSAdminLog.Error("Error when reading from registry.");
318 }
319 }
320 Application.Exit();
321 return 0;
322 }
323 }
324 else
325 {
326 MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
327
328 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
329 {
330 using (log4net.NDC.Push("Value is missing"))
331 {
332 Logging.ATSAdminLog.Error("Error when reading from registry.");
333 }
334 }
335
336 Application.Exit();
337 return 0;
338 }
339 }
340 else
341 {
342 MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + regValue);
343
344 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
345 {
346 using (log4net.NDC.Push("Key is missing"))
347 {
348 Logging.ATSAdminLog.Error("Error when reading from registry.");
349 }
350 }
351
352 Application.Exit();
353 }
354 return 0; // No value could be retrieved from registry
355 }
356
357 // Set a registry integer
358 public static void SetRegValue(string regKey, string regValue, int value)
359 {
360 Microsoft.Win32.RegistryKey objRegkey;
361
362 try
363 {
364 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey,true);
365 }
366 catch (ArgumentNullException e)
367 {
368 MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
369 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
370 {
371 using (log4net.NDC.Push("Installation info missing"))
372 {
373 Logging.ATSAdminLog.Error("Error when writing to registry.");
374 }
375 }
376 Application.Exit();
377 return;
378 }
379 catch (SecurityException e)
380 {
381 MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
382 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
383 {
384 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
385 {
386 using (log4net.NDC.Push("Invalid user rights"))
387 {
388 Logging.ATSAdminLog.Error("Error when writing to registry.");
389 }
390 }
391 }
392 Application.Exit();
393 return;
394 }
395 catch (Exception e)
396 {
397 MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
398 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
399 {
400 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
401 {
402 Logging.ATSAdminLog.Error("Error when reading from registry.");
403 }
404 }
405 Application.Exit();
406 return;
407 }
408
409 if (objRegkey != null)
410 {
411 try
412 {
413 objRegkey.SetValue(regValue, value);
414 }
415 catch (Exception e)
416 {
417 MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
418 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
419 {
420 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
421 {
422 Logging.ATSAdminLog.Error("Error when writing to registry.");
423 }
424 }
425 Application.Exit();
426 }
427 }
428 else
429 {
430 MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
431
432 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
433 {
434 using (log4net.NDC.Push("Key is missing"))
435 {
436 Logging.ATSAdminLog.Error("Error when writing to registry.");
437 }
438 }
439
440 Application.Exit();
441 }
442 }
443
444 // Set a registry string
445 public static void SetRegValue(string regKey, string regValue, string value)
446 {
447 Microsoft.Win32.RegistryKey objRegkey;
448
449 try
450 {
451 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey, true);
452 }
453 catch (ArgumentNullException e)
454 {
455 MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
456 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
457 {
458 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
459 {
460 Logging.ATSAdminLog.Error("Error when writing to registry.");
461 }
462 }
463 Application.Exit();
464 return;
465 }
466 catch (SecurityException e)
467 {
468 MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
469 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
470 {
471 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
472 {
473 using (log4net.NDC.Push("Invalid user rights"))
474 {
475 Logging.ATSAdminLog.Error("Error when writing to registry.");
476 }
477 }
478 }
479 Application.Exit();
480 return;
481 }
482 catch (Exception e)
483 {
484 MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
485 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
486 {
487 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
488 {
489 Logging.ATSAdminLog.Error("Error when reading from registry.");
490 }
491 }
492 Application.Exit();
493 return;
494 }
495
496 if (objRegkey != null)
497 {
498 try
499 {
500 objRegkey.SetValue(regValue, value);
501 }
502 catch (Exception e)
503 {
504 MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
505 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
506 {
507 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
508 {
509 Logging.ATSAdminLog.Error("Error when writing to registry.");
510 }
511 }
512 Application.Exit();
513 }
514 }
515 else
516 {
517 MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
518 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
519 {
520 using (log4net.NDC.Push("Key is missing"))
521 {
522 Logging.ATSAdminLog.Error("Error when writing to registry.");
523 }
524 }
525
526 Application.Exit();
527 }
528 }
529
530 // Check if a registry int value exists
531 public static bool RegValueExists(string regKey, string regValue)
532 {
533 Microsoft.Win32.RegistryKey objRegkey;
534
535 try
536 {
537 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
538 }
539 catch (ArgumentNullException e)
540 {
541 MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (29411)");
542 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
543 {
544 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
545 {
546 using (log4net.NDC.Push("Installation info missing"))
547 {
548 Logging.ATSAdminLog.Error("Error when reading from registry.");
549 }
550 }
551 }
552 Application.Exit();
553 return false;
554 }
555 catch (SecurityException e)
556 {
557 MessageBox.Show("Error when reading from registry. You do not have the necessary permission (29412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
558 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
559 {
560 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
561 {
562 using (log4net.NDC.Push("Invalid user rights"))
563 {
564 Logging.ATSAdminLog.Error("Error when reading from registry.");
565 }
566 }
567 }
568 Application.Exit();
569 return false;
570 }
571 catch (Exception e)
572 {
573 MessageBox.Show("Error when reading from registry (29413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
574 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
575 {
576 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
577 {
578 Logging.ATSAdminLog.Error("Error when reading from registry.");
579 }
580 }
581 Application.Exit();
582 return false;
583 }
584
585 if (objRegkey != null)
586 {
587 if (objRegkey.GetValue(regValue) != null)
588 {
589 return true; // We could retrive the value
590 }
591 else
592 {
593 return false; // No value found
594 }
595 }
596 else
597 {
598 MessageBox.Show("Error when reading from registry (59221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
599
600 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
601 {
602 using (log4net.NDC.Push("Key is missing"))
603 {
604 Logging.ATSAdminLog.Error("Error when reading from registry.");
605 }
606 }
607
608 Application.Exit();
609 }
610 return false; // No value could be retrieved from registry
611 }
612
613 // Validate MAC a MAC address.
614 public static string IsValidMAC(string macAddress)
615 {
616 macAddress = macAddress.Replace(":", "");
617 macAddress = macAddress.ToUpper();
618 string result = "";
619 Regex rx = new Regex("([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase);
620 Match m = rx.Match(macAddress);
621 result = m.Groups[0].Value;
622 if (result.Length == 17)
623 {
624 return result;
625 }
626 else
627 {
628 rx = new Regex("([0-9a-fA-F][0-9a-fA-F]){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase);
629 Match m2 = rx.Match(macAddress);
630 result = m2.Groups[0].Value;
631 if (result.Length == 12)
632 {
633 return result;
634 }
635 return result;
636 }
637 }
638
639 // Try to extract a mac address from an ATS client name in the format 'ATSxxxxxxxxxxxx', where xxxxxxxxxx is a mac address.
640 public static string GetMacFromATSname(string name)
641 {
642 string strMac;
643 if (name.Length != 15)
644 {
645 return ""; // Not an ATS name
646 }
647 if (!name.StartsWith("ATS"))
648 {
649 return ""; // Not an ATS name
650 }
651 strMac = ATSGlobals.IsValidMAC(name.Substring(3));
652 if (strMac == "")
653 {
654 return ""; // Not an ATS name
655 }
656 // We have a MAC address
657 return strMac;
658 }
659
660 // Create all needed registry values
661 public static void CreateRegistryValues()
662 {
663 // Create registry values for ATS Admin Application
664 CreateRegistryValue(strATSregRoot, "CheckUpdate", 1);
665 CreateRegistryValue(strATSregRoot, strRegConfigured, 0);
666 CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseDir, "");
667 CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseServer, "");
668 CreateRegistryValue(strATSregRoot, ProSupport.strRegDestDir, "");
669 CreateRegistryValue(strATSregRoot, strRegDHCPconfig , 0);
670 CreateRegistryValue(strATSregRoot, strRegManagedMode, 1);
671 CreateRegistryValue(strATSregRoot, strRegTerminalServer, 0);
672 CreateRegistryValue(strATSregRoot, strRegTFTPconfig, 0);
673 CreateRegistryValue(strATSregRoot, strRegTFTP_root,"");
674
675 // Check if the admin app is intalled on this computer and if so, add reg values for TFTP 32
676 if (RegValueExists(strATSregRoot, strRegAdminVersion))
677 { // The admin app is installed, define keys for TFTP32. These should not be installed for the control panel.
678 // Create registry values for TFTPD32
679 CreateRegistryValue(strTFTPD32RegRoot, "BaseDirectory", "");
680 CreateRegistryValue(strTFTPD32RegRoot, "Beep", 0);
681 CreateRegistryValue(strTFTPD32RegRoot, "DirText", 0);
682 CreateRegistryValue(strTFTPD32RegRoot, "Hide", 0);
683 CreateRegistryValue(strTFTPD32RegRoot, "LastWindowPos", "60 49 860 642 ");
684 CreateRegistryValue(strTFTPD32RegRoot, "LocalIP", "");
685 CreateRegistryValue(strTFTPD32RegRoot, "MaxRetransmit", 6);
686 CreateRegistryValue(strTFTPD32RegRoot, "Negociate", 1);
687 CreateRegistryValue(strTFTPD32RegRoot, "PXECompatibility", 0);
688 CreateRegistryValue(strTFTPD32RegRoot, "SaveSyslogFile", "");
689 CreateRegistryValue(strTFTPD32RegRoot, "SecurityLevel", 1);
690 CreateRegistryValue(strTFTPD32RegRoot, "Services", 2);
691 CreateRegistryValue(strTFTPD32RegRoot, "ShowProgressBar", 0);
692 CreateRegistryValue(strTFTPD32RegRoot, "TftpLogFile", "");
693 CreateRegistryValue(strTFTPD32RegRoot, "TftpPort", 69);
694 CreateRegistryValue(strTFTPD32RegRoot, "Timeout", 3);
695 CreateRegistryValue(strTFTPD32RegRoot, "UnixStrings", 1);
696 CreateRegistryValue(strTFTPD32RegRoot, "VirtualRoot", 1);
697 CreateRegistryValue(strTFTPD32RegRoot, "WinSize", 0);
698
699 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber1", 0);
700 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber2", 0);
701 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue1", "");
702 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue2", "");
703 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "BootFile", "client.zpxe");
704 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DNS", 16834314);
705 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DomainName", "");
706 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Gateway", 16834314);
707 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "IP_Pool", 335601418);
708 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Mask", 65535);
709 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "PoolSize", 200);
710 }
711 }
712
713 // If a registry key does not exist, create it with the given default value
714 public static void CreateRegistryValue(string regKey, string regValue, int value)
715 {
716 Microsoft.Win32.RegistryKey objRegkey;
717
718 try
719 {
720 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
721 }
722 catch (ArgumentNullException e)
723 {
724 MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
725 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
726 {
727 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
728 {
729 using (log4net.NDC.Push("Installation info missing"))
730 {
731 Logging.ATSAdminLog.Error("Error when reading from registry.");
732 }
733 }
734 }
735 Application.Exit();
736 return;
737 }
738 catch (SecurityException e)
739 {
740 MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: "+ regKey + " Value: " + regValue + " Error details:" + e.Message);
741 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
742 {
743 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
744 {
745 using (log4net.NDC.Push("Invalid user rights"))
746 {
747 Logging.ATSAdminLog.Error("Error when reading from registry.");
748 }
749 }
750 }
751 Application.Exit();
752 return;
753 }
754 catch (Exception e)
755 {
756 MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
757 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
758 {
759 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
760 {
761 Logging.ATSAdminLog.Error("Error when reading from registry.");
762
763 }
764 }
765 Application.Exit();
766 return;
767 }
768
769 if (objRegkey != null)
770 {
771 if (objRegkey.GetValue(regValue) == null)
772 { // No reg value, create one
773 SetRegValue(regKey, regValue, value);
774 }
775 }
776 else
777 {
778 MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
779
780 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
781 {
782 Logging.ATSAdminLog.Error("Error when reading from registry.");
783 }
784
785 Application.Exit();
786 }
787 }
788
789
790
791 // If a registry key does not exist, create it with the given default value
792 public static void CreateRegistryValue(string regKey, string regValue, string value)
793 {
794 Microsoft.Win32.RegistryKey objRegkey;
795
796 try
797 {
798 objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
799 }
800 catch (ArgumentNullException e)
801 {
802 MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
803 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
804 {
805 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
806 {
807 using (log4net.NDC.Push("Installation info missing"))
808 {
809 Logging.ATSAdminLog.Error("Error when reading from registry.");
810 }
811 }
812 }
813 Application.Exit();
814 return;
815 }
816 catch (SecurityException e)
817 {
818 MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
819 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
820 {
821 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
822 {
823 using (log4net.NDC.Push("Invalid users rights"))
824 {
825 Logging.ATSAdminLog.Error("Error when reading from registry.");
826 }
827 }
828 }
829 Application.Exit();
830 return;
831 }
832 catch (Exception e)
833 {
834 MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
835 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
836 {
837 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
838 {
839 Logging.ATSAdminLog.Error("Error when reading from registry.");
840 }
841 }
842 Application.Exit();
843 return;
844 }
845
846 if (objRegkey != null)
847 {
848 if (objRegkey.GetValue(regValue) == null)
849 { // No reg value, create one
850 SetRegValue(regKey, regValue, value);
851 }
852 }
853 else
854 {
855 MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
856
857 using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
858 {
859 Logging.ATSAdminLog.Error("Error when reading from registry.");
860 }
861
862 Application.Exit();
863 }
864 }
865
866 // Extract two integers from a string, separated by a character
867 // Result: True = extraction ok, false = invalid string.
868 // twointegers: String with two integers, separated by a character
869 // separator: the character separating the strings
870 // value1: (out) The first integer in the string
871 // value2: (out) The second integer in the string
872 public static bool ExtractIntegers(string twointegers, char separator, out int value1, out int value2)
873 {
874 string[] parts;
875 value1 = 0; // Default
876 value2 = 0; // Default
877 parts = twointegers.Split(separator);
878 if (parts.Length != 2)
879 {
880 return false;
881 }
882 // Convert and return
883 value1 = Convert.ToInt32(parts[0]); // Default
884 value2 = Convert.ToInt32(parts[1]); // Default
885 return true;
886 }
887
888 } // Class ATSGlobals
889 } // Namespace Anywhere TS

  ViewVC Help
Powered by ViewVC 1.1.22