diff options
author | sr55 <[email protected]> | 2011-12-27 22:52:43 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-12-27 22:52:43 +0000 |
commit | 5b745b8f17f8acc6d3799eb3cb86e09c7ca99017 (patch) | |
tree | 5a97790d448b6ac3b85b46f1803df00c34a39820 /win/CS | |
parent | 20fd52b888f111ac2d7670fa3c41e495661cdebd (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')
18 files changed, 780 insertions, 54 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs index a51a7d43a..13216b608 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs @@ -5,11 +5,10 @@ namespace HandBrake.ApplicationServices.Model
{
- using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.Linq;
using HandBrake.ApplicationServices.Model.Encoding;
- using HandBrake.ApplicationServices.Parsing;
using HandBrake.Interop.Model;
using HandBrake.Interop.Model.Encoding;
using HandBrake.Interop.Model.Encoding.x264;
@@ -363,5 +362,29 @@ namespace HandBrake.ApplicationServices.Model /// </summary>
public bool UsesPictureSettings { get; set; }
#endregion
+
+ #region Helpers
+
+ /// <summary>
+ /// Gets a value indicating whether M4v extension is required.
+ /// </summary>
+ public bool RequiresM4v
+ {
+ get
+ {
+ if (this.OutputFormat == OutputFormat.M4V || this.OutputFormat == OutputFormat.Mp4)
+ {
+ bool audio = this.AudioTracks.Any(item => item.Encoder == AudioEncoder.Ac3Passthrough ||
+ item.Encoder == AudioEncoder.Ac3 || item.Encoder == AudioEncoder.DtsPassthrough || item.Encoder == AudioEncoder.Passthrough);
+
+ bool subtitles = this.SubtitleTracks.Any(track => track.SubtitleType != SubtitleType.VobSub);
+
+ return audio || subtitles;
+ }
+
+ return false;
+ }
+ }
+ #endregion
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs index 0c8d97c53..b4a23231e 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs @@ -94,7 +94,11 @@ namespace HandBrake.ApplicationServices.Services.Base {
get
{
- return string.IsNullOrEmpty(this.logBuffer.ToString()) ? this.header + "No log data available..." : this.header + this.logBuffer.ToString();
+ string noLog =
+ "No log data available... Log data will show when you start an encode. \n\nOpen the log file directory to get previous log files.";
+ return string.IsNullOrEmpty(this.logBuffer.ToString())
+ ? this.header + noLog
+ : this.header + this.logBuffer.ToString();
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs index b3470d63e..da9be176b 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs @@ -98,7 +98,8 @@ namespace HandBrake.ApplicationServices.Services {
get
{
- return string.IsNullOrEmpty(this.logBuffer.ToString()) ? this.header + "No log data available..." : this.header + this.logBuffer.ToString();
+ string noLog = "No log data available... Log data will show where after you scan a source. \n\nOpen the log file directory to get previous log files.";
+ return string.IsNullOrEmpty(this.logBuffer.ToString()) ? this.header + noLog : this.header + this.logBuffer.ToString();
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs index 5cf5d7712..7ba4d2f7d 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs @@ -16,6 +16,7 @@ namespace HandBrake.ApplicationServices.Utilities using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model.Encoding;
+ using HandBrake.Interop.Model.Encoding.x264;
/// <summary>
/// Generate a CLI Query for HandBrakeCLI
@@ -767,11 +768,24 @@ namespace HandBrake.ApplicationServices.Utilities {
if (task.VideoEncoder == VideoEncoder.X264)
{
- return string.Format(
- " --x264-preset={0} --x264-tune={1} --x264-profile={2}",
- task.x264Preset.ToString().ToLower().Replace(" ", string.Empty),
- task.X264Tune.ToString().ToLower().Replace(" ", string.Empty),
- task.x264Profile.ToString().ToLower().Replace(" ", string.Empty));
+ string query = string.Empty;
+
+ if (task.x264Preset != x264Preset.None)
+ {
+ query += string.Format("--x264-preset={0} ", task.x264Preset.ToString().ToLower().Replace(" ", string.Empty));
+ }
+
+ if (task.x264Profile != x264Profile.None)
+ {
+ query += string.Format("--x264-profile={0} ", task.x264Profile.ToString().ToLower().Replace(" ", string.Empty));
+ }
+
+ if (task.X264Tune != x264Tune.None)
+ {
+ query += string.Format("--x264-tune={0} ", task.X264Tune.ToString().ToLower().Replace(" ", string.Empty));
+ }
+
+ return query;
}
return string.IsNullOrEmpty(task.AdvancedEncoderOptions) ? string.Empty : string.Format(" -x {0}", task.AdvancedEncoderOptions);
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Preset.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Preset.cs index 45fbeb5d5..d0bb915a4 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Preset.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Preset.cs @@ -16,8 +16,11 @@ namespace HandBrake.Interop.Model.Encoding.x264 /// </summary>
public enum x264Preset
{
+ [Display(Name = "None")]
+ None = 0,
+
[Display(Name = "Ultrafast")]
- Ultrafast = 0,
+ Ultrafast,
[Display(Name = "Super Fast")]
Superfast,
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Profile.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Profile.cs index 837fbd28f..9cbce6161 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Profile.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Profile.cs @@ -16,8 +16,11 @@ namespace HandBrake.Interop.Model.Encoding.x264 /// </summary>
public enum x264Profile
{
+ [Display(Name = "None")]
+ None = 0,
+
[Display(Name = "Baseline")]
- Baseline = 0,
+ Baseline,
[Display(Name = "Main")]
Main,
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Tune.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Tune.cs index cc199e810..60421cc02 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Tune.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/x264/x264Tune.cs @@ -16,8 +16,11 @@ namespace HandBrake.Interop.Model.Encoding.x264 /// </summary>
public enum x264Tune
{
+ [Display(Name = "None")]
+ None = 0,
+
[Display(Name = "Film")]
- Film = 0,
+ Film,
[Display(Name = "Animation")]
Animation,
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index b6ab522d8..d91abdb9f 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -82,9 +82,12 @@ <SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converters\BooleanToVisibilityConverter.cs" />
+ <Compile Include="Helpers\AutoNameHelper.cs" />
<Compile Include="Helpers\ListBoxHelper.cs" />
<Compile Include="Services\ErrorService.cs" />
<Compile Include="Services\Interfaces\IErrorService.cs" />
+ <Compile Include="Services\Interfaces\IUpdateVersionService.cs" />
+ <Compile Include="Services\UpdateVersionService.cs" />
<Compile Include="Startup\CastleBootstrapper.cs" />
<Compile Include="Startup\MefBootstrapper.cs" />
<Compile Include="UserSettingConstants.cs" />
diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs new file mode 100644 index 000000000..13095ce30 --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -0,0 +1,174 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AutoNameHelper.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 AutoNameHelper type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+
+ using HandBrake.ApplicationServices.Extensions;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Model.Encoding;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ /// <summary>
+ /// The Destination AutoName Helper
+ /// </summary>
+ public class AutoNameHelper
+ {
+ /// <summary>
+ /// Backing field for the user setting service
+ /// </summary>
+ private static IUserSettingService userSettingService;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AutoNameHelper"/> class.
+ /// </summary>
+ /// <param name="userSetting">
+ /// The user Setting.
+ /// </param>
+ public AutoNameHelper(IUserSettingService userSetting)
+ {
+ userSettingService = userSetting;
+ }
+
+ /// <summary>
+ /// Function which generates the filename and path automatically based on
+ /// the Source Name, DVD title and DVD Chapters
+ /// </summary>
+ /// <param name="task">
+ /// The task.
+ /// </param>
+ /// <param name="sourceOrLabelName">
+ /// The Source or Label Name
+ /// </param>
+ /// <returns>
+ /// The Generated FileName
+ /// </returns>
+ public static string AutoName(EncodeTask task, string sourceOrLabelName)
+ {
+ string autoNamePath = string.Empty;
+ if (task.Title != 0) // TODO check.
+ {
+ // Get the Source Name and remove any invalid characters
+ string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty));
+ sourceName = Path.GetFileNameWithoutExtension(sourceName);
+
+ // Remove Underscores
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
+ sourceName = sourceName.Replace("_", " ");
+
+ // Switch to "Title Case"
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameTitleCase))
+ sourceName = sourceName.ToTitleCase();
+
+ // Get the Selected Title Number
+
+ string dvdTitle = task.Title.ToString();
+
+ // Get the Chapter Start and Chapter End Numbers
+ string chapterStart = task.StartPoint.ToString();
+ string chapterFinish = task.EndPoint.ToString();
+ string combinedChapterTag = chapterStart;
+ if (chapterFinish != chapterStart && chapterFinish != string.Empty)
+ combinedChapterTag = chapterStart + "-" + chapterFinish;
+
+ /*
+ * File Name
+ */
+ string destinationFilename;
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != string.Empty)
+ {
+ destinationFilename = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat);
+ destinationFilename = destinationFilename.Replace("{source}", sourceName)
+ .Replace("{title}", dvdTitle)
+ .Replace("{chapters}", combinedChapterTag)
+ .Replace("{date}", DateTime.Now.Date.ToShortDateString().Replace('/', '-'));
+ }
+ else
+ destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
+
+ /*
+ * File Extension
+ */
+ if (task.OutputFormat == OutputFormat.Mp4 || task.OutputFormat == OutputFormat.M4V)
+ {
+ switch (userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v))
+ {
+ case 0: // Automatic
+ destinationFilename += task.IncludeChapterMarkers || task.RequiresM4v ? ".m4v" : ".mp4";
+ break;
+ case 1: // Always MP4
+ destinationFilename += ".mp4";
+ break;
+ case 2: // Always M4V
+ destinationFilename += ".m4v";
+ break;
+ }
+ }
+ else if (task.OutputFormat == OutputFormat.Mkv)
+ destinationFilename += ".mkv";
+
+ /*
+ * File Destination Path
+ */
+
+ // If there is an auto name path, use it...
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source))
+ {
+ string savedPath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty);
+
+ string directory = Directory.Exists(task.Source)
+ ? task.Source
+ : Path.GetDirectoryName(task.Source);
+ string requestedPath = Path.Combine(directory, savedPath);
+
+ autoNamePath = Path.Combine(requestedPath, destinationFilename);
+ if (autoNamePath == task.Source)
+ {
+ // Append out_ to files that already exist or is the source file
+ autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename);
+ }
+ }
+ else if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source))
+ {
+ // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source.
+ string path = Path.GetDirectoryName(task.Source);
+ if (!string.IsNullOrEmpty(path))
+ {
+ string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
+ string sourceFolder = filesArray[filesArray.Length - 1];
+
+ autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename);
+ }
+ }
+ else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString()))
+ {
+ // Third case: If the destination box doesn't already contain a path, make one.
+ if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != string.Empty &&
+ userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location")
+ {
+ autoNamePath = Path.Combine(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath), destinationFilename);
+ }
+ else // ...otherwise, output to the source directory
+ autoNamePath = null;
+ }
+ else // Otherwise, use the path that is already there.
+ {
+ // Use the path and change the file extension to match the previous destination
+ autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename);
+ }
+ }
+
+ return autoNamePath;
+ }
+ }
+ }
+}
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();
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index 13e5a896e..8c2e05d93 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -61,6 +61,7 @@ namespace HandBrakeWPF.Startup this.windsorContainer.Register(Component.For<ILogViewModel>().ImplementedBy<LogViewModel>().LifeStyle.Is(LifestyleType.Singleton));
this.windsorContainer.Register(Component.For<IAboutViewModel>().ImplementedBy<AboutViewModel>().LifeStyle.Is(LifestyleType.Singleton));
this.windsorContainer.Register(Component.For<IOptionsViewModel>().ImplementedBy<OptionsViewModel>().LifeStyle.Is(LifestyleType.Singleton));
+ this.windsorContainer.Register(Component.For<IUpdateVersionService>().ImplementedBy<UpdateVersionService>().LifeStyle.Is(LifestyleType.Singleton));
}
/// <summary>
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index 83a185276..aeba8e32e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -9,25 +9,233 @@ namespace HandBrakeWPF.ViewModels
{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Windows;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
using Caliburn.Micro;
- using HandBrakeWPF.ViewModels.Interfaces;
+ using Interfaces;
+
+ using HandBrake.ApplicationServices.EventArgs;
/// <summary>
/// The Log View Model
/// </summary>
public class LogViewModel : ViewModelBase, ILogViewModel
{
+ /**
+ * TODO
+ * - Live update the log file.
+ */
+
+ #region Private Fields
+
+ /// <summary>
+ /// Backing field for the encodeService service
+ /// </summary>
+ private readonly IEncode encodeService;
+
+ /// <summary>
+ /// Backing field for the Scan Service
+ /// </summary>
+ private readonly IScan scanService;
+
+ /// <summary>
+ /// Backing field for the selected mode
+ /// </summary>
+ private int selectedMode;
+
+ /// <summary>
+ /// Backing field for the log info.
+ /// </summary>
+ private string log;
+
+ #endregion
+
/// <summary>
/// Initializes a new instance of the <see cref="LogViewModel"/> class.
/// </summary>
/// <param name="windowManager">
/// The window manager.
/// </param>
- public LogViewModel(IWindowManager windowManager)
+ /// <param name="encodeService">
+ /// The encode service.
+ /// </param>
+ /// <param name="scanService">
+ /// The scan service.
+ /// </param>
+ public LogViewModel(IWindowManager windowManager, IEncode encodeService, IScan scanService)
: base(windowManager)
{
+ this.encodeService = encodeService;
+ this.scanService = scanService;
this.Title = "Log Viewer";
+ this.SelectedMode = 0;
+ }
+
+ /// <summary>
+ /// Gets or sets Log.
+ /// </summary>
+ public string Log
+ {
+ get
+ {
+ return log;
+ }
+ set
+ {
+ log = value;
+ this.NotifyOfPropertyChange("Log");
+ }
+ }
+
+ /// <summary>
+ /// Gets LogModes.
+ /// </summary>
+ public IEnumerable<string> LogModes
+ {
+ get
+ {
+ return new List<string> { "Encode Log", "Scan Log" };
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets SelectedMode.
+ /// </summary>
+ public int SelectedMode
+ {
+ get
+ {
+ return selectedMode;
+ }
+ set
+ {
+ selectedMode = value;
+ this.NotifyOfPropertyChange("SelectedMode");
+ this.ChangeLogDisplay();
+ }
+ }
+
+ /// <summary>
+ /// Open the Log file directory
+ /// </summary>
+ public void OpenLogDirectory()
+ {
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string windir = Environment.GetEnvironmentVariable("WINDIR");
+ Process prc = new Process { StartInfo = { FileName = windir + @"\explorer.exe", Arguments = logDir } };
+ prc.Start();
+ }
+
+ /// <summary>
+ /// Copy the log file to the system clipboard
+ /// </summary>
+ public void CopyLog()
+ {
+ Clipboard.SetDataObject(this.Log, true);
+ }
+
+ /// <summary>
+ /// Handle the OnActivate Caliburn Event
+ /// </summary>
+ protected override void OnActivate()
+ {
+ this.scanService.ScanStared += scanService_ScanStared;
+ this.scanService.ScanCompleted += scanService_ScanCompleted;
+ this.encodeService.EncodeStarted += encodeService_EncodeStarted;
+ this.encodeService.EncodeCompleted += encodeService_EncodeCompleted;
+ base.OnActivate();
+ }
+
+ /// <summary>
+ /// Handle the OnDeactivate Caliburn Event
+ /// </summary>
+ /// <param name="close">
+ /// The close.
+ /// </param>
+ protected override void OnDeactivate(bool close)
+ {
+ this.scanService.ScanStared -= scanService_ScanStared;
+ this.encodeService.EncodeStarted -= encodeService_EncodeStarted;
+ this.Load();
+ base.OnDeactivate(close);
+ }
+
+ /// <summary>
+ /// Change the Log Display
+ /// </summary>
+ private void ChangeLogDisplay()
+ {
+ this.Log = this.SelectedMode == 0 ? this.encodeService.ActivityLog : this.scanService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Encode Started Event Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeStarted(object sender, EventArgs e)
+ {
+ this.SelectedMode = 0;
+ this.Log = this.encodeService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Scan Started Event Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void scanService_ScanStared(object sender, EventArgs e)
+ {
+ this.SelectedMode = 1;
+ this.Log = this.scanService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Scan Completed Event Handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void scanService_ScanCompleted(object sender, ScanCompletedEventArgs e)
+ {
+ if (this.SelectedMode == 1)
+ {
+ this.Log = this.scanService.ActivityLog;
+ }
+ }
+
+ /// <summary>
+ /// Encode Completed Event Handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeCompleted(object sender, EncodeCompletedEventArgs e)
+ {
+ if (this.SelectedMode == 0)
+ {
+ this.Log = this.encodeService.ActivityLog;
+ }
}
}
-}
+}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 5a8ecd233..1e6034cf9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -83,6 +83,11 @@ namespace HandBrakeWPF.ViewModels /// </summary>
private string sourceLabel;
+ public string sourcePath;
+ private string dvdDrivePath;
+ private string dvdDriveLabel;
+ private List<DriveInformation> drives;
+
/// <summary>
/// The Toolbar Status Label
/// </summary>
@@ -278,6 +283,43 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Gets SourceName.
+ /// </summary>
+ public string SourceName
+ {
+ get
+ {
+ if (this.selectedSourceType == SourceType.DvdDrive)
+ {
+ return this.dvdDriveLabel;
+ }
+
+ if (selectedTitle != null && !string.IsNullOrEmpty(selectedTitle.SourceName))
+ {
+ return Path.GetFileName(selectedTitle.SourceName);
+ }
+
+ // We have a drive, selected as a folder.
+ if (this.sourcePath.EndsWith("\\"))
+ {
+ drives = GeneralUtilities.GetDrives();
+ foreach (DriveInformation item in drives)
+ {
+ if (item.RootDirectory.Contains(this.sourcePath))
+ {
+ return item.VolumeLabel;
+ }
+ }
+ }
+
+ if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
+ return Path.GetFileNameWithoutExtension(this.sourcePath);
+
+ return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
+ }
+ }
+
+ /// <summary>
/// Gets RangeMode.
/// </summary>
public IEnumerable<PointToPointMode> RangeMode
@@ -832,6 +874,7 @@ namespace HandBrakeWPF.ViewModels {
// TODO
// 1. Disable GUI.
+ this.sourcePath = filename;
this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting<int>(ASUserSettingConstants.PreviewScanCount));
}
diff --git a/win/CS/HandBrakeWPF/Views/LogView.xaml b/win/CS/HandBrakeWPF/Views/LogView.xaml index 1d26ef28c..24e05acdd 100644 --- a/win/CS/HandBrakeWPF/Views/LogView.xaml +++ b/win/CS/HandBrakeWPF/Views/LogView.xaml @@ -1,7 +1,7 @@ <Window x:Class="HandBrakeWPF.Views.LogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="{Binding Title}" Height="600" Width="420">
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.caliburnproject.org"
+ Title="{Binding Title}" Height="600" Width="500">
<Grid>
<Grid>
<Grid.RowDefinitions>
@@ -9,24 +9,26 @@ <RowDefinition Height="*" />
</Grid.RowDefinitions>
<ToolBar Grid.Row="0">
- <Button>
+ <Button cal:Message.Attach="[Event Click] = [Action CopyLog]">
<StackPanel Orientation="Horizontal">
<Image Source="Images/copy.png" Width="16"/>
<TextBlock Text="Copy" Margin="2,0,0,0" />
</StackPanel>
</Button>
- <Button Margin="5,0,0,0" >
+ <Button Margin="5,0,0,0" cal:Message.Attach="[Event Click] = [Action OpenLogDirectory]">
<StackPanel Orientation="Horizontal">
<Image Source="Images/folder.png" Width="16"/>
<TextBlock Text="Open Log Directory" Margin="2,0,0,0" />
</StackPanel>
</Button>
- <ComboBox Width="75" HorizontalAlignment="Right">
+ <Separator />
+
+ <ComboBox Width="100" HorizontalAlignment="Right" ItemsSource="{Binding LogModes}" SelectedIndex="{Binding SelectedMode}">
</ComboBox>
</ToolBar>
- <RichTextBox Grid.Row="1" />
+ <TextBox AcceptsReturn="True" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Visible" IsReadOnly="True" Grid.Row="1" Text="{Binding Log}" />
</Grid>
</Grid>
diff --git a/win/CS/HandBrakeWPF/Views/LogView.xaml.cs b/win/CS/HandBrakeWPF/Views/LogView.xaml.cs index 375cbed43..79a8986a9 100644 --- a/win/CS/HandBrakeWPF/Views/LogView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/LogView.xaml.cs @@ -1,18 +1,16 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogView.xaml.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>
+// Interaction logic for LogView.xaml
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
+ using System.Windows;
+
/// <summary>
/// Interaction logic for LogView.xaml
/// </summary>
|