diff --git a/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs b/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs index 6f8c5bf18..0869140d0 100644 --- a/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs +++ b/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs @@ -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; diff --git a/trunk/ProcessHacker/Program/Updater.cs b/trunk/ProcessHacker/Program/Updater.cs index 76107df58..6201d853d 100644 --- a/trunk/ProcessHacker/Program/Updater.cs +++ b/trunk/ProcessHacker/Program/Updater.cs @@ -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; - } - } } } diff --git a/trunk/ProcessHacker/Properties/Settings.Designer.cs b/trunk/ProcessHacker/Properties/Settings.Designer.cs index 33fe7dd12..9a4e15a93 100644 --- a/trunk/ProcessHacker/Properties/Settings.Designer.cs +++ b/trunk/ProcessHacker/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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"])); + } + } } } diff --git a/trunk/ProcessHacker/Properties/Settings.settings b/trunk/ProcessHacker/Properties/Settings.settings index 8b68dd624..b14b6cb43 100644 --- a/trunk/ProcessHacker/Properties/Settings.settings +++ b/trunk/ProcessHacker/Properties/Settings.settings @@ -6,7 +6,7 @@ 1000 - 820, 549 + 825, 549 200, 200 @@ -398,5 +398,8 @@ 0 + + http://processhacker.sourceforge.net/AppUpdate.xml + \ No newline at end of file diff --git a/trunk/ProcessHacker/app.config b/trunk/ProcessHacker/app.config index 121079ad4..8e459225b 100644 --- a/trunk/ProcessHacker/app.config +++ b/trunk/ProcessHacker/app.config @@ -4,6 +4,9 @@
+ +
+ @@ -11,7 +14,7 @@ 1000 - 820, 549 + 825, 549 200, 200 @@ -405,4 +408,11 @@ + + + + http://processhacker.sourceforge.net/AppUpdate.xml + + + \ No newline at end of file