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

Contents of /trunk/TSAdminTool/frmConfigureMode.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download)
Wed Jul 11 14:19:13 2012 UTC (7 years, 7 months ago) by william
File size: 7720 byte(s)
imported from https://anywherets.svn.sourceforge.net/svnroot/anywherets/trunk/
Revision: 1
Author: beartown
Date: 3:10:40 AM, Monday, June 21, 2010
Message:
First upload. Still todo in order to get a fully working product: Replace Thinstation images with vanilla Thinstation, modify ImageDesigntimeConfig.cs, ImageRuntimeConfig.cs in order to support the Thinstation image
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9 using System.Security.AccessControl;
10 using System.Security.Principal;
11
12 namespace AnywhereTS
13 {
14 public partial class frmConfigureMode : Form
15 {
16 public frmConfigureMode()
17 {
18 InitializeComponent();
19 }
20
21 DatabaseSupport dataSupport;
22
23 private void radMangedMode_CheckedChanged(object sender, EventArgs e)
24 {
25 if (radManagedMode.Checked)
26 {
27 lblTFTPpath.Enabled = true;
28 txtTFTPpath.Enabled = true;
29 btnBrowseTFTP.Enabled = true;
30 lblDatabasePath.Enabled = true;
31 txtDatabasePath.Enabled = true;
32 btnBrowseDatabase.Enabled = true;
33 }
34 }
35
36 private void radUnmanagedMode_CheckedChanged(object sender, EventArgs e)
37 {
38 if (radUnmanagedMode.Checked)
39 {
40 lblTFTPpath.Enabled = false;
41 txtTFTPpath.Enabled = false;
42 btnBrowseTFTP.Enabled = false;
43 lblDatabasePath.Enabled = false;
44 txtDatabasePath.Enabled = false;
45 btnBrowseDatabase.Enabled = false;
46 }
47
48 }
49
50 private void frmConfigureMode_Load(object sender, EventArgs e)
51 {
52 if (ATSGlobals.managedMode == 0)
53 { // Mode not selected yet
54 radManagedMode.Checked = true;
55 txtTFTPpath.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS\TFTP";
56 txtDatabasePath.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS";
57 }
58 else if (ATSGlobals.managedMode == 1)
59 { // We are already running in mangaed mode
60 radManagedMode.Checked = true;
61 txtTFTPpath.Text = ATSGlobals.strTFTPdir;
62 txtDatabasePath.Text = ProSupport.strDatabasePath;
63 txtTFTPpath.Enabled = false;
64 txtDatabasePath.Enabled = false;
65 btnBrowseDatabase.Enabled = false;
66 btnBrowseTFTP.Enabled = false;
67 }
68 else if (ATSGlobals.managedMode == 2)
69 { // We are running in unmanaged mode
70 radUnmanagedMode.Checked = true;
71 }
72 }
73
74 private void btnBrowseTFTP_Click(object sender, EventArgs e)
75 {
76 // Show the FolderBrowserDialog.
77 DialogResult result = folderBrowserDialog.ShowDialog();
78 if (result == DialogResult.OK)
79 {
80 txtTFTPpath.Text = folderBrowserDialog.SelectedPath;
81 }
82 }
83
84 private void btnBrowseDatabase_Click(object sender, EventArgs e)
85 {
86 // Show the FolderBrowserDialog.
87 DialogResult result = folderBrowserDialog.ShowDialog();
88 if (result == DialogResult.OK)
89 {
90 txtDatabasePath.Text = folderBrowserDialog.SelectedPath;
91 }
92 }
93
94 private void btnOK_Click(object sender, EventArgs e)
95 {
96
97 if (radManagedMode.Checked)
98 {
99 ATSGlobals.managedMode = 1; // We are running in Managed Mode
100
101 // Validate directories
102 if (txtTFTPpath.Text.Trim().Length == 0)
103 {
104 MessageBox.Show("You must specifiy a directory for the AnywhereTS shared network files.");
105 txtDatabasePath.Focus();
106 return;
107 }
108
109 if (txtDatabasePath.Text.Trim().Length == 0)
110 {
111 MessageBox.Show("You must specifiy a directory for the AnywhereTS database.");
112 txtDatabasePath.Focus();
113 return;
114 }
115
116 // Create TFTP directory
117 try
118 {
119 Directory.CreateDirectory(txtTFTPpath.Text);
120 }
121 catch (Exception ex)
122 {
123 MessageBox.Show("Could not create directory '" + txtTFTPpath.Text + "'. Error: " + ex.Message);
124 return;
125 }
126
127 // Set user rights to TFTP directory, all remote desktop users should be able to write files.
128 try
129 {
130 // Create a new DirectoryInfo object.
131 DirectoryInfo dInfo = new DirectoryInfo(txtTFTPpath.Text);
132
133 // Get a DirectorySecurity object that represents the
134 // current security settings.
135 DirectorySecurity dSecurity = dInfo.GetAccessControl();
136
137 // Add a FileSystemAccessRule to the security settings, to allow write.
138 // No general rights to delete files. These rights are set on the individual files.
139 dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinRemoteDesktopUsersSid, null), FileSystemRights.Write, AccessControlType.Allow));
140
141 // Set the new access settings.
142 dInfo.SetAccessControl(dSecurity);
143
144 }
145 catch (Exception ex)
146 {
147 MessageBox.Show("Could not set user access rights for TFTP directory. Do you have sufficient right? (29991). Error: " + ex.Message);
148 return;
149 }
150
151
152 // Create Datbase directory
153 try
154 {
155 Directory.CreateDirectory(txtDatabasePath.Text.Trim());
156 }
157 catch (Exception ex)
158 {
159 MessageBox.Show("Could not create directory '" + txtTFTPpath.Text + "'. Error: " + ex.Message);
160 return;
161 }
162
163 // Set user rights in TFTP directory
164
165
166
167 // Save the TFTP directory to registry
168 ATSGlobals.strTFTPdir = txtTFTPpath.Text.Trim(); // Set the C# version of TFTP dir
169 Globals.strTFTPdir = ATSGlobals.strTFTPdir; // Set the VB version of TFTP dir
170 ATSGlobals.SetATSRegValue(ATSGlobals.strRegTFTP_root, ATSGlobals.strTFTPdir);
171
172 // Save the database directory to registry
173 ProSupport.strDatabasePath = txtDatabasePath.Text.Trim();
174 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath);
175
176 // Set up database
177 dataSupport = new DatabaseSupport();
178 dataSupport.SetupDatabase(); // Creates updates the database if necessary
179
180 // Configure TFTPD32
181 AtsDhcp.SetTFTPD32service(true, false);
182 }
183 else if (radUnmanagedMode.Checked)
184 {
185 ATSGlobals.managedMode = 2; // We are running in unmanaged mode
186 AtsDhcp.SetTFTPD32service(false, false);
187 }
188 else
189 throw new Exception("Error: Unknown mode (8777)");
190
191
192 // Save mode
193 ATSGlobals.SetATSRegValue(ProSupport.strRegManagedMode, ATSGlobals.managedMode);
194
195 // Terminate window
196 DialogResult = DialogResult.OK;
197 }
198 }
199 }

  ViewVC Help
Powered by ViewVC 1.1.22