summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-03-19 20:18:46 +0000
committersr55 <[email protected]>2012-03-19 20:18:46 +0000
commit582d0170487c8dcd113cae0e0b38345226f3147e (patch)
tree5b1f9ea1fae5652418b22bb2e103e886fdf26fba /win/CS
parent4ff24a85e32d10ee8ab5ed524ec03e3f22da92e1 (diff)
WinGui: (WPF) Started implementing the startup procedure: Update checking, Preset updates, CLI monitoring.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs129
-rw-r--r--win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs70
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs21
4 files changed, 211 insertions, 10 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index c148f6bde..580a9fb56 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -100,6 +100,7 @@
<Compile Include="Converters\EnumComboConverter.cs" />
<Compile Include="Converters\FullPathToFileNameConverter.cs" />
<Compile Include="Helpers\AutoNameHelper.cs" />
+ <Compile Include="Helpers\CliCheckHelper.cs" />
<Compile Include="Helpers\ListBoxHelper.cs" />
<Compile Include="Helpers\QueueRecoveryHelper.cs" />
<Compile Include="Helpers\UpdateCheckHelper.cs" />
diff --git a/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs b/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs
new file mode 100644
index 000000000..3dd9f8ba3
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs
@@ -0,0 +1,129 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="CliCheckHelper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the CliCheckHelper type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Security.Cryptography;
+ using System.Text.RegularExpressions;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// The cli check helper.
+ /// </summary>
+ public class CliCheckHelper
+ {
+ /// <summary>
+ /// The check cli version.
+ /// </summary>
+ /// <returns>
+ /// Returns True when CLI is unchanged,
+ /// False when there is a change
+ /// </returns>
+ public static void CheckCLIVersion()
+ {
+ IErrorService errorService = IoC.Get<IErrorService>();
+
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+
+ string line;
+
+ // 0 = SVN Build / Version
+ // 1 = Build Date
+
+ // 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 (userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakeExeHash) == base64Hash)
+ {
+ return;
+ }
+
+ // 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")
+ {
+ UseShellExecute = false,
+ RedirectStandardError = true,
+ RedirectStandardOutput = true,
+ CreateNoWindow = true
+ };
+ cliProcess.StartInfo = handBrakeCli;
+
+ try
+ {
+ cliProcess.Start();
+
+ // Retrieve standard output and report back to parent thread until the process is complete
+ TextReader stdOutput = cliProcess.StandardError;
+
+ while (!cliProcess.HasExited)
+ {
+ line = stdOutput.ReadLine() ?? string.Empty;
+ Match m = Regex.Match(line, @"HandBrake ([svnM0-9.]*) \(([0-9]*)\)");
+ Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -");
+
+ if (m.Success)
+ {
+ string version = m.Groups[1].Success ? m.Groups[1].Value : string.Empty;
+ string build = m.Groups[2].Success ? m.Groups[2].Value : string.Empty;
+
+ int buildValue;
+ int.TryParse(build, out buildValue);
+
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, buildValue);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeVersion, version);
+ }
+
+ if (platform.Success)
+ {
+ userSettingService.SetUserSetting(
+ ASUserSettingConstants.HandBrakePlatform, platform.Value.Replace("-", string.Empty).Trim());
+ }
+
+ if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.
+ {
+ Process cli = Process.GetProcessById(cliProcess.Id);
+ if (!cli.HasExited)
+ {
+ cli.Kill();
+ }
+ }
+ }
+
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeExeHash, base64Hash);
+ }
+ catch (Exception e)
+ {
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, 0);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakePlatform, string.Empty);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeVersion, string.Empty);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeExeHash, string.Empty);
+
+ errorService.ShowError(
+ "Unable to Initialise HandBrake. This error is unrecoverable.", " Try restarting.", e);
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs
index 11917e771..2e5398cd0 100644
--- a/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs
+++ b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs
@@ -14,8 +14,10 @@ namespace HandBrakeWPF.Helpers
using Caliburn.Micro;
+ using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Model.General;
using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrakeWPF.Services.Interfaces;
@@ -25,12 +27,77 @@ namespace HandBrakeWPF.Helpers
public class UpdateCheckHelper
{
/// <summary>
+ /// Perform a startup update check. Abiding by user settings.
+ /// </summary>
+ public static void PerformStartupUpdateCheck()
+ {
+ // Make sure it's running on the calling thread
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.UpdateStatus))
+ {
+ if (DateTime.Now.Subtract(userSettingService.GetUserSetting<DateTime>(UserSettingConstants.LastUpdateCheckDate)).TotalDays
+ > userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck))
+ {
+ userSettingService.SetUserSetting(UserSettingConstants.LastUpdateCheckDate, DateTime.Now);
+ string url = userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakePlatform).Contains("x86_64")
+ ? userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_x64)
+ : userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_i686);
+ UpdateService.BeginCheckForUpdates(UpdateCheckDone, false,
+ url, userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild),
+ userSettingService.GetUserSetting<int>(UserSettingConstants.Skipversion));
+ }
+ }
+ }
+
+ /// <summary>
+ /// Check for Updates.
+ /// </summary>
+ public static void CheckForUpdates()
+ {
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ userSettingService.SetUserSetting(UserSettingConstants.LastUpdateCheckDate, DateTime.Now);
+ string url = userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakePlatform).Contains("x86_64")
+ ? userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_x64)
+ : userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_i686);
+ UpdateService.BeginCheckForUpdates(UpdateCheckDoneMenu, false,
+ url, userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild),
+ userSettingService.GetUserSetting<int>(UserSettingConstants.Skipversion));
+ }
+
+ /// <summary>
+ /// Handle the Update Check Finishing.
+ /// </summary>
+ /// <param name="result">
+ /// The result.
+ /// </param>
+ private static void UpdateCheckDone(IAsyncResult result)
+ {
+ // Make sure it's running on the calling thread
+ IErrorService errorService = IoC.Get<IErrorService>();
+ try
+ {
+ // Get the information about the new build, if any, and close the window
+ UpdateCheckInformation info = UpdateService.EndCheckForUpdates(result);
+
+ if (info.NewVersionAvailable)
+ {
+ errorService.ShowMessageBox(
+ "A New Update is Available", "Update available!", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ }
+ catch (Exception ex)
+ {
+ errorService.ShowError("Unable to check for updates", "Please try again later, the update service may currently be down.", ex);
+ }
+ }
+
+ /// <summary>
/// Handle the Update Check Finishing.
/// </summary>
/// <param name="result">
/// The result.
/// </param>
- public static void UpdateCheckDoneMenu(IAsyncResult result)
+ private static void UpdateCheckDoneMenu(IAsyncResult result)
{
// Make sure it's running on the calling thread
IErrorService errorService = IoC.Get<IErrorService>();
@@ -49,7 +116,6 @@ namespace HandBrakeWPF.Helpers
errorService.ShowMessageBox(
"There is no new version at this time.", "No Updates", MessageBoxButton.OK, MessageBoxImage.Information);
}
- return;
}
catch (Exception ex)
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index d42e535c7..c37d36eb8 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -629,6 +629,18 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public override void OnLoad()
{
+ // Check the CLI Executable.
+ CliCheckHelper.CheckCLIVersion();
+
+ // Perform an update check if required
+ UpdateCheckHelper.PerformStartupUpdateCheck();
+
+ // Setup the presets.
+ if (this.presetService.CheckIfPresetsAreOutOfDate())
+ if (!this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PresetNotification))
+ this.errorService.ShowMessageBox("HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
+ "Preset Update", MessageBoxButton.OK, MessageBoxImage.Information);
+
this.SelectedPreset = this.presetService.DefaultPreset;
}
@@ -706,14 +718,7 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void CheckForUpdates()
{
- // TODO The update service needs refactoring.
- this.userSettingService.SetUserSetting(UserSettingConstants.LastUpdateCheckDate, DateTime.Now);
- string url = userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakePlatform).Contains("x86_64")
- ? userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_x64)
- : userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_i686);
- UpdateService.BeginCheckForUpdates(UpdateCheckHelper.UpdateCheckDoneMenu, false,
- url, userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild),
- userSettingService.GetUserSetting<int>(UserSettingConstants.Skipversion));
+ UpdateCheckHelper.CheckForUpdates();
}
/// <summary>