Fixing updater to better check version. Preventing accidentally updating to older version when testing.

This commit is contained in:
niel-archer 2012-02-08 16:02:54 +00:00
parent ce3c5e6493
commit b17e824301
4 changed files with 187 additions and 127 deletions

Binary file not shown.

View file

@ -8,7 +8,7 @@
<body style="background-color: white; font-family: Verdana, sans-serif;font-size: 13px;line-height: 1.3"> <body style="background-color: white; font-family: Verdana, sans-serif;font-size: 13px;line-height: 1.3">
<div> <div>
<div> <div>
<h3><span class="date">2012-02-01</span> - Release 2.44.1</h3> <h3><span class="date">2012-02-08</span> - Release 2.44.1</h3>
- Added: constants: - Added: constants:
<ul> <ul>
<li>AGENT_AUTOPILOT</li> <li>AGENT_AUTOPILOT</li>
@ -51,6 +51,7 @@
<ul> <ul>
<li>Opening files no longer assumes ANSI format. Instead, we attempt to detect file encoding and default to UTF-8 if no encoding is obvious.</li> <li>Opening files no longer assumes ANSI format. Instead, we attempt to detect file encoding and default to UTF-8 if no encoding is obvious.</li>
<li>Removed ANSI as an output format option.</li> <li>Removed ANSI as an output format option.</li>
<li>Fixed updater to disallow accidental updating with older files.</li>
</ul> </ul>
</div> </div>
<div> <div>

View file

@ -29,27 +29,27 @@ namespace LSLEditor
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label(); this.labelHelpversionString = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label(); this.labelHelpFile = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label4 = new System.Windows.Forms.Label(); this.labelLatestVersionString = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label(); this.labelOurVersionString = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.labelLatestVersion = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.labelOurVersion = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.labelHelpversionString);
this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.labelHelpFile);
this.groupBox1.Controls.Add(this.progressBar1); this.groupBox1.Controls.Add(this.progressBar1);
this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.labelLatestVersionString);
this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.labelOurVersionString);
this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.labelLatestVersion);
this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.labelOurVersion);
this.groupBox1.Location = new System.Drawing.Point(8, 8); this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(216, 128); this.groupBox1.Size = new System.Drawing.Size(216, 128);
@ -57,22 +57,22 @@ namespace LSLEditor
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "version information"; this.groupBox1.Text = "version information";
// //
// label6 // labelHelpversionString
// //
this.label6.AutoSize = true; this.labelHelpversionString.AutoSize = true;
this.label6.Location = new System.Drawing.Point(104, 72); this.labelHelpversionString.Location = new System.Drawing.Point(104, 72);
this.label6.Name = "label6"; this.labelHelpversionString.Name = "labelHelpversionString";
this.label6.Size = new System.Drawing.Size(0, 13); this.labelHelpversionString.Size = new System.Drawing.Size(0, 13);
this.label6.TabIndex = 6; this.labelHelpversionString.TabIndex = 6;
// //
// label5 // labelHelpFile
// //
this.label5.AutoSize = true; this.labelHelpFile.AutoSize = true;
this.label5.Location = new System.Drawing.Point(16, 72); this.labelHelpFile.Location = new System.Drawing.Point(16, 72);
this.label5.Name = "label5"; this.labelHelpFile.Name = "labelHelpFile";
this.label5.Size = new System.Drawing.Size(48, 13); this.labelHelpFile.Size = new System.Drawing.Size(48, 13);
this.label5.TabIndex = 5; this.labelHelpFile.TabIndex = 5;
this.label5.Text = "Help file:"; this.labelHelpFile.Text = "Help file:";
// //
// progressBar1 // progressBar1
// //
@ -81,67 +81,67 @@ namespace LSLEditor
this.progressBar1.Size = new System.Drawing.Size(184, 15); this.progressBar1.Size = new System.Drawing.Size(184, 15);
this.progressBar1.TabIndex = 4; this.progressBar1.TabIndex = 4;
// //
// label4 // labelLatestVersionString
// //
this.label4.AutoSize = true; this.labelLatestVersionString.AutoSize = true;
this.label4.Location = new System.Drawing.Point(104, 48); this.labelLatestVersionString.Location = new System.Drawing.Point(104, 48);
this.label4.Name = "label4"; this.labelLatestVersionString.Name = "labelLatestVersionString";
this.label4.Size = new System.Drawing.Size(0, 13); this.labelLatestVersionString.Size = new System.Drawing.Size(0, 13);
this.label4.TabIndex = 3; this.labelLatestVersionString.TabIndex = 3;
// //
// label3 // labelOurVersionString
// //
this.label3.AutoSize = true; this.labelOurVersionString.AutoSize = true;
this.label3.Location = new System.Drawing.Point(104, 24); this.labelOurVersionString.Location = new System.Drawing.Point(104, 24);
this.label3.Name = "label3"; this.labelOurVersionString.Name = "labelOurVersionString";
this.label3.Size = new System.Drawing.Size(0, 13); this.labelOurVersionString.Size = new System.Drawing.Size(0, 13);
this.label3.TabIndex = 2; this.labelOurVersionString.TabIndex = 2;
// //
// label2 // labelLatestVersion
// //
this.label2.AutoSize = true; this.labelLatestVersion.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 48); this.labelLatestVersion.Location = new System.Drawing.Point(16, 48);
this.label2.Name = "label2"; this.labelLatestVersion.Name = "labelLatestVersion";
this.label2.Size = new System.Drawing.Size(81, 13); this.labelLatestVersion.Size = new System.Drawing.Size(76, 13);
this.label2.TabIndex = 1; this.labelLatestVersion.TabIndex = 1;
this.label2.Text = "Current version:"; this.labelLatestVersion.Text = "Latest version:";
// //
// label1 // labelOurVersion
// //
this.label1.AutoSize = true; this.labelOurVersion.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 24); this.labelOurVersion.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1"; this.labelOurVersion.Name = "labelOurVersion";
this.label1.Size = new System.Drawing.Size(69, 13); this.labelOurVersion.Size = new System.Drawing.Size(69, 13);
this.label1.TabIndex = 0; this.labelOurVersion.TabIndex = 0;
this.label1.Text = "Your version:"; this.labelOurVersion.Text = "Your version:";
// //
// button1 // buttonUpdate
// //
this.button1.Location = new System.Drawing.Point(48, 144); this.buttonUpdate.Location = new System.Drawing.Point(48, 144);
this.button1.Name = "button1"; this.buttonUpdate.Name = "buttonUpdate";
this.button1.Size = new System.Drawing.Size(75, 23); this.buttonUpdate.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1; this.buttonUpdate.TabIndex = 1;
this.button1.Text = "Update"; this.buttonUpdate.Text = "Update";
this.button1.UseVisualStyleBackColor = true; this.buttonUpdate.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
// //
// button2 // buttonCancel
// //
this.button2.Location = new System.Drawing.Point(136, 144); this.buttonCancel.Location = new System.Drawing.Point(136, 144);
this.button2.Name = "button2"; this.buttonCancel.Name = "buttonCancel";
this.button2.Size = new System.Drawing.Size(75, 23); this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2; this.buttonCancel.TabIndex = 2;
this.button2.Text = "Cancel"; this.buttonCancel.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
// //
// UpdateApplicationForm // UpdateApplicationForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(234, 177); this.ClientSize = new System.Drawing.Size(234, 177);
this.Controls.Add(this.button2); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.button1); this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false; this.MaximizeBox = false;
@ -160,14 +160,14 @@ namespace LSLEditor
#endregion #endregion
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label labelLatestVersionString;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label labelOurVersionString;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label labelLatestVersion;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label labelOurVersion;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button buttonUpdate;
private System.Windows.Forms.Button button2; private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label6; private System.Windows.Forms.Label labelHelpversionString;
private System.Windows.Forms.Label label5; private System.Windows.Forms.Label labelHelpFile;
} }
} }

View file

@ -55,24 +55,52 @@ namespace LSLEditor
private WebClient manifest; private WebClient manifest;
private WebClient client; private WebClient client;
private string strHashNew; private string strHashWeb;
private string strDownloadUrl; private string strDownloadUrl;
private string strHelpHashNew; private string strHelpHashWeb;
private string strHelpUrl; private string strHelpUrl;
private string strHelpReferer; private string strHelpReferer;
private bool blnOnlyHelpFile; private bool blnOnlyHelpFile;
private struct versionInfo
{
public Version version;
public string hash;
public string uri;
public versionInfo(string ver)
{
version = new Version(ver);
hash = "";
uri = "";
}
public versionInfo(string ver, string md5)
{
version = new Version(ver);
hash = md5;
uri = "";
}
public versionInfo(string ver, string md5, string URI)
{
version = new Version(ver);
hash = md5;
uri = URI;
}
}
public UpdateApplicationForm() public UpdateApplicationForm()
{ {
InitializeComponent(); InitializeComponent();
this.strHashNew = ""; this.strHashWeb = "";
this.strHelpHashNew = ""; this.strHelpHashWeb = "";
this.strDownloadUrl = null; this.strDownloadUrl = null;
this.strHelpUrl = null; this.strHelpUrl = null;
this.strHelpReferer = null; this.strHelpReferer = null;
this.button1.Enabled = false; this.buttonUpdate.Enabled = false;
this.blnOnlyHelpFile = false; this.blnOnlyHelpFile = false;
} }
@ -123,44 +151,48 @@ namespace LSLEditor
if (blnForce) if (blnForce)
{ {
Properties.Settings.Default.CheckDate = DateTime.Now; Properties.Settings.Default.CheckDate = DateTime.Now;
Properties.Settings.Default.Save(); // save also al settings Properties.Settings.Default.Save(); // save also all settings
StartDownloadinManifest(); StartDownloadinManifest();
} }
} }
// TODO This callback needs to determine if this version is not older than current and disable the Update button if so.
void manifest_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e) void manifest_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{ {
if (e.Error != null) if (e.Error != null)
return; return;
string strHashOld = Decompressor.MD5Verify.ComputeHash(Assembly.GetExecutingAssembly().Location); versionInfo bzip = new versionInfo();
string strVersionOld = Assembly.GetExecutingAssembly().GetName().Version.ToString(); versionInfo gzip = new versionInfo();
string strVersionNew = strVersionOld; versionInfo wzip = new versionInfo();
string strHelpHashOld = ""; versionInfo web = new versionInfo();
versionInfo current = new versionInfo(Assembly.GetExecutingAssembly().GetName().Version.ToString());
current.hash = Decompressor.MD5Verify.ComputeHash(Assembly.GetExecutingAssembly().Location);
current.uri = "";
string strHelpHashMe = "";
string strHelpFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Properties.Settings.Default.HelpOfflineFile); string strHelpFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Properties.Settings.Default.HelpOfflineFile);
if (File.Exists(strHelpFile)) if (File.Exists(strHelpFile))
{ {
strHelpHashOld = Decompressor.MD5Verify.ComputeHash(strHelpFile); strHelpHashMe = Decompressor.MD5Verify.ComputeHash(strHelpFile);
} }
else else
{ {
// help file does not exist // help file does not exist
if (Properties.Settings.Default.HelpOffline || blnOnlyHelpFile) if (Properties.Settings.Default.HelpOffline || blnOnlyHelpFile)
{ {
strHelpHashOld = "*"; // force new update strHelpHashMe = "*"; // force new update
} }
else else
{ {
strHelpHashOld = ""; // no update strHelpHashMe = ""; // no update
this.label5.Visible = false; this.labelHelpFile.Visible = false;
this.label6.Visible = false; this.labelHelpversionString.Visible = false;
} }
} }
strHashNew = strHashOld;
StringReader sr = new StringReader(e.Result); StringReader sr = new StringReader(e.Result);
for (int intI = 0; intI < 255; intI++) for (int intI = 0; intI < 255; intI++)
{ {
@ -175,37 +207,41 @@ namespace LSLEditor
string strName = strLine.Substring(0, intSplit); string strName = strLine.Substring(0, intSplit);
string strValue = strLine.Substring(intSplit + 1); string strValue = strLine.Substring(intSplit + 1);
//All hashes are of the uncompressed file. However, different archives may contain different versions.
switch (strName) switch (strName)
{ {
case "Version": case "Version":
strVersionNew = strValue; case "BZipVersion":
bzip = new versionInfo(strValue);
break; break;
case "Hash": case "Hash":
strHashNew = strValue; case "BZipHash":
bzip.hash = strValue;
break; break;
case "Url": case "Url":
strDownloadUrl = strValue; case "BZipUrl":
bzip.uri = strValue;
break; break;
case "GZipVersion": case "GZipVersion":
strVersionNew = strValue; gzip = new versionInfo(strValue);
break; break;
case "GZipHash": case "GZipHash":
strHashNew = strValue; gzip.hash = strValue;
break; break;
case "GZipUrl": case "GZipUrl":
strDownloadUrl = strValue; gzip.uri = strValue;
break; break;
case "ZipVersion": case "ZipVersion":
strVersionNew = strValue; wzip = new versionInfo(strValue);
break; break;
case "ZipHash": case "ZipHash":
strHashNew = strValue; wzip.hash = strValue;
break; break;
case "ZipUrl": case "ZipUrl":
strDownloadUrl = strValue; wzip.uri = strValue;
break; break;
case "HelpHash": case "HelpHash":
strHelpHashNew = strValue; strHelpHashWeb = strValue;
break; break;
case "HelpUrl2": case "HelpUrl2":
strHelpUrl = strValue; strHelpUrl = strValue;
@ -218,51 +254,74 @@ namespace LSLEditor
} }
} }
this.label3.Text = strVersionOld; web = bzip;
this.label4.Text = strVersionNew; /*
if (!String.IsNullOrEmpty(gzip.uri) && (gzip.compare(web) == 1))
if (strHelpHashOld == "")
strHelpHashOld = strHelpHashNew;
if (strHelpHashOld == strHelpHashNew)
{ {
this.label6.Text = "Up to date"; web = gzip;
}
if (!String.IsNullOrEmpty(wzip.uri) && (wzip.compare(web) == 1))
{
web = wzip;
}
*/
this.labelOurVersionString.Text = current.version.ToString();
this.labelLatestVersionString.Text = web.version.ToString();
if (String.IsNullOrEmpty(web.uri) || (web.version.CompareTo(current.version) != 1))
{
return;
}
if (strHelpHashMe == "")
strHelpHashMe = strHelpHashWeb;
if (strHelpHashMe == strHelpHashWeb)
{
this.labelHelpversionString.Text = "Up to date";
this.strHelpUrl = null; this.strHelpUrl = null;
} }
else else
{ {
this.label6.Text = "Out of date"; this.labelHelpversionString.Text = "Out of date";
} }
if (strHashOld == strHashNew) if (current.hash == web.hash)
{ {
this.strDownloadUrl = null; this.strDownloadUrl = null;
} }
else
{
this.strDownloadUrl = web.uri;
}
if (this.blnOnlyHelpFile) if (this.blnOnlyHelpFile)
{ {
this.strDownloadUrl = null; this.strDownloadUrl = null;
this.label2.Visible = false; this.labelLatestVersion.Visible = false;
this.label4.Visible = false; this.labelLatestVersionString.Visible = false;
} }
if (this.strHelpUrl != null || this.strDownloadUrl != null) if (this.strHelpUrl != null || this.strDownloadUrl != null)
{ {
this.button1.Enabled = true; this.buttonUpdate.Enabled = true;
if (OnUpdateAvailable != null) if (OnUpdateAvailable != null)
OnUpdateAvailable(this, null); OnUpdateAvailable(this, null);
} }
} }
private void button2_Click(object sender, EventArgs e) private void buttonCancel_Click(object sender, EventArgs e)
{ {
this.Close(); this.Close();
} }
private void button1_Click(object sender, EventArgs e) private void buttonUpdate_Click(object sender, EventArgs e)
{ {
this.button1.Enabled = false; this.buttonUpdate.Enabled = false;
Download(); Download();
} }
@ -311,9 +370,9 @@ namespace LSLEditor
string strNewFile = Path.Combine(strDirectory, Properties.Settings.Default.HelpOfflineFile); string strNewFile = Path.Combine(strDirectory, Properties.Settings.Default.HelpOfflineFile);
string strComputedHash = Decompressor.MD5Verify.ComputeHash(strNewFile); string strComputedHash = Decompressor.MD5Verify.ComputeHash(strNewFile);
if (strComputedHash != strHelpHashNew) if (strComputedHash != strHelpHashWeb)
{ {
this.button1.Enabled = true; this.buttonUpdate.Enabled = true;
throw new Exception("MD5 Hash of HelpFile not correct, try downloading again!"); throw new Exception("MD5 Hash of HelpFile not correct, try downloading again!");
} }
if (this.strDownloadUrl != null) if (this.strDownloadUrl != null)
@ -387,7 +446,7 @@ namespace LSLEditor
break; break;
} }
string strComputedHash = Decompressor.MD5Verify.ComputeHash(strNewFile); string strComputedHash = Decompressor.MD5Verify.ComputeHash(strNewFile);
if (strComputedHash == strHashNew) if (strComputedHash == strHashWeb)
{ {
if (File.Exists(strOldFile)) if (File.Exists(strOldFile))
File.Delete(strOldFile); File.Delete(strOldFile);
@ -407,7 +466,7 @@ namespace LSLEditor
} }
else else
{ {
this.button1.Enabled = true; this.buttonUpdate.Enabled = true;
throw new Exception("MD5 Hash not correct, try downloading again!"); throw new Exception("MD5 Hash not correct, try downloading again!");
} }
} }