using System.Windows.Forms;\r
using Functions;\r
\r
+ using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Parsing;\r
\r
using Presets;\r
using System.Globalization;\r
using System.Windows.Forms;\r
\r
+ using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Parsing;\r
\r
using Presets;\r
<HintPath>..\libraries\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>\r
</Reference>\r
<Reference Include="PresentationCore" />\r
+ <Reference Include="PresentationFramework" />\r
<Reference Include="System" />\r
<Reference Include="System.Core">\r
<RequiredTargetFramework>3.5</RequiredTargetFramework>\r
<Compile Include="Model\Encoding\SubtitleTrack.cs" />\r
<Compile Include="Model\Encoding\VideoEncoder.cs" />\r
<Compile Include="Model\Encoding\VideoEncodeMode.cs" />\r
+ <Compile Include="Model\Preset.cs" />\r
<Compile Include="Model\QueueTask.cs" />\r
<Compile Include="Model\Encoding\SubtitleType.cs" />\r
<Compile Include="Parsing\AudioTrack.cs" />\r
<Compile Include="Services\Interfaces\IQueueManager.cs" />\r
<Compile Include="Services\Interfaces\IQueueProcessor.cs" />\r
<Compile Include="Services\Interfaces\IScan.cs" />\r
+ <Compile Include="Services\Interfaces\IPresetService.cs" />\r
<Compile Include="Services\LibScan.cs" />\r
+ <Compile Include="Services\PresetService.cs" />\r
<Compile Include="Services\QueueManager.cs" />\r
<Compile Include="Services\QueueProcessor.cs" />\r
<Compile Include="Services\ScanService.cs" />\r
/// </summary>\r
public class Init\r
{\r
+ /**\r
+ * I really dislike this, Need to replace this sooner rather than later.\r
+ **/ \r
+\r
+\r
/// <summary>\r
/// Setup the Settings used by the applicaiton with this library\r
/// </summary>\r
/// <param name="preventSleep">\r
/// Prevent the system from sleeping\r
/// </param>\r
- public static void SetupSettings(string versionString, int instanceId, string completionOption, bool disableDvdNav,\r
+ public static void SetupSettings(string versionString, string version, int instanceId, string completionOption, bool disableDvdNav,\r
bool growlEncode, bool growlQueue, string processPriority, string saveLogPath, bool saveLogToSpecifiedPath,\r
bool saveLogWithVideo, bool showCliForInGuiEncodeStatus, bool preventSleep)\r
{\r
InstanceId = instanceId;\r
HandBrakeGuiVersionString = versionString;\r
+ Version = version;\r
CompletionOption = completionOption;\r
DisableDvdNav = disableDvdNav;\r
GrowlEncode = growlEncode;\r
/// </summary>\r
public static string HandBrakeGuiVersionString;\r
\r
+ /// <summary>\r
+ /// HandBrakes Version or Svn revision\r
+ /// </summary>\r
+ public static string Version;\r
+\r
/// <summary>\r
/// What to do when the encode completes.\r
/// </summary>\r
Homepage: <http://handbrake.fr>.\r
It may be used under the terms of the GNU General Public License. */\r
\r
-namespace Handbrake.Presets\r
+namespace HandBrake.ApplicationServices.Model\r
{\r
/// <summary>\r
- /// A Preset\r
+ /// A Preset for encoding with.\r
/// </summary>\r
public class Preset \r
{\r
/// </summary>\r
public bool CropSettings { get; set; }\r
\r
+ /// <summary>\r
+ /// Gets or sets the Settings for this encode/preset. Can be used in place of Query property.\r
+ /// </summary>\r
+ public EncodeTask EncodeSettings { get; set; }\r
+\r
/// <summary>\r
/// Gets or sets The version number which associates this preset with a HB build\r
/// </summary>\r
/// Gets or sets the Description for the preset\r
/// </summary>\r
public string Description { get; set; }\r
+\r
+ /// <summary>\r
+ /// Gets or sets a value indicating whether this is a built in preset\r
+ /// </summary>\r
+ public bool IsBuildIn { get; set; }\r
}\r
}
\ No newline at end of file
--- /dev/null
+/* IPresetService.cs $\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
+\r
+namespace HandBrake.ApplicationServices.Services.Interfaces\r
+{\r
+ using System.ComponentModel;\r
+\r
+ using HandBrake.ApplicationServices.Model;\r
+\r
+ /// <summary>\r
+ /// The Preset Service Interface\r
+ /// </summary>\r
+ public interface IPresetService\r
+ {\r
+ /// <summary>\r
+ /// Gets or sets a Collection of presets.\r
+ /// </summary>\r
+ ICollectionView Presets { get; set; }\r
+\r
+ /// <summary>\r
+ /// Add a new preset to the system\r
+ /// </summary>\r
+ /// <param name="preset">\r
+ /// A Preset to add\r
+ /// </param>\r
+ /// <returns>\r
+ /// True if added,\r
+ /// False if name already exists\r
+ /// </returns>\r
+ bool Add(Preset preset);\r
+\r
+ /// <summary>\r
+ /// Remove a preset with a given name from either the built in or user preset list.\r
+ /// </summary>\r
+ /// <param name="preset">\r
+ /// The Preset to remove\r
+ /// </param>\r
+ void Remove(Preset preset);\r
+\r
+ /// <summary>\r
+ /// Get a Preset\r
+ /// </summary>\r
+ /// <param name="name">\r
+ /// The name of the preset to get\r
+ /// </param>\r
+ /// <returns>\r
+ /// A Preset or null object\r
+ /// </returns>\r
+ Preset GetPreset(string name);\r
+\r
+ /// <summary>\r
+ /// Clear Built-in Presets\r
+ /// </summary>\r
+ void ClearBuiltIn();\r
+\r
+ /// <summary>\r
+ /// Clear all presets\r
+ /// </summary>\r
+ void ClearAll();\r
+\r
+ /// <summary>\r
+ /// Reads the CLI's CLI output format and load's them into the preset List Preset\r
+ /// </summary>\r
+ /// <param name="cliPath">\r
+ /// The Path to the CLI, leave blank for current folder.\r
+ /// </param>\r
+ void UpdateBuiltInPresets(string cliPath);\r
+\r
+ /// <summary>\r
+ /// Check if the built in Presets stored are not out of date.\r
+ /// Update them if they are.\r
+ /// </summary>\r
+ /// <returns>true if out of date</returns>\r
+ bool CheckIfPresetsAreOutOfDate();\r
+\r
+ /// <summary>\r
+ /// Check if the preset "name" exists in either Presets or UserPresets lists.\r
+ /// </summary>\r
+ /// <param name="name">Name of the preset</param>\r
+ /// <returns>True if found</returns>\r
+ bool CheckIfPresetExists(string name);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* PresetService.cs $\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
+\r
+namespace HandBrake.ApplicationServices.Services\r
+{\r
+ using System;\r
+ using System.Collections.Generic;\r
+ using System.Collections.ObjectModel;\r
+ using System.ComponentModel;\r
+ using System.Diagnostics;\r
+ using System.IO;\r
+ using System.Linq;\r
+ using System.Text.RegularExpressions;\r
+ using System.Windows.Data;\r
+ using System.Xml.Serialization;\r
+\r
+ using HandBrake.ApplicationServices.Model;\r
+ using HandBrake.ApplicationServices.Services.Interfaces;\r
+\r
+ /// <summary>\r
+ /// The preset service manages HandBrake's presets\r
+ /// </summary>\r
+ public class PresetService : IPresetService\r
+ {\r
+ /**\r
+ * TODO:\r
+ * - Wire this into the Forms and WPF UI's\r
+ * - Note: This is untested so far. It'll likely need fixes before it can be used.\r
+ **/ \r
+\r
+ #region Private Variables\r
+\r
+ /// <summary>\r
+ /// XML Serializer\r
+ /// </summary>\r
+ private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Preset>));\r
+\r
+ /// <summary>\r
+ /// The User Preset file\r
+ /// </summary>\r
+ private readonly string userPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\user_presets.xml";\r
+\r
+ /// <summary>\r
+ /// The Built In Presets File\r
+ /// </summary>\r
+ private readonly string builtInPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\presets.xml";\r
+\r
+ /// <summary>\r
+ /// A Collection of presets\r
+ /// </summary>\r
+ private ObservableCollection<Preset> presets = new ObservableCollection<Preset>();\r
+\r
+ #endregion\r
+\r
+ /// <summary>\r
+ /// Initializes a new instance of the <see cref="PresetService"/> class.\r
+ /// </summary>\r
+ public PresetService()\r
+ {\r
+ this.Presets = CollectionViewSource.GetDefaultView(this.presets);\r
+ this.LoadPresets();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Gets or sets a Collection of presets.\r
+ /// </summary>\r
+ public ICollectionView Presets { get; set; }\r
+\r
+ #region Public Methods\r
+\r
+ /// <summary>\r
+ /// Add a new preset to the system\r
+ /// </summary>\r
+ /// <param name="preset">\r
+ /// A Preset to add\r
+ /// </param>\r
+ /// <returns>\r
+ /// True if added,\r
+ /// False if name already exists\r
+ /// </returns>\r
+ public bool Add(Preset preset)\r
+ {\r
+ if (this.CheckIfPresetExists(preset.Name) == false)\r
+ {\r
+ this.presets.Add(preset);\r
+\r
+ // Update the presets file\r
+ this.UpdatePresetFiles();\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Remove a preset with a given name from either the built in or user preset list.\r
+ /// </summary>\r
+ /// <param name="preset">\r
+ /// The Preset to remove\r
+ /// </param>\r
+ public void Remove(Preset preset)\r
+ {\r
+ this.presets.Remove(preset);\r
+\r
+ // Update the presets file\r
+ this.UpdatePresetFiles();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get a Preset\r
+ /// </summary>\r
+ /// <param name="name">\r
+ /// The name of the preset to get\r
+ /// </param>\r
+ /// <returns>\r
+ /// A Preset or null object\r
+ /// </returns>\r
+ public Preset GetPreset(string name)\r
+ {\r
+ return this.presets.FirstOrDefault(item => item.Name == name);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Clear Built-in Presets\r
+ /// </summary>\r
+ public void ClearBuiltIn()\r
+ {\r
+ List<Preset> remove = this.presets.Where(p => p.IsBuildIn).ToList();\r
+ foreach (Preset preset in remove)\r
+ {\r
+ this.presets.Remove(preset);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Clear all presets\r
+ /// </summary>\r
+ public void ClearAll()\r
+ {\r
+ this.presets.Clear();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Reads the CLI's CLI output format and load's them into the preset List Preset\r
+ /// </summary>\r
+ /// <param name="cliPath">\r
+ /// The Path to the CLI, leave blank for current folder.\r
+ /// </param>\r
+ public void UpdateBuiltInPresets(string cliPath)\r
+ {\r
+ // Create a new tempory file and execute the CLI to get the built in Presets.\r
+ string handbrakeCLIPath = Path.Combine(cliPath, "HandBrakeCLI.exe");\r
+ string presetsPath = Path.Combine(Path.GetTempPath(), "temp_presets.dat");\r
+ string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath);\r
+ \r
+ ProcessStartInfo getPresets = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden };\r
+\r
+ Process hbproc = Process.Start(getPresets);\r
+ hbproc.WaitForExit();\r
+ hbproc.Dispose();\r
+ hbproc.Close();\r
+\r
+ // Clear the current built in Presets and now parse the tempory Presets file.\r
+ this.presets.Clear();\r
+\r
+ if (File.Exists(presetsPath))\r
+ {\r
+ StreamReader presetInput = new StreamReader(presetsPath);\r
+\r
+ string category = String.Empty;\r
+\r
+ while (!presetInput.EndOfStream)\r
+ {\r
+ string line = presetInput.ReadLine();\r
+\r
+ // Found the beginning of a preset block \r
+ if (line != null && line.Contains("<") && !line.Contains("<<")) \r
+ {\r
+ category = line.Replace("<", string.Empty).Trim();\r
+ }\r
+\r
+ // Found a preset\r
+ if (line != null && line.Contains("+")) \r
+ {\r
+ Regex r = new Regex("(: )"); // Split on hyphens. \r
+ string[] presetName = r.Split(line);\r
+\r
+ bool pic = false;\r
+ if (presetName[2].Contains("crop"))\r
+ {\r
+ pic = true;\r
+ }\r
+\r
+ Preset newPreset = new Preset\r
+ {\r
+ Category = category,\r
+ Name = presetName[0].Replace("+", string.Empty).Trim(),\r
+ Query = presetName[2],\r
+ Version = Init.Version,\r
+ CropSettings = pic,\r
+ Description = string.Empty // Maybe one day we will populate this.\r
+ };\r
+ this.presets.Add(newPreset);\r
+ }\r
+ }\r
+ presetInput.Close();\r
+ presetInput.Dispose();\r
+ }\r
+\r
+ // Finally, Create a new or update the current Presets.xml file\r
+ this.UpdatePresetFiles();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Check if the built in Presets stored are not out of date.\r
+ /// Update them if they are.\r
+ /// </summary>\r
+ /// <returns>true if out of date</returns>\r
+ public bool CheckIfPresetsAreOutOfDate()\r
+ {\r
+ // Update built-in Presets if the built-in Presets belong to an older version.\r
+ if (this.presets.Count != 0)\r
+ {\r
+ if (this.presets[0].Version != Init.Version)\r
+ {\r
+ this.UpdateBuiltInPresets(string.Empty);\r
+ return true;\r
+ }\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Check if the preset "name" exists in either Presets or UserPresets lists.\r
+ /// </summary>\r
+ /// <param name="name">Name of the preset</param>\r
+ /// <returns>True if found</returns>\r
+ public bool CheckIfPresetExists(string name)\r
+ {\r
+ return name == string.Empty || this.presets.Any(item => item.Name == name);\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Private Helpers\r
+\r
+ /// <summary>\r
+ /// Recover from a courrpted preset file\r
+ /// Add .old to the current filename, and delete the current file.\r
+ /// </summary>\r
+ /// <param name="file">\r
+ /// The broken presets file.\r
+ /// </param>\r
+ private static void RecoverFromCorruptedPresetFile(string file)\r
+ {\r
+ // Recover from Error.\r
+ if (File.Exists(file))\r
+ {\r
+ string disabledFile = file + ".old";\r
+ File.Move(file, disabledFile);\r
+ if (File.Exists(file))\r
+ {\r
+ File.Delete(file);\r
+ }\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Load in the Built-in and User presets into the collection\r
+ /// </summary>\r
+ private void LoadPresets()\r
+ {\r
+ // First clear the Presets arraylists\r
+ this.presets.Clear();\r
+\r
+ // Load in the users Presets from UserPresets.xml\r
+ try\r
+ {\r
+ if (File.Exists(this.builtInPresetFile))\r
+ {\r
+ StreamReader reader = new StreamReader(this.builtInPresetFile);\r
+ List<Preset> list = (List<Preset>)Ser.Deserialize(reader);\r
+ foreach (Preset preset in list)\r
+ {\r
+ this.presets.Add(preset);\r
+ }\r
+\r
+ reader.Close();\r
+ }\r
+ }\r
+ catch (Exception)\r
+ {\r
+ RecoverFromCorruptedPresetFile(this.builtInPresetFile);\r
+ this.UpdateBuiltInPresets(string.Empty);\r
+ }\r
+\r
+ // Load in the users Presets from UserPresets.xml\r
+ try\r
+ {\r
+ if (File.Exists(this.userPresetFile))\r
+ {\r
+ StreamReader reader = new StreamReader(this.userPresetFile);\r
+ List<Preset> list = (List<Preset>)Ser.Deserialize(reader);\r
+ foreach (Preset preset in list)\r
+ {\r
+ this.presets.Add(preset);\r
+ }\r
+\r
+ reader.Close();\r
+ }\r
+ }\r
+ catch (Exception)\r
+ {\r
+ RecoverFromCorruptedPresetFile(this.userPresetFile);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Update the preset files\r
+ /// </summary>\r
+ private void UpdatePresetFiles()\r
+ {\r
+ try\r
+ {\r
+ using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write))\r
+ {\r
+ Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn));\r
+ strm.Close();\r
+ strm.Dispose();\r
+ }\r
+\r
+ using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write))\r
+ {\r
+ Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false));\r
+ strm.Close();\r
+ strm.Dispose();\r
+ }\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ throw new Exception("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n Error Information: \n\n", exc);\r
+ }\r
+ }\r
+\r
+ #endregion\r
+ }\r
+}\r
-namespace HandBrake.ApplicationServices.Services\r
+/* QueueManager.cs $\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
+\r
+namespace HandBrake.ApplicationServices.Services\r
{\r
using System;\r
using System.Collections.Generic;\r
<StyleCopSettings Version="4.3">\r
+ <GlobalSettings>\r
+ <BooleanProperty Name="WriteCache">False</BooleanProperty>\r
+ </GlobalSettings>\r
<Analyzers>\r
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules">\r
<Rules>\r
</Compile>\r
<Compile Include="Model\SourceType.cs" />\r
<Compile Include="Presets\PlistPresetHandler.cs" />\r
- <Compile Include="Presets\Preset.cs" />\r
<Compile Include="Presets\PresetsHandler.cs" />\r
<Compile Include="Functions\QueryParser.cs" />\r
<Compile Include="Program.cs" />\r
using System.Xml;\r
using Functions;\r
\r
+ using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Model.Encoding;\r
\r
- using Model;\r
-\r
/// <summary>\r
/// Plist Preset Converter\r
/// </summary>\r
using System.Windows.Forms;\r
using System.Xml.Serialization;\r
\r
+ using HandBrake.ApplicationServices.Model;\r
+\r
/// <summary>\r
/// The Preset Handler Class\r
/// </summary>\r
private static void InitializeApplicationServices()\r
{\r
string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
- Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
+ Init.SetupSettings(versionId, Settings.Default.hb_version, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
Settings.Default.growlEncode, Settings.Default.growlQueue,\r
Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath,\r
Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep);\r
"Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
Init.SetupSettings(\r
versionId,\r
+ Settings.Default.hb_version,\r
Program.InstanceId,\r
Settings.Default.CompletionOption,\r
Settings.Default.noDvdNav,\r
<value>2.0</value>\r
</resheader>\r
<resheader name="reader">\r
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
</resheader>\r
<resheader name="writer">\r
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
</resheader>\r
- <metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>132, 18</value>\r
</metadata>\r
<data name="check_m4v.ToolTip" xml:space="preserve">\r
\r
When disabled, Presseting "Stop" on the main winow will render the encode unplayable.</value>\r
</data>\r
- <metadata name="pathFinder.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="pathFinder.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>17, 17</value>\r
</metadata>\r
- <metadata name="openFile_vlc.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="openFile_vlc.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>224, 18</value>\r
</metadata>\r
- <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />\r
+ <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />\r
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">\r
<value>\r
AAABAAYAMDAAAAEACACoDgAAZgAAACAgAAABAAgAqAgAAA4PAAAQEAAAAQAIAGgFAAC2FwAAMDAAAAEA\r