From 6d44f4db6459a4cec248130438319aa18b86ac1c Mon Sep 17 00:00:00 2001 From: sr55 Date: Wed, 12 Jan 2011 19:43:35 +0000 Subject: WinGui: - Switch to using a SHA1 hash of the cli executable to make cli exe version validation more reliable. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3741 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/Main.cs | 19 +++++++++++++++---- win/C#/Properties/Settings.Designer.cs | 7 ++++--- win/C#/Properties/Settings.settings | 2 +- win/C#/app.config | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index 2edfd1568..8f7cea326 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -10,6 +10,7 @@ namespace Handbrake.Functions using System.Diagnostics; using System.IO; using System.Linq; + using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -291,15 +292,22 @@ namespace Handbrake.Functions // 0 = SVN Build / Version // 1 = Build Date - DateTime lastModified = File.GetLastWriteTime("HandBrakeCLI.exe"); - if (Properties.Settings.Default.hb_build != 0 && Properties.Settings.Default.cliLastModified == lastModified) + // Get the SHA1 Hash of HandBrakeCLI + byte[] hash; + using (Stream stream = File.OpenRead("HandBrakeCLI.exe")) + { + hash = SHA1.Create().ComputeHash(stream); + } + string base64Hash = Convert.ToBase64String(hash); + + // Compare the hash with the last known hash. If it's the same, return. + if (Properties.Settings.Default.CliExeHash == base64Hash) { return; } - Properties.Settings.Default.cliLastModified = lastModified; - + // It's not the same, so start the CLI to get it's version data. Process cliProcess = new Process(); ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0") { @@ -350,11 +358,14 @@ namespace Handbrake.Functions } } + Properties.Settings.Default.CliExeHash = base64Hash; + Properties.Settings.Default.Save(); } catch (Exception e) { Properties.Settings.Default.hb_build = 0; + Properties.Settings.Default.CliExeHash = null; Properties.Settings.Default.Save(); ShowExceptiowWindow("Unable to retrieve version information from the CLI.", e.ToString()); diff --git a/win/C#/Properties/Settings.Designer.cs b/win/C#/Properties/Settings.Designer.cs index e02976a64..9dad5078d 100644 --- a/win/C#/Properties/Settings.Designer.cs +++ b/win/C#/Properties/Settings.Designer.cs @@ -420,12 +420,13 @@ namespace Handbrake.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public global::System.DateTime cliLastModified { + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string CliExeHash { get { - return ((global::System.DateTime)(this["cliLastModified"])); + return ((string)(this["CliExeHash"])); } set { - this["cliLastModified"] = value; + this["CliExeHash"] = value; } } diff --git a/win/C#/Properties/Settings.settings b/win/C#/Properties/Settings.settings index 563a4ec22..2cd3898de 100644 --- a/win/C#/Properties/Settings.settings +++ b/win/C#/Properties/Settings.settings @@ -101,7 +101,7 @@ False - + diff --git a/win/C#/app.config b/win/C#/app.config index 3f2c566ed..cea155aab 100644 --- a/win/C#/app.config +++ b/win/C#/app.config @@ -110,7 +110,7 @@ False - + -- cgit v1.2.3