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

Annotation of /trunk/TSAdminTool/frmConfigServices.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 182 - (hide annotations) (download)
Mon Jul 16 13:25:17 2012 UTC (8 years, 11 months ago) by william
File size: 29484 byte(s)
terminalserverconfig value was not being read from registry: fixed

1 william 156 #define DISALLOW_SETTING_OF_TFTP_FOLDER_ACLS // when defined will not allow RDP only acl to be placed on TFTP folder
2 william 4 using System;
3     using System.Collections.Generic;
4     using System.ComponentModel;
5     using System.Data;
6     using System.Drawing;
7     using System.Text;
8     using System.Windows.Forms;
9     using System.IO;
10     using System.Security.AccessControl;
11     using System.Security.Principal;
12 william 180 using System.Threading;
13 william 4
14     namespace AnywhereTS
15     {
16 william 180
17 william 4 public partial class frmConfigServices : Form
18     {
19     public frmConfigServices()
20     {
21     InitializeComponent();
22     }
23    
24     private atsDataSet.TftpServerDataTable datatableTFTP; // TFTP server directories
25     private atsDataSet.TerminalServerDataTable datatableTerminalServer; // terminal servers
26     const string strATSshareName = @"AnywhereTS$"; // The name of the AnywhereTS Win32 file share for the local TFTP server.
27     const string strShareDesc = @"Used by AnywhereTS";
28     private List<string> tftpUncPaths; // List with the corresponding UNC paths for items in lstTFTP.
29    
30     private void frmConfigureMode_Load(object sender, EventArgs e)
31     {
32 william 59 //this.Cursor = Cursors.WaitCursor;
33 william 4
34     tftpUncPaths = new List<string>(); // Create a list for the TFTP UNC paths.
35    
36     // Setup database
37     if (ProSupport.tftpServerTableAdapter == null || ProSupport.terminalServerTableAdapter == null) // Is database initiated?
38     {
39     // Databases is not initiated, do it now
40     ProSupport.InitDatabase();
41     }
42    
43     datatableTFTP = new atsDataSet.TftpServerDataTable();
44     ProSupport.tftpServerTableAdapter.Fill(datatableTFTP);
45     datatableTerminalServer = new atsDataSet.TerminalServerDataTable();
46     ProSupport.terminalServerTableAdapter.Fill(datatableTerminalServer);
47    
48     if (ATSGlobals.configured == 0)
49     { // ATS not configured yet
50     RadTSthisComputer.Checked = true;
51     txtTFTPpath.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS\TFTP";
52     radTFTPinternal.Checked = true;
53     }
54     else
55     { // ATS already configured.
56     txtTFTPpath.Text = ATSGlobals.strTFTPdir;
57     radTFTPinternal.Checked = (ATSGlobals.tftpConfig == 0);
58     radTFTPexternal.Checked = (ATSGlobals.tftpConfig == 1);
59     if (ATSGlobals.terminalServerConfig == 0)
60     { // This computer is terminal server
61    
62 william 181 //if (datatableTerminalServer.Rows.Count == 0) //Any other terminal servers?
63     //{ // No other terminal servers
64     // RadTSthisComputer.Checked = true;
65     //}
66     //else
67     //{ // At least one other
68     // radTSboth.Checked = true;
69     //}
70     RadTSthisComputer.Checked = true;
71 william 182 radTSboth.Checked = false;
72 william 181 radTSother.Checked = false;
73 william 4 }
74 william 181 else if (ATSGlobals.terminalServerConfig == 1)
75     {
76     RadTSthisComputer.Checked = false;
77 william 182 radTSboth.Checked = true;
78 william 181 radTSother.Checked = false;
79     }
80     else if (ATSGlobals.terminalServerConfig == 2)
81     {
82     RadTSthisComputer.Checked = false;
83 william 182 radTSboth.Checked = false;
84 william 4 radTSother.Checked = true;
85     }
86 william 181 else
87     {
88     string error = "Error: Undefined terminal servers config (42002)";
89     using (log4net.NDC.Push(string.Format("terminalServerConfig={0}", ATSGlobals.terminalServerConfig)))
90     {
91     Logging.ATSAdminLog.Error(error);
92     }
93     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("terminalServerConfig={0}", ATSGlobals.terminalServerConfig)));
94     return;
95     }
96 william 4
97     }
98    
99    
100     // Update terminal server list
101     UpdateTerminalServerList();
102    
103     // Update TFTP server directories list
104     if (ATSGlobals.tftpConfig == 1)
105     {
106     UpdateTftpList();
107     }
108    
109     helpProvider.HelpNamespace = ATSGlobals.strHelpFilePath; // Initiate helpProvider
110    
111     UpdateControls();
112    
113     this.Cursor = Cursors.Default;
114     }
115    
116    
117     private void btnOK_Click(object sender, EventArgs e)
118     {
119     this.Cursor = Cursors.WaitCursor;
120    
121     if (RadTSthisComputer.Checked)
122     ATSGlobals.terminalServerConfig = 0;
123     else if (radTSboth.Checked)
124 william 181 ATSGlobals.terminalServerConfig = 1;
125 william 4 else if (radTSother.Checked)
126 william 181 ATSGlobals.terminalServerConfig = 2;
127 william 4 else
128 william 64 {
129     string error = "Error: Undefined terminal servers config (42001)";
130     using (log4net.NDC.Push(string.Format("terminalServerConfig={0}", ATSGlobals.terminalServerConfig)))
131     {
132     Logging.ATSAdminLog.Error(error);
133     }
134     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("terminalServerConfig={0}", ATSGlobals.terminalServerConfig)));
135     return;
136     }
137 william 181 ATSGlobals.SetATSRegValue(ATSGlobals.strRegTerminalServer, ATSGlobals.terminalServerConfig);
138 william 4
139    
140     string strPath; // The TFTP path
141     strPath = txtTFTPpath.Text.Trim();
142    
143     if (radTFTPinternal.Checked)
144     { // We are using the internal TFTP
145     ATSGlobals.tftpConfig = 0; // Use ATS TFTP
146     // Validate TFTP directory
147     if (strPath.Length == 0)
148     {
149     this.Cursor = Cursors.Default;
150     MessageBox.Show("You must specifiy a directory for the AnywhereTS shared network files.");
151     txtTFTPpath.Focus();
152     return;
153     }
154    
155     if (strPath.StartsWith(".") || strPath.StartsWith(@"\"))
156     {
157     this.Cursor = Cursors.Default;
158     MessageBox.Show("Invalid path for the AnywhereTS shared network files.");
159 william 46 using (log4net.NDC.Push(string.Format("path={0}", strPath)))
160     {
161     Logging.ATSAdminLog.Error("Invalid path for the AnywhereTS shared network files.");
162     }
163 william 4 txtTFTPpath.Focus();
164     return;
165     }
166    
167     // Create TFTP directory
168     try
169     {
170     Directory.CreateDirectory(strPath);
171     }
172     catch (Exception ex)
173     {
174     this.Cursor = Cursors.Default;
175     MessageBox.Show("Could not create directory '" + strPath + "'. Error: " + ex.Message);
176 william 46 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
177     {
178     using (log4net.NDC.Push(string.Format("directory={0}", strPath)))
179     {
180     Logging.ATSAdminLog.Error("Could not create directory.");
181     }
182     }
183 william 4 txtTFTPpath.Select();
184     return;
185     }
186    
187     // Check that the directory is local
188     ShareUtil shUtil = new ShareUtil(); // Create a util class
189     if (shUtil.IsNetworkPath(strPath))
190     { // The path is a network path
191     MessageBox.Show("A network path cannot be used for the local TFTP server. Please enter a local path.");
192     txtTFTPpath.Select();
193     return;
194     }
195     // Save the TFTP directory to registry
196     ATSGlobals.strTFTPdir = strPath; // Set the C# version of TFTP dir
197     Globals.strTFTPdir = strPath; // Set the VB version of TFTP dir
198     ATSGlobals.SetATSRegValue(ATSGlobals.strRegTFTP_root, ATSGlobals.strTFTPdir);
199    
200     // Delete all TFTP roots from database
201     foreach (DataRow row in datatableTFTP.Rows)
202     {
203     row.Delete();
204     }
205     ProSupport.tftpServerTableAdapter.Update(datatableTFTP);
206    
207     if (!RadTSthisComputer.Checked)
208     { // There are external terminal servers.
209    
210     // Create a share, save the UNC path to the database, add rights to TFTP directory
211     AddTFTPpath(ATSGlobals.strTFTPdir);
212     }
213     else
214     { // We are only using this computer as terminal server
215     SetTFTPrights(ATSGlobals.strTFTPdir);
216     }
217     }
218     else
219     {
220     // Use other TFTP
221     ATSGlobals.tftpConfig = 1; // Use other TFTP
222    
223     if (lstTFTP.Items.Count == 0)
224     {
225     this.Cursor = Cursors.Default;
226     MessageBox.Show("You must choose at least one TFTP server root directory, where AnywhereTS can place client images and configurations.");
227     btnAddTFTPpath.Focus();
228     return;
229     }
230     }
231    
232     // Check if we are using external terminal servers
233     if (RadTSthisComputer.Checked)
234     { // Only this computer is a terminal server. Delete all other terminal servers.
235     foreach (DataRow row in datatableTerminalServer.Rows)
236     {
237     row.Delete();
238     }
239     ProSupport.terminalServerTableAdapter.Update(datatableTerminalServer);
240     }
241     else
242     { // We have external terminal servers
243     if (lstTerminalServer.Items.Count == 0)
244     {
245     this.Cursor = Cursors.Default;
246     MessageBox.Show("You must specify at least one Terminal Server!");
247     btnAddTerminalServer.Focus();
248     return;
249     }
250    
251     // Close database connections
252     datatableTFTP.Dispose();
253     datatableTerminalServer.Dispose();
254     ProSupport.clientTableAdapter.Connection.Close();
255     ProSupport.terminalServerTableAdapter.Connection.Close();
256     ProSupport.clientTableAdapter.Dispose();
257     ProSupport.terminalServerTableAdapter.Dispose();
258    
259     // Configure SQL browser service (needed for the control panel to be able to access the database).
260    
261     bool sqlServerRestarted = DatabaseSupport.EnableNamedPipes(); // Enable named pipes in the SQL server
262     DatabaseSupport.AutostartSQLbrowserService(); // Configure the SQL Browser service to autostart.
263     DatabaseSupport.StartSQLbrowserService(); // Start the SQL Browser service
264    
265     if (sqlServerRestarted)
266     {
267     // SQL server was restarted. Try to reconnect to database in order to repair the database connectivity
268     ProSupport.InitDatabase();
269    
270     try
271     {
272     datatableTFTP = new atsDataSet.TftpServerDataTable();
273     ProSupport.tftpServerTableAdapter.Fill(datatableTFTP); // This operation causes an error and forces the connectivity to recover.
274     }
275     catch
276     { // Do nothing, just catch the error that will most likely occur here.
277     }
278     finally
279     {
280     System.Threading.Thread.Sleep(5000); // Wait for the SQL connection to recover.
281     }
282     }
283     }
284    
285     // Save DHCP options
286     if (radAtsDhcp.Checked)
287     {
288     ATSGlobals.dhcpConfig = 0; // Use the internal DCHP server
289     }
290     else
291     {
292     ATSGlobals.dhcpConfig = 1; // Use the other DCHP server
293     }
294    
295     // Save TFTP configuration to registry
296     ATSGlobals.SetATSRegValue(ATSGlobals.strRegTFTPconfig,ATSGlobals.tftpConfig);
297    
298     // Save DCHP configuration to registry
299     ATSGlobals.SetATSRegValue(ATSGlobals.strRegDHCPconfig, ATSGlobals.dhcpConfig);
300    
301     // Terminate window
302     this.Cursor = Cursors.Default;
303     DialogResult = DialogResult.OK;
304     }
305    
306    
307     private void AddTFTPpath(string strPath)
308     {
309     string uncPath; // The path in UNC format
310     string strLocalPath = ""; // Local path to save in database for display purposes. Only set if path is local
311    
312     ShareUtil shUtil = new ShareUtil(); // Create a util class
313    
314     // Check if path is a network path
315     if (shUtil.IsNetworkPath(strPath))
316     { // The path is a network path
317     if (strPath.StartsWith("\\"))
318     { // The network path is a UNC path, no need to convert it
319     uncPath = strPath;
320     }
321     else
322     { // The network path is not a UNC path, convert it
323     uncPath = UNCconverter.ConvertLocalPathToUnc(strPath);
324     }
325     }
326     else
327     { // User is adding a local path
328     strLocalPath = strPath;
329     string strThisComputer = Environment.MachineName; // The name of this computer
330     // Compile the UNC path
331     uncPath = @"\\" + strThisComputer + @"\" + strATSshareName;
332    
333     // Delete ATS share if it exists
334     shUtil.DeleteShare(strATSshareName);
335    
336     // Delete share from database if it exists
337     ProSupport.tftpServerTableAdapter.Fill(datatableTFTP); // Refresh data table
338     DataRow rowToDelete;
339     rowToDelete = datatableTFTP.Rows.Find(uncPath);
340     if (rowToDelete != null)
341     { // The local TFTP path exists in database, delete it
342     rowToDelete.Delete();
343     ProSupport.tftpServerTableAdapter.Update(datatableTFTP);
344     }
345    
346     // Create network share
347    
348     uint nRetVal;
349     nRetVal = shUtil.CreateShare(strShareDesc, strATSshareName, strPath);
350     if (nRetVal == 0)
351     {
352     // Share created
353     }
354     else
355     {
356     // Error
357     MessageBox.Show("Could not create a share for the AnywereTS TFTP data. Do you have sufficient rights? (25322)");
358     return;
359     }
360    
361     }
362    
363     // Add the remote or local directory path to the database
364     if (uncPath.Length <= 255)
365     { // The path will fit in the database
366     atsDataSet.TftpServerRow row = (atsDataSet.TftpServerRow)datatableTFTP.NewRow();
367     row["Path"] = uncPath;
368     row["LocalPath"] = strLocalPath;
369    
370     try
371     {
372     datatableTFTP.AddTftpServerRow(row);
373     }
374     catch (ConstraintException)
375     {
376     MessageBox.Show("'" + uncPath + "' is already in the list.");
377     return;
378     }
379    
380     ProSupport.tftpServerTableAdapter.Update(datatableTFTP);
381    
382     // Ask if we are going to add righs to the TFTP root directory, set rights.
383     SetTFTPrights(row["Path"].ToString());
384     UpdateTftpList(); // Update the list box
385     lstTFTP.Select();
386     }
387     else
388     { // Path is too long
389     MessageBox.Show("The directory path is too long, please use a path that is max 255 character");
390     }
391    
392     }
393    
394     private void radAtsDhcp_CheckedChanged(object sender, EventArgs e)
395     {
396     UpdateControls(); // Set text "Next >" or "Finish" on the Ok button
397     }
398    
399     private void radExternalDhcp_CheckedChanged(object sender, EventArgs e)
400     {
401     UpdateControls(); // Set text "Next >" or "Finish" on the Ok button
402     }
403    
404     private void UpdateControls()
405     {
406     if (RadTSthisComputer.Checked)
407     { // Only this computer as terminal server
408     lblTerminalServers.Enabled = false;
409     lstTerminalServer.Enabled = false;
410     btnAddTerminalServer.Enabled = false;
411     btnDeleteTerminalServer.Enabled = false;
412     }
413     else
414     { // Other terminal servers
415     lblTerminalServers.Enabled = true;
416     lstTerminalServer.Enabled = true;
417     btnAddTerminalServer.Enabled = true;
418     if (lstTerminalServer.SelectedIndex == -1)
419     btnDeleteTerminalServer.Enabled = false;
420     else
421     btnDeleteTerminalServer.Enabled = true;
422     }
423    
424     if (radTFTPinternal.Checked)
425     {
426     lblTFTPpath.Enabled = true;
427     txtTFTPpath.Enabled = true;
428     btnBrowseTFTP.Enabled = true;
429     lblTFTPdirectories.Enabled = false;
430     lstTFTP.Enabled = false;
431     btnAddTFTPpath.Enabled = false;
432     btnDeleteTFTP.Enabled = false;
433     radAtsDhcp.Enabled = true;
434     lstTFTP.SelectedIndex = -1;
435     btnOK.Text = "Next >";
436     }
437     else
438     {
439     lblTFTPdirectories.Enabled = true;
440     lstTFTP.Enabled = true;
441     btnAddTFTPpath.Enabled = true;
442     if (lstTFTP.SelectedIndex == -1)
443     btnDeleteTFTP.Enabled = false;
444     else
445     btnDeleteTFTP.Enabled = true;
446     lblTFTPpath.Enabled = false;
447     txtTFTPpath.Enabled = false;
448     btnBrowseTFTP.Enabled = false;
449     btnOK.Text = "Finish";
450     radAtsDhcp.Enabled = false;
451     radExternalDhcp.Checked = true;
452     }
453     }
454    
455     private void radTFTPinternal_CheckedChanged(object sender, EventArgs e)
456     {
457     UpdateControls();
458     }
459    
460     private void radTFTPexternal_CheckedChanged(object sender, EventArgs e)
461     {
462     if (radTFTPexternal.Checked && ATSGlobals.tftpConfig == 0)
463     { // We have just de-selected internal TFTP server
464    
465     // Delete all TFTP roots from database
466     foreach (DataRow row in datatableTFTP.Rows)
467     {
468     row.Delete();
469     }
470     ProSupport.tftpServerTableAdapter.Update(datatableTFTP);
471     UpdateTftpList();
472    
473     // Delete the file share for the internal TFTP directory if it exists.
474     ShareUtil shUtil = new ShareUtil(); // Create a util class
475     shUtil.DeleteShare("AnywhereTS$");
476    
477     // ATS is now in a non configured state
478     ATSGlobals.configured = 0;
479     ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured, ATSGlobals.configured);
480     }
481     UpdateControls();
482     }
483    
484     // Update the list with TFTP directories from database.
485     private void UpdateTftpList()
486     {
487     lstTFTP.Items.Clear();
488     tftpUncPaths.Clear();
489     ProSupport.tftpServerTableAdapter.Fill(datatableTFTP);
490     foreach (DataRow row in datatableTFTP.Rows)
491     { // Display local path if possible
492    
493    
494     lstTFTP.Items.Add(ProSupport.GetTftpPath(row));
495     //string gg = row["Path"].ToString();
496     //tftpUncPaths.Add(gg);
497     tftpUncPaths.Add(row["Path"].ToString()); // Add the UNC path to the list.
498     }
499     btnDeleteTFTP.Enabled = false;
500     }
501    
502     // Update the list with terminal servers from database.
503     private void UpdateTerminalServerList()
504     {
505     lstTerminalServer.Items.Clear();
506     foreach (DataRow row in datatableTerminalServer.Rows)
507     {
508     lstTerminalServer.Items.Add(row["Path"].ToString());
509     }
510     btnDeleteTerminalServer.Enabled = false;
511     }
512    
513     private void lstTFTP_SelectedIndexChanged(object sender, EventArgs e)
514     {
515     if (lstTFTP.SelectedIndex == -1)
516     { // No item selcted in the TFTP directory list
517     btnDeleteTFTP.Enabled = false;
518     }
519     else
520     { // User has selcted an item in the list
521     btnDeleteTFTP.Enabled = true;
522     }
523     }
524    
525     // Delete the row selected in the TFTP directory list box.
526     private void btnDeleteTFTP_Click(object sender, EventArgs e)
527     {
528     DataRow rowToDelete;
529     rowToDelete = datatableTFTP.Rows.Find(tftpUncPaths[lstTFTP.SelectedIndex]);
530     rowToDelete.Delete();
531     ProSupport.tftpServerTableAdapter.Update(datatableTFTP);
532     UpdateTftpList(); // Update the list box
533    
534     if (datatableTFTP.Rows.Count == 0)
535     { // Last row deleted
536     // ATS is now in a non configured state
537     ATSGlobals.configured = 0;
538     ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured, ATSGlobals.configured);
539     }
540     }
541    
542     // Set user rights to TFTP directory, all remote desktop users should be able to write files.
543     void SetTFTPrights(string path)
544     {
545 william 156 #if DISALLOW_SETTING_OF_TFTP_FOLDER_ACLS
546     return;
547     #else
548 william 4 // Ask if we are going to add righs to the TFTP root directory
549     DialogResult resultRights;
550     resultRights = MessageBox.Show(this, "In order for users to use the AnywhereTS control panel, they need rights to write in the TFTP root directory. Do you want AnywhereTS to add these rights now?", "AnywhereTS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
551     if (resultRights == DialogResult.Yes)
552     {
553     try
554     {
555     // Create a new DirectoryInfo object.
556     DirectoryInfo dInfo = new DirectoryInfo(path);
557     // Get a DirectorySecurity object that represents the
558     // current security settings.
559     DirectorySecurity dSecurity = dInfo.GetAccessControl();
560     // Add a FileSystemAccessRule to the security settings, to allow write.
561     // No general rights to delete files. These rights are set on the individual files.
562     dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.WriteData, AccessControlType.Allow));
563     // Set the new access settings.
564     dInfo.SetAccessControl(dSecurity);
565     }
566     catch (Exception ex)
567     {
568     this.Cursor = Cursors.Default;
569     MessageBox.Show("Could not set user access rights for TFTP directory. Do you have sufficient right? (29991). Error: " + ex.Message);
570 william 46 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
571     {
572     Logging.ATSAdminLog.Error("Could not set user access rights for TFTP directory.");
573     }
574 william 4 return;
575     }
576     }
577 william 156 #endif
578 william 4 }
579    
580     private void btnDeleteTerminalServer_Click(object sender, EventArgs e)
581     {
582     DataRow rowToDelete;
583     rowToDelete = datatableTerminalServer.Rows.Find(lstTerminalServer.SelectedItem);
584     rowToDelete.Delete();
585     ProSupport.terminalServerTableAdapter.Update(datatableTerminalServer);
586     UpdateTerminalServerList(); // Update the list box
587     }
588    
589     private void btnAddTerminalServer_Click(object sender, EventArgs e)
590     {
591     // Show dialog
592     frmAddTerminalServer addTSdialog = new frmAddTerminalServer();
593     DialogResult result = addTSdialog.ShowDialog();
594     if (result == DialogResult.OK)
595     {
596     // Add the server to the database
597     if (addTSdialog.inputstring.Trim().Length <= 255)
598     { // The path will fit in the database
599     atsDataSet.TerminalServerRow row = (atsDataSet.TerminalServerRow)datatableTerminalServer.NewRow();
600     row["Path"] = addTSdialog.inputstring.Trim();
601     try
602     {
603     datatableTerminalServer.AddTerminalServerRow(row);
604     }
605     catch (ConstraintException)
606     {
607     MessageBox.Show("'" + row["Path"] + "' is already in the list.");
608     return;
609     }
610    
611     ProSupport.terminalServerTableAdapter.Update(datatableTerminalServer);
612    
613     UpdateTerminalServerList(); // Update the list box
614     lstTerminalServer.Select();
615     }
616     else
617     { // Path is too long
618     MessageBox.Show("The server path is too long, please use a path that is max 255 character");
619     }
620     }
621     }
622    
623     private void lstTerminalServer_SelectedIndexChanged(object sender, EventArgs e)
624     {
625     if (lstTerminalServer.SelectedIndex == -1)
626     { // No item selcted in the TFTP directory list
627     btnDeleteTerminalServer.Enabled = false;
628     }
629     else
630     { // User has selcted an item in the list
631     btnDeleteTerminalServer.Enabled = true;
632     }
633     }
634    
635     private void RadTSthisComputer_CheckedChanged(object sender, EventArgs e)
636     {
637     UpdateControls();
638     }
639    
640     private void radTSother_CheckedChanged(object sender, EventArgs e)
641     {
642     UpdateControls();
643     }
644    
645     private void radTSboth_CheckedChanged(object sender, EventArgs e)
646     {
647     UpdateControls();
648     }
649    
650     // Add a TFTP server
651     private void btnAddTFTPpath_Click(object sender, EventArgs e)
652     {
653     // Show dialog
654     frmAddTFTP addTFTPdialog = new frmAddTFTP();
655     DialogResult result = addTFTPdialog.ShowDialog();
656     if (result == DialogResult.OK)
657     {
658     string strPath;
659     strPath = addTFTPdialog.inputstring.Trim();
660    
661     if (Directory.Exists(strPath))
662     {
663     // Convert to UNC, share local directory, add directory to database
664     AddTFTPpath(strPath);
665     }
666     else
667     {
668     MessageBox.Show("Error: Cannot find or access the directory. Please check name and rights. (34212)");
669     }
670     UpdateTftpList();
671     }
672     }
673 william 180 string tftp_path = string.Empty;
674 william 4 private void btnBrowseTFTP_Click(object sender, EventArgs e)
675     {
676 william 180 var t = new Thread(new ThreadStart(CreateFolderBrowser));
677     t.IsBackground = true;
678     t.SetApartmentState(ApartmentState.STA);
679     t.Start();
680     while (t.IsAlive) { Application.DoEvents(); }
681     txtTFTPpath.Text = tftp_path;
682     txtTFTPpath.Select();
683     }
684     private void CreateFolderBrowser()
685     {
686     folderBrowserDialog = new FolderBrowserDialog();
687     folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
688 william 4 DialogResult result = folderBrowserDialog.ShowDialog();
689 william 180 if (result != DialogResult.OK) return;
690     tftp_path = folderBrowserDialog.SelectedPath.Trim();
691 william 4 }
692     }
693     }
694    

  ViewVC Help
Powered by ViewVC 1.1.22