summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs103
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj1
-rw-r--r--win/CS/HandBrake.ApplicationServices/Parsing/Title.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/Properties/Settings.Designer.cs266
-rw-r--r--win/CS/HandBrake.ApplicationServices/Properties/Settings.settings71
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs14
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode.cs13
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs45
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs11
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/PresetService.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs17
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ScanService.cs10
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs146
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs9
-rw-r--r--win/CS/HandBrake.ApplicationServices/app.config74
16 files changed, 285 insertions, 522 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs b/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs
new file mode 100644
index 000000000..b492bc2f0
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs
@@ -0,0 +1,103 @@
+/* SerializableDictionary.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Collections
+{
+ using System.Collections.Generic;
+ using System.Runtime.Serialization;
+ using System.Xml.Serialization;
+
+ /// <summary>
+ /// A Serializable Dictionary
+ /// </summary>
+ /// <typeparam name="TKey">
+ /// The Key Type
+ /// </typeparam>
+ /// <typeparam name="TValue">
+ /// The Value Type
+ /// </typeparam>
+ [XmlRoot("dictionary")]
+ public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
+ {
+ #region IXmlSerializable Members
+
+ /// <summary>
+ /// Get the Schema
+ /// </summary>
+ /// <returns>
+ /// Nothing. We don't use this.
+ /// </returns>
+ public System.Xml.Schema.XmlSchema GetSchema()
+ {
+ return null;
+ }
+
+ /// <summary>
+ /// Deserialize some XML into a dictionary
+ /// </summary>
+ /// <param name="reader">
+ /// The reader.
+ /// </param>
+ public void ReadXml(System.Xml.XmlReader reader)
+ {
+ XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
+ XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
+
+ bool wasEmpty = reader.IsEmptyElement;
+ reader.Read();
+
+ if (wasEmpty)
+ return;
+
+ while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
+ {
+ reader.ReadStartElement("item");
+
+ reader.ReadStartElement("key");
+ TKey key = (TKey)keySerializer.Deserialize(reader);
+ reader.ReadEndElement();
+
+ reader.ReadStartElement("value");
+ TValue value = (TValue)valueSerializer.Deserialize(reader);
+ reader.ReadEndElement();
+
+ this.Add(key, value);
+
+ reader.ReadEndElement();
+ reader.MoveToContent();
+ }
+ reader.ReadEndElement();
+ }
+
+ /// <summary>
+ /// Write the Dictionary out to XML
+ /// </summary>
+ /// <param name="writer">
+ /// The writer.
+ /// </param>
+ public void WriteXml(System.Xml.XmlWriter writer)
+ {
+ XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
+ XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
+
+ foreach (TKey key in this.Keys)
+ {
+ writer.WriteStartElement("item");
+
+ writer.WriteStartElement("key");
+ keySerializer.Serialize(writer, key);
+ writer.WriteEndElement();
+
+ writer.WriteStartElement("value");
+ TValue value = this[key];
+ valueSerializer.Serialize(writer, value);
+ writer.WriteEndElement();
+
+ writer.WriteEndElement();
+ }
+ }
+ #endregion
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index 4a6b13b34..78480847c 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -77,6 +77,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Collections\SerializableDictionary.cs" />
<Compile Include="Converters\EnumToDescConverter.cs" />
<Compile Include="Exceptions\GeneralApplicationException.cs" />
<Compile Include="EventArgs\EncodeCompletedEventArgs.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs b/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs
index 9b7146512..1ddb4730d 100644
--- a/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs
+++ b/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs
@@ -13,6 +13,8 @@ namespace HandBrake.ApplicationServices.Parsing
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model;
using Size = System.Drawing.Size;
@@ -28,6 +30,11 @@ namespace HandBrake.ApplicationServices.Parsing
private static readonly CultureInfo Culture = new CultureInfo("en-US", false);
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private static IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// Initializes a new instance of the <see cref="Title"/> class.
/// </summary>
public Title()
@@ -151,7 +158,7 @@ namespace HandBrake.ApplicationServices.Parsing
}
// Multi-Angle Support if LibDvdNav is enabled
- if (!Properties.Settings.Default.DisableLibDvdNav)
+ if (!userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav))
{
m = Regex.Match(nextLine, @" \+ angle\(s\) ([0-9])");
if (m.Success)
diff --git a/win/CS/HandBrake.ApplicationServices/Properties/Settings.Designer.cs b/win/CS/HandBrake.ApplicationServices/Properties/Settings.Designer.cs
index 7489ba72a..fd41570e6 100644
--- a/win/CS/HandBrake.ApplicationServices/Properties/Settings.Designer.cs
+++ b/win/CS/HandBrake.ApplicationServices/Properties/Settings.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.431
+// Runtime Version:4.0.30319.468
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -22,269 +22,5 @@ namespace HandBrake.ApplicationServices.Properties {
return defaultInstance;
}
}
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1")]
- public int Verbosity {
- get {
- return ((int)(this["Verbosity"]));
- }
- set {
- this["Verbosity"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0.5")]
- public double X264Step {
- get {
- return ((double)(this["X264Step"]));
- }
- set {
- this["X264Step"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("Do Nothing")]
- public string WhenCompleteAction {
- get {
- return ((string)(this["WhenCompleteAction"]));
- }
- set {
- this["WhenCompleteAction"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool GrowlEncode {
- get {
- return ((bool)(this["GrowlEncode"]));
- }
- set {
- this["GrowlEncode"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool GrowlQueue {
- get {
- return ((bool)(this["GrowlQueue"]));
- }
- set {
- this["GrowlQueue"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("Below Normal")]
- public string ProcessPriority {
- get {
- return ((string)(this["ProcessPriority"]));
- }
- set {
- this["ProcessPriority"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool PreventSleep {
- get {
- return ((bool)(this["PreventSleep"]));
- }
- set {
- this["PreventSleep"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool ShowCLI {
- get {
- return ((bool)(this["ShowCLI"]));
- }
- set {
- this["ShowCLI"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool SaveLogToCopyDirectory {
- get {
- return ((bool)(this["SaveLogToCopyDirectory"]));
- }
- set {
- this["SaveLogToCopyDirectory"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool SaveLogWithVideo {
- get {
- return ((bool)(this["SaveLogWithVideo"]));
- }
- set {
- this["SaveLogWithVideo"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string SaveLogCopyDirectory {
- get {
- return ((string)(this["SaveLogCopyDirectory"]));
- }
- set {
- this["SaveLogCopyDirectory"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string HandBrakeVersion {
- get {
- return ((string)(this["HandBrakeVersion"]));
- }
- set {
- this["HandBrakeVersion"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
- public int HandBrakeBuild {
- get {
- return ((int)(this["HandBrakeBuild"]));
- }
- set {
- this["HandBrakeBuild"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string InstanceId {
- get {
- return ((string)(this["InstanceId"]));
- }
- set {
- this["InstanceId"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool DisableLibDvdNav {
- get {
- return ((bool)(this["DisableLibDvdNav"]));
- }
- set {
- this["DisableLibDvdNav"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string HandBrakePlatform {
- get {
- return ((string)(this["HandBrakePlatform"]));
- }
- set {
- this["HandBrakePlatform"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string HandBrakeExeHash {
- get {
- return ((string)(this["HandBrakeExeHash"]));
- }
- set {
- this["HandBrakeExeHash"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string Setting {
- get {
- return ((string)(this["Setting"]));
- }
- set {
- this["Setting"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string SendFileTo {
- get {
- return ((string)(this["SendFileTo"]));
- }
- set {
- this["SendFileTo"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string SendFileToArgs {
- get {
- return ((string)(this["SendFileToArgs"]));
- }
- set {
- this["SendFileToArgs"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool SendFile {
- get {
- return ((bool)(this["SendFile"]));
- }
- set {
- this["SendFile"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("10")]
- public int MinTitleScanDuration {
- get {
- return ((int)(this["MinTitleScanDuration"]));
- }
- set {
- this["MinTitleScanDuration"] = value;
- }
- }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Properties/Settings.settings b/win/CS/HandBrake.ApplicationServices/Properties/Settings.settings
index 9ef6aaa0f..2bd17f050 100644
--- a/win/CS/HandBrake.ApplicationServices/Properties/Settings.settings
+++ b/win/CS/HandBrake.ApplicationServices/Properties/Settings.settings
@@ -1,72 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
-<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="HandBrake.ApplicationServices.Properties" GeneratedClassName="Settings">
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles />
- <Settings>
- <Setting Name="Verbosity" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">1</Value>
- </Setting>
- <Setting Name="X264Step" Type="System.Double" Scope="User">
- <Value Profile="(Default)">0.5</Value>
- </Setting>
- <Setting Name="WhenCompleteAction" Type="System.String" Scope="User">
- <Value Profile="(Default)">Do Nothing</Value>
- </Setting>
- <Setting Name="GrowlEncode" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="GrowlQueue" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="ProcessPriority" Type="System.String" Scope="User">
- <Value Profile="(Default)">Below Normal</Value>
- </Setting>
- <Setting Name="PreventSleep" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">True</Value>
- </Setting>
- <Setting Name="ShowCLI" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="SaveLogToCopyDirectory" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="SaveLogWithVideo" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="SaveLogCopyDirectory" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="HandBrakeVersion" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="HandBrakeBuild" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
- </Setting>
- <Setting Name="InstanceId" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="DisableLibDvdNav" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="HandBrakePlatform" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="HandBrakeExeHash" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="Setting" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="SendFileTo" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="SendFileToArgs" Type="System.String" Scope="User">
- <Value Profile="(Default)" />
- </Setting>
- <Setting Name="SendFile" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
- </Setting>
- <Setting Name="MinTitleScanDuration" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">10</Value>
- </Setting>
- </Settings>
+ <Settings />
</SettingsFile> \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
index 978d4c9af..48505fc6f 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
@@ -8,7 +8,6 @@ namespace HandBrake.ApplicationServices.Services.Base
using System;
using System.IO;
using System.Text;
- using System.Threading;
using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Functions;
@@ -29,6 +28,11 @@ namespace HandBrake.ApplicationServices.Services.Base
private static readonly object fileWriterLock = new object();
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// Windows 7 API Pack wrapper
/// </summary>
private Win7 windowsSeven = new Win7();
@@ -210,17 +214,17 @@ namespace HandBrake.ApplicationServices.Services.Base
File.Copy(tempLogFile, Path.Combine(logDir, encodeLogFile));
// Save a copy of the log file in the same location as the enocde.
- if (Properties.Settings.Default.SaveLogWithVideo)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.SaveLogWithVideo))
{
File.Copy(tempLogFile, Path.Combine(encodeDestinationPath, encodeLogFile));
}
// Save a copy of the log file to a user specified location
- if (Directory.Exists(Properties.Settings.Default.SaveLogCopyDirectory) &&
- Properties.Settings.Default.SaveLogToCopyDirectory)
+ if (Directory.Exists(this.userSettingService.GetUserSetting<string>(UserSettingConstants.SaveLogCopyDirectory)) &&
+ this.userSettingService.GetUserSetting<bool>(UserSettingConstants.SaveLogToCopyDirectory))
{
File.Copy(
- tempLogFile, Path.Combine(Properties.Settings.Default.SaveLogCopyDirectory, encodeLogFile));
+ tempLogFile, Path.Combine(this.userSettingService.GetUserSetting<string>(UserSettingConstants.SaveLogCopyDirectory), encodeLogFile));
}
}
catch (Exception)
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
index 6acfe5807..04290eced 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
@@ -26,6 +26,11 @@ namespace HandBrake.ApplicationServices.Services
#region Private Variables
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// Gets The Process Handle
/// </summary>
private IntPtr processHandle;
@@ -102,7 +107,7 @@ namespace HandBrake.ApplicationServices.Services
}
}
- if (Properties.Settings.Default.PreventSleep)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep))
{
Win32.PreventSleep();
}
@@ -116,7 +121,7 @@ namespace HandBrake.ApplicationServices.Services
RedirectStandardOutput = true,
RedirectStandardError = enableLogging ? true : false,
UseShellExecute = false,
- CreateNoWindow = !Properties.Settings.Default.ShowCLI ? true : false
+ CreateNoWindow = !this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ShowCLI) ? true : false
};
this.HbProcess = new Process { StartInfo = cliStart };
@@ -142,7 +147,7 @@ namespace HandBrake.ApplicationServices.Services
}
// Set the Process Priority
- switch (Properties.Settings.Default.ProcessPriority)
+ switch (this.userSettingService.GetUserSetting<string>(UserSettingConstants.ProcessPriority))
{
case "Realtime":
this.HbProcess.PriorityClass = ProcessPriorityClass.RealTime;
@@ -253,7 +258,7 @@ namespace HandBrake.ApplicationServices.Services
this.WindowsSeven.SetTaskBarProgressToNoProgress();
}
- if (Properties.Settings.Default.PreventSleep)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep))
{
Win32.AllowSleep();
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs
index 9a96edab2..c3290f64f 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs
@@ -23,48 +23,18 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void SetUserSetting(string name, object value);
/// <summary>
- /// Get an Integer type user setting
+ /// Get user setting for a given key.
/// </summary>
/// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- int GetUserSettingInt(string name);
-
- /// <summary>
- /// Get an String type user setting
- /// </summary>
- /// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- string GetUserSettingString(string name);
-
- /// <summary>
- /// Get an Boolean type user setting
- /// </summary>
- /// <param name="name">
- /// The setting name
+ /// The name.
/// </param>
+ /// <typeparam name="T">
+ /// The Type of the setting
+ /// </typeparam>
/// <returns>
- /// The settings value
+ /// The user setting
/// </returns>
- bool GetUserSettingBoolean(string name);
-
- /// <summary>
- /// Get an Double type user setting
- /// </summary>
- /// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- double GetUserSettingDouble(string name);
+ T GetUserSetting<T>(string name);
/// <summary>
/// Get an StringCollection type user setting
@@ -76,6 +46,5 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
/// The settings value
/// </returns>
System.Collections.Specialized.StringCollection GetUserSettingStringCollection(string name);
-
}
} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
index d7af9b224..e677d4784 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
@@ -33,6 +33,11 @@ namespace HandBrake.ApplicationServices.Services
private static readonly object logLock = new object();
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// The Start time of the current Encode;
/// </summary>
private DateTime startTime;
@@ -109,7 +114,7 @@ namespace HandBrake.ApplicationServices.Services
}
// Prvent the system from sleeping if the user asks
- if (Properties.Settings.Default.PreventSleep)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep) )
{
Win32.PreventSleep();
}
@@ -121,7 +126,7 @@ namespace HandBrake.ApplicationServices.Services
this.instance.StartEncode(encodeJob);
// Set the Process Priority
- switch (Properties.Settings.Default.ProcessPriority)
+ switch (this.userSettingService.GetUserSetting<string>(UserSettingConstants.ProcessPriority))
{
case "Realtime":
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
@@ -280,7 +285,7 @@ namespace HandBrake.ApplicationServices.Services
this.WindowsSeven.SetTaskBarProgressToNoProgress();
}
- if (Properties.Settings.Default.PreventSleep)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep))
{
Win32.AllowSleep();
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs
index 09788e6b4..9cad60e4e 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs
@@ -40,6 +40,11 @@ namespace HandBrake.ApplicationServices.Services
private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Preset>));
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// The User Preset file
/// </summary>
private readonly string userPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\user_presets.xml";
@@ -257,7 +262,7 @@ namespace HandBrake.ApplicationServices.Services
Category = category,
Name = presetName[0].Replace("+", string.Empty).Trim(),
Query = presetName[2],
- Version = Properties.Settings.Default.HandBrakeVersion,
+ Version = this.userSettingService.GetUserSetting<string>(UserSettingConstants.HandBrakeVersion),
CropSettings = pic,
Description = string.Empty, // Maybe one day we will populate this.
IsBuildIn = true
@@ -297,7 +302,7 @@ namespace HandBrake.ApplicationServices.Services
List<Preset> preset = this.presets.Where(p => p.IsBuildIn).ToList();
if (preset.Count > 0)
{
- if (preset[0].Version != Properties.Settings.Default.HandBrakeVersion)
+ if (preset[0].Version != this.userSettingService.GetUserSetting<string>(UserSettingConstants.HandBrakeVersion))
{
this.UpdateBuiltInPresets();
return true;
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
index be9c46359..30ba395f4 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
@@ -21,6 +21,11 @@ namespace HandBrake.ApplicationServices.Services
public class QueueProcessor : IQueueProcessor
{
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private static IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// Initializes a new instance of the <see cref="QueueProcessor"/> class.
/// </summary>
/// <param name="queueManager">
@@ -196,7 +201,7 @@ namespace HandBrake.ApplicationServices.Services
this.QueueManager.LastProcessedJob.Status = QueueItemStatus.Completed;
// Growl
- if (Properties.Settings.Default.GrowlEncode)
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlEncode))
GrowlCommunicator.Notify("Encode Completed",
"Put down that cocktail...\nyour Handbrake encode is done.");
@@ -266,10 +271,10 @@ namespace HandBrake.ApplicationServices.Services
/// <param name="file"> The file path</param>
private static void SendToApplication(string file)
{
- if (Properties.Settings.Default.SendFile && !string.IsNullOrEmpty(Properties.Settings.Default.SendFileTo))
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.SendFile) && !string.IsNullOrEmpty(userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileTo)))
{
- string args = string.Format("{0} \"{1}\"", Properties.Settings.Default.SendFileToArgs, file);
- ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.SendFileTo, args);
+ string args = string.Format("{0} \"{1}\"", userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileToArgs), file);
+ ProcessStartInfo vlc = new ProcessStartInfo(userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileTo), args);
Process.Start(vlc);
}
}
@@ -280,13 +285,13 @@ namespace HandBrake.ApplicationServices.Services
private static void Finish()
{
// Growl
- if (Properties.Settings.Default.GrowlQueue)
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlQueue))
{
GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");
}
// Do something whent he encode ends.
- switch (Properties.Settings.Default.WhenCompleteAction)
+ switch (userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction))
{
case "Shutdown":
Process.Start("Shutdown", "-s -t 60");
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
index 3c2a736e8..652115c06 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
@@ -44,6 +44,11 @@ namespace HandBrake.ApplicationServices.Services
/// </summary>
StringBuilder header = GeneralUtilities.CreateCliLogHeader();
+ /// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private IUserSettingService userSettingService = new UserSettingService();
+
#endregion
/// <summary>
@@ -190,13 +195,12 @@ namespace HandBrake.ApplicationServices.Services
extraArguments += " --previews " + previewCount;
}
-
- if (Properties.Settings.Default.DisableLibDvdNav)
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav))
{
extraArguments += " --no-dvdnav";
}
- extraArguments += string.Format(" --min-duration={0}", Properties.Settings.Default.MinTitleScanDuration);
+ extraArguments += string.Format(" --min-duration={0}", this.userSettingService.GetUserSetting<int>(UserSettingConstants.MinScanDuration));
if (title > 0)
{
diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
index f6d6c55e2..6ef071d4b 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
@@ -5,6 +5,14 @@
namespace HandBrake.ApplicationServices.Services
{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.Specialized;
+ using System.IO;
+ using System.Xml.Serialization;
+
+ using HandBrake.ApplicationServices.Collections;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
@@ -13,6 +21,33 @@ namespace HandBrake.ApplicationServices.Services
public class UserSettingService : IUserSettingService
{
/// <summary>
+ /// The Settings File
+ /// </summary>
+ private readonly string settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\settings.xml";
+
+ /// <summary>
+ /// The XML Serializer
+ /// </summary>
+ readonly XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, object>));
+
+ /// <summary>
+ /// The User Settings
+ /// </summary>
+ private SerializableDictionary<string, object> userSettings;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UserSettingService"/> class.
+ /// </summary>
+ public UserSettingService()
+ {
+ this.Load();
+ if (userSettings == null || userSettings.Count == 0)
+ {
+ this.LoadDefaults();
+ }
+ }
+
+ /// <summary>
/// Set the specified user setting.
/// </summary>
/// <param name="name">
@@ -23,29 +58,34 @@ namespace HandBrake.ApplicationServices.Services
/// </param>
public void SetUserSetting(string name, object value)
{
- Properties.Settings.Default[name] = value;
- Properties.Settings.Default.Save();
+ this.userSettings[name] = value;
+ this.Save();
}
/// <summary>
- /// Get an Integer type user setting
+ /// Get user setting for a given key.
/// </summary>
/// <param name="name">
- /// The setting name
+ /// The name.
/// </param>
+ /// <typeparam name="T">
+ /// The Type of the setting
+ /// </typeparam>
/// <returns>
- /// The settings value
+ /// The user setting
/// </returns>
- public int GetUserSettingInt(string name)
+ public T GetUserSetting<T>(string name)
{
- int value;
- int.TryParse(Properties.Settings.Default[name].ToString(), out value);
+ if (this.userSettings.ContainsKey(name))
+ {
+ return (T)this.userSettings[name];
+ }
- return value;
+ return default(T);
}
/// <summary>
- /// Get an String type user setting
+ /// Get an StringCollection type user setting
/// </summary>
/// <param name="name">
/// The setting name
@@ -53,62 +93,68 @@ namespace HandBrake.ApplicationServices.Services
/// <returns>
/// The settings value
/// </returns>
- public string GetUserSettingString(string name)
+ public StringCollection GetUserSettingStringCollection(string name)
{
- return Properties.Settings.Default[name].ToString();
+ return (StringCollection)this.userSettings[name];
}
/// <summary>
- /// Get an Boolean type user setting
+ /// Save the User Settings
/// </summary>
- /// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- public bool GetUserSettingBoolean(string name)
+ private void Save()
{
- bool value;
- bool.TryParse(Properties.Settings.Default[name].ToString(), out value);
-
- return value;
+ using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))
+ {
+ serializer.Serialize(strm, this.userSettings);
+ }
}
/// <summary>
- /// Get an Double type user setting
+ /// Load the User Settings
/// </summary>
- /// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- public double GetUserSettingDouble(string name)
+ private void Load()
{
- double value;
- double.TryParse(Properties.Settings.Default[name].ToString(), out value);
-
- return value;
+ try
+ {
+ if (File.Exists(this.settingsFile))
+ {
+ using (StreamReader reader = new StreamReader(this.settingsFile))
+ {
+ SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
+ this.userSettings = data;
+ }
+ }
+ }
+ catch (Exception exc)
+ {
+ throw new GeneralApplicationException(
+ "HandBrake has detected corruption in the settings file. User settings will now be reset to defaults.",
+ "Please restart HandBrake before continuing.",
+ exc);
+ }
}
/// <summary>
- /// Get an StringCollection type user setting
+ /// Load Default Settings
/// </summary>
- /// <param name="name">
- /// The setting name
- /// </param>
- /// <returns>
- /// The settings value
- /// </returns>
- public System.Collections.Specialized.StringCollection GetUserSettingStringCollection(string name)
+ private void LoadDefaults()
{
- System.Collections.Specialized.StringCollection value;
-
- value = (System.Collections.Specialized.StringCollection) Properties.Settings.Default[name];
-
- return value;
+ // TODO, maybe extract this out to a file.
+ userSettings = new SerializableDictionary<string, object>();
+ userSettings[UserSettingConstants.X264Step] = 0.25;
+ userSettings[UserSettingConstants.Verbosity] = 1;
+ userSettings[UserSettingConstants.WhenCompleteAction] = "Do Nothing";
+ userSettings[UserSettingConstants.GrowlEncode] = false;
+ userSettings[UserSettingConstants.GrowlQueue] = false;
+ userSettings[UserSettingConstants.ProcessPriority] = "Below Normal";
+ userSettings[UserSettingConstants.PreventSleep] = true;
+ userSettings[UserSettingConstants.ShowCLI] = false;
+ userSettings[UserSettingConstants.SaveLogToCopyDirectory] = false;
+ userSettings[UserSettingConstants.SaveLogWithVideo] = false;
+ userSettings[UserSettingConstants.DisableLibDvdNav] = false;
+ userSettings[UserSettingConstants.SendFile] = false;
+ userSettings[UserSettingConstants.MinScanDuration] = 10;
+ userSettings[UserSettingConstants.HandBrakeBuild] = 0;
}
-
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
index 40317d8b7..746f36937 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
@@ -14,6 +14,8 @@ namespace HandBrake.ApplicationServices.Utilities
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
/// A Set of Static Utilites
@@ -21,6 +23,11 @@ namespace HandBrake.ApplicationServices.Utilities
public class GeneralUtilities
{
/// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private static IUserSettingService userSettingService = new UserSettingService();
+
+ /// <summary>
/// The Default Log Directory
/// </summary>
private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
@@ -106,7 +113,7 @@ namespace HandBrake.ApplicationServices.Utilities
{
StringBuilder logHeader = new StringBuilder();
- logHeader.AppendLine(String.Format("HandBrake {0} {1}", Properties.Settings.Default.HandBrakeVersion, Properties.Settings.Default.HandBrakeBuild));
+ logHeader.AppendLine(String.Format("HandBrake {0} {1}", userSettingService.GetUserSetting<string>(UserSettingConstants.HandBrakeVersion), userSettingService.GetUserSetting<int>(UserSettingConstants.HandBrakeBuild)));
logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));
logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));
logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
index 3b514b198..a75741277 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
@@ -15,6 +15,8 @@ namespace HandBrake.ApplicationServices.Utilities
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model.Encoding;
/// <summary>
@@ -22,6 +24,11 @@ namespace HandBrake.ApplicationServices.Utilities
/// </summary>
public class PlistPresetHandler
{
+ /// <summary>
+ /// The User Setting Service
+ /// </summary>
+ private static IUserSettingService userSettingService = new UserSettingService();
+
/**
* TODO:
* - Update with the new vfr,pfr,cfr keys
@@ -540,7 +547,7 @@ namespace HandBrake.ApplicationServices.Utilities
AddEncodeElement(xmlWriter, "PictureWidth", "integer", parsed.Width.ToString());
// Preset Information
- AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", Properties.Settings.Default.HandBrakeBuild.ToString());
+ AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", userSettingService.GetUserSetting<string>(UserSettingConstants.HandBrakeBuild));
AddEncodeElement(xmlWriter, "PresetDescription", "string", "No Description");
AddEncodeElement(xmlWriter, "PresetName", "string", preset.Name);
AddEncodeElement(xmlWriter, "Type", "integer", "1"); // 1 is user preset, 0 is built in
diff --git a/win/CS/HandBrake.ApplicationServices/app.config b/win/CS/HandBrake.ApplicationServices/app.config
index c2bffe7e3..1747ee2d8 100644
--- a/win/CS/HandBrake.ApplicationServices/app.config
+++ b/win/CS/HandBrake.ApplicationServices/app.config
@@ -1,83 +1,9 @@
<?xml version="1.0"?>
<configuration>
<configSections>
- <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
- <section name="HandBrake.ApplicationServices.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
- </sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
- <userSettings>
-
- <HandBrake.ApplicationServices.Properties.Settings>
- <setting name="Verbosity" serializeAs="String">
- <value>1</value>
- </setting>
- <setting name="X264Step" serializeAs="String">
- <value>0.5</value>
- </setting>
- <setting name="WhenCompleteAction" serializeAs="String">
- <value>Do Nothing</value>
- </setting>
- <setting name="GrowlEncode" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="GrowlQueue" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="ProcessPriority" serializeAs="String">
- <value>Below Normal</value>
- </setting>
- <setting name="PreventSleep" serializeAs="String">
- <value>True</value>
- </setting>
- <setting name="ShowCLI" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="SaveLogToCopyDirectory" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="SaveLogWithVideo" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="SaveLogCopyDirectory" serializeAs="String">
- <value />
- </setting>
- <setting name="HandBrakeVersion" serializeAs="String">
- <value />
- </setting>
- <setting name="HandBrakeBuild" serializeAs="String">
- <value>0</value>
- </setting>
- <setting name="InstanceId" serializeAs="String">
- <value />
- </setting>
- <setting name="DisableLibDvdNav" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="HandBrakePlatform" serializeAs="String">
- <value />
- </setting>
- <setting name="HandBrakeExeHash" serializeAs="String">
- <value />
- </setting>
- <setting name="Setting" serializeAs="String">
- <value />
- </setting>
- <setting name="SendFileTo" serializeAs="String">
- <value />
- </setting>
- <setting name="SendFileToArgs" serializeAs="String">
- <value />
- </setting>
- <setting name="SendFile" serializeAs="String">
- <value>False</value>
- </setting>
- <setting name="MinTitleScanDuration" serializeAs="String">
- <value>10</value>
- </setting>
- </HandBrake.ApplicationServices.Properties.Settings>
- </userSettings>
</configuration>