summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-08-15 16:54:19 +0000
committersr55 <[email protected]>2011-08-15 16:54:19 +0000
commit44b2c7e69d5613631a4ab39a91e01b673046f030 (patch)
tree8fe8f170aea693a9993c44db3826a324a46cbd4b /win/CS/HandBrake.ApplicationServices/Services
parent3e3deb33d5c5ec4aca3d6c855db646b511bf788b (diff)
WinGui: Finished re-writing the user settings service to use xml file storage rather than built-in settings. Moved all the Services Library settings over to use the service. Main application will be done later.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4175 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
-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
8 files changed, 154 insertions, 111 deletions
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;
}
-
}
}