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">
<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:
<ul>
<li>AGENT_AUTOPILOT</li>
@ -51,6 +51,7 @@
<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>Removed ANSI as an output format option.</li>
<li>Fixed updater to disallow accidental updating with older files.</li>
</ul>
</div>
<div>

View file

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

View file

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