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

Annotation of /trunk/TSAdminTool/Globals.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations) (download)
Thu Jul 12 14:29:34 2012 UTC (8 years, 2 months ago) by william
File size: 43841 byte(s)
+ fix compilation errors

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

  ViewVC Help
Powered by ViewVC 1.1.22