Revision 6f03d6e1 trunk/NetSparkle/NetSparkleDownloadProgress.cs
b/trunk/NetSparkle/NetSparkleDownloadProgress.cs | ||
---|---|---|
11 | 11 |
using System.IO; |
12 | 12 |
using System.Diagnostics; |
13 | 13 |
using System.Reflection; |
14 |
using log4net; |
|
14 | 15 |
|
15 | 16 |
namespace AppLimit.NetSparkle |
16 | 17 |
{ |
17 | 18 |
public partial class NetSparkleDownloadProgress : Form |
18 | 19 |
{ |
20 |
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
|
21 |
|
|
19 | 22 |
private String _tempName; |
20 | 23 |
private NetSparkleAppCastItem _item; |
21 | 24 |
private String _referencedAssembly; |
... | ... | |
69 | 72 |
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
70 | 73 |
{ |
71 | 74 |
progressDownload.Visible = false; |
72 |
btnInstallAndReLaunch.Visible = true; |
|
75 |
btnInstallAndReLaunch.Visible = true; |
|
76 |
|
|
77 |
if (e.Error != null) |
|
78 |
{ |
|
79 |
Log.Error("Update download failed ",e.Error); |
|
80 |
Size = new Size(Size.Width, 137); |
|
81 |
lblSecurityHint.Text = "An error occured while downloading the update. Please try again later."; |
|
82 |
lblSecurityHint.Visible = true; |
|
83 |
BackColor = Color.Tomato; |
|
84 |
_sparkle.ReportDiagnosticMessage("Failed downloading file to: " + _tempName); |
|
85 |
btnInstallAndReLaunch.Click-=btnInstallAndReLaunch_Click; |
|
86 |
btnInstallAndReLaunch.Text = "Close"; |
|
87 |
btnInstallAndReLaunch.Click+=(s,args)=> Close(); |
|
88 |
btnInstallAndReLaunch.Visible = true; |
|
89 |
return; |
|
90 |
} |
|
73 | 91 |
|
74 | 92 |
// report message |
75 | 93 |
_sparkle.ReportDiagnosticMessage("Finished downloading file to: " + _tempName); |
... | ... | |
129 | 147 |
|
130 | 148 |
private void btnInstallAndReLaunch_Click(object sender, EventArgs e) |
131 | 149 |
{ |
132 |
// get the commandline |
|
133 |
String cmdLine = Environment.CommandLine; |
|
134 |
String workingDir = Environment.CurrentDirectory; |
|
150 |
try |
|
151 |
{ |
|
135 | 152 |
|
136 |
// generate the batch file path |
|
137 |
|
|
138 |
String cmd = Environment.ExpandEnvironmentVariables("%temp%\\" + Guid.NewGuid() + ".cmd"); |
|
139 |
String installerCMD; |
|
153 |
// get the commandline |
|
154 |
String cmdLine = Environment.CommandLine; |
|
155 |
String workingDir = Environment.CurrentDirectory; |
|
140 | 156 |
|
141 |
// get the file type |
|
142 |
var extension = Path.GetExtension(_tempName).ToLower(); |
|
143 |
switch (extension) |
|
144 |
{ |
|
145 |
case ".exe": |
|
146 |
installerCMD = _tempName; |
|
147 |
break; |
|
148 |
case ".msi": |
|
149 |
installerCMD = String.Format("msiexec /i \"{0}\"",_tempName); |
|
150 |
break; |
|
151 |
default: |
|
152 |
MessageBox.Show("Updater not supported, please execute " + _tempName + " manually", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
153 |
Environment.Exit(-1); |
|
154 |
return; |
|
155 |
} |
|
157 |
// generate the batch file path |
|
156 | 158 |
|
157 |
// generate the batch file
|
|
158 |
_sparkle.ReportDiagnosticMessage("Generating MSI batch in " + Path.GetFullPath(cmd));
|
|
159 |
String cmd = Environment.ExpandEnvironmentVariables("%temp%\\" + Guid.NewGuid() + ".cmd");
|
|
160 |
String installerCMD;
|
|
159 | 161 |
|
160 |
using (var write = new StreamWriter(cmd)) |
|
161 |
{ |
|
162 |
write.WriteLine(installerCMD); |
|
163 |
write.WriteLine("cd " + workingDir); |
|
164 |
write.WriteLine(cmdLine); |
|
165 |
write.Close(); |
|
166 |
} |
|
162 |
// get the file type |
|
163 |
var extension = Path.GetExtension(_tempName).ToLower(); |
|
164 |
switch (extension) |
|
165 |
{ |
|
166 |
case ".exe": |
|
167 |
installerCMD = _tempName; |
|
168 |
break; |
|
169 |
case ".msi": |
|
170 |
installerCMD = String.Format("msiexec /i \"{0}\"", _tempName); |
|
171 |
break; |
|
172 |
default: |
|
173 |
MessageBox.Show("Updater not supported, please execute " + _tempName + " manually", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
174 |
Environment.Exit(-1); |
|
175 |
return; |
|
176 |
} |
|
167 | 177 |
|
168 |
// report
|
|
169 |
_sparkle.ReportDiagnosticMessage("Going to execute batch: " + cmd);
|
|
178 |
// generate the batch file
|
|
179 |
_sparkle.ReportDiagnosticMessage("Generating MSI batch in " + Path.GetFullPath(cmd));
|
|
170 | 180 |
|
171 |
// start the installer helper |
|
172 |
var process = new Process(); |
|
173 |
process.StartInfo.FileName = cmd; |
|
174 |
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; |
|
175 |
process.Start(); |
|
181 |
using (var write = new StreamWriter(cmd)) |
|
182 |
{ |
|
183 |
write.WriteLine(installerCMD); |
|
184 |
write.WriteLine("cd " + workingDir); |
|
185 |
write.WriteLine(cmdLine); |
|
186 |
write.Close(); |
|
187 |
} |
|
176 | 188 |
|
177 |
// quit the app |
|
178 |
Environment.Exit(0); |
|
189 |
// report |
|
190 |
_sparkle.ReportDiagnosticMessage("Going to execute batch: " + cmd); |
|
191 |
|
|
192 |
// start the installer helper |
|
193 |
var process = new Process(); |
|
194 |
process.StartInfo.FileName = cmd; |
|
195 |
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; |
|
196 |
process.Start(); |
|
197 |
|
|
198 |
// quit the app |
|
199 |
Environment.Exit(0); |
|
200 |
} |
|
201 |
catch (Exception exc) |
|
202 |
{ |
|
203 |
|
|
204 |
Log.Error("Error while launching the update", exc); |
|
205 |
this.DialogResult = DialogResult.Cancel; |
|
206 |
MessageBox.Show("An error occured while executing the update.", "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
|
207 |
} |
|
179 | 208 |
} |
180 | 209 |
} |
181 | 210 |
} |
Also available in: Unified diff