ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSAdminTool/ImageRuntimeConfig.cs
Revision: 47
Committed: Thu Jul 12 14:29:34 2012 UTC (10 years, 10 months ago) by william
File size: 32079 byte(s)
Log Message:
+ fix compilation errors

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Data;
5 using System.IO;
6 using System.Net;
7 using System.Windows.Forms;
8 using log4net;
9 namespace AnywhereTS
10 {
11 // An image config set for an ATSImage, AnywhereTS Image
12 public class ATSImageRuntimeConfig
13 {
14
15 public enum ATSScreenColorDepth
16 {
17 ATS16Bit,
18 ATS24Bit
19 }
20
21 public enum ATSSessionType
22 {
23 ATSRDP,
24 ATSICA,
25 ATSPNA
26 }
27
28 public enum ATSServerVersion
29 {
30 ATSWin2000,
31 ATSWin2003 // 2003 or later
32 }
33
34 public enum ATSIcaProtocol
35 {
36 ATSUDP,
37 ATSHTTPOnTCP
38 }
39
40 public enum ATSIcaAudioQuality
41 {
42 Low,
43 Medium,
44 High
45 }
46
47 public enum ATSUsbDrive
48 {
49 None,
50 One,
51 Many
52 }
53
54
55 // Client options with defined defaults
56 public int ScreenResolutionX = 1024;
57 public int ScreenResolutionY = 768;
58
59 public ATSScreenColorDepth ScreenColorDepth = ATSScreenColorDepth.ATS16Bit;
60
61 public string ServerName ="";
62 public string ServerDomain = "";
63 public ATSServerVersion ServerVersion = ATSServerVersion.ATSWin2003; // Meta option, used to control other options. Only used if the server is another computer than the one running AnywhereTS
64 public ATSSessionType SessionType = ATSSessionType.ATSRDP;
65
66 public bool NumLock = true; // true = numlook on at boot time
67 public bool ReconnectPrompt = true;
68 public bool RedirectFloppy = true;
69 public bool RedirectCD = true;
70 public bool RedirectSound = true;
71 public int AudioLevel = 100;
72 public int MouseResolution = 50;
73 public string UserName = "";
74 public string Password = "";
75
76 public bool DailyReboot = true;
77
78 public string KeyboardMap = ATSKeyboard.DefaultKeyboardMap();
79 public string TimeZone = ATSTimeZone.DefaultTimeZone();
80
81 public bool DigitalMonitor = true; // Will force 60 Hz for digital monitors
82
83 public ATSIcaProtocol ICAProtocol = ATSIcaProtocol.ATSUDP;
84 public string ICAEncryption = "Basic";
85 public bool ICACompression = true;
86 public ATSIcaAudioQuality IcaAudioQuality = ATSIcaAudioQuality.High;
87 public string ICAServer = "";
88 public string ICAApplicationSet = "";
89 public string ICAServerURL = "";
90 public string ICAResource = "XenDesktop";
91
92 public string GraphicsAdapter = ""; // "" = Autodetect
93
94 public bool MiscFlippedFix = false;
95 public bool MiscMousefix = false;
96 public bool MiscNoAcceleration = false;
97 public bool MiscRedirectCom1 = false;
98 public bool MiscRedirectCom2 = false;
99 public ATSUsbDrive UsbDrive = ATSUsbDrive.None; // One is default if Pro version
100 public string UsbDriveName = "USB-Memory";
101 public int ServerPort = -1; // -1 = Not defined
102
103 // Constructor
104 public ATSImageRuntimeConfig()
105 {
106 // Set defaults
107 UsbDrive = ATSUsbDrive.One;
108 }
109
110 public void ReadDefaultFromDatabase()
111 {
112 atsDataSetTableAdapters.ClientTableAdapter clientTableAdapter;
113 atsDataSet datasetClient;
114 DataRow row;
115 clientTableAdapter = new atsDataSetTableAdapters.ClientTableAdapter();
116 datasetClient = new atsDataSet();
117
118 clientTableAdapter.Fill(datasetClient.Client);
119
120 // Loook up the row
121 row = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
122 if (row != null)
123 {
124 // Read from database
125 ReadFromDatabase(row);
126 }
127 else
128 { // Row could not be found
129 // Create a default row
130 DataRow newRow = datasetClient.Client.NewRow();
131
132 ATSImageRuntimeConfig defaultConfig = new ATSImageRuntimeConfig();
133 defaultConfig.WriteDefaultsToDatabase();
134
135 clientTableAdapter.Fill(datasetClient.Client); // Refresh with the new default record.
136
137 // Look up the row
138 row = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
139 if (row != null)
140 {
141 // Read from database
142 ReadFromDatabase(row);
143 }
144 else
145 throw new Exception("Error: Default record not written (27773).");
146 }
147 }
148
149 public void ReadFromDatabase(DataRow row)
150 {
151 ExtractResolution(row["ScreenResolution"].ToString(), out ScreenResolutionX, out ScreenResolutionY);
152
153 switch (row["ScreenColorDepth"].ToString())
154 {
155 case "16":
156 ScreenColorDepth = ATSScreenColorDepth.ATS16Bit;
157 break;
158 case "24":
159 ScreenColorDepth = ATSScreenColorDepth.ATS24Bit;
160 break;
161 default:
162 throw new Exception("Error: Invalid color depth: " + row["ScreenColorDepth"].ToString());
163 }
164
165 ServerName = row["ServerName"].ToString();
166 ServerDomain = row["ServerDomain"].ToString();
167
168 if (row["ServerVersion"].ToString() == "Win2000")
169 ServerVersion = ATSServerVersion.ATSWin2000;
170 else
171 ServerVersion = ATSServerVersion.ATSWin2003; // Meta option, used to control other options. Only used if the server is another computer than the one running AnywhereTS
172
173 if (row["SessionType"].ToString() == "rdesktop")
174 SessionType = ATSSessionType.ATSRDP;
175 else if (row["SessionType"].ToString() == "ICA")
176 SessionType = ATSSessionType.ATSICA;
177 else if (row["SessionType"].ToString() == "PNA")
178 SessionType = ATSSessionType.ATSPNA;
179 else throw new Exception("Data conversion error 44539");
180
181 ReconnectPrompt = (bool)row["ReconnectPrompt"];
182 RedirectFloppy = (bool)row["RedirectFloppy"];
183 RedirectCD = (bool)row["RedirectCD"];
184 RedirectSound = (bool)row["RedirectSound"];
185
186 AudioLevel = (int)row["AudioLevel"];
187 MouseResolution = (int)row["MouseResolution"];
188 UserName = row["Username"].ToString();
189 Password = row["Password"].ToString();
190
191 DailyReboot = (bool)row["DailyReboot"];
192 KeyboardMap = row["KeyboardMap"].ToString();
193 TimeZone = row["TimeZone"].ToString();
194 DigitalMonitor = (bool)row["DigitalMonitor"]; // Will force 60 Hz for digital monitors
195
196 if (row["IcaProtocol"].ToString() == "UDP")
197 ICAProtocol = ATSIcaProtocol.ATSUDP;
198 else if (row["IcaProtocol"].ToString() == "HTTPonTCP")
199 ICAProtocol = ATSIcaProtocol.ATSHTTPOnTCP;
200 else
201 throw new Exception("Unknown ICA protocol. Error 19732");
202 ICAEncryption = row["IcaEncryption"].ToString();
203
204 ICACompression = (bool)row["IcaCompression"];
205
206 if (row["IcaAudioQuality"].ToString() == "Low")
207 IcaAudioQuality = ATSIcaAudioQuality.Low;
208 else if (row["IcaAudioQuality"].ToString() == "Medium")
209 IcaAudioQuality = ATSIcaAudioQuality.Medium;
210 else if (row["IcaAudioQuality"].ToString() == "High")
211 IcaAudioQuality = ATSIcaAudioQuality.High;
212 else
213 throw new Exception("Unknown ICA audio quality. Error 34732");
214
215 ICAServer = row["IcaServer"].ToString();
216 ICAApplicationSet = row["IcaApplicationSet"].ToString();
217 if (row["TempString"].ToString().Length == 0) // Not yet implemented into new version of database
218 {
219 ICAServerURL = @"http://"; // Not yet implemented into new version of database
220 }
221 else
222 {
223 ICAServerURL = row["TempString"].ToString(); // Not yet implemented into new version of database
224 }
225
226
227 MiscFlippedFix = (bool)row["MiscFlippedFix"];
228 MiscMousefix = (bool)row["MiscMousefix"];
229 MiscNoAcceleration = (bool)row["MiscNoAcceleration"];
230 MiscRedirectCom1 = (bool)row["RedirectCom1"];
231 MiscRedirectCom2 = (bool)row["RedirectCom2"];
232
233 if (row["UsbDrive"] != DBNull.Value)
234 {
235 switch ((int) row["UsbDrive"])
236 {
237 case 0:
238 UsbDrive = ATSUsbDrive.None;
239 break;
240 case 1:
241 UsbDrive = ATSUsbDrive.One;
242 break;
243 case 2:
244 UsbDrive = ATSUsbDrive.Many;
245 break;
246 default:
247 throw new Exception("Error: Invalid USB Drive config:" + row["UsbDrive"].ToString());
248 }
249 }
250 else
251 {
252 UsbDrive = ATSUsbDrive.None;
253 }
254
255 if (row["UsbDriveName"] != DBNull.Value)
256 UsbDriveName = row["UsbDriveName"].ToString();
257 else
258 UsbDriveName = "USB";
259
260 NumLock = (bool)row["NumLock"];
261 if (row["ServerPort"] != DBNull.Value)
262 ServerPort = (int) row["ServerPort"];
263 else
264 ServerPort = -1;
265 MouseResolution = (int)row["MouseResolution"];
266
267 }
268
269
270 public void WriteDefaultsToDatabase()
271 {
272 atsDataSetTableAdapters.ClientTableAdapter clientTableAdapter;
273 atsDataSet datasetClient;
274 DataRow defaultRow;
275
276 clientTableAdapter = new atsDataSetTableAdapters.ClientTableAdapter();
277 datasetClient = new atsDataSet();
278
279 clientTableAdapter.Fill(datasetClient.Client);
280
281 // Loook up the default row
282 defaultRow = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
283 if (defaultRow != null)
284 {
285 WriteToDatabase(defaultRow);
286 }
287 else
288 {
289 // There is no default record, create one
290 DataRow newRow = datasetClient.Client.NewRow();
291 WriteToDatabase(newRow);
292 newRow["macAddress"] = ProSupport.DEFAULT_RECORD_MAC;
293 datasetClient.Client.Rows.Add(newRow);
294 }
295
296 // Save default row
297 clientTableAdapter.Update(datasetClient.Client);
298 }
299
300
301 public void WriteToDatabase(DataRow row)
302 {
303 row["ScreenResolution"] = ScreenResolutionX.ToString() + "x" + ScreenResolutionY.ToString();
304
305 switch (ScreenColorDepth)
306 {
307 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit:
308 row["ScreenColorDepth"] = "16";
309 break;
310 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit:
311 row["ScreenColorDepth"] = "24";
312 break;
313 default:
314 throw new Exception("Data conversion error 76532");
315 }
316 row["ServerName"] = ServerName;
317 row["ServerDomain"] = ServerDomain;
318
319 if (ServerVersion == ATSServerVersion.ATSWin2000)
320 row["ServerVersion"] = "Win2000";
321 else
322 row["ServerVersion"] = "Win2003";
323
324 switch (SessionType)
325 {
326 case ATSImageRuntimeConfig.ATSSessionType.ATSRDP:
327 row["SessionType"] = "rdesktop";
328 break;
329 case ATSImageRuntimeConfig.ATSSessionType.ATSICA:
330 row["SessionType"] = "ICA";
331 break;
332 case ATSImageRuntimeConfig.ATSSessionType.ATSPNA:
333 row["SessionType"] = "PNA";
334 break;
335 default:
336 throw new Exception("Data conversion error 44532");
337 }
338 row["ReconnectPrompt"] = ReconnectPrompt;
339 row["RedirectFloppy"] = RedirectFloppy;
340 row["RedirectCD"] = RedirectCD;
341 row["RedirectSound"] = RedirectSound;
342
343 row["AudioLevel"] = AudioLevel;
344 row["MouseResolution"]= MouseResolution;
345 row["Username"] = UserName;
346 row["Password"] = Password;
347
348 row["DailyReboot"] = DailyReboot;
349 row["KeyboardMap"] = KeyboardMap;
350 row["TimeZone"] = TimeZone;
351
352 row["DigitalMonitor"] = DigitalMonitor;
353
354 if (ICAProtocol == ATSIcaProtocol.ATSUDP)
355 row["IcaProtocol"]= "UDP";
356 else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
357 row["IcaProtocol"] = "HTTPonTCP";
358 else
359 throw new Exception("Unknown ICA protocol. Error 19732");
360
361 row["IcaEncryption"] = ICAEncryption;
362 row["IcaCompression"] = ICACompression;
363
364 if (IcaAudioQuality == ATSIcaAudioQuality.Low)
365 row["IcaAudioQuality"] = "Low";
366 else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
367 row["IcaAudioQuality"]= "Medium";
368 else if (IcaAudioQuality == ATSIcaAudioQuality.High)
369 row["IcaAudioQuality"]= "High";
370 else
371 throw new Exception("Unknown ICA audio quality. Error 39702");
372
373 row["IcaServer"] = ICAServer;
374 row["IcaApplicationSet"] = ICAApplicationSet;
375 row["TempString"] = ICAServerURL; // Test!
376
377
378 row["MiscFlippedFix"] = MiscFlippedFix;
379 row["MiscMousefix"] = MiscMousefix;
380 row["MiscNoAcceleration"] = MiscNoAcceleration;
381 row["RedirectCom1"] = MiscRedirectCom1;
382 row["RedirectCom2"] = MiscRedirectCom2;
383
384 switch (UsbDrive)
385 {
386 case ATSUsbDrive.None:
387 row["UsbDrive"] = 0;
388 break;
389 case ATSUsbDrive.One:
390 row["UsbDrive"] = 1;
391 break;
392 case ATSUsbDrive.Many:
393 row["UsbDrive"] = 2;
394 break;
395 default:
396 throw new Exception("Data conversion error 32244");
397 }
398 row["UsbDrivename"] = UsbDriveName;
399
400 row["NumLock"] = NumLock;
401 row["ServerPort"] = ServerPort;
402 if (row["Created"] == DBNull.Value)
403 { // This is a new client, save creation date
404 row["Created"] = DateTime.Now;
405 }
406 row["Modified"] = DateTime.Now;
407 }
408
409
410
411 // Write parameters to file. Used only by write config file in this class and in the class ATSImage
412 public void WriteParameters(StreamWriter writer)
413 {
414 writer.WriteLine("KEYBOARD_MAP=" + KeyboardMap);
415
416 if (NumLock)
417 writer.WriteLine("X_NUMLOCK=On");
418 else
419 writer.WriteLine("X_NUMLOCK=Off");
420
421 writer.WriteLine(@"SCREEN_RESOLUTION=""" + ScreenResolutionX.ToString() + @"x" + ScreenResolutionY.ToString() + @"""");
422
423 writer.Write("SCREEN_COLOR_DEPTH=");
424 if (ScreenColorDepth == ATSScreenColorDepth.ATS16Bit)
425 writer.WriteLine("16");
426 else if (ScreenColorDepth == ATSScreenColorDepth.ATS24Bit)
427 writer.WriteLine("24");
428 else
429 throw new Exception("Error: Unknown color depth 63342");
430 if (UsbDrive == ATSUsbDrive.One)
431 writer.WriteLine(@"USB_STORAGE_MULTI=OFF");
432 if (UsbDrive == ATSUsbDrive.Many)
433 writer.WriteLine(@"USB_STORAGE_MULTI=On");
434 if (MouseResolution < 51)
435 { // Create a fraction 1/11 to 1 from MouseResolution values 0-49
436 // MouseResolution 1 -> MOUSE_ACCELERATION = 1/11
437 // MouseResolution 49 -> MOUSE_ACCELERATION = 1
438 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution / 5) + 1).ToString() + @"/11""");
439 }
440 else
441 { // Create a fraction 10/10 to 100/10 from MouseResolution values 50-100
442 // MouseResolution 50 -> MOUSE_ACCELERATION = 1
443 // MouseResolution 100 -> MOUSE_ACCELERATION = 10
444 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution*9/5)-80).ToString() + @"/10""");
445 }
446
447 writer.WriteLine(@"NET_BASE_NAME=""anywhereTS""");
448 writer.WriteLine(@"TIME_ZONE=""" + TimeZone + @"""");
449 writer.WriteLine("AUDIO_LEVEL=" + AudioLevel.ToString());
450 //writer.WriteLine(@"USB_STORAGE_BASENAME=""USBFOO""");
451 //writer.WriteLine("USB_STORAGE_SYNC=ON");
452 //writer.WriteLine("USB_STORAGE_MULTI=OFF");
453
454 if (DailyReboot)
455 writer.WriteLine("DAILY_REBOOT=On");
456 else
457 writer.WriteLine("DAILY_REBOOT=Off");
458
459 writer.Write("RECONNECT_PROMPT=");
460 if (ReconnectPrompt)
461 writer.WriteLine("On");
462 else
463 writer.WriteLine("Off");
464
465
466 writer.WriteLine(@"SCREEN=0"); //Could be removed and put in default file
467 writer.WriteLine(@"WORKSPACE=1"); //Could be removed and put in default file
468 writer.WriteLine(@"#SCREEN_HORIZSYNC=""30-64 | *"""); //Could be removed
469
470 if (DigitalMonitor)
471 {
472 writer.WriteLine(@"SCREEN_VERTREFRESH=60");
473 }
474 else
475 writer.WriteLine(@"#SCREEN_VERTREFRESH=""56-87 | 60 | 56 | 70 | 72 | 75"""); //Could be removed and put in default file
476
477 writer.WriteLine("SESSION_0_SCREEN=0"); //Could be removed and put in default file
478
479 writer.Write("SESSION_0_TYPE=");
480 if (SessionType == ATSSessionType.ATSRDP)
481 writer.WriteLine("rdesktop");
482 else if (SessionType == ATSSessionType.ATSICA)
483 {
484 writer.WriteLine("ICA"); //Ica 9
485 }
486 else if (SessionType == ATSSessionType.ATSPNA)
487 {
488 writer.WriteLine("pnabrowse");
489 }
490 else
491 throw new Exception("Error: Unknown color depth 61132");
492
493 // Server
494 if (ServerPort == -1)
495 { // No RDP port specified, use default
496 writer.WriteLine("SESSION_0_RDESKTOP_SERVER=" + ServerName);
497 }
498 else
499 { // RDP port specified, add it.
500 writer.WriteLine("SESSION_0_RDESKTOP_SERVER=" + ServerName + ":" + ServerPort.ToString());
501 }
502
503 // RDP OPTIONS:
504 writer.Write(@"SESSION_0_RDESKTOP_OPTIONS=""-u '");
505
506 // RDP User name
507 if (UserName.Length > 0)
508 writer.Write(UserName);
509 writer.Write("'");
510
511 // RDP keyboard (no need to define this, uses a format different from keyboard map, so needs conversion)
512 // writer.Write(" -k "+ KeyboardMap);
513
514 // RDP color depth
515 if (ServerVersion == ATSServerVersion.ATSWin2000)
516 writer.Write(" -a 8");
517 else
518 {
519 if (ScreenColorDepth == ATSScreenColorDepth.ATS16Bit)
520 writer.Write(" -a 16"); //Test 32bit
521 else if (ScreenColorDepth == ATSScreenColorDepth.ATS24Bit)
522 writer.Write(" -a 24");
523 else
524 throw new Exception("Error: Unknown color depth 63342");
525 }
526
527 // RDP sound
528 if (RedirectSound)
529 writer.Write(" -r sound");
530
531 // RDP Floppy if is 2003 server or later and redirect floppy
532 if (RedirectFloppy && !ServerIsWin2000())
533 writer.Write(" -r disk:floppy=/mnt/floppy");
534
535 // RDP CD if is 2003 server or later and redirect CD
536 if (RedirectCD && !ServerIsWin2000())
537 writer.Write(" -r disk:cdrom=/mnt/cdrom");
538 // RDP USB if is 2003 server or later and redirect USB Memmory
539 if (UsbDrive!=ATSUsbDrive.None)
540 writer.Write(" -r disk:" + UsbDriveName + "=/mnt/usbdevice");
541
542 // RDP COM if is 2003 server or later and redirect Comport
543 if ((MiscRedirectCom1 || MiscRedirectCom2) && !ServerIsWin2000())
544 // RDP com1 if is 2003 server or later and redirect com1
545 if (MiscRedirectCom1 && MiscRedirectCom2)
546 writer.Write(" -r comport:COM1=/dev/ttyS0,COM2=/dev/ttyS1");
547 else
548 if (MiscRedirectCom1)
549 writer.Write(" -r comport:COM1=/dev/ttyS0");
550 else
551 writer.Write(" -r comport:COM2=/dev/ttyS1");
552
553 writer.Write(" -B -C -z -x l"); // Misc swithces
554
555 // RDP domain
556 if (ServerDomain.Length != 0)
557 writer.Write(" -d " + ServerDomain);
558
559 // RDP password
560 if (Password.Length > 0)
561 writer.Write(" -p " + Password);
562
563 writer.WriteLine(@" -N"""); //Finalise the RDESKTOP_OPTIONS line
564
565 if (ServerIsWin2000() && (RedirectCD || RedirectFloppy ))
566 { // We have a win 2000 server with redirected local drives, we need to enable samba
567 writer.WriteLine("SAMBA_ENABLED=On");
568 writer.WriteLine("SAMBA_WORKGROUP=thinclient");
569 writer.WriteLine("SAMBA_SECURITY=USER");
570 writer.WriteLine("SAMBA_SERVER=ts*");
571 writer.WriteLine("SAMBA_HARDDISK=Off");
572 writer.WriteLine("SAMBA_USB=Off");
573 writer.WriteLine("SAMBA_PRINTER=Off");
574
575 if(RedirectFloppy)
576 writer.WriteLine("SAMBA_FLOPPY=On");
577 else
578 writer.WriteLine("SAMBA_FLOPPY=Off");
579
580 if(RedirectCD)
581 writer.WriteLine("SAMBA_CDROM=On");
582 else
583 writer.WriteLine("SAMBA_CDROM=Off");
584 }
585
586 if (SessionType == ATSSessionType.ATSICA)
587 {
588 writer.WriteLine(@"SESSION_0_ICA_APPLICATION_SET=""" + ICAApplicationSet + @"""");
589 }
590 else if (SessionType == ATSSessionType.ATSPNA)
591 {
592 writer.WriteLine(@"PNABROWSE_URL=""" + ICAServerURL + @"""");
593 writer.WriteLine(@"PNABROWSE_RESOURCE=""" + ICAResource + @"""");
594 writer.WriteLine(@"PNABROWSE_LOGIN=""" + UserName + @"""");
595 writer.WriteLine(@"PNABROWSE_PASSWORD=""" + Password + @"""");
596 writer.WriteLine(@"PNABROWSE_DOMAIN=""" + ServerDomain + @"""");
597 }
598
599 if (SessionType == ATSSessionType.ATSICA || SessionType == ATSSessionType.ATSPNA)
600 {
601 writer.WriteLine("SESSION_0_ICA_APPSRV_USEFULLSCREEN=Yes"); //tabort
602 writer.WriteLine("SESSION_0_SCREEN=0"); //tabort
603 writer.WriteLine("SESSION_0_TITLE=ATS*"); //tabort
604 writer.WriteLine("SESSION_0_AUTOSTART=ON"); //tabort
605 writer.WriteLine("SESSION_0_CUSTOM_CONFIG=OFF"); //tabort
606 writer.WriteLine("ICA_USE_SERVER_KEYBOARD=ON"); //tabort
607 // ICA Desktop Citrix 10
608
609 if (ICAProtocol == ATSIcaProtocol.ATSUDP)
610 writer.WriteLine("ICA_BROWSER_PROTOCOL=UDP");
611 else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
612 writer.WriteLine("ICA_BROWSER_PROTOCOL=HTTPonTCP");
613 else
614 throw new Exception("Unknown ICA protocol Error: 34211");
615
616 writer.WriteLine("SESSION_0_ICA_SERVER=" + ServerName);
617 writer.WriteLine(@"ICA_ENCRYPTION=""" + ICAEncryption + @"""");
618
619 if (ICACompression)
620 writer.WriteLine("ICA_COMPRESS=On");
621 else
622 writer.WriteLine("ICA_COMPRESS=Off");
623
624 if (RedirectSound)
625 writer.WriteLine("ICA_AUDIO=On");
626 else
627 writer.WriteLine("ICA_AUDIO=Off");
628
629 if (IcaAudioQuality == ATSIcaAudioQuality.Low)
630 writer.WriteLine("ICA_AUDIO_QUALITY=Low");
631 else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
632 writer.WriteLine("ICA_AUDIO_QUALITY=Medium");
633 else if (IcaAudioQuality == ATSIcaAudioQuality.High)
634 writer.WriteLine("ICA_AUDIO_QUALITY=High");
635 else
636 throw new Exception("Unknown ICA audio quality. Error 23165");
637
638 writer.WriteLine("ICA_PRINTER=OFF"); //tabort
639 writer.WriteLine("ICA_SEAMLESS_WINDOW=OFF"); //tabort
640
641 // ICA OPTIONS:
642 writer.Write(@"SESSION_0_ICA_OPTIONS=""");
643
644 // ICA User name
645 if (UserName.Length > 0)
646 writer.Write("-username " + UserName);
647
648 // ICA password
649 if (Password.Length > 0)
650 writer.Write(" -clearpassword " + Password);
651 // ICA domain
652 if (ServerDomain.Length != 0)
653 writer.Write(" -domain " + ServerDomain);
654
655 writer.WriteLine(@""""); // Finalise the ICA_OPTIONS line
656 } // end ICA parameters
657
658 if (GraphicsAdapter.Length != 0)
659 writer.WriteLine(@"X_DRIVER_NAME=""" + GraphicsAdapter + @"""");
660
661 if (MiscFlippedFix )
662 writer.WriteLine(@"X_DRIVER_OPTION1=""XaaNoMono8x8PatternFillRect On""");
663
664 if (MiscMousefix)
665 writer.WriteLine(@"X_DRIVER_OPTION2=""SWCursor On""");
666
667 if (MiscNoAcceleration)
668 writer.WriteLine(@"X_DRIVER_OPTION3=""NoAccel On""");
669 }
670
671 // Write a config file to disk based upon the data in this class.
672 // The config is written to the file pathfile.
673 public bool WriteConfigFile(string pathfile)
674 {
675 bool result = false; // Assume we have a problem.
676 // Delete old backup, so that a new file will always be created and the current user owner. This enables the user to set rights on the file.
677 try
678 {
679
680 if (System.IO.File.Exists(pathfile))
681 {
682 System.IO.File.Delete(pathfile);
683 }
684 }
685 catch (Exception e)
686 {
687 MessageBox.Show("Error cannot delete old config file (24573). Path: '" + pathfile + "'. Error: " + e.Message);
688 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
689 {
690 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
691 {
692 Logging.ATSAdminLog.Error("Cannot delete old config file");
693 }
694 }
695 return result;
696 }
697
698 System.IO.StreamWriter writer = null;
699
700 // Write a runtime new client config file.
701 try
702 {
703 writer = new StreamWriter(pathfile);
704 writer.NewLine = "\n"; // Unix style line terminators
705 writer.WriteLine("# This is a client file generated by AnywhereTS. Do not change.");
706 writer.WriteLine("# This file will be overwritten.");
707 WriteParameters(writer);
708 result = true; // It went ok.
709 }
710 catch (System.IO.IOException e)
711 {
712 // (Could be improved with auto-retry)
713 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 a little later. Error details: "+ e.Message);
714 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
715 {
716 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
717 {
718 Logging.ATSAdminLog.Error("Could not write configuration data to disk");
719 }
720 }
721 }
722 finally
723 {
724 if (writer != null)
725 writer.Close();
726 }
727
728 return result;
729 }
730
731 // True if the client is connecting to a Windows 2000 server
732 public bool ServerIsWin2000()
733 {
734 return (ServerName == Environment.MachineName && Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0) || (Environment.MachineName != ServerName && ServerVersion == ATSServerVersion.ATSWin2000);
735 }
736
737 // Reset all properties that to the state they should have in a non-licensed version of ATS.
738 // This is useful when switching from the Pro version to a free version image, to make
739 // sure no pro features remain enabled.
740 public void ResetProProperties()
741 {
742 NumLock = true;
743 MiscRedirectCom1 = false;
744 MiscRedirectCom2 = false;
745 UsbDrive = ATSUsbDrive.None; // One is default if Pro version
746 ServerPort = -1; // -1 = Not defined
747 if
748 (!(
749 (ScreenResolutionX == 640 && ScreenResolutionY == 480) ||
750 (ScreenResolutionX == 800 && ScreenResolutionY == 600) ||
751 (ScreenResolutionX == 1024 && ScreenResolutionY == 768) ||
752 (ScreenResolutionX == 1280 && ScreenResolutionY == 1024)
753 ))
754 {
755 // Screen resolution is not a standard resoltion available in the free version
756 // Reset screen res to a resolution that is available in the free version.
757 ScreenResolutionX = 1024;
758 ScreenResolutionY = 768;
759 }
760 }
761
762 // Extract the x and y screen resolution from a string
763 // twointegers: String with resolution in the format '1024X768'
764 // x: (out) The x resolution from the string
765 // y: (out) The y resolution from the string
766
767 private void ExtractResolution(string twointegers, out int x, out int y)
768 {
769 ATSGlobals.ExtractIntegers(twointegers, 'x', out x, out y);
770 }
771
772 } // class
773 } // namespace