using System.IO;
using System.Diagnostics;
using System.Reflection;
+using log4net;
namespace AppLimit.NetSparkle
{
public partial class NetSparkleDownloadProgress : Form
{
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
private String _tempName;
private NetSparkleAppCastItem _item;
private String _referencedAssembly;
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
progressDownload.Visible = false;
- btnInstallAndReLaunch.Visible = true;
+ btnInstallAndReLaunch.Visible = true;
+
+ if (e.Error != null)
+ {
+ Log.Error("Update download failed ",e.Error);
+ Size = new Size(Size.Width, 137);
+ lblSecurityHint.Text = "An error occured while downloading the update. Please try again later.";
+ lblSecurityHint.Visible = true;
+ BackColor = Color.Tomato;
+ _sparkle.ReportDiagnosticMessage("Failed downloading file to: " + _tempName);
+ btnInstallAndReLaunch.Click-=btnInstallAndReLaunch_Click;
+ btnInstallAndReLaunch.Text = "Close";
+ btnInstallAndReLaunch.Click+=(s,args)=> Close();
+ btnInstallAndReLaunch.Visible = true;
+ return;
+ }
// report message
_sparkle.ReportDiagnosticMessage("Finished downloading file to: " + _tempName);
{
_sparkle.ReportDiagnosticMessage("No DSA check needed");
}
- else
+ /*else
{
Boolean bDSAOk = false;
lblSecurityHint.Visible = true;
BackColor = Color.Tomato;
}
- }
+ }*/
// Check the unattended mode
if (_unattend)
private void btnInstallAndReLaunch_Click(object sender, EventArgs e)
{
- // get the commandline
- String cmdLine = Environment.CommandLine;
- String workingDir = Environment.CurrentDirectory;
+ try
+ {
- // generate the batch file path
- String cmd = Environment.ExpandEnvironmentVariables("%temp%\\" + Guid.NewGuid() + ".cmd");
- String installerCMD;
+ // get the commandline
+ String cmdLine = Environment.CommandLine;
+ String workingDir = Environment.CurrentDirectory;
- // get the file type
- if (Path.GetExtension(_tempName).ToLower().Equals(".exe"))
- {
- // build the command line
- installerCMD = _tempName;
- }
- else if (Path.GetExtension(_tempName).ToLower().Equals(".msi"))
- {
- // buid the command line
- installerCMD = "msiexec /i \"" + _tempName + "\"";
- }
- else
- {
- MessageBox.Show("Updater not supported, please execute " + _tempName + " manually", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- Environment.Exit(-1);
- return;
- }
+ // generate the batch file path
- // generate the batch file
- _sparkle.ReportDiagnosticMessage("Generating MSI batch in " + Path.GetFullPath(cmd));
+ String cmd = Environment.ExpandEnvironmentVariables("%temp%\\" + Guid.NewGuid() + ".cmd");
+ String installerCMD;
- StreamWriter write = new StreamWriter(cmd);
- write.WriteLine(installerCMD);
- write.WriteLine("cd " + workingDir);
- write.WriteLine(cmdLine);
- write.Close();
+ // get the file type
+ var extension = Path.GetExtension(_tempName).ToLower();
+ switch (extension)
+ {
+ case ".exe":
+ installerCMD = _tempName;
+ break;
+ case ".msi":
+ installerCMD = String.Format("msiexec /i \"{0}\"", _tempName);
+ break;
+ default:
+ MessageBox.Show("Updater not supported, please execute " + _tempName + " manually", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ Environment.Exit(-1);
+ return;
+ }
- // report
- _sparkle.ReportDiagnosticMessage("Going to execute batch: " + cmd);
+ // generate the batch file
+ _sparkle.ReportDiagnosticMessage("Generating MSI batch in " + Path.GetFullPath(cmd));
- // start the installer helper
- Process process = new Process();
- process.StartInfo.FileName = cmd;
- process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- process.Start();
-
+ using (var write = new StreamWriter(cmd))
+ {
+ write.WriteLine(installerCMD);
+ write.WriteLine("cd " + workingDir);
+ write.WriteLine(cmdLine);
+ write.Close();
+ }
+
+ // report
+ _sparkle.ReportDiagnosticMessage("Going to execute batch: " + cmd);
+
+ // start the installer helper
+ var process = new Process();
+ process.StartInfo.FileName = cmd;
+ process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+ process.Start();
- // quit the app
- Environment.Exit(0);
+ // quit the app
+ Environment.Exit(0);
+ }
+ catch (Exception exc)
+ {
+
+ Log.Error("Error while launching the update", exc);
+ this.DialogResult = DialogResult.Cancel;
+ MessageBox.Show("An error occured while executing the update.", "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
}
}
}