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 |
|
10 |
namespace AnywhereTS |
11 |
{ |
12 |
public static class ATSGlobals |
13 |
{ |
14 |
// Version |
15 |
public const string strDatabaseVersion = "1.0.0.3"; // The version string for the ATS database |
16 |
//[SerializableAttribute] public struct Color; |
17 |
|
18 |
// Registry keys |
19 |
public static string strATSregRoot; // Registry root for AnywhereTS |
20 |
public static string strTFTPD32RegRoot; // Registry root for TFTPD32 |
21 |
public const string strRegDHCPconfig = "DHCP"; // DCHP config in registry |
22 |
public const string strRegTFTPconfig = "TFTP"; // TFTP root directory in registry |
23 |
public const string strRegTFTP_root = "TFTP_root"; // TFTP root directory in registry |
24 |
public const string strRegManagedMode = "ManagedMode"; // Reg key for managed mode. |
25 |
public const string strRegConfigured = "Configured"; // Reg key for indicating of ATS is configured. |
26 |
public const string strRegTerminalServer = "TerminalServer"; // Reg key for terinal server config. |
27 |
public const string strRegRunFirstTime = "RunFirstTime"; // Reg key for first time run. |
28 |
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. |
29 |
|
30 |
// Help |
31 |
public static string helpFile; // The ATS help file |
32 |
|
33 |
// Directories |
34 |
static public string strTFTPdir; // The TFP root directory, including final "\" |
35 |
static public string strExecPath; // The directory for the application exe-file |
36 |
static public string strHelpFilePath; // The path (incl filname) to the application help file |
37 |
|
38 |
|
39 |
// Other global variables |
40 |
static public int managedMode; // 0=Not definied, 1=Managed, 2=Unmanged |
41 |
static public int configured; // 0=ATS not configured, 1=ATS is configured, 2=Configured for control panel only. |
42 |
static public int dhcpConfig; // 0=Use internal DHCP, 1=Other DHCP |
43 |
static public int tftpConfig; // 0=Use internal TFTP, 1=Other TFTP |
44 |
static public int terminalServerConfig; // 0=Terminal server on this computer, 1=No terminal server on this computer. |
45 |
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. |
46 |
|
47 |
static public bool isPro=true; // True = we are running the Pro version. Always true for the open source version. |
48 |
static public bool isEval=true; //True if evalversion of client Non pro feature |
49 |
static public string SelectedGraphicsAdaptersFile; // Name of the file for graphics adapters that corresponds to the users selection of linux kernel |
50 |
static public string SelectedNicAdaptersFile; // Name of the file for network adapters that corresponds to the users selection of linux kernel |
51 |
static public string SelectedSoundAdaptersFile; // Name of the file for sound adapters that corresponds to the users selection of linux kernel |
52 |
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. |
53 |
static public string ApplicationTitle = ApplicationName; // The title of the application, used for the main window bar and about box. |
54 |
|
55 |
//File names |
56 |
public const string GraphicsAdaptersA = "Graphics30.ats"; //The file containing the list of all graphics adapters |
57 |
public const string NicAdaptersA = "Nic30.ats"; // The file containing the list of all network adapters |
58 |
public const string SoundAdaptersA = "Sound30.ats"; // The file containing the list of all sound adapters |
59 |
|
60 |
// Client connect time options |
61 |
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 } }; |
62 |
|
63 |
// Constructor |
64 |
static ATSGlobals() |
65 |
{ |
66 |
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. |
67 |
|
68 |
// Set registry root |
69 |
// This is how we find the OS on run time |
70 |
// on 32 bit OS IntPtr.Size = 4 |
71 |
// on 64 bit OS IntPtr.Size = 8 |
72 |
if (IntPtr.Size == 8) |
73 |
{ // 64 bit OS |
74 |
strATSregRoot = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; |
75 |
} |
76 |
else |
77 |
{ // 32 bit OS |
78 |
strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; |
79 |
} |
80 |
|
81 |
|
82 |
// Set registry root for TFTPD32 |
83 |
// This is how we find the OS on run time |
84 |
// on 32 bit OS IntPtr.Size = 4 |
85 |
// on 64 bit OS IntPtr.Size = 8 |
86 |
if (IntPtr.Size == 8) |
87 |
{ // 64 bit OS |
88 |
strTFTPD32RegRoot = @"SOFTWARE\Wow6432Node\TFTPD32"; |
89 |
} |
90 |
else |
91 |
{ // 32 bit OS |
92 |
strTFTPD32RegRoot = @"SOFTWARE\TFTPD32"; |
93 |
} |
94 |
|
95 |
|
96 |
helpFile = "AnywhereTS.chm"; // The ATS help file |
97 |
|
98 |
if (GetATSRegValueInt(strRegRunFirstTime) == 1) |
99 |
{ // We are runnning this version for the first time, write the needed registry values |
100 |
CreateRegistryValues(); |
101 |
} |
102 |
|
103 |
strExecPath = Path.GetDirectoryName(Application.ExecutablePath); |
104 |
|
105 |
strHelpFilePath = strExecPath + @"\" + helpFile; |
106 |
|
107 |
// Get TFTP config |
108 |
tftpConfig = GetATSRegValueInt(strRegTFTPconfig); |
109 |
|
110 |
// Get TFTP root |
111 |
strTFTPdir = GetATSRegValueString(strRegTFTP_root); |
112 |
|
113 |
// Get DHCP config |
114 |
dhcpConfig = GetATSRegValueInt(strRegDHCPconfig); |
115 |
|
116 |
configured = GetATSRegValueInt(strRegConfigured); |
117 |
|
118 |
managedMode = GetATSRegValueInt(strRegManagedMode); |
119 |
|
120 |
runFirstTime = GetATSRegValueInt(strRegRunFirstTime); |
121 |
|
122 |
// Currently only the 3.0 version of the drivers are supported |
123 |
SelectedGraphicsAdaptersFile = GraphicsAdaptersA; |
124 |
SelectedNicAdaptersFile = NicAdaptersA; |
125 |
SelectedSoundAdaptersFile = SoundAdaptersA; |
126 |
|
127 |
} |
128 |
|
129 |
// Get a registry string |
130 |
public static string GetATSRegValueString(string regValue) |
131 |
{ |
132 |
return GetRegValue(strATSregRoot, regValue); |
133 |
} |
134 |
|
135 |
|
136 |
// Get a registry integer from the application key |
137 |
public static int GetATSRegValueInt(string regValue) |
138 |
{ |
139 |
return GetRegValueInt(strATSregRoot, regValue); |
140 |
} |
141 |
|
142 |
// Set a registry integer in the the application key |
143 |
public static void SetATSRegValue(string regValue, int value) |
144 |
{ |
145 |
SetRegValue(strATSregRoot, regValue, value); |
146 |
} |
147 |
|
148 |
// Set a registry string in the the application key |
149 |
public static void SetATSRegValue(string regValue, string value) |
150 |
{ |
151 |
SetRegValue(strATSregRoot, regValue, value); |
152 |
} |
153 |
|
154 |
// Get a registry string |
155 |
public static string GetRegValue(string regKey, string regValue) |
156 |
{ |
157 |
Microsoft.Win32.RegistryKey objRegkey; |
158 |
|
159 |
try |
160 |
{ |
161 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); |
162 |
} |
163 |
catch (ArgumentNullException) |
164 |
{ |
165 |
MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)"); |
166 |
Application.Exit(); |
167 |
return ""; |
168 |
} |
169 |
catch (SecurityException e) |
170 |
{ |
171 |
MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: "+ regKey + " Value: " + regValue + " Error details:" + e.Message); |
172 |
Application.Exit(); |
173 |
return ""; |
174 |
} |
175 |
catch (Exception e) |
176 |
{ |
177 |
MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
178 |
Application.Exit(); |
179 |
return ""; |
180 |
} |
181 |
|
182 |
if (objRegkey != null) |
183 |
{ |
184 |
if (objRegkey.GetValue(regValue) != null) |
185 |
{ |
186 |
try |
187 |
{ |
188 |
return objRegkey.GetValue(regValue).ToString(); |
189 |
} |
190 |
catch (Exception e) |
191 |
{ |
192 |
MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
193 |
Application.Exit(); |
194 |
return ""; |
195 |
} |
196 |
} |
197 |
else |
198 |
{ |
199 |
MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue); |
200 |
Application.Exit(); |
201 |
return ""; |
202 |
} |
203 |
} |
204 |
else |
205 |
{ |
206 |
MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); |
207 |
Application.Exit(); |
208 |
} |
209 |
return ""; // No value could be retrieved from registry |
210 |
} |
211 |
|
212 |
// Get a registry integer |
213 |
public static int GetRegValueInt(string regKey, string regValue) |
214 |
{ |
215 |
Microsoft.Win32.RegistryKey objRegkey; |
216 |
|
217 |
try |
218 |
{ |
219 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); |
220 |
} |
221 |
catch (ArgumentNullException) |
222 |
{ |
223 |
MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)"); |
224 |
Application.Exit(); |
225 |
return 0; |
226 |
} |
227 |
catch (SecurityException e) |
228 |
{ |
229 |
MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
230 |
Application.Exit(); |
231 |
return 0; |
232 |
} |
233 |
catch (Exception e) |
234 |
{ |
235 |
MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
236 |
Application.Exit(); |
237 |
return 0; |
238 |
} |
239 |
|
240 |
if (objRegkey != null) |
241 |
{ |
242 |
if (objRegkey.GetValue(regValue) != null) |
243 |
{ |
244 |
try |
245 |
{ |
246 |
return (int)objRegkey.GetValue(regValue); |
247 |
} |
248 |
catch (Exception e) |
249 |
{ |
250 |
MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
251 |
Application.Exit(); |
252 |
return 0; |
253 |
} |
254 |
} |
255 |
else |
256 |
{ |
257 |
MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue); |
258 |
Application.Exit(); |
259 |
return 0; |
260 |
} |
261 |
} |
262 |
else |
263 |
{ |
264 |
MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + regValue); |
265 |
Application.Exit(); |
266 |
} |
267 |
return 0; // No value could be retrieved from registry |
268 |
} |
269 |
|
270 |
// Set a registry integer |
271 |
public static void SetRegValue(string regKey, string regValue, int value) |
272 |
{ |
273 |
Microsoft.Win32.RegistryKey objRegkey; |
274 |
|
275 |
try |
276 |
{ |
277 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey,true); |
278 |
} |
279 |
catch (ArgumentNullException) |
280 |
{ |
281 |
MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)"); |
282 |
Application.Exit(); |
283 |
return; |
284 |
} |
285 |
catch (SecurityException e) |
286 |
{ |
287 |
MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
288 |
Application.Exit(); |
289 |
return; |
290 |
} |
291 |
catch (Exception e) |
292 |
{ |
293 |
MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
294 |
Application.Exit(); |
295 |
return; |
296 |
} |
297 |
|
298 |
if (objRegkey != null) |
299 |
{ |
300 |
try |
301 |
{ |
302 |
objRegkey.SetValue(regValue, value); |
303 |
} |
304 |
catch (Exception e) |
305 |
{ |
306 |
MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
307 |
Application.Exit(); |
308 |
} |
309 |
} |
310 |
else |
311 |
{ |
312 |
MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue); |
313 |
Application.Exit(); |
314 |
} |
315 |
} |
316 |
|
317 |
// Set a registry string |
318 |
public static void SetRegValue(string regKey, string regValue, string value) |
319 |
{ |
320 |
Microsoft.Win32.RegistryKey objRegkey; |
321 |
|
322 |
try |
323 |
{ |
324 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey, true); |
325 |
} |
326 |
catch (ArgumentNullException) |
327 |
{ |
328 |
MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)"); |
329 |
Application.Exit(); |
330 |
return; |
331 |
} |
332 |
catch (SecurityException e) |
333 |
{ |
334 |
MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
335 |
Application.Exit(); |
336 |
return; |
337 |
} |
338 |
catch (Exception e) |
339 |
{ |
340 |
MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
341 |
Application.Exit(); |
342 |
return; |
343 |
} |
344 |
|
345 |
if (objRegkey != null) |
346 |
{ |
347 |
try |
348 |
{ |
349 |
objRegkey.SetValue(regValue, value); |
350 |
} |
351 |
catch (Exception e) |
352 |
{ |
353 |
MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
354 |
Application.Exit(); |
355 |
} |
356 |
} |
357 |
else |
358 |
{ |
359 |
MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue); |
360 |
Application.Exit(); |
361 |
} |
362 |
} |
363 |
|
364 |
// Check if a registry int value exists |
365 |
public static bool RegValueExists(string regKey, string regValue) |
366 |
{ |
367 |
Microsoft.Win32.RegistryKey objRegkey; |
368 |
|
369 |
try |
370 |
{ |
371 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); |
372 |
} |
373 |
catch (ArgumentNullException) |
374 |
{ |
375 |
MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (29411)"); |
376 |
Application.Exit(); |
377 |
return false; |
378 |
} |
379 |
catch (SecurityException e) |
380 |
{ |
381 |
MessageBox.Show("Error when reading from registry. You do not have the necessary permission (29412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
382 |
Application.Exit(); |
383 |
return false; |
384 |
} |
385 |
catch (Exception e) |
386 |
{ |
387 |
MessageBox.Show("Error when reading from registry (29413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
388 |
Application.Exit(); |
389 |
return false; |
390 |
} |
391 |
|
392 |
if (objRegkey != null) |
393 |
{ |
394 |
if (objRegkey.GetValue(regValue) != null) |
395 |
{ |
396 |
return true; // We could retrive the value |
397 |
} |
398 |
else |
399 |
{ |
400 |
return false; // No value found |
401 |
} |
402 |
} |
403 |
else |
404 |
{ |
405 |
MessageBox.Show("Error when reading from registry (59221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); |
406 |
Application.Exit(); |
407 |
} |
408 |
return false; // No value could be retrieved from registry |
409 |
} |
410 |
|
411 |
// Validate MAC a MAC address. |
412 |
public static string IsValidMAC(string macAddress) |
413 |
{ |
414 |
macAddress = macAddress.Replace(":", ""); |
415 |
macAddress = macAddress.ToUpper(); |
416 |
string result = ""; |
417 |
Regex rx = new Regex("([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase); |
418 |
Match m = rx.Match(macAddress); |
419 |
result = m.Groups[0].Value; |
420 |
if (result.Length == 17) |
421 |
{ |
422 |
return result; |
423 |
} |
424 |
else |
425 |
{ |
426 |
rx = new Regex("([0-9a-fA-F][0-9a-fA-F]){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase); |
427 |
Match m2 = rx.Match(macAddress); |
428 |
result = m2.Groups[0].Value; |
429 |
if (result.Length == 12) |
430 |
{ |
431 |
return result; |
432 |
} |
433 |
return result; |
434 |
} |
435 |
} |
436 |
|
437 |
// Try to extract a mac address from an ATS client name in the format 'ATSxxxxxxxxxxxx', where xxxxxxxxxx is a mac address. |
438 |
public static string GetMacFromATSname(string name) |
439 |
{ |
440 |
string strMac; |
441 |
if (name.Length != 15) |
442 |
{ |
443 |
return ""; // Not an ATS name |
444 |
} |
445 |
if (!name.StartsWith("ATS")) |
446 |
{ |
447 |
return ""; // Not an ATS name |
448 |
} |
449 |
strMac = ATSGlobals.IsValidMAC(name.Substring(3)); |
450 |
if (strMac == "") |
451 |
{ |
452 |
return ""; // Not an ATS name |
453 |
} |
454 |
// We have a MAC address |
455 |
return strMac; |
456 |
} |
457 |
|
458 |
// Create all needed registry values |
459 |
public static void CreateRegistryValues() |
460 |
{ |
461 |
// Create registry values for ATS Admin Application |
462 |
CreateRegistryValue(strATSregRoot, "CheckUpdate", 1); |
463 |
CreateRegistryValue(strATSregRoot, strRegConfigured, 0); |
464 |
CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseDir, ""); |
465 |
CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseServer, ""); |
466 |
CreateRegistryValue(strATSregRoot, ProSupport.strRegDestDir, ""); |
467 |
CreateRegistryValue(strATSregRoot, strRegDHCPconfig , 0); |
468 |
CreateRegistryValue(strATSregRoot, strRegManagedMode, 1); |
469 |
CreateRegistryValue(strATSregRoot, strRegTerminalServer, 0); |
470 |
CreateRegistryValue(strATSregRoot, strRegTFTPconfig, 0); |
471 |
CreateRegistryValue(strATSregRoot, strRegTFTP_root,""); |
472 |
|
473 |
// Check if the admin app is intalled on this computer and if so, add reg values for TFTP 32 |
474 |
if (RegValueExists(strATSregRoot, strRegAdminVersion)) |
475 |
{ // The admin app is installed, define keys for TFTP32. These should not be installed for the control panel. |
476 |
// Create registry values for TFTPD32 |
477 |
CreateRegistryValue(strTFTPD32RegRoot, "BaseDirectory", ""); |
478 |
CreateRegistryValue(strTFTPD32RegRoot, "Beep", 0); |
479 |
CreateRegistryValue(strTFTPD32RegRoot, "DirText", 0); |
480 |
CreateRegistryValue(strTFTPD32RegRoot, "Hide", 0); |
481 |
CreateRegistryValue(strTFTPD32RegRoot, "LastWindowPos", "60 49 860 642 "); |
482 |
CreateRegistryValue(strTFTPD32RegRoot, "LocalIP", ""); |
483 |
CreateRegistryValue(strTFTPD32RegRoot, "MaxRetransmit", 6); |
484 |
CreateRegistryValue(strTFTPD32RegRoot, "Negociate", 1); |
485 |
CreateRegistryValue(strTFTPD32RegRoot, "PXECompatibility", 0); |
486 |
CreateRegistryValue(strTFTPD32RegRoot, "SaveSyslogFile", ""); |
487 |
CreateRegistryValue(strTFTPD32RegRoot, "SecurityLevel", 1); |
488 |
CreateRegistryValue(strTFTPD32RegRoot, "Services", 2); |
489 |
CreateRegistryValue(strTFTPD32RegRoot, "ShowProgressBar", 0); |
490 |
CreateRegistryValue(strTFTPD32RegRoot, "TftpLogFile", ""); |
491 |
CreateRegistryValue(strTFTPD32RegRoot, "TftpPort", 69); |
492 |
CreateRegistryValue(strTFTPD32RegRoot, "Timeout", 3); |
493 |
CreateRegistryValue(strTFTPD32RegRoot, "UnixStrings", 1); |
494 |
CreateRegistryValue(strTFTPD32RegRoot, "VirtualRoot", 1); |
495 |
CreateRegistryValue(strTFTPD32RegRoot, "WinSize", 0); |
496 |
|
497 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber1", 0); |
498 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber2", 0); |
499 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue1", ""); |
500 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue2", ""); |
501 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "BootFile", "client.zpxe"); |
502 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DNS", 16834314); |
503 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DomainName", ""); |
504 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Gateway", 16834314); |
505 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "IP_Pool", 335601418); |
506 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Mask", 65535); |
507 |
CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "PoolSize", 200); |
508 |
} |
509 |
} |
510 |
|
511 |
// If a registry key does not exist, create it with the given default value |
512 |
public static void CreateRegistryValue(string regKey, string regValue, int value) |
513 |
{ |
514 |
Microsoft.Win32.RegistryKey objRegkey; |
515 |
|
516 |
try |
517 |
{ |
518 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); |
519 |
} |
520 |
catch (ArgumentNullException) |
521 |
{ |
522 |
MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)"); |
523 |
Application.Exit(); |
524 |
return; |
525 |
} |
526 |
catch (SecurityException e) |
527 |
{ |
528 |
MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: "+ regKey + " Value: " + regValue + " Error details:" + e.Message); |
529 |
Application.Exit(); |
530 |
return; |
531 |
} |
532 |
catch (Exception e) |
533 |
{ |
534 |
MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
535 |
Application.Exit(); |
536 |
return; |
537 |
} |
538 |
|
539 |
if (objRegkey != null) |
540 |
{ |
541 |
if (objRegkey.GetValue(regValue) == null) |
542 |
{ // No reg value, create one |
543 |
SetRegValue(regKey, regValue, value); |
544 |
} |
545 |
} |
546 |
else |
547 |
{ |
548 |
MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); |
549 |
Application.Exit(); |
550 |
} |
551 |
} |
552 |
|
553 |
|
554 |
|
555 |
// If a registry key does not exist, create it with the given default value |
556 |
public static void CreateRegistryValue(string regKey, string regValue, string value) |
557 |
{ |
558 |
Microsoft.Win32.RegistryKey objRegkey; |
559 |
|
560 |
try |
561 |
{ |
562 |
objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); |
563 |
} |
564 |
catch (ArgumentNullException) |
565 |
{ |
566 |
MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)"); |
567 |
Application.Exit(); |
568 |
return; |
569 |
} |
570 |
catch (SecurityException e) |
571 |
{ |
572 |
MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
573 |
Application.Exit(); |
574 |
return; |
575 |
} |
576 |
catch (Exception e) |
577 |
{ |
578 |
MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message); |
579 |
Application.Exit(); |
580 |
return; |
581 |
} |
582 |
|
583 |
if (objRegkey != null) |
584 |
{ |
585 |
if (objRegkey.GetValue(regValue) == null) |
586 |
{ // No reg value, create one |
587 |
SetRegValue(regKey, regValue, value); |
588 |
} |
589 |
} |
590 |
else |
591 |
{ |
592 |
MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); |
593 |
Application.Exit(); |
594 |
} |
595 |
} |
596 |
|
597 |
// Extract two integers from a string, separated by a character |
598 |
// Result: True = extraction ok, false = invalid string. |
599 |
// twointegers: String with two integers, separated by a character |
600 |
// separator: the character separating the strings |
601 |
// value1: (out) The first integer in the string |
602 |
// value2: (out) The second integer in the string |
603 |
public static bool ExtractIntegers(string twointegers, char separator, out int value1, out int value2) |
604 |
{ |
605 |
string[] parts; |
606 |
value1 = 0; // Default |
607 |
value2 = 0; // Default |
608 |
parts = twointegers.Split(separator); |
609 |
if (parts.Length != 2) |
610 |
{ |
611 |
return false; |
612 |
} |
613 |
// Convert and return |
614 |
value1 = Convert.ToInt32(parts[0]); // Default |
615 |
value2 = Convert.ToInt32(parts[1]); // Default |
616 |
return true; |
617 |
} |
618 |
|
619 |
} // Class ATSGlobals |
620 |
} // Namespace Anywhere TS |