summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-12-27 22:52:43 +0000
committersr55 <[email protected]>2011-12-27 22:52:43 +0000
commit5b745b8f17f8acc6d3799eb3cb86e09c7ca99017 (patch)
tree5a97790d448b6ac3b85b46f1803df00c34a39820 /win/CS/HandBrakeWPF/Services
parent20fd52b888f111ac2d7670fa3c41e495661cdebd (diff)
WinGui: (WPF) Initial work to hookup the log viewer + some additional helper classes ported over form the WinForms version.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4390 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/ErrorService.cs61
-rw-r--r--win/CS/HandBrakeWPF/Services/Interfaces/IErrorService.cs59
-rw-r--r--win/CS/HandBrakeWPF/Services/Interfaces/IUpdateVersionService.cs22
-rw-r--r--win/CS/HandBrakeWPF/Services/UpdateVersionService.cs146
4 files changed, 267 insertions, 21 deletions
diff --git a/win/CS/HandBrakeWPF/Services/ErrorService.cs b/win/CS/HandBrakeWPF/Services/ErrorService.cs
index c5d89d5cf..3228ab363 100644
--- a/win/CS/HandBrakeWPF/Services/ErrorService.cs
+++ b/win/CS/HandBrakeWPF/Services/ErrorService.cs
@@ -9,6 +9,7 @@
namespace HandBrakeWPF.Services
{
+ using System;
using System.Windows;
using Interfaces;
using Caliburn.Micro;
@@ -20,11 +21,17 @@ namespace HandBrakeWPF.Services
public class ErrorService : IErrorService
{
/// <summary>
- /// Show an Exception Error Window.
+ /// Show an Exception Error Window
/// </summary>
- /// <param name="message"></param>
- /// <param name="solution"></param>
- /// <param name="details"></param>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="details">
+ /// The details.
+ /// </param>
public void ShowError(string message, string solution, string details)
{
IWindowManager windowManager = IoC.Get<IWindowManager>();
@@ -40,14 +47,50 @@ namespace HandBrakeWPF.Services
}
/// <summary>
+ /// Show an Exception Error Window
+ /// </summary>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="exception">
+ /// The exception.
+ /// </param>
+ public void ShowError(string message, string solution, Exception exception)
+ {
+ IWindowManager windowManager = IoC.Get<IWindowManager>();
+ IErrorViewModel errorViewModel = IoC.Get<IErrorViewModel>();
+
+ if (windowManager != null && errorViewModel != null)
+ {
+ errorViewModel.ErrorMessage = message;
+ errorViewModel.Solution = solution;
+ errorViewModel.Details = exception.ToString();
+ windowManager.ShowDialog(errorViewModel);
+ }
+ }
+
+ /// <summary>
/// Show a Message Box.
/// It is good practice to use this, so that if we ever introduce unit testing, the message boxes won't cause issues.
/// </summary>
- /// <param name="message"></param>
- /// <param name="header"></param>
- /// <param name="image"></param>
- /// <param name="buttons"></param>
- /// <returns></returns>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="header">
+ /// The header.
+ /// </param>
+ /// <param name="buttons">
+ /// The buttons.
+ /// </param>
+ /// <param name="image">
+ /// The image.
+ /// </param>
+ /// <returns>
+ /// The MessageBoxResult Object
+ /// </returns>
public MessageBoxResult ShowMessageBox(string message, string header, MessageBoxButton buttons, MessageBoxImage image)
{
return MessageBox.Show(message, header, buttons, image);
diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IErrorService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/IErrorService.cs
index cba3a79b3..cc9ef968c 100644
--- a/win/CS/HandBrakeWPF/Services/Interfaces/IErrorService.cs
+++ b/win/CS/HandBrakeWPF/Services/Interfaces/IErrorService.cs
@@ -7,28 +7,63 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------
-using System.Windows;
-
namespace HandBrakeWPF.Services.Interfaces
{
+ using System;
+ using System.Windows;
+
+ /// <summary>
+ /// The Interface to the Error Service.
+ /// </summary>
public interface IErrorService
{
/// <summary>
- /// Show an Error Window with debug output.
+ /// Show an Exception Error Window
/// </summary>
- /// <param name="message"></param>
- /// <param name="solution"></param>
- /// <param name="details"></param>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="details">
+ /// The details.
+ /// </param>
void ShowError(string message, string solution, string details);
/// <summary>
- /// Show a Message Box
+ /// Show an Exception Error Window
+ /// </summary>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="exception">
+ /// The exception.
+ /// </param>
+ void ShowError(string message, string solution, Exception exception);
+
+ /// <summary>
+ /// Show a Message Box.
+ /// It is good practice to use this, so that if we ever introduce unit testing, the message boxes won't cause issues.
/// </summary>
- /// <param name="message"></param>
- /// <param name="header"></param>
- /// <param name="image"></param>
- /// <param name="buttons"></param>
- /// <returns></returns>
+ /// <param name="message">
+ /// The message.
+ /// </param>
+ /// <param name="header">
+ /// The header.
+ /// </param>
+ /// <param name="buttons">
+ /// The buttons.
+ /// </param>
+ /// <param name="image">
+ /// The image.
+ /// </param>
+ /// <returns>
+ /// The MessageBoxResult Object
+ /// </returns>
MessageBoxResult ShowMessageBox(string message, string header, MessageBoxButton buttons, MessageBoxImage image);
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IUpdateVersionService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/IUpdateVersionService.cs
new file mode 100644
index 000000000..3a84e68fc
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/Interfaces/IUpdateVersionService.cs
@@ -0,0 +1,22 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="IUpdateVersionService.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 IUpdateVersionService type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Interfaces
+{
+ /// <summary>
+ /// The IUpdateVersionService Interface
+ /// </summary>
+ public interface IUpdateVersionService
+ {
+ /// <summary>
+ /// Get's HandBrakes version data from the CLI.
+ /// </summary>
+ void SetCliVersionData();
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/UpdateVersionService.cs b/win/CS/HandBrakeWPF/Services/UpdateVersionService.cs
new file mode 100644
index 000000000..4f99720db
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/UpdateVersionService.cs
@@ -0,0 +1,146 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="UpdateVersionService.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 UpdateVersionService type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services
+{
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Security.Cryptography;
+ using System.Text.RegularExpressions;
+ using System.Windows;
+
+ using HandBrake.ApplicationServices;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// Update Version Service - Handlers Update and Versioning.
+ /// </summary>
+ public class UpdateVersionService : IUpdateVersionService
+ {
+ /// <summary>
+ /// The Backing field for the user setting service
+ /// </summary>
+ private readonly IUserSettingService userSettingService;
+
+ /// <summary>
+ /// The Error Service Backing field.
+ /// </summary>
+ private readonly IErrorService errorService;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UpdateVersionService"/> class.
+ /// </summary>
+ /// <param name="userSettingService">
+ /// The user setting service.
+ /// </param>
+ /// <param name="errorService">
+ /// The error Service.
+ /// </param>
+ public UpdateVersionService(IUserSettingService userSettingService, IErrorService errorService)
+ {
+ this.userSettingService = userSettingService;
+ this.errorService = errorService;
+ }
+
+ /// <summary>
+ /// Get's HandBrakes version data from the CLI.
+ /// </summary>
+ public void SetCliVersionData()
+ {
+ string line;
+
+ // 0 = SVN Build / Version
+ // 1 = Build Date
+
+ // Get the SHA1 Hash of HandBrakeCLI
+ byte[] hash;
+ string starupPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
+
+ using (Stream stream = File.OpenRead(Path.Combine(starupPath, "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>(UserSettingConstants.CliExeHash) == 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, string.Empty);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakePlatform, string.Empty);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeVersion, string.Empty);
+ userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeExeHash, string.Empty);
+
+ this.errorService.ShowError("Unable to Initialise HandBrake", "This error is unrecoverable. Maybe try restarting.", e);
+
+ Application.Current.Shutdown();
+ }
+ }
+ }
+}