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

Contents of /trunk/TSAdminTool/ProSupport.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 178 - (show annotations) (download)
Mon Jul 16 12:15:31 2012 UTC (7 years, 7 months ago) by william
File size: 32117 byte(s)
set defaults
public static string strDatabaseServer = "localhost";
public static string strDatabaseInstance = "SQLEXPRESS";

1
2 using System;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Text;
6 using System.Windows.Forms;
7 using System.Globalization;
8 using System.Data;
9 using System.Security.AccessControl;
10 using System.Security.Principal;
11 using System.IO;
12 using System.Management;
13 using System.Net;
14 using log4net;
15
16 // Support class for the AnywhereTS version. This file should only be included in the Pro version.
17 namespace AnywhereTS
18 {
19 public static class ProSupport
20 {
21 // File names
22 public const string strHostsFilename = "hosts"; // The name of the thin clients host file.
23 public const string strNetworkConfigFilename = "network"; // Name of the Thinstation common config file in the TFTP root directory.
24 public const string strDatabaseFilename = "ats.mdf"; // Name of the AnywhereTS SQL express database file.
25 public const string strDatabaseFilename2 = "ats_log.ldf"; // Name of the AnywhereTS SQL express database log file.
26
27 // Registry keys
28 public const string strRegTFTP_root = "TFTP_root"; // Reg key for TFTP root directory in database
29
30 public const string strRegAnywhereTSServer = "ATSServer"; // Reg key for database server
31 public const string strRegDatabaseServer = "DatabaseServer"; // Reg key for database server
32 public const string strRegDatabaseInstance = "DatabaseInstance"; // Reg key for database server
33 #if HAVE_FRMCONFIGMODE
34 [Obsolete("strRegDatabaseDir has been deprecated in favor of Direct SQL Server Access")]
35 public const string strRegDatabaseDir = "DatabaseDir"; // Reg key for database directory
36 public const string strRegDestDir = "DestDir"; // Reg key for Destination directory, used in unmanged mode..
37 #endif
38
39 // Database constants
40 public const string DEFAULT_RECORD_MAC = "Default "; // Phony MAC address (12 chars) used to identify the client record that contains the default settings for all new clients
41
42 // Database variables
43 public static atsDataSetTableAdapters.ClientTableAdapter clientTableAdapter; // The AnywhereTS application data adapter for the clients table. Only this adapter should be used.
44 public static atsDataSetTableAdapters.TftpServerTableAdapter tftpServerTableAdapter; // The AnywhereTS application data adapter for the TFTP servers table. Only this adapter should be used.
45 public static atsDataSetTableAdapters.TerminalServerTableAdapter terminalServerTableAdapter; // The AnywhereTS application data adapter for the terminal servers table. Only this adapter should be used.
46 public static atsDataSetTableAdapters.AppInfoTableAdapter appInfoTableAdapter; // The AnywhereTS application data adapter for the AppInfo table. Only this adapter should be used.
47
48 public static string strAnywhereTSServer; // If this computer does not contain the database server, this is the name of the database server that contains the ATS database. Used by the Control Panel
49 public static string strDatabaseServer = "localhost"; // If this computer does not contain the database server, this is the name of the database server that contains the ATS database. Used by the Control Panel
50 public static string strDatabaseInstance = "SQLEXPRESS"; // If this computer does not contain the database server, this is the name of the database server that contains the ATS database. Used by the Control Panel
51
52 // Directories
53 #if HAVE_FRMCONFIGMODE
54 [Obsolete("strDatabasePath has been deprecated in favor of Direct SQL Server Access")]
55 public static string strDatabasePath; // The directory where the database file is located.
56 public static string strDestDir; // Destination directory for client files in unmanaged mode.
57 #endif
58 // Constructor Initializes the global variables
59 static ProSupport()
60 {
61 // Initiate variables from registry
62 strAnywhereTSServer = ATSGlobals.GetATSRegValueString(strRegAnywhereTSServer);
63 #if HAVE_FRMCONFIGMODE
64 strDatabasePath = ATSGlobals.GetATSRegValueString(strRegDatabaseDir);
65 strDestDir = ATSGlobals.GetATSRegValueString(strRegDestDir);
66 #endif
67 strDatabaseServer = ATSGlobals.GetATSRegValueString(strRegDatabaseServer);
68 strDatabaseInstance = ATSGlobals.GetATSRegValueString(strRegDatabaseInstance);
69 }
70
71 // Loook up local IP for computer
72 public static void ThisComputerIp (System.Windows.Forms.ComboBox combo, bool bolServerName)
73 {
74 ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
75
76 ManagementObjectCollection queryCollection = query.Get();
77 combo.Items.Clear();
78 if (bolServerName == true) //Add computer name
79 {
80 combo.Items.Add(Dns.GetHostName());
81 }
82 foreach (ManagementObject mo in queryCollection)
83 {
84 string[] addresses = (string[])mo["IPAddress"];
85 foreach (string ipaddress in addresses)
86 {
87 if (ipaddress !="0.0.0.0")
88 combo.Items.Add(ipaddress);
89
90 }
91 }
92 }
93
94 // Compate two DriveInfo arrays and return TRUE if they are equal.
95 public static bool CompareDriveInfoArrays(List<DriveInfo> data1, List<DriveInfo> data2)
96 {
97 // If both are null, they're equal
98 if (data1 == null && data2 == null)
99 {
100 return true;
101 }
102 // If either but not both are null, they're not equal
103 if (data1 == null || data2 == null)
104 {
105 return false;
106 }
107 if (data1.Count != data2.Count)
108 {
109 return false;
110 }
111 for (int i = 0; i < data1.Count; i++)
112 {
113 if (data1[i].Name + data1[i].VolumeLabel != data2[i].Name + data2[i].VolumeLabel)
114 {
115 return false;
116 }
117 }
118 return true;
119 }
120
121 // Get an IP parameter (IP, netmask, gateway) from the local machine
122 // Paramters:
123 // Out: IP address in the format "x.x.x.x"
124 // strNetworkConf = "IPAddress": Get IPAddress
125 // strNetworkConf = "IPSubnet": Get netmask
126 // strNetworkConf = "DefaultIPGateway": Get gateway
127 // strNetworkConf = "Description": Get network card
128 // strNetworkConf = "MACAddress": Get MAC address
129 // strNetworkConf = "DNSServerSearchOrder": Get DNS
130 public static string ThisComputerNetworkConf(string strNetworkConf)
131 {
132 ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
133 ManagementObjectCollection queryCollection = query.Get();
134 foreach (ManagementObject mo in queryCollection)
135 {
136 string[] addresses = (string[])mo[strNetworkConf];
137 return addresses[0];
138 }
139 return ""; // No network adapter found.
140 }
141
142 // Initiate the database
143 public static void InitDatabase()
144 {
145 //// Create and set the connection string
146 //string dataServerName; // The name of the database server in the connection string
147 //if (strDatabaseServer.Length != 0)
148 //{ // We have a database server
149 // dataServerName = strDatabaseServer;
150 //}
151 //else
152 //{ // We do not have an external, data server.
153 // dataServerName = ".";
154 //}
155 //Properties.Settings.Default["atsConnectionString"] = @"Data Source=" + dataServerName + @"\SQLEXPRESS;Database='AnywhereTS';Integrated Security=True;Connect Timeout=30;User Instance=False";
156 //Properties.Settings.Default.Save();
157
158 // Set up table adapters
159 clientTableAdapter = new atsDataSetTableAdapters.ClientTableAdapter();
160 tftpServerTableAdapter = new atsDataSetTableAdapters.TftpServerTableAdapter();
161 terminalServerTableAdapter = new atsDataSetTableAdapters.TerminalServerTableAdapter();
162 appInfoTableAdapter = new atsDataSetTableAdapters.AppInfoTableAdapter();
163 }
164
165 // Adds an ACL entry for RW access on the specified file for Remote desktop users.
166 [Obsolete("GrantRWaccessForRemoteDesktopUsers has been deprecated - define user access rights via SQL Server")]
167 public static void GrantRWaccessForRemoteDesktopUsers(string fileName)
168 {
169 // Get a FileSecurity object that represents the current security settings.
170 FileSecurity fSecurity = File.GetAccessControl(fileName);
171
172 // Add FileSystemAccessRule:s to the security settings.
173 // Remote desktop users can read and write, but not delete
174 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Read, AccessControlType.Allow));
175 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Write, AccessControlType.Allow));
176
177 // Set the new access settings.
178 File.SetAccessControl(fileName, fSecurity);
179 }
180
181 // Adds an ACL entry for ReadWriteModify access on the specified file for Remote desktop users.
182 [Obsolete("GrantRWMaccessForRemoteDesktopUsers has been deprecated - define user access rights via SQL Server")]
183 public static void GrantRWMaccessForRemoteDesktopUsers(string fileName)
184 {
185 // Get a FileSecurity object that represents the current security settings.
186 FileSecurity fSecurity = File.GetAccessControl(fileName);
187
188 // Add FileSystemAccessRule:s to the security settings.
189 // Remote desktop users can read and write, but not delete
190 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Read, AccessControlType.Allow));
191 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Write, AccessControlType.Allow));
192 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Modify, AccessControlType.Allow));
193
194 // Set the new access settings.
195 File.SetAccessControl(fileName, fSecurity);
196 }
197
198 // (obsolete)
199 // Adds an ACL entry for to deny modify access on the specified file for all users.
200 [Obsolete("DenyAccessRightModifyForUsers has been deprecated - define user access rights via SQL Server")]
201 public static void DenyAccessRightModifyForUsers(string fileName)
202 {
203 // Get a FileSecurity object that represents the current security settings.
204 FileSecurity fSecurity = File.GetAccessControl(fileName);
205
206 // Add FileSystemAccessRule:s to the security settings.
207 // Remote desktop users can read and write, but not delete
208 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), FileSystemRights.Write, AccessControlType.Deny));
209 fSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), FileSystemRights.Modify, AccessControlType.Deny));
210
211 // Set the new access settings.
212 File.SetAccessControl(fileName, fSecurity);
213 }
214
215
216 // Writes config files to all of the TFTP directories definied in registry and database,
217 // and set rights.
218 public static void WriteConfigFiles(ATSImageRuntimeConfig config, string fileName, bool setRights)
219 { // config: The config that should be written to disk
220 // fileName: Name of the config file to write
221 // setRights: True = Set access rights on the file, so that all remote desktop users can delete the file.
222 // Write client config file
223
224 if (ATSGlobals.tftpConfig == 0)
225 { // Use ATS TFTP
226 WriteConfigFile(config, ATSGlobals.strTFTPdir + @"\" + fileName, setRights);
227 }
228 else if (ATSGlobals.tftpConfig == 1)
229 { // External TFTP
230 // Write the config file to all TFTP directories
231 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
232 atsDataSetTableAdapters.TftpServerTableAdapter tftpServerTableAdapter; // The AnywhereTS application data adapter for the TFTP servers table. Only this adapter should be used.
233
234 tftpServerTableAdapter = new AnywhereTS.atsDataSetTableAdapters.TftpServerTableAdapter();
235 datatableTFTP = new atsDataSet.TftpServerDataTable();
236
237 tftpServerTableAdapter.Fill(datatableTFTP);
238 foreach (DataRow row in datatableTFTP.Rows)
239 {
240 WriteConfigFile(config, GetTftpPath(row) + @"\" + fileName, setRights);
241 }
242 }
243 else
244 {
245 string error = "Error: Unknown TFTP Config mode (28158)";
246 using (log4net.NDC.Push(string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)))
247 {
248 Logging.ATSAdminLog.Error(error);
249 }
250 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)));
251 return;
252 }
253 }
254
255 // Copy image file to all external tftp directories/servers
256 public static void CopyImageFile(string path, string sourceFileName, string destFileName)
257 {
258 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
259 datatableTFTP = new atsDataSet.TftpServerDataTable();
260 atsDataSetTableAdapters.TftpServerTableAdapter tftpServerTableAdapter; // The AnywhereTS application data adapter for the TFTP servers table. Only this adapter should be used.
261 tftpServerTableAdapter = new AnywhereTS.atsDataSetTableAdapters.TftpServerTableAdapter();
262
263 tftpServerTableAdapter.Fill(datatableTFTP);
264 foreach (DataRow row in datatableTFTP.Rows)
265 {
266 // Copy to the TFTP server
267 try
268 {
269 File.Copy(path + @"\" + sourceFileName, GetTftpPath(row) + @"\" + destFileName, true);
270 }
271 catch (Exception e)
272 {
273 MessageBox.Show("Could not update TFTP server '" + GetTftpPath(row) + "' (22181). Error: " + e.Message);
274 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
275 {
276 using (log4net.NDC.Push(string.Format("tftpPath={0}", GetTftpPath(row))))
277 {
278 Logging.ATSAdminLog.Error("Could not update TFTP server");
279 }
280 }
281 }
282
283 // Try to set rights for image the image file
284 // (not implemented)
285 /*
286 try
287 {
288 DenyAccessRightModifyForUsers(row["Path"].ToString() + @"\" + file);
289 }
290 catch (Exception e)
291 {
292 MessageBox.Show("Could not set rights for image file on TFTP server '" + row["Path"].ToString() + "' (22183). Error: " + e.Message);
293 } */
294 }
295 }
296
297 // Create subdirectory in all external tftp directories/servers
298 public static void CreateDirectoryOnTFTP_servers(string directoryName)
299 {
300 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
301 datatableTFTP = new atsDataSet.TftpServerDataTable();
302 atsDataSetTableAdapters.TftpServerTableAdapter tftpServerTableAdapter; // The AnywhereTS application data adapter for the TFTP servers table. Only this adapter should be used.
303 tftpServerTableAdapter = new AnywhereTS.atsDataSetTableAdapters.TftpServerTableAdapter();
304
305 tftpServerTableAdapter.Fill(datatableTFTP);
306 foreach (DataRow row in datatableTFTP.Rows)
307 {
308 // Create the Directory on the TFTP server
309 try
310 {
311 Directory.CreateDirectory(GetTftpPath(row) + @"\" + directoryName);
312 }
313 catch (Exception e)
314 {
315 MessageBox.Show("Could not update TFTP server '" + GetTftpPath(row) + "' (22381). Error: " + e.Message);
316 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
317 {
318 using (log4net.NDC.Push(string.Format("tftpPath={0}", GetTftpPath(row))))
319 {
320 Logging.ATSAdminLog.Error("Could not update TFTP server");
321 }
322 }
323 }
324 }
325 }
326
327 public static void WriteConfigFile(ATSImageRuntimeConfig config, string path, bool setRights)
328 {
329 config.WriteConfigFile(path);
330
331 if (setRights)
332 {
333 // Set access rights for the config file.
334 try
335 {
336 // Add an access control entry to the config file.
337 ProSupport.GrantRWMaccessForRemoteDesktopUsers(path);
338 }
339 catch (Exception ex)
340 {
341 MessageBox.Show("Cannot set access rights for client configuration. Application will abort. Error: " + ex.Message);
342 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
343 {
344 Logging.ATSAdminLog.Error("Cannot set access rights for client configuration");
345 }
346 Application.Exit();
347 return;
348 }
349 }
350 }
351
352
353 // Writes host files to all of the TFTP directories definied in registry and database.
354 public static void WriteHostsFiles()
355 {
356 if (ATSGlobals.tftpConfig == 0)
357 { // Use ATS TFTP
358 WriteHostsFile(ATSGlobals.strTFTPdir + @"\" + strHostsFilename);
359 }
360 else if (ATSGlobals.tftpConfig == 1)
361 { // External TFTP
362 // Write the config file to all TFTP directories
363 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
364 datatableTFTP = new atsDataSet.TftpServerDataTable();
365 tftpServerTableAdapter.Fill(datatableTFTP);
366 foreach (DataRow row in datatableTFTP.Rows)
367 {
368 WriteHostsFile(GetTftpPath(row) + @"\" + strHostsFilename);
369 }
370 }
371 else
372 {
373 string error = "Error: Unknown TFTP Config mode (48158)";
374 using (log4net.NDC.Push(string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)))
375 {
376 Logging.ATSAdminLog.Error(error);
377 }
378 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)));
379 return;
380 }
381 }
382
383
384 // Create a (new) encrypted hosts file from data in the database.
385 private static void WriteHostsFile(string path)
386 {
387 atsDataSet datasetClient = new atsDataSet();
388 ProSupport.clientTableAdapter.FillClients(datasetClient.Client);
389
390 // System.IO.StreamWriter writer = null;
391 CryptStream writer = null;
392
393 // Delete old hosts file
394 if (System.IO.File.Exists(path))
395 {
396 System.IO.File.Delete(path);
397 }
398
399 // Write a new hosts file.
400 try
401 {
402 //writer = new System.IO.StreamWriter(path);
403 writer = new CryptStream(path);
404 writer.NewLine = "\n"; // Unix style line terminators
405 writer.WriteLine("# This is a hosts file generated by AnywhereTS. Do not change.");
406 foreach (DataRow row in datasetClient.Client.Rows)
407 {
408 writer.WriteLine(row["ClientName"].ToString() + " " + row["MacAddress"].ToString());
409 }
410 writer.WriteLine("# Detta e slutet."); // Termination string to avoid decryptation bug.
411 }
412 catch (Exception e)
413 {
414 //improve autoretry
415 MessageBox.Show("Error: Could not write configuration data to disk. Possibly the data is being accessed by another component right now or you do not have the sufficient rights. Please retry this operation later (52044). Error details: " + e.Message);
416 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
417 {
418 using (log4net.NDC.Push(string.Format("path={0}", path)))
419 {
420 Logging.ATSAdminLog.Error("Could not write configuration data to disk");
421 }
422 }
423 }
424
425 finally
426 {
427 if (writer != null)
428 writer.Close();
429 }
430
431 // DenyAccessRightModifyForUsers(path); // Prevent users from deleting or modifying the hosts file.
432 }
433
434
435 // Check if user is administrator
436 // Returns true if user is administrator
437 public static bool IsAnAdministrator()
438 {
439 WindowsIdentity identity =
440 WindowsIdentity.GetCurrent();
441 WindowsPrincipal principal =
442 new WindowsPrincipal(identity);
443 return principal.IsInRole
444 (WindowsBuiltInRole.Administrator);
445 }
446
447 public static string GetMacAddressFromNameAndDatabase(string strName)
448 {
449 string macAddress;
450 // Try to extract MAC address from client name.
451 macAddress = ATSGlobals.GetMacFromATSname(strName);
452 if (macAddress.Length == 0)
453 { // MAC not in name, try to lookup client name in database
454 atsDataSet datasetClientName = new atsDataSet();
455 // Update dataset with the client row matching the name
456 try
457 {
458 ProSupport.clientTableAdapter.FillOnName(datasetClientName.Client, strName);
459 }
460 catch
461 { // Error when accessing database
462 return "";
463 }
464 if (datasetClientName.Client.Rows.Count > 0)
465 { // Client row found in database
466 macAddress = datasetClientName.Client.Rows[0]["MacAddress"].ToString();
467 }
468 else
469 { // Name not found
470 macAddress = "";
471 }
472 }
473 return macAddress;
474 }
475
476 // Re-writes all config files, so that they will be containing new parameters.
477 // Also creates config files if they have been deleted, i.e by an expired beta.
478 public static void RecreateConfigFiles()
479 {
480 // Re-create all config files
481 if (ATSGlobals.tftpConfig == 0)
482 { // Use ATS TFTP
483 WriteConfigFiles(ATSGlobals.strTFTPdir);
484 }
485 else if (ATSGlobals.tftpConfig == 1)
486 { // External TFTP
487 // Write the config file to all TFTP directories
488 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
489 datatableTFTP = new atsDataSet.TftpServerDataTable();
490 tftpServerTableAdapter.Fill(datatableTFTP);
491 foreach (DataRow row in datatableTFTP.Rows)
492 {
493 // Write to TFTP path
494 WriteConfigFiles(GetTftpPath(row));
495 }
496 }
497 else
498 {
499 string error = "Error: Unknown TFTP Config mode (88158)";
500 using (log4net.NDC.Push(string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)))
501 {
502 Logging.ATSAdminLog.Error(error);
503 }
504 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)));
505 return;
506 }
507
508 WriteHostsFiles();
509 ATSImageRuntimeConfig currentConfig = new ATSImageRuntimeConfig();
510 currentConfig.ReadDefaultFromDatabase();
511 ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
512 }
513
514
515 static void WriteConfigFiles(string strDirectory)
516 {
517 ATSImageRuntimeConfig currentConfig = new ATSImageRuntimeConfig();
518 atsDataSet datasetClient = new atsDataSet();
519 ProSupport.clientTableAdapter.FillClients(datasetClient.Client);
520 string strFilePath;
521 foreach (DataRow row in datasetClient.Client.Rows)
522 {
523 // Write the config file corresponding to the client
524 currentConfig.ReadFromDatabase(row);
525 strFilePath = strDirectory + @"\" + row["MacAddress"];
526 currentConfig.WriteConfigFile(strFilePath);
527 }
528 }
529
530 // Return a local or UNC path for TFTP server, depending on what it best.
531 public static string GetTftpPath(DataRow tftpRow)
532 {
533 // Extract computer name from UNC Path
534 string uncPath = tftpRow["Path"].ToString();
535 string uncComputer = uncPath.Substring(2, uncPath.IndexOf(@"\", 2) - 2);
536 if (uncComputer.ToUpper() == Environment.MachineName)
537 { // The UNC path resides on this computer, use a local path if it is available
538 if (tftpRow["LocalPath"].ToString().Length > 0)
539 { // We have a local path
540 return tftpRow["LocalPath"].ToString();
541 }
542 else
543 { // No local path, we have to go with the UNC path referring to the local machine.
544 return tftpRow["Path"].ToString();
545 }
546 }
547 else
548 { // The UNC path does not reside on this computer, use it as it is.
549 return tftpRow["Path"].ToString();
550 }
551 }
552
553
554 // Sub routines used by wizard for screen resolution
555 //-----------------------------------------------------
556
557 public static void UpdateScreenResolutionControls(int x, int y, TextBox txtScreenResX, TextBox txtScreenResY, TrackBar tbrScreenResolution)
558 {
559 txtScreenResX.Text = x.ToString();
560 txtScreenResY.Text = y.ToString();
561
562 for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
563 {
564 if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
565 {
566 tbrScreenResolution.Value = i + 1;
567 return;
568 }
569
570 }
571 // Values could not be expressed using the track bar. Set it at default.
572 tbrScreenResolution.Value = 4;
573 }
574
575 public static void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
576 {
577 x = ATSGlobals.ScreenResolutions[tbr.Value - 1, 0];
578 y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
579 }
580
581 public static void UpdateResolutionTrackbar(TextBox txtScreenResX, TextBox txtScreenResY, TrackBar tbrScreenResolution)
582 { // Try to convert x, y values to trackbar.
583 int x, y;
584 try
585 {
586 x = Int32.Parse(txtScreenResX.Text.Trim());
587 }
588 catch (Exception)
589 {
590 x = 0;
591 }
592
593 try
594 {
595 y = Int32.Parse(txtScreenResY.Text.Trim());
596 }
597 catch (Exception)
598 {
599 y = 0;
600 }
601
602 UpdateScreenResolutionControls(x, y, txtScreenResX, txtScreenResY, tbrScreenResolution);
603 }
604
605
606
607 public static void copyDirectory(string Src,string Dst)
608 {
609 String[] Files;
610
611 if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
612 Dst+=Path.DirectorySeparatorChar;
613 if(!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
614 Files=Directory.GetFileSystemEntries(Src);
615 foreach(string Element in Files){
616 // Sub directories
617
618 if(Directory.Exists(Element))
619 copyDirectory(Element,Dst+Path.GetFileName(Element));
620 // Files in directory
621
622 else
623 File.Copy(Element,Dst+Path.GetFileName(Element), true);
624 }
625 }
626
627
628
629
630 } // end class Prosupport
631
632
633 public class CryptStream : StreamWriter
634 {
635 BinaryWriter outStream;
636
637 const byte offset1 = 36;
638 const byte offset2 = 0xab;
639 const byte key = 0x36;
640 byte value;
641
642 public CryptStream(string s)
643 : base(s)
644 {
645 // Base constructor has created a stream. Steal it.
646 outStream = new BinaryWriter(base.BaseStream);
647 WriteHeader();
648 }
649
650
651 public CryptStream(Stream s)
652 : base(s)
653 {
654 outStream = new BinaryWriter(s);
655 WriteHeader();
656 }
657
658
659 private void WriteHeader()
660 {
661 outStream.Write((byte)0x41);
662 outStream.Write((byte)0x54);
663 outStream.Write((byte)0x53);
664 outStream.Write((byte)0x78);
665 value = key;
666 }
667
668
669 private byte Crypt(byte ch1)
670 {
671 byte ch2 = (byte)((ch1 + offset1) & 0xFF);
672 byte ch3 = (byte)((ch2 ^ value) & 0xFF);
673 value = (byte)((value + offset2) & 0xFF);
674 return ch3;
675 }
676
677 public override void Write(string s)
678 {
679 for (int i = 0; i < s.Length; i++)
680 outStream.Write(Crypt((byte)s[i]));
681 }
682
683
684 public override void WriteLine(string s)
685 {
686 Write(s);
687 Write("\n");
688 }
689 }
690
691 } //end namespace

  ViewVC Help
Powered by ViewVC 1.1.22