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

Contents of /trunk/TSAdminTool/ProSupport.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 440 - (show annotations) (download)
Tue Aug 28 12:54:55 2012 UTC (7 years, 11 months ago) by william
File size: 32211 byte(s)

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 new FileInfo(GetTftpPath(row) + @"\" + destFileName).Directory.Create();
270 File.Copy(path + @"\" + sourceFileName, GetTftpPath(row) + @"\" + destFileName, true);
271 }
272 catch (Exception e)
273 {
274 MessageBox.Show("Could not update TFTP server '" + GetTftpPath(row) + "' (22181). Error: " + e.Message);
275 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
276 {
277 using (log4net.NDC.Push(string.Format("tftpPath={0}", GetTftpPath(row))))
278 {
279 Logging.ATSAdminLog.Error("Could not update TFTP server");
280 }
281 }
282 }
283
284 // Try to set rights for image the image file
285 // (not implemented)
286 /*
287 try
288 {
289 DenyAccessRightModifyForUsers(row["Path"].ToString() + @"\" + file);
290 }
291 catch (Exception e)
292 {
293 MessageBox.Show("Could not set rights for image file on TFTP server '" + row["Path"].ToString() + "' (22183). Error: " + e.Message);
294 } */
295 }
296 }
297
298 // Create subdirectory in all external tftp directories/servers
299 public static void CreateDirectoryOnTFTP_servers(string directoryName)
300 {
301 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
302 datatableTFTP = new atsDataSet.TftpServerDataTable();
303 atsDataSetTableAdapters.TftpServerTableAdapter tftpServerTableAdapter; // The AnywhereTS application data adapter for the TFTP servers table. Only this adapter should be used.
304 tftpServerTableAdapter = new AnywhereTS.atsDataSetTableAdapters.TftpServerTableAdapter();
305
306 tftpServerTableAdapter.Fill(datatableTFTP);
307 foreach (DataRow row in datatableTFTP.Rows)
308 {
309 // Create the Directory on the TFTP server
310 try
311 {
312 Directory.CreateDirectory(GetTftpPath(row) + @"\" + directoryName);
313 }
314 catch (Exception e)
315 {
316 MessageBox.Show("Could not update TFTP server '" + GetTftpPath(row) + "' (22381). Error: " + e.Message);
317 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
318 {
319 using (log4net.NDC.Push(string.Format("tftpPath={0}", GetTftpPath(row))))
320 {
321 Logging.ATSAdminLog.Error("Could not update TFTP server");
322 }
323 }
324 }
325 }
326 }
327
328 public static void WriteConfigFile(ATSImageRuntimeConfig config, string path, bool setRights)
329 {
330 config.WriteConfigFile(path);
331
332 if (setRights)
333 {
334 // Set access rights for the config file.
335 try
336 {
337 // Add an access control entry to the config file.
338 ProSupport.GrantRWMaccessForRemoteDesktopUsers(path);
339 }
340 catch (Exception ex)
341 {
342 MessageBox.Show("Cannot set access rights for client configuration. Application will abort. Error: " + ex.Message);
343 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
344 {
345 Logging.ATSAdminLog.Error("Cannot set access rights for client configuration");
346 }
347 Application.Exit();
348 return;
349 }
350 }
351 }
352
353
354 // Writes host files to all of the TFTP directories definied in registry and database.
355 public static void WriteHostsFiles()
356 {
357 if (ATSGlobals.tftpConfig == 0)
358 { // Use ATS TFTP
359 WriteHostsFile(ATSGlobals.strTFTPdir + @"\" + strHostsFilename);
360 }
361 else if (ATSGlobals.tftpConfig == 1)
362 { // External TFTP
363 // Write the config file to all TFTP directories
364 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
365 datatableTFTP = new atsDataSet.TftpServerDataTable();
366 tftpServerTableAdapter.Fill(datatableTFTP);
367 foreach (DataRow row in datatableTFTP.Rows)
368 {
369 WriteHostsFile(GetTftpPath(row) + @"\" + strHostsFilename);
370 }
371 }
372 else
373 {
374 string error = "Error: Unknown TFTP Config mode (48158)";
375 using (log4net.NDC.Push(string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)))
376 {
377 Logging.ATSAdminLog.Error(error);
378 }
379 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)));
380 return;
381 }
382 }
383
384
385 // Create a (new) encrypted hosts file from data in the database.
386 private static void WriteHostsFile(string path)
387 {
388 atsDataSet datasetClient = new atsDataSet();
389 ProSupport.clientTableAdapter.FillClients(datasetClient.Client);
390
391 // System.IO.StreamWriter writer = null;
392 CryptStream writer = null;
393
394 // Delete old hosts file
395 if (System.IO.File.Exists(path))
396 {
397 System.IO.File.Delete(path);
398 }
399
400 // Write a new hosts file.
401 try
402 {
403 //writer = new System.IO.StreamWriter(path);
404 writer = new CryptStream(path);
405 writer.NewLine = "\n"; // Unix style line terminators
406 writer.WriteLine("# This is a hosts file generated by AnywhereTS. Do not change.");
407 foreach (DataRow row in datasetClient.Client.Rows)
408 {
409 writer.WriteLine(row["ClientName"].ToString() + " " + row["MacAddress"].ToString());
410 }
411 writer.WriteLine("# Detta e slutet."); // Termination string to avoid decryptation bug.
412 }
413 catch (Exception e)
414 {
415 //improve autoretry
416 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);
417 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("path={0}", path)))
420 {
421 Logging.ATSAdminLog.Error("Could not write configuration data to disk");
422 }
423 }
424 }
425
426 finally
427 {
428 if (writer != null)
429 writer.Close();
430 }
431
432 // DenyAccessRightModifyForUsers(path); // Prevent users from deleting or modifying the hosts file.
433 }
434
435
436 // Check if user is administrator
437 // Returns true if user is administrator
438 public static bool IsAnAdministrator()
439 {
440 WindowsIdentity identity =
441 WindowsIdentity.GetCurrent();
442 WindowsPrincipal principal =
443 new WindowsPrincipal(identity);
444 return principal.IsInRole
445 (WindowsBuiltInRole.Administrator);
446 }
447
448 public static string GetMacAddressFromNameAndDatabase(string strName)
449 {
450 string macAddress;
451 // Try to extract MAC address from client name.
452 macAddress = ATSGlobals.GetMacFromATSname(strName);
453 if (macAddress.Length == 0)
454 { // MAC not in name, try to lookup client name in database
455 atsDataSet datasetClientName = new atsDataSet();
456 // Update dataset with the client row matching the name
457 try
458 {
459 ProSupport.clientTableAdapter.FillOnName(datasetClientName.Client, strName);
460 }
461 catch
462 { // Error when accessing database
463 return "";
464 }
465 if (datasetClientName.Client.Rows.Count > 0)
466 { // Client row found in database
467 macAddress = datasetClientName.Client.Rows[0]["MacAddress"].ToString();
468 }
469 else
470 { // Name not found
471 macAddress = "";
472 }
473 }
474 return macAddress;
475 }
476
477 // Re-writes all config files, so that they will be containing new parameters.
478 // Also creates config files if they have been deleted, i.e by an expired beta.
479 public static void RecreateConfigFiles()
480 {
481 // Re-create all config files
482 if (ATSGlobals.tftpConfig == 0)
483 { // Use ATS TFTP
484 WriteConfigFiles(ATSGlobals.strTFTPdir);
485 }
486 else if (ATSGlobals.tftpConfig == 1)
487 { // External TFTP
488 // Write the config file to all TFTP directories
489 atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
490 datatableTFTP = new atsDataSet.TftpServerDataTable();
491 tftpServerTableAdapter.Fill(datatableTFTP);
492 foreach (DataRow row in datatableTFTP.Rows)
493 {
494 // Write to TFTP path
495 WriteConfigFiles(GetTftpPath(row));
496 }
497 }
498 else
499 {
500 string error = "Error: Unknown TFTP Config mode (88158)";
501 using (log4net.NDC.Push(string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)))
502 {
503 Logging.ATSAdminLog.Error(error);
504 }
505 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tftpConfig={0}", ATSGlobals.tftpConfig)));
506 return;
507 }
508
509 WriteHostsFiles();
510 ATSImageRuntimeConfig currentConfig = new ATSImageRuntimeConfig();
511 currentConfig.ReadDefaultFromDatabase();
512 ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
513 }
514
515
516 static void WriteConfigFiles(string strDirectory)
517 {
518 ATSImageRuntimeConfig currentConfig = new ATSImageRuntimeConfig();
519 atsDataSet datasetClient = new atsDataSet();
520 ProSupport.clientTableAdapter.FillClients(datasetClient.Client);
521 string strFilePath;
522 foreach (DataRow row in datasetClient.Client.Rows)
523 {
524 // Write the config file corresponding to the client
525 currentConfig.ReadFromDatabase(row);
526 strFilePath = strDirectory + @"\" + row["MacAddress"];
527 currentConfig.WriteConfigFile(strFilePath);
528 }
529 }
530
531 // Return a local or UNC path for TFTP server, depending on what it best.
532 public static string GetTftpPath(DataRow tftpRow)
533 {
534 // Extract computer name from UNC Path
535 string uncPath = tftpRow["Path"].ToString();
536 string uncComputer = uncPath.Substring(2, uncPath.IndexOf(@"\", 2) - 2);
537 if (uncComputer.ToUpper() == Environment.MachineName)
538 { // The UNC path resides on this computer, use a local path if it is available
539 if (tftpRow["LocalPath"].ToString().Length > 0)
540 { // We have a local path
541 return tftpRow["LocalPath"].ToString();
542 }
543 else
544 { // No local path, we have to go with the UNC path referring to the local machine.
545 return tftpRow["Path"].ToString();
546 }
547 }
548 else
549 { // The UNC path does not reside on this computer, use it as it is.
550 return tftpRow["Path"].ToString();
551 }
552 }
553
554
555 // Sub routines used by wizard for screen resolution
556 //-----------------------------------------------------
557
558 public static void UpdateScreenResolutionControls(int x, int y, TextBox txtScreenResX, TextBox txtScreenResY, TrackBar tbrScreenResolution)
559 {
560 txtScreenResX.Text = x.ToString();
561 txtScreenResY.Text = y.ToString();
562
563 for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
564 {
565 if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
566 {
567 tbrScreenResolution.Value = i + 1;
568 return;
569 }
570
571 }
572 // Values could not be expressed using the track bar. Set it at default.
573 tbrScreenResolution.Value = 4;
574 }
575
576 public static void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
577 {
578 x = ATSGlobals.ScreenResolutions[tbr.Value - 1, 0];
579 y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
580 }
581
582 public static void UpdateResolutionTrackbar(TextBox txtScreenResX, TextBox txtScreenResY, TrackBar tbrScreenResolution)
583 { // Try to convert x, y values to trackbar.
584 int x, y;
585 try
586 {
587 x = Int32.Parse(txtScreenResX.Text.Trim());
588 }
589 catch (Exception)
590 {
591 x = 0;
592 }
593
594 try
595 {
596 y = Int32.Parse(txtScreenResY.Text.Trim());
597 }
598 catch (Exception)
599 {
600 y = 0;
601 }
602
603 UpdateScreenResolutionControls(x, y, txtScreenResX, txtScreenResY, tbrScreenResolution);
604 }
605
606
607
608 public static void copyDirectory(string Src,string Dst)
609 {
610 String[] Files;
611
612 if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
613 Dst+=Path.DirectorySeparatorChar;
614 if(!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
615 Files=Directory.GetFileSystemEntries(Src);
616 foreach(string Element in Files){
617 // Sub directories
618
619 if(Directory.Exists(Element))
620 copyDirectory(Element,Dst+Path.GetFileName(Element));
621 // Files in directory
622
623 else
624 File.Copy(Element,Dst+Path.GetFileName(Element), true);
625 }
626 }
627
628
629
630
631 } // end class Prosupport
632
633
634 public class CryptStream : StreamWriter
635 {
636 BinaryWriter outStream;
637
638 const byte offset1 = 36;
639 const byte offset2 = 0xab;
640 const byte key = 0x36;
641 byte value;
642
643 public CryptStream(string s)
644 : base(s)
645 {
646 // Base constructor has created a stream. Steal it.
647 outStream = new BinaryWriter(base.BaseStream);
648 WriteHeader();
649 }
650
651
652 public CryptStream(Stream s)
653 : base(s)
654 {
655 outStream = new BinaryWriter(s);
656 WriteHeader();
657 }
658
659
660 private void WriteHeader()
661 {
662 outStream.Write((byte)0x41);
663 outStream.Write((byte)0x54);
664 outStream.Write((byte)0x53);
665 outStream.Write((byte)0x78);
666 value = key;
667 }
668
669
670 private byte Crypt(byte ch1)
671 {
672 byte ch2 = (byte)((ch1 + offset1) & 0xFF);
673 byte ch3 = (byte)((ch2 ^ value) & 0xFF);
674 value = (byte)((value + offset2) & 0xFF);
675 return ch3;
676 }
677
678 public override void Write(string s)
679 {
680 for (int i = 0; i < s.Length; i++)
681 outStream.Write(Crypt((byte)s[i]));
682 }
683
684
685 public override void WriteLine(string s)
686 {
687 Write(s);
688 Write("\n");
689 }
690 }
691
692 } //end namespace

  ViewVC Help
Powered by ViewVC 1.1.22