From 746186658150dcbca2721d6d6fea77b4d7c09467 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 15 Aug 2011 19:23:58 +0000 Subject: WinGui: Add a service manager to maintain single instances of services & update the user settings service to import defaults from an xml file. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4177 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Collections/SerializableDictionary.cs | 26 +++++++++-- .../HandBrake.ApplicationServices.csproj | 1 + .../HandBrake.ApplicationServices/Parsing/Title.cs | 2 +- .../ServiceManager.cs | 27 +++++++++++ .../Services/Base/EncodeBase.cs | 2 +- .../Services/Encode.cs | 2 +- .../Services/LibEncode.cs | 2 +- .../Services/PresetService.cs | 2 +- .../Services/QueueProcessor.cs | 2 +- .../Services/ScanService.cs | 2 +- .../Services/UserSettingService.cs | 53 +++++++++++++++++++++- .../Utilities/GeneralUtilities.cs | 2 +- .../Utilities/PlistUtility.cs | 2 +- 13 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 win/CS/HandBrake.ApplicationServices/ServiceManager.cs (limited to 'win/CS/HandBrake.ApplicationServices') diff --git a/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs b/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs index b492bc2f0..ad6a56221 100644 --- a/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs +++ b/win/CS/HandBrake.ApplicationServices/Collections/SerializableDictionary.cs @@ -6,6 +6,7 @@ namespace HandBrake.ApplicationServices.Collections { using System.Collections.Generic; + using System.Collections.Specialized; using System.Runtime.Serialization; using System.Xml.Serialization; @@ -60,7 +61,16 @@ namespace HandBrake.ApplicationServices.Collections reader.ReadEndElement(); reader.ReadStartElement("value"); - TValue value = (TValue)valueSerializer.Deserialize(reader); + TValue value; + if (reader.Name.Contains("ArrayOfString")) + { + XmlSerializer scSerializer = new XmlSerializer(typeof(StringCollection)); + value = (TValue)scSerializer.Deserialize(reader); + } + else + { + value = (TValue)valueSerializer.Deserialize(reader); + } reader.ReadEndElement(); this.Add(key, value); @@ -92,8 +102,18 @@ namespace HandBrake.ApplicationServices.Collections writer.WriteStartElement("value"); TValue value = this[key]; - valueSerializer.Serialize(writer, value); - writer.WriteEndElement(); + + if (value.GetType() == typeof(StringCollection)) + { + XmlSerializer scSerializer = new XmlSerializer(typeof(StringCollection)); + scSerializer.Serialize(writer, value); + writer.WriteEndElement(); + } + else + { + valueSerializer.Serialize(writer, value); + writer.WriteEndElement(); + } writer.WriteEndElement(); } diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 78480847c..0c417c279 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -128,6 +128,7 @@ True Settings.settings + diff --git a/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs b/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs index 1ddb4730d..ac8bcf6d3 100644 --- a/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs +++ b/win/CS/HandBrake.ApplicationServices/Parsing/Title.cs @@ -32,7 +32,7 @@ namespace HandBrake.ApplicationServices.Parsing /// /// The User Setting Service /// - private static IUserSettingService userSettingService = new UserSettingService(); + private static IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// Initializes a new instance of the class. diff --git a/win/CS/HandBrake.ApplicationServices/ServiceManager.cs b/win/CS/HandBrake.ApplicationServices/ServiceManager.cs new file mode 100644 index 000000000..06b4422e2 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/ServiceManager.cs @@ -0,0 +1,27 @@ +namespace HandBrake.ApplicationServices +{ + using HandBrake.ApplicationServices.Services; + using HandBrake.ApplicationServices.Services.Interfaces; + + /// + /// Tempory Class which manages services until Windosor is added back into the project to handle it for us. + /// + public class ServiceManager + { + /// + /// Backing Field for the User Setting Service. + /// + private static IUserSettingService userSettingService; + + /// + /// Gets UserSettingService. + /// + public static IUserSettingService UserSettingService + { + get + { + return userSettingService ?? (userSettingService = new UserSettingService()); + } + } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs index 48505fc6f..6ab0e52a8 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs @@ -30,7 +30,7 @@ namespace HandBrake.ApplicationServices.Services.Base /// /// The User Setting Service /// - private IUserSettingService userSettingService = new UserSettingService(); + private IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// Windows 7 API Pack wrapper diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs index 04290eced..70f8f86ee 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs @@ -28,7 +28,7 @@ namespace HandBrake.ApplicationServices.Services /// /// The User Setting Service /// - private IUserSettingService userSettingService = new UserSettingService(); + private IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// Gets The Process Handle diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs index e677d4784..7ee9a9df3 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs @@ -35,7 +35,7 @@ namespace HandBrake.ApplicationServices.Services /// /// The User Setting Service /// - private IUserSettingService userSettingService = new UserSettingService(); + private IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// The Start time of the current Encode; diff --git a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs index 9cad60e4e..b856577a9 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs @@ -42,7 +42,7 @@ namespace HandBrake.ApplicationServices.Services /// /// The User Setting Service /// - private IUserSettingService userSettingService = new UserSettingService(); + private IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// The User Preset file diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs index 30ba395f4..478fa3661 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs @@ -23,7 +23,7 @@ namespace HandBrake.ApplicationServices.Services /// /// The User Setting Service /// - private static IUserSettingService userSettingService = new UserSettingService(); + private static IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// Initializes a new instance of the class. diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs index 652115c06..a9c9e07ce 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs @@ -47,7 +47,7 @@ namespace HandBrake.ApplicationServices.Services /// /// The User Setting Service /// - private IUserSettingService userSettingService = new UserSettingService(); + private IUserSettingService userSettingService = ServiceManager.UserSettingService; #endregion diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs index 424d0a752..6a8584018 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs @@ -9,6 +9,7 @@ namespace HandBrake.ApplicationServices.Services using System.Collections.Generic; using System.Collections.Specialized; using System.IO; + using System.Windows.Forms; using System.Xml.Serialization; using HandBrake.ApplicationServices.Collections; @@ -139,7 +140,22 @@ namespace HandBrake.ApplicationServices.Services /// private void LoadDefaults() { - // TODO, maybe extract this out to a file. + string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml"); + if (File.Exists(defaults)) + { + using (StreamReader reader = new StreamReader(defaults)) + { + SerializableDictionary data = (SerializableDictionary)serializer.Deserialize(reader); + this.userSettings = data; + } + } + } + + /// + /// This is just a utility method for creating a defaults xml file. Don't use this!!! + /// + private void SetAllDefaults() + { userSettings = new SerializableDictionary(); userSettings[UserSettingConstants.X264Step] = 0.25; userSettings[UserSettingConstants.Verbosity] = 1; @@ -156,6 +172,41 @@ namespace HandBrake.ApplicationServices.Services userSettings[UserSettingConstants.MinScanDuration] = 10; userSettings[UserSettingConstants.HandBrakeBuild] = 0; userSettings[UserSettingConstants.HandBrakeVersion] = string.Empty; + userSettings["updateStatus"] = true; + userSettings["tooltipEnable"] = true; + userSettings["defaultPreset"] = string.Empty; + userSettings["skipversion"] = 0; + userSettings["autoNaming"] = true; + userSettings["autoNamePath"] = string.Empty; + userSettings["appcast"] = "http://handbrake.fr/appcast.xml"; + userSettings["appcast_unstable"] = "http://handbrake.fr/appcast_unstable.xml"; + userSettings["autoNameFormat"] = "{source}-{title}"; + userSettings["VLC_Path"] = "C:\\Program Files\\VideoLAN\\vlc\\vlc.exe"; + userSettings["MainWindowMinimize"] = true; + userSettings["QueryEditorTab"] = false; + userSettings["presetNotification"] = false; + userSettings["trayIconAlerts"] = true; + userSettings["lastUpdateCheckDate"] = DateTime.Today; + userSettings["daysBetweenUpdateCheck"] = 7; + userSettings["useM4v"] = 0; + userSettings["PromptOnUnmatchingQueries"] = true; + userSettings["NativeLanguage"] = "Any"; + userSettings["DubMode"] = 255; + userSettings["CliExeHash"] = string.Empty; + userSettings["previewScanCount"] = 10; + userSettings["clearOldLogs"] = true; + userSettings["AutoNameTitleCase"] = true; + userSettings["AutoNameRemoveUnderscore"] = true; + userSettings["ActivityWindowLastMode"] = 0; + userSettings["useClosedCaption"] = false; + userSettings["batchMinDuration"] = 35; + userSettings["batchMaxDuration"] = 65; + userSettings["defaultPlayer"] = false; + userSettings["SelectedLanguages"] = new StringCollection(); + userSettings["DubModeAudio"] = 0; + userSettings["DubModeSubtitle"] = 0; + userSettings["addOnlyOneAudioPerLanguage"] = true; + userSettings["MinTitleLength"] = 10; } } } diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs index 746f36937..b2187ed4b 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs @@ -25,7 +25,7 @@ namespace HandBrake.ApplicationServices.Utilities /// /// The User Setting Service /// - private static IUserSettingService userSettingService = new UserSettingService(); + private static IUserSettingService userSettingService = ServiceManager.UserSettingService; /// /// The Default Log Directory diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs index a75741277..392abc569 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs @@ -27,7 +27,7 @@ namespace HandBrake.ApplicationServices.Utilities /// /// The User Setting Service /// - private static IUserSettingService userSettingService = new UserSettingService(); + private static IUserSettingService userSettingService = ServiceManager.UserSettingService; /** * TODO: -- cgit v1.2.3