mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
fixed update detection logic (perfect detection, see comments http://processhacker.sourceforge.net/AppUpdate.xml), removed unused variables, hard-coded UpdateURL moved to app.config, fixed default HackerWindow UI size inconsistency
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1786 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
@@ -50,11 +50,11 @@ public partial class UpdaterDownloadWindow : Form
|
||||
{
|
||||
string version;
|
||||
|
||||
version = _updateItem.Version.Major + "." + _updateItem.Version.Minor;
|
||||
version = _updateItem.appUpdateVersion.Major + "." + _updateItem.appUpdateVersion.Minor;
|
||||
_fileName = Path.GetTempPath() + "processhacker-" + version + "-setup.exe";
|
||||
|
||||
labelTitle.Text = "Downloading: Process Hacker " + version;
|
||||
labelReleased.Text = "Released: " + _updateItem.Date.ToString();
|
||||
labelReleased.Text = "Released: " + _updateItem.appUpdateDate.ToString();
|
||||
|
||||
_webClient = new WebClient();
|
||||
_webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
|
||||
@@ -64,7 +64,7 @@ public partial class UpdaterDownloadWindow : Form
|
||||
|
||||
try
|
||||
{
|
||||
_webClient.DownloadFileAsync(new Uri(_updateItem.Url), _fileName);
|
||||
_webClient.DownloadFileAsync(new Uri(_updateItem.appUpdateUrl), _fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -208,7 +208,7 @@ public partial class UpdaterDownloadWindow : Form
|
||||
sb.AppendFormat("{0:x2}", b);
|
||||
}
|
||||
|
||||
if (_updateItem.Hash.Equals(sb.ToString(), StringComparison.InvariantCultureIgnoreCase))
|
||||
if (_updateItem.appUpdateHash.Equals(sb.ToString(), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
labelProgress.Text = "Download completed and SHA1 verified successfully.";
|
||||
buttonInstall.Enabled = true;
|
||||
|
||||
@@ -33,7 +33,7 @@ using System.Globalization;
|
||||
|
||||
namespace ProcessHacker
|
||||
{
|
||||
public enum AppUpdateLevel
|
||||
public enum AppUpdateLevel: int
|
||||
{
|
||||
Stable = 0,
|
||||
Beta = 1,
|
||||
@@ -49,37 +49,36 @@ namespace ProcessHacker
|
||||
{
|
||||
public UpdateItem()
|
||||
{
|
||||
this.Version = new Version(Application.ProductVersion);
|
||||
this.Date = GetAssemblyBuildDate();
|
||||
this.appUpdateVersion = new Version(Application.ProductVersion);
|
||||
}
|
||||
|
||||
public string appUpdateName { get; private set; }
|
||||
public Version appUpdateVersion { get; private set; }
|
||||
public DateTime appUpdateDate { get; private set; }
|
||||
public AppUpdateLevel appUpdateType { get; private set; }
|
||||
public string appUpdateMessage { get; private set; }
|
||||
public string appUpdateUrl { get; private set; }
|
||||
public string appUpdateHash { get; private set; }
|
||||
|
||||
public UpdateItem(XmlNode node)
|
||||
{
|
||||
this.Name = node["title"].InnerText;
|
||||
this.Version = new Version(node["version"].InnerText);
|
||||
this.Date = DateTime.Parse(node["released"].InnerText, DateTimeFormatInfo.InvariantInfo);
|
||||
this.Type = GetUpdateLevel(node["type"].InnerText);
|
||||
this.Message = node["description"].InnerText;
|
||||
this.Url = node["updateurl"].InnerText;
|
||||
this.Hash = node["hash"].InnerText;
|
||||
this.appUpdateName = node["title"].InnerText;
|
||||
this.appUpdateVersion = new Version(node["version"].InnerText);
|
||||
this.appUpdateDate = DateTime.Parse(node["released"].InnerText, DateTimeFormatInfo.InvariantInfo);
|
||||
this.appUpdateType = GetUpdateLevel(node["type"].InnerText);
|
||||
this.appUpdateMessage = node["description"].InnerText;
|
||||
this.appUpdateUrl = node["updateurl"].InnerText;
|
||||
this.appUpdateHash = node["hash"].InnerText;
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
public Version Version { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
public AppUpdateLevel Type { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
public string Url { get; private set; }
|
||||
public string Hash { get; private set; }
|
||||
|
||||
public bool IsBetterThan(UpdateItem update, AppUpdateLevel preferredType)
|
||||
public bool IsBetterThan(UpdateItem update, AppUpdateLevel preferredUpdateType)
|
||||
{
|
||||
if (update == null)
|
||||
return true;
|
||||
if ((int)this.Type > (int)preferredType)
|
||||
return false;
|
||||
|
||||
return this.Version > update.Version || this.Date > update.Date;
|
||||
if (this.appUpdateType == preferredUpdateType && this.appUpdateVersion > update.appUpdateVersion)
|
||||
return true;
|
||||
else if (this.appUpdateType == AppUpdateLevel.Stable && this.appUpdateVersion > update.appUpdateVersion)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ namespace ProcessHacker
|
||||
|
||||
try
|
||||
{
|
||||
xDoc.Load("http://processhacker.sourceforge.net/AppUpdate.xml");
|
||||
xDoc.Load(Properties.Settings.Default.AppUpdateURL);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -111,28 +110,21 @@ namespace ProcessHacker
|
||||
return;
|
||||
}
|
||||
|
||||
var mainWindow = new WindowFromHandle(Program.HackerWindowHandle);
|
||||
|
||||
UpdateItem currentVersion = new UpdateItem();
|
||||
UpdateItem bestUpdate = currentVersion;
|
||||
|
||||
XmlNodeList nodes = xDoc.SelectNodes("//update");
|
||||
|
||||
foreach (XmlNode node in nodes)
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateItem update = new UpdateItem(node);
|
||||
{
|
||||
UpdateItem update = new UpdateItem(node);
|
||||
|
||||
// Check if this update is better than the one we already have.
|
||||
if (update.IsBetterThan(bestUpdate, (AppUpdateLevel)Properties.Settings.Default.AppUpdateLevel))
|
||||
bestUpdate = update;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(ex);
|
||||
// Check if this update is better than the one we already have.
|
||||
if (update.IsBetterThan(bestUpdate, (AppUpdateLevel)Properties.Settings.Default.AppUpdateLevel))
|
||||
{
|
||||
bestUpdate = update;
|
||||
}
|
||||
}
|
||||
Program.HackerWindow.QueueMessage("Found New Update: " + bestUpdate.appUpdateVersion + " " + bestUpdate.appUpdateType);
|
||||
|
||||
PromptWithUpdate(form, bestUpdate, currentVersion);
|
||||
}
|
||||
@@ -154,8 +146,8 @@ namespace ProcessHacker
|
||||
TaskDialog td = new TaskDialog();
|
||||
td.PositionRelativeToWindow = true;
|
||||
td.Content =
|
||||
"Your Version: " + currentVersion.Version.ToString() +
|
||||
"\nServer Version: " + bestUpdate.Version.ToString() + "\n\n" + "\n" + bestUpdate.Message;
|
||||
"Your Version: " + currentVersion.appUpdateVersion.ToString() +
|
||||
"\nServer Version: " + bestUpdate.appUpdateVersion.ToString() + "\n\n" + "\n" + bestUpdate.appUpdateMessage;
|
||||
td.MainInstruction = "Process Hacker update available";
|
||||
td.WindowTitle = "Update available";
|
||||
td.MainIcon = TaskDialogIcon.SecurityWarning;
|
||||
@@ -171,8 +163,8 @@ namespace ProcessHacker
|
||||
{
|
||||
dialogResult = MessageBox.Show(
|
||||
form,
|
||||
"Your Version: " + currentVersion.Version.ToString() +
|
||||
"\nServer Version: " + bestUpdate.Version.ToString() + "\n\n" + bestUpdate.Message +
|
||||
"Your Version: " + currentVersion.appUpdateVersion.ToString() +
|
||||
"\nServer Version: " + bestUpdate.appUpdateVersion.ToString() + "\n\n" + bestUpdate.appUpdateMessage +
|
||||
"\n\nDo you want to download the update now?",
|
||||
"Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation
|
||||
);
|
||||
@@ -182,7 +174,6 @@ namespace ProcessHacker
|
||||
{
|
||||
DownloadUpdate(form, bestUpdate);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -191,8 +182,8 @@ namespace ProcessHacker
|
||||
TaskDialog td = new TaskDialog();
|
||||
td.PositionRelativeToWindow = true;
|
||||
td.Content =
|
||||
"Your Version: " + currentVersion.Version.ToString() +
|
||||
"\nServer Version: " + bestUpdate.Version.ToString();
|
||||
"Your Version: " + currentVersion.appUpdateVersion.ToString() +
|
||||
"\nServer Version: " + bestUpdate.appUpdateVersion.ToString();
|
||||
td.MainInstruction = "Process Hacker is up-to-date";
|
||||
td.WindowTitle = "No updates available";
|
||||
td.MainIcon = TaskDialogIcon.SecuritySuccess;
|
||||
@@ -220,42 +211,5 @@ namespace ProcessHacker
|
||||
|
||||
new UpdaterDownloadWindow(updateItem).ShowDialog(form);
|
||||
}
|
||||
|
||||
private static DateTime? AssemblyBuildDate = null;
|
||||
private static DateTime GetAssemblyBuildDate()
|
||||
{
|
||||
if (AssemblyBuildDate != null) //Performance fix - Prevent reading current Assembly multiple times
|
||||
{
|
||||
return (DateTime)AssemblyBuildDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
const int PeHeaderOffset = 60;
|
||||
const int LinkerTimestampOffset = 8;
|
||||
|
||||
byte[] b = new byte[2048];
|
||||
System.IO.Stream s = default(System.IO.Stream);
|
||||
try
|
||||
{
|
||||
s = new System.IO.FileStream(System.Reflection.Assembly.GetExecutingAssembly().Location, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
s.Read(b, 0, 2048);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ((s != null))
|
||||
s.Close();
|
||||
}
|
||||
|
||||
int i = BitConverter.ToInt32(b, PeHeaderOffset);
|
||||
int SecondsSince1970 = BitConverter.ToInt32(b, i + LinkerTimestampOffset);
|
||||
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
|
||||
dt = dt.AddSeconds(SecondsSince1970);
|
||||
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
|
||||
|
||||
AssemblyBuildDate = dt;
|
||||
|
||||
return (DateTime)AssemblyBuildDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.4016
|
||||
// Runtime Version:2.0.50727.4927
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@@ -37,7 +37,7 @@ namespace ProcessHacker.Properties {
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("820, 549")]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("825, 549")]
|
||||
public global::System.Drawing.Size WindowSize {
|
||||
get {
|
||||
return ((global::System.Drawing.Size)(this["WindowSize"]));
|
||||
@@ -1608,5 +1608,14 @@ namespace ProcessHacker.Properties {
|
||||
this["AppUpdateLevel"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("http://processhacker.sourceforge.net/AppUpdate.xml")]
|
||||
public string AppUpdateURL {
|
||||
get {
|
||||
return ((string)(this["AppUpdateURL"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<Value Profile="(Default)">1000</Value>
|
||||
</Setting>
|
||||
<Setting Name="WindowSize" Type="System.Drawing.Size" Scope="User">
|
||||
<Value Profile="(Default)">820, 549</Value>
|
||||
<Value Profile="(Default)">825, 549</Value>
|
||||
</Setting>
|
||||
<Setting Name="WindowLocation" Type="System.Drawing.Point" Scope="User">
|
||||
<Value Profile="(Default)">200, 200</Value>
|
||||
@@ -398,5 +398,8 @@
|
||||
<Setting Name="AppUpdateLevel" Type="System.Int32" Scope="User">
|
||||
<Value Profile="(Default)">0</Value>
|
||||
</Setting>
|
||||
<Setting Name="AppUpdateURL" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">http://processhacker.sourceforge.net/AppUpdate.xml</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -4,6 +4,9 @@
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="ProcessHacker.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="ProcessHacker.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<userSettings>
|
||||
<ProcessHacker.Properties.Settings>
|
||||
@@ -11,7 +14,7 @@
|
||||
<value>1000</value>
|
||||
</setting>
|
||||
<setting name="WindowSize" serializeAs="String">
|
||||
<value>820, 549</value>
|
||||
<value>825, 549</value>
|
||||
</setting>
|
||||
<setting name="WindowLocation" serializeAs="String">
|
||||
<value>200, 200</value>
|
||||
@@ -405,4 +408,11 @@
|
||||
</setting>
|
||||
</ProcessHacker.Properties.Settings>
|
||||
</userSettings>
|
||||
<applicationSettings>
|
||||
<ProcessHacker.Properties.Settings>
|
||||
<setting name="AppUpdateURL" serializeAs="String">
|
||||
<value>http://processhacker.sourceforge.net/AppUpdate.xml</value>
|
||||
</setting>
|
||||
</ProcessHacker.Properties.Settings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user