1 |
william |
145 |
using System; |
2 |
|
|
using System.Collections; |
3 |
|
|
using System.Collections.Generic; |
4 |
|
|
using System.ComponentModel; |
5 |
|
|
using System.Configuration.Install; |
6 |
|
|
using System.Linq; |
7 |
william |
149 |
using System.Reflection; |
8 |
william |
152 |
using System.Threading; |
9 |
|
|
using System.Windows.Forms; |
10 |
|
|
using System.Drawing; |
11 |
william |
157 |
using AnywhereTS.DBSupport; |
12 |
|
|
using System.Data.SqlClient; |
13 |
william |
145 |
|
14 |
|
|
|
15 |
|
|
namespace AnywhereTS |
16 |
|
|
{ |
17 |
|
|
[RunInstaller(true)] |
18 |
|
|
public partial class ATSAmdin : System.Configuration.Install.Installer |
19 |
|
|
{ |
20 |
william |
152 |
string DBServer; |
21 |
|
|
string DBInstance; |
22 |
william |
145 |
public ATSAmdin() |
23 |
|
|
{ |
24 |
|
|
InitializeComponent(); |
25 |
|
|
} |
26 |
william |
157 |
#region Install Members |
27 |
william |
152 |
DatabaseInstallerWaitDialog dlg; |
28 |
|
|
public void InstallDatabaseWaitMessage() |
29 |
|
|
{ |
30 |
|
|
dlg = new DatabaseInstallerWaitDialog("", string.Format(@"Please Wait... Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName)); |
31 |
|
|
dlg.ForeColor = Color.Black; |
32 |
|
|
dlg.ShowDialog(); |
33 |
william |
157 |
} |
34 |
william |
153 |
private void InstallDatabase() |
35 |
|
|
{ |
36 |
|
|
// install the database |
37 |
|
|
Thread db_installer_thread = new Thread(new ThreadStart(InstallDatabaseWaitMessage)); |
38 |
|
|
db_installer_thread.IsBackground = true; |
39 |
|
|
db_installer_thread.Start(); |
40 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat(@"Installing database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); |
41 |
|
|
AnywhereTS.DatabaseSupport dbsup = new DatabaseSupport(); |
42 |
|
|
dbsup.SetupDatabase(); |
43 |
|
|
dlg.Message = string.Format(@"Successfully installed the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); |
44 |
|
|
dlg.ForeColor = Color.Green; |
45 |
|
|
Thread.Sleep(new TimeSpan(0, 0, 15)); |
46 |
|
|
dlg.Close(); |
47 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat(@"Successfully Installed database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
private void ConfigureATS() |
51 |
|
|
{ |
52 |
|
|
try |
53 |
|
|
{ |
54 |
william |
155 |
Logging.ATSAdminInstallerLog.Debug("Configuring AnywhereTS"); |
55 |
william |
153 |
frmAdmin atsadmin = new frmAdmin(); |
56 |
|
|
if (!atsadmin.ConfigureATS()) |
57 |
|
|
{ |
58 |
|
|
throw new Exception("AnywhereTS cannot be installed without configuring it first."); |
59 |
|
|
} |
60 |
william |
155 |
Logging.ATSAdminInstallerLog.Debug("Successfully Configured AnywhereTS"); |
61 |
william |
153 |
} |
62 |
|
|
catch (Exception ex) |
63 |
|
|
{ |
64 |
|
|
// database install failed |
65 |
|
|
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
66 |
|
|
{ |
67 |
|
|
Logging.ATSAdminInstallerLog.Error("ConfigureATS() failed."); |
68 |
|
|
} |
69 |
|
|
throw ex; |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
william |
149 |
public override void Install(IDictionary stateSaver) |
74 |
|
|
{ |
75 |
|
|
base.Install(stateSaver); |
76 |
william |
150 |
try |
77 |
|
|
{ |
78 |
william |
152 |
|
79 |
william |
150 |
string path = this.Context.Parameters["targetdir"]; |
80 |
|
|
Logging.UpdateLogPath(string.Format(@"{0}\logs", path)); |
81 |
|
|
using (log4net.NDC.Push("Logged from ATSAdmin.Installer")) |
82 |
|
|
{ |
83 |
|
|
// setup database |
84 |
william |
152 |
DBServer = this.Context.Parameters["DBSERVER"]; |
85 |
|
|
DBInstance = this.Context.Parameters["DBINSTANCE"]; |
86 |
william |
150 |
// Log the entered data |
87 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Server={0} Instance={1}", DBServer, DBInstance); |
88 |
|
|
CreateRegistryConfigKeys(); |
89 |
|
|
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer); |
90 |
|
|
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance); |
91 |
william |
152 |
ProSupport.strDatabaseServer = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); |
92 |
|
|
ProSupport.strDatabaseInstance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); |
93 |
william |
153 |
|
94 |
|
|
InstallDatabase(); |
95 |
|
|
ConfigureATS(); |
96 |
william |
149 |
} |
97 |
william |
150 |
} |
98 |
|
|
catch (Exception ex) |
99 |
|
|
{ |
100 |
william |
152 |
Logging.ATSAdminInstallerLog.DebugFormat(@"Failed to Install database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); |
101 |
|
|
dlg.Message = string.Format(@"Failed to install the database: {2} to {0}\{1}", DBServer, DBInstance, ATSGlobals.strDatabaseName); |
102 |
|
|
dlg.ForeColor = Color.Red; |
103 |
|
|
Thread.Sleep(new TimeSpan(0, 0, 15)); |
104 |
|
|
dlg.Close(); |
105 |
william |
150 |
// database install failed |
106 |
|
|
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
107 |
william |
149 |
{ |
108 |
william |
150 |
Logging.ATSAdminInstallerLog.Error("Install() failed."); |
109 |
william |
149 |
} |
110 |
william |
150 |
throw ex; |
111 |
william |
149 |
} |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
private void CreateRegistryConfigKeys() |
115 |
|
|
{ |
116 |
william |
150 |
try |
117 |
|
|
{ |
118 |
|
|
Microsoft.Win32.RegistryKey key = null; |
119 |
|
|
if (IntPtr.Size == 8) |
120 |
|
|
{ // 64 bit OS |
121 |
|
|
//string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; |
122 |
|
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true); |
123 |
|
|
key.CreateSubKey("TFTPD32").CreateSubKey("DHCP"); |
124 |
|
|
key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config"); |
125 |
|
|
} |
126 |
|
|
else |
127 |
|
|
{ // 32 bit OS |
128 |
|
|
//strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; |
129 |
|
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true); |
130 |
|
|
key.CreateSubKey("TFTPD32").CreateSubKey("DHCP"); |
131 |
|
|
key = key.CreateSubKey(ATSGlobals.ApplicationName).CreateSubKey("ts-config"); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
// AdminVersion = 2 |
135 |
|
|
key.SetValue("AdminVersion", 2); |
136 |
|
|
// RunFirstTime = 1 |
137 |
|
|
key.SetValue("RunFirstTime", 1); |
138 |
|
|
ATSGlobals.CreateRegistryValues(); |
139 |
william |
149 |
} |
140 |
william |
150 |
catch (Exception ex) |
141 |
|
|
{ |
142 |
william |
152 |
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
143 |
william |
150 |
{ |
144 |
|
|
Logging.ATSAdminInstallerLog.Error("CreateRegistryConfigKeys() failed."); |
145 |
|
|
} |
146 |
william |
149 |
} |
147 |
|
|
} |
148 |
william |
157 |
#endregion |
149 |
|
|
|
150 |
|
|
public override void Uninstall(IDictionary savedState) |
151 |
|
|
{ |
152 |
|
|
using (log4net.NDC.Push("Logged from ATSAdmin.Installer")) |
153 |
|
|
{ |
154 |
|
|
try |
155 |
|
|
{ |
156 |
|
|
string path = this.Context.Parameters["targetdir"]; |
157 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Install Dir: {0}", path); |
158 |
|
|
Logging.UpdateLogPath(string.Format(@"{0}\logs", path)); |
159 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Showing uninstall dialog"); |
160 |
|
|
UninstallDialog udlg = new UninstallDialog(); |
161 |
|
|
DialogResult result = udlg.ShowDialog(); |
162 |
|
|
if (result == DialogResult.Cancel) |
163 |
|
|
{ |
164 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("user aborted uninstall"); |
165 |
|
|
MessageBox.Show("Uninstall canceled ... nothing was uninstalled", "Uinstall was canceled by user", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
166 |
|
|
return; |
167 |
|
|
} |
168 |
|
|
base.Uninstall(savedState); |
169 |
|
|
using (log4net.NDC.Push(string.Format("KeepDatabase={0} KeepApplicationSettings={1} KeepClientImages={2}", udlg.KeepDatabase, udlg.KeepApplicationSettings, udlg.KeepClientImages))) |
170 |
|
|
{ |
171 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Unistall options"); |
172 |
|
|
} |
173 |
|
|
string server = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseServer); |
174 |
|
|
string instance = ATSGlobals.GetATSRegValueString(ProSupport.strRegDatabaseInstance); |
175 |
|
|
string database = ATSGlobals.strDatabaseName; |
176 |
|
|
if (!udlg.KeepDatabase) |
177 |
|
|
{ |
178 |
|
|
Exception ErrorInfo = null; |
179 |
|
|
// delete database |
180 |
|
|
using (MsSqlConnector conn = new MsSqlConnector(server, instance, "master")) |
181 |
|
|
{ |
182 |
|
|
try |
183 |
|
|
{ |
184 |
|
|
conn.CreateConnection(out ErrorInfo); |
185 |
|
|
conn.OpenConnection(out ErrorInfo); |
186 |
|
|
SqlConnection sqlCon; |
187 |
|
|
conn.GetConnectionClone(out sqlCon, out ErrorInfo); |
188 |
|
|
SqlCommand sqlCmd = new SqlCommand(); |
189 |
|
|
sqlCmd.Connection = sqlCon; |
190 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Removing database: {0}", database); |
191 |
|
|
sqlCmd.CommandText = string.Format("DROP DATABASE {0};",database); |
192 |
|
|
sqlCmd.ExecuteNonQuery(); |
193 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed database: {0}", database); |
194 |
|
|
} |
195 |
|
|
catch (Exception ex) |
196 |
|
|
{ |
197 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove database: {0}", database); |
198 |
|
|
ErrorInfo = ex; |
199 |
|
|
} |
200 |
|
|
} |
201 |
|
|
if (ErrorInfo != null) |
202 |
|
|
throw ErrorInfo; |
203 |
|
|
} |
204 |
|
|
if (!udlg.KeepApplicationSettings) |
205 |
|
|
{ |
206 |
|
|
// delete registry settings |
207 |
|
|
try |
208 |
|
|
{ |
209 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Removing AnywhereTS Registry settings"); |
210 |
|
|
Microsoft.Win32.RegistryKey key = null; |
211 |
|
|
if (IntPtr.Size == 8) |
212 |
|
|
{ // 64 bit OS |
213 |
|
|
//string t = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; |
214 |
|
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\", true); |
215 |
|
|
key.DeleteSubKey("TFTPD32", false); |
216 |
|
|
key.DeleteSubKey(ATSGlobals.ApplicationName, false); |
217 |
|
|
} |
218 |
|
|
else |
219 |
|
|
{ // 32 bit OS |
220 |
|
|
//strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; |
221 |
|
|
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true); |
222 |
|
|
key.DeleteSubKey("TFTPD32", false); |
223 |
|
|
key.DeleteSubKey(ATSGlobals.ApplicationName, false); |
224 |
|
|
} |
225 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Successfully removed AnywhereTS Registry settings"); |
226 |
|
|
} |
227 |
|
|
catch (Exception ex) |
228 |
|
|
{ |
229 |
|
|
Logging.ATSAdminInstallerLog.DebugFormat("Failed to remove AnywhereTS Registry settings"); |
230 |
|
|
throw ex; |
231 |
|
|
} |
232 |
|
|
} |
233 |
|
|
if (!udlg.KeepClientImages) |
234 |
|
|
{ |
235 |
|
|
// delete client images |
236 |
|
|
try |
237 |
|
|
{ |
238 |
|
|
} |
239 |
|
|
catch (Exception ex) |
240 |
|
|
{ |
241 |
|
|
} |
242 |
|
|
} |
243 |
|
|
} |
244 |
|
|
catch (Exception ex) |
245 |
|
|
{ |
246 |
|
|
// database install failed |
247 |
|
|
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
248 |
|
|
{ |
249 |
|
|
Logging.ATSAdminInstallerLog.Error("Install() failed."); |
250 |
|
|
} |
251 |
|
|
throw ex; |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
} |
255 |
william |
145 |
} |
256 |
|
|
} |