1 |
//#define HAVE_FRMCONFIGMODE // when set frmConfigMode can be used, otherwise it is disabled |
2 |
#if HAVE_FRMCONFIGMODE |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.ComponentModel; |
6 |
using System.Data; |
7 |
using System.Drawing; |
8 |
using System.Text; |
9 |
using System.Windows.Forms; |
10 |
using System.IO; |
11 |
|
12 |
namespace AnywhereTS |
13 |
{ |
14 |
public partial class frmConfigMode : Form |
15 |
{ |
16 |
DatabaseSupport dataSupport; |
17 |
|
18 |
public frmConfigMode() |
19 |
{ |
20 |
InitializeComponent(); |
21 |
} |
22 |
|
23 |
private void Mode_Load(object sender, EventArgs e) |
24 |
{ |
25 |
//this.Cursor = Cursors.WaitCursor; |
26 |
if (ATSGlobals.configured == 0) |
27 |
{ // ATS not configured yet |
28 |
radManagedMode.Checked = true; |
29 |
//txtDatabasePath.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS"; |
30 |
txtDestinationDir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\AnywhereTS"; |
31 |
} |
32 |
else |
33 |
{ // ATS already configured |
34 |
//txtDatabasePath.Text = ProSupport.strDatabasePath; |
35 |
txtDestinationDir.Text = ProSupport.strDestDir; |
36 |
txtDatabasePath.Enabled = false; |
37 |
btnBrowseDatabase.Enabled = false; |
38 |
// Update radio buttons |
39 |
if (ATSGlobals.managedMode == 1) |
40 |
// We are running in managed mode |
41 |
radManagedMode.Checked = true; |
42 |
|
43 |
else if (ATSGlobals.managedMode == 2) |
44 |
{ // We are running in unmanaged mode |
45 |
radUnmanagedMode.Checked = true; |
46 |
} |
47 |
} |
48 |
|
49 |
this.Cursor = Cursors.Default; |
50 |
|
51 |
} |
52 |
|
53 |
|
54 |
private void btnOK_Click(object sender, EventArgs e) |
55 |
{ |
56 |
if (radManagedMode.Checked) |
57 |
{ // Managed mode is selected |
58 |
// Validate database directory |
59 |
if (txtDatabasePath.Text.Trim().Length == 0) |
60 |
{ |
61 |
MessageBox.Show("You must specifiy a directory for the AnywhereTS database."); |
62 |
txtDatabasePath.Focus(); |
63 |
return; |
64 |
} |
65 |
this.Cursor = Cursors.WaitCursor; |
66 |
|
67 |
// Create Datbase directory |
68 |
try |
69 |
{ |
70 |
Directory.CreateDirectory(txtDatabasePath.Text.Trim()); |
71 |
} |
72 |
catch (Exception ex) |
73 |
{ |
74 |
this.Cursor = Cursors.Default; |
75 |
MessageBox.Show("Could not create directory '" + txtDatabasePath.Text.Trim() + "'. Error: " + ex.Message); |
76 |
using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString()))) |
77 |
{ |
78 |
using (log4net.NDC.Push(string.Format("directory={0}", txtDatabasePath.Text))) |
79 |
{ |
80 |
Logging.ATSAdminLog.Error("Could not create directory."); |
81 |
} |
82 |
} |
83 |
return; |
84 |
} |
85 |
|
86 |
// Save the database directory to registry |
87 |
ProSupport.strDatabasePath = txtDatabasePath.Text.Trim(); |
88 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath); |
89 |
|
90 |
// Set up database |
91 |
dataSupport = new DatabaseSupport(); |
92 |
dataSupport.SetupDatabase(); // Creates updates the database if necessary |
93 |
|
94 |
ATSGlobals.managedMode = 1; // We are running in Managed Mode |
95 |
} |
96 |
else if (radUnmanagedMode.Checked) |
97 |
{ // Unmanaged mode is selected |
98 |
// Validate database dest dir |
99 |
if (txtDestinationDir.Text.Trim().Length == 0) |
100 |
{ |
101 |
MessageBox.Show("You must specifiy a destination directory for the AnywhereTS boot image files."); |
102 |
txtDestinationDir.Focus(); |
103 |
return; |
104 |
} |
105 |
|
106 |
// Create Dest directory |
107 |
try |
108 |
{ |
109 |
Directory.CreateDirectory(txtDestinationDir.Text.Trim()); |
110 |
} |
111 |
catch (Exception ex) |
112 |
{ |
113 |
this.Cursor = Cursors.Default; |
114 |
MessageBox.Show("Could not create directory '" + txtDestinationDir.Text.Trim() + "'. Error: " + ex.Message); |
115 |
using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString()))) |
116 |
{ |
117 |
using (log4net.NDC.Push(string.Format("directory={0}", txtDestinationDir.Text))) |
118 |
{ |
119 |
Logging.ATSAdminLog.Error("Could not create directory."); |
120 |
} |
121 |
} |
122 |
return; |
123 |
} |
124 |
|
125 |
ATSGlobals.managedMode = 2; // We are running in unmanaged mode |
126 |
// No services should be run in unmanaged mode |
127 |
ATSGlobals.dhcpConfig = 1; // Other DHCP |
128 |
ATSGlobals.tftpConfig = 1; // Other TFTP |
129 |
ProSupport.strDestDir = txtDestinationDir.Text.Trim(); |
130 |
|
131 |
} |
132 |
else |
133 |
{ |
134 |
string error = "Error: Unknown mode (84377)"; |
135 |
using (log4net.NDC.Push(string.Format("mode={0}", ATSGlobals.managedMode))) |
136 |
{ |
137 |
Logging.ATSAdminLog.Error(error); |
138 |
} |
139 |
MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("mode={0}", ATSGlobals.managedMode))); |
140 |
return; |
141 |
|
142 |
} |
143 |
// Save the database directory to registry |
144 |
ProSupport.strDatabasePath = txtDatabasePath.Text.Trim(); |
145 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath); |
146 |
|
147 |
// Save mode |
148 |
ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode); |
149 |
|
150 |
// Save destination directory |
151 |
ATSGlobals.SetATSRegValue(ProSupport.strRegDestDir, ProSupport.strDestDir); |
152 |
|
153 |
// Terminate window |
154 |
this.Cursor = Cursors.Default; |
155 |
DialogResult = DialogResult.OK; |
156 |
} |
157 |
|
158 |
private void btnBrowseDatabase_Click(object sender, EventArgs e) |
159 |
{ |
160 |
// Show the FolderBrowserDialog. |
161 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
162 |
if (result == DialogResult.OK) |
163 |
{ |
164 |
txtDatabasePath.Text = folderBrowserDialog.SelectedPath; |
165 |
} |
166 |
} |
167 |
|
168 |
private void radManagedMode_CheckedChanged(object sender, EventArgs e) |
169 |
{ |
170 |
UpdateControls(); |
171 |
} |
172 |
|
173 |
private void radUnmanagedMode_CheckedChanged(object sender, EventArgs e) |
174 |
{ |
175 |
UpdateControls(); |
176 |
} |
177 |
|
178 |
private void UpdateControls() |
179 |
{ |
180 |
if (radManagedMode.Checked) |
181 |
{ // Managed mode |
182 |
//lblDatabasePath.Enabled = true; |
183 |
//txtDatabasePath.Enabled = true; |
184 |
//btnBrowseDatabase.Enabled = true; |
185 |
lblDestinationDir.Enabled = false; |
186 |
txtDestinationDir.Enabled = false; |
187 |
btnBrowseDestinationDir.Enabled = false; |
188 |
btnOK.Text = "Next >"; |
189 |
} |
190 |
else |
191 |
{ // Unmanaged mode |
192 |
//lblDatabasePath.Enabled = false; |
193 |
//txtDatabasePath.Enabled = false; |
194 |
//btnBrowseDatabase.Enabled = false; |
195 |
lblDestinationDir.Enabled = true; |
196 |
txtDestinationDir.Enabled = true; |
197 |
btnBrowseDestinationDir.Enabled = true; |
198 |
btnOK.Text = "Finish"; |
199 |
} |
200 |
|
201 |
} |
202 |
|
203 |
private void btnBrowseDestinationDir_Click(object sender, EventArgs e) |
204 |
{ |
205 |
// Show the FolderBrowserDialog. |
206 |
DialogResult result = folderBrowserDialog.ShowDialog(); |
207 |
if (result == DialogResult.OK) |
208 |
{ |
209 |
txtDestinationDir.Text = folderBrowserDialog.SelectedPath; |
210 |
} |
211 |
} |
212 |
|
213 |
} |
214 |
} |
215 |
#endif |