From f0dbe6e2a2af173e60a20da86c78692757e69112 Mon Sep 17 00:00:00 2001 From: sr55 Date: Tue, 19 Nov 2013 22:41:36 +0000 Subject: WinGui: Finish off moving the User Settings service to the UI Layer. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5898 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../ASUserSettingConstants.cs | 27 --- .../HandBrake.ApplicationServices.csproj | 3 - .../Services/Interfaces/IQueueProcessor.cs | 5 +- .../Services/Interfaces/IUserSettingService.cs | 71 ------- .../Services/QueueProcessor.cs | 23 ++- .../Services/UserSettingService.cs | 226 -------------------- .../ServicesWindsorInstaller.cs | 1 - .../Converters/Video/VideoEncoderConverter.cs | 2 + .../Factories/HBConfigurationFactory.cs | 2 + win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 + win/CS/HandBrakeWPF/Helpers/AppStyleHelper.cs | 2 + win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 2 + win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs | 4 +- .../HandBrakeWPF/Services/EncodeServiceWrapper.cs | 2 + .../Services/Interfaces/IUserSettingService.cs | 71 +++++++ win/CS/HandBrakeWPF/Services/UpdateService.cs | 2 +- win/CS/HandBrakeWPF/Services/UserSettingService.cs | 227 +++++++++++++++++++++ win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs | 1 + win/CS/HandBrakeWPF/UserSettingConstants.cs | 9 + win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 1 + .../HandBrakeWPF/ViewModels/ChaptersViewModel.cs | 1 + win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 1 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 7 +- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 4 +- .../ViewModels/PictureSettingsViewModel.cs | 1 + win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs | 2 +- win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs | 95 ++++----- win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs | 1 + win/CS/HandBrakeWPF/Views/ShellView.xaml.cs | 1 + 29 files changed, 399 insertions(+), 397 deletions(-) delete mode 100644 win/CS/HandBrake.ApplicationServices/ASUserSettingConstants.cs delete mode 100644 win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs delete mode 100644 win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs create mode 100644 win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs create mode 100644 win/CS/HandBrakeWPF/Services/UserSettingService.cs diff --git a/win/CS/HandBrake.ApplicationServices/ASUserSettingConstants.cs b/win/CS/HandBrake.ApplicationServices/ASUserSettingConstants.cs deleted file mode 100644 index bea0a8844..000000000 --- a/win/CS/HandBrake.ApplicationServices/ASUserSettingConstants.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// The User Setting Constants -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices -{ - /// - /// Constants for the User Settings Service - /// - public class ASUserSettingConstants - { - /// - /// HandBrakes build - /// - public const string HandBrakeBuild = "HandBrakeBuild"; - - /// - /// Clear completed items from the queue automatically. - /// - public const string ClearCompletedFromQueue = "ClearCompletedFromQueue"; - } -} diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index e9386ac37..6110c187d 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -143,13 +143,10 @@ - - - diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs index f1ba5c7fe..8fb61109a 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs @@ -173,7 +173,10 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// Starts encoding the first job in the queue and continues encoding until all jobs /// have been encoded. /// - void Start(); + /// + /// The clear Completed. + /// + void Start(bool clearCompleted); #endregion } diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs deleted file mode 100644 index bf6cb9c91..000000000 --- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IUserSettingService.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// The User Setting Service Interace. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Services.Interfaces -{ - using HandBrake.ApplicationServices.EventArgs; - - /// - /// The setting event handler. - /// - /// - /// The sender. - /// - /// - /// The e. - /// - public delegate void SettingEventHandler(object sender, SettingChangedEventArgs e); - - /// - /// The User Setting Service Interace. - /// - public interface IUserSettingService - { - /// - /// The setting changed. - /// - event SettingEventHandler SettingChanged; - - /// - /// Set the specified user setting. - /// - /// - /// Name of the property - /// - /// - /// The value to store. - /// - void SetUserSetting(string name, object value); - - /// - /// Get user setting for a given key. - /// - /// - /// The name. - /// - /// - /// The Type of the setting - /// - /// - /// The user setting - /// - T GetUserSetting(string name); - - /// - /// Get an StringCollection type user setting - /// - /// - /// The setting name - /// - /// - /// The settings value - /// - System.Collections.Specialized.StringCollection GetUserSettingStringCollection(string name); - } -} \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs index 1ade60d74..43c11a9bf 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs @@ -42,14 +42,14 @@ namespace HandBrake.ApplicationServices.Services private readonly BindingList queue = new BindingList(); /// - /// The User Setting Service + /// HandBrakes Queue file with a place holder for an extra string. /// - private readonly IUserSettingService userSettingService; + private readonly string queueFile; /// - /// HandBrakes Queue file with a place holder for an extra string. + /// The clear completed. /// - private readonly string queueFile; + private bool clearCompleted; #endregion @@ -61,15 +61,11 @@ namespace HandBrake.ApplicationServices.Services /// /// The encode Service. /// - /// - /// The user Setting Service. - /// /// /// Services are not setup /// - public QueueProcessor(IEncodeServiceWrapper encodeService, IUserSettingService userSettingService) + public QueueProcessor(IEncodeServiceWrapper encodeService) { - this.userSettingService = userSettingService; this.EncodeService = encodeService; // If this is the first instance, just use the main queue file, otherwise add the instance id to the filename. @@ -436,13 +432,18 @@ namespace HandBrake.ApplicationServices.Services /// Starts encoding the first job in the queue and continues encoding until all jobs /// have been encoded. /// - public void Start() + /// + /// The is Clear Completed. + /// + public void Start(bool isClearCompleted) { if (this.IsProcessing) { throw new Exception("Already Processing the Queue"); } + clearCompleted = isClearCompleted; + this.EncodeService.EncodeCompleted -= this.EncodeServiceEncodeCompleted; this.EncodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted; @@ -472,7 +473,7 @@ namespace HandBrake.ApplicationServices.Services this.LastProcessedJob.Status = QueueItemStatus.Completed; // Clear the completed item of the queue if the setting is set. - if (this.userSettingService.GetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue)) + if (clearCompleted) { this.ClearCompleted(); } diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs deleted file mode 100644 index 7f40bffff..000000000 --- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs +++ /dev/null @@ -1,226 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// The User Setting Serivce -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Services -{ - using System; - using System.Collections.Specialized; - using System.IO; - using System.Linq; - using System.Reflection; - using System.Xml.Serialization; - - using HandBrake.ApplicationServices.Collections; - using HandBrake.ApplicationServices.EventArgs; - using HandBrake.ApplicationServices.Exceptions; - using HandBrake.ApplicationServices.Services.Interfaces; - - /// - /// The User Setting Serivce - /// - public class UserSettingService : IUserSettingService - { - /// - /// The Settings File - /// - private readonly string settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\settings.xml"; - - /// - /// The XML Serializer - /// - readonly XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary)); - - /// - /// The User Settings - /// - private SerializableDictionary userSettings; - - /// - /// Initializes a new instance of the class. - /// - public UserSettingService() - { - this.Load(); - } - - /// - /// The setting changed. - /// - public event SettingEventHandler SettingChanged; - - /// - /// Set the specified user setting. - /// - /// - /// Name of the property - /// - /// - /// The value to store. - /// - public void SetUserSetting(string name, object value) - { - this.userSettings[name] = value; - this.Save(); - - this.OnSettingChanged(new SettingChangedEventArgs { Key = name, Value = value }); - } - - /// - /// Get user setting for a given key. - /// - /// - /// The name. - /// - /// - /// The Type of the setting - /// - /// - /// The user setting - /// - public T GetUserSetting(string name) - { - if (this.userSettings.ContainsKey(name)) - { - return (T)this.userSettings[name]; - } - - return default(T); - } - - /// - /// Get an StringCollection type user setting - /// - /// - /// The setting name - /// - /// - /// The settings value - /// - public StringCollection GetUserSettingStringCollection(string name) - { - return (StringCollection)this.userSettings[name]; - } - - /// - /// The on setting changed. - /// - /// - /// The e. - /// - protected virtual void OnSettingChanged(SettingChangedEventArgs e) - { - SettingEventHandler handler = this.SettingChanged; - if (handler != null) - { - handler(this, e); - } - } - - /// - /// Save the User Settings - /// - private void Save() - { - try - { - string directory = Path.GetDirectoryName(this.settingsFile); - if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write)) - { - serializer.Serialize(strm, this.userSettings); - } - } - catch (Exception exc) - { - throw new GeneralApplicationException( - "A problem occured when trying to save your preferences.", - "Any settings you changed may need to be reset the next time HandBrake launches.", - exc); - } - } - - /// - /// Load the User Settings - /// - private void Load() - { - try - { - // Load up the users current settings file. - if (File.Exists(this.settingsFile)) - { - using (StreamReader reader = new StreamReader(this.settingsFile)) - { - SerializableDictionary data = (SerializableDictionary)serializer.Deserialize(reader); - this.userSettings = data; - } - } - else - { - this.userSettings = new SerializableDictionary(); - } - - // Add any missing / new settings - SerializableDictionary defaults = this.GetDefaults(); - foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key))) - { - this.userSettings.Add(item.Key, item.Value); - this.Save(); - } - } - catch (Exception exc) - { - try - { - this.userSettings = this.GetDefaults(); - if (File.Exists(this.settingsFile)) - { - File.Delete(this.settingsFile); - } - this.Save(); - - throw new GeneralApplicationException("Warning, your settings have been reset!", "Your user settings file was corrupted or inaccessible. Settings have been reset to defaults.", exc); - } - catch (Exception) - { - throw new GeneralApplicationException("Unable to load user settings file: " + this.settingsFile, "Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one.", exc); - } - } - } - - /// - /// Load Default Settings - /// - /// - /// The get defaults. - /// - private SerializableDictionary GetDefaults() - { - try - { - Assembly assembly = Assembly.GetEntryAssembly(); - Stream stream = assembly.GetManifestResourceStream("HandBrakeWPF.defaultsettings.xml"); - if (stream != null) - { - return (SerializableDictionary)this.serializer.Deserialize(stream); - } - } - catch (Exception exc) - { - return new SerializableDictionary(); - } - - return new SerializableDictionary(); - } - } -} diff --git a/win/CS/HandBrake.ApplicationServices/ServicesWindsorInstaller.cs b/win/CS/HandBrake.ApplicationServices/ServicesWindsorInstaller.cs index b787aa18b..2ffd29046 100644 --- a/win/CS/HandBrake.ApplicationServices/ServicesWindsorInstaller.cs +++ b/win/CS/HandBrake.ApplicationServices/ServicesWindsorInstaller.cs @@ -31,7 +31,6 @@ namespace HandBrake.ApplicationServices { container.Register(Component.For().ImplementedBy()); container.Register(Component.For().ImplementedBy()); - container.Register(Component.For().ImplementedBy()); } #endregion diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs index eecb25890..2dd2e82d8 100644 --- a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs @@ -23,6 +23,8 @@ namespace HandBrakeWPF.Converters.Video using HandBrake.ApplicationServices.Utilities; using HandBrake.Interop.Model.Encoding; + using HandBrakeWPF.Services.Interfaces; + /// /// Video Encoder Converter /// diff --git a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs index 86f061eca..8be9bcd41 100644 --- a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs +++ b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs @@ -14,6 +14,8 @@ namespace HandBrakeWPF.Factories using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrakeWPF.Services.Interfaces; + /// /// HBConfiguration Factory /// diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index d6eb10641..5e8ab59c2 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -141,6 +141,8 @@ + + diff --git a/win/CS/HandBrakeWPF/Helpers/AppStyleHelper.cs b/win/CS/HandBrakeWPF/Helpers/AppStyleHelper.cs index 9b67f97e2..556cf53b4 100644 --- a/win/CS/HandBrakeWPF/Helpers/AppStyleHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AppStyleHelper.cs @@ -15,6 +15,8 @@ namespace HandBrakeWPF.Helpers using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrakeWPF.Services.Interfaces; + /// /// The AppStyle Helper. /// diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs index 8c4032466..e9e4d0278 100644 --- a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -21,6 +21,8 @@ namespace HandBrakeWPF.Helpers using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.Interop.Model.Encoding; + using HandBrakeWPF.Services.Interfaces; + /// /// The Destination AutoName Helper /// diff --git a/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs b/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs index 0060b1d15..ede46fa8b 100644 --- a/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/CliCheckHelper.cs @@ -85,7 +85,7 @@ namespace HandBrakeWPF.Helpers int buildValue; int.TryParse(build, out buildValue); - userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, buildValue); + userSettingService.SetUserSetting(UserSettingConstants.HandBrakeBuild, buildValue); success = true; } } @@ -109,7 +109,7 @@ namespace HandBrakeWPF.Helpers } catch (Exception e) { - userSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, 0); + userSettingService.SetUserSetting(UserSettingConstants.HandBrakeBuild, 0); userSettingService.SetUserSetting(UserSettingConstants.HandBrakeExeHash, string.Empty); errorService.ShowError( diff --git a/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs index 254ccefb9..b8d715ede 100644 --- a/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs +++ b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs @@ -19,6 +19,8 @@ namespace HandBrakeWPF.Services using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrakeWPF.Services.Interfaces; + using EncodeCompletedEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs; using EncodeProgressEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs; diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs new file mode 100644 index 000000000..d2f433bc1 --- /dev/null +++ b/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs @@ -0,0 +1,71 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The User Setting Service Interace. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Services.Interfaces +{ + using HandBrake.ApplicationServices.EventArgs; + + /// + /// The setting event handler. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + public delegate void SettingEventHandler(object sender, SettingChangedEventArgs e); + + /// + /// The User Setting Service Interace. + /// + public interface IUserSettingService + { + /// + /// The setting changed. + /// + event SettingEventHandler SettingChanged; + + /// + /// Set the specified user setting. + /// + /// + /// Name of the property + /// + /// + /// The value to store. + /// + void SetUserSetting(string name, object value); + + /// + /// Get user setting for a given key. + /// + /// + /// The name. + /// + /// + /// The Type of the setting + /// + /// + /// The user setting + /// + T GetUserSetting(string name); + + /// + /// Get an StringCollection type user setting + /// + /// + /// The setting name + /// + /// + /// The settings value + /// + System.Collections.Specialized.StringCollection GetUserSettingStringCollection(string name); + } +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/UpdateService.cs b/win/CS/HandBrakeWPF/Services/UpdateService.cs index b95a1d862..41135743b 100644 --- a/win/CS/HandBrakeWPF/Services/UpdateService.cs +++ b/win/CS/HandBrakeWPF/Services/UpdateService.cs @@ -92,7 +92,7 @@ namespace HandBrakeWPF.Services : Constants.Appcast32; var currentBuild = - this.userSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild); + this.userSettingService.GetUserSetting(UserSettingConstants.HandBrakeBuild); var skipBuild = this.userSettingService.GetUserSetting( UserSettingConstants.Skipversion); diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs new file mode 100644 index 000000000..6b7df3d85 --- /dev/null +++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs @@ -0,0 +1,227 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The User Setting Serivce +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Services +{ + using System; + using System.Collections.Specialized; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Xml.Serialization; + + using HandBrake.ApplicationServices.Collections; + using HandBrake.ApplicationServices.EventArgs; + using HandBrake.ApplicationServices.Exceptions; + + using HandBrakeWPF.Services.Interfaces; + + /// + /// The User Setting Serivce + /// + public class UserSettingService : IUserSettingService + { + /// + /// The Settings File + /// + private readonly string settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\settings.xml"; + + /// + /// The XML Serializer + /// + readonly XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary)); + + /// + /// The User Settings + /// + private SerializableDictionary userSettings; + + /// + /// Initializes a new instance of the class. + /// + public UserSettingService() + { + this.Load(); + } + + /// + /// The setting changed. + /// + public event SettingEventHandler SettingChanged; + + /// + /// Set the specified user setting. + /// + /// + /// Name of the property + /// + /// + /// The value to store. + /// + public void SetUserSetting(string name, object value) + { + this.userSettings[name] = value; + this.Save(); + + this.OnSettingChanged(new SettingChangedEventArgs { Key = name, Value = value }); + } + + /// + /// Get user setting for a given key. + /// + /// + /// The name. + /// + /// + /// The Type of the setting + /// + /// + /// The user setting + /// + public T GetUserSetting(string name) + { + if (this.userSettings.ContainsKey(name)) + { + return (T)this.userSettings[name]; + } + + return default(T); + } + + /// + /// Get an StringCollection type user setting + /// + /// + /// The setting name + /// + /// + /// The settings value + /// + public StringCollection GetUserSettingStringCollection(string name) + { + return (StringCollection)this.userSettings[name]; + } + + /// + /// The on setting changed. + /// + /// + /// The e. + /// + protected virtual void OnSettingChanged(SettingChangedEventArgs e) + { + SettingEventHandler handler = this.SettingChanged; + if (handler != null) + { + handler(this, e); + } + } + + /// + /// Save the User Settings + /// + private void Save() + { + try + { + string directory = Path.GetDirectoryName(this.settingsFile); + if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write)) + { + this.serializer.Serialize(strm, this.userSettings); + } + } + catch (Exception exc) + { + throw new GeneralApplicationException( + "A problem occured when trying to save your preferences.", + "Any settings you changed may need to be reset the next time HandBrake launches.", + exc); + } + } + + /// + /// Load the User Settings + /// + private void Load() + { + try + { + // Load up the users current settings file. + if (File.Exists(this.settingsFile)) + { + using (StreamReader reader = new StreamReader(this.settingsFile)) + { + SerializableDictionary data = (SerializableDictionary)this.serializer.Deserialize(reader); + this.userSettings = data; + } + } + else + { + this.userSettings = new SerializableDictionary(); + } + + // Add any missing / new settings + SerializableDictionary defaults = this.GetDefaults(); + foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key))) + { + this.userSettings.Add(item.Key, item.Value); + this.Save(); + } + } + catch (Exception exc) + { + try + { + this.userSettings = this.GetDefaults(); + if (File.Exists(this.settingsFile)) + { + File.Delete(this.settingsFile); + } + this.Save(); + + throw new GeneralApplicationException("Warning, your settings have been reset!", "Your user settings file was corrupted or inaccessible. Settings have been reset to defaults.", exc); + } + catch (Exception) + { + throw new GeneralApplicationException("Unable to load user settings file: " + this.settingsFile, "Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one.", exc); + } + } + } + + /// + /// Load Default Settings + /// + /// + /// The get defaults. + /// + private SerializableDictionary GetDefaults() + { + try + { + Assembly assembly = Assembly.GetEntryAssembly(); + Stream stream = assembly.GetManifestResourceStream("HandBrakeWPF.defaultsettings.xml"); + if (stream != null) + { + return (SerializableDictionary)this.serializer.Deserialize(stream); + } + } + catch (Exception exc) + { + return new SerializableDictionary(); + } + + return new SerializableDictionary(); + } + } +} diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index 34f58c862..45dbde20d 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -62,6 +62,7 @@ namespace HandBrakeWPF.Startup this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); + this.windsorContainer.Register(Component.For().ImplementedBy()); // Commands this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index bf50ec8db..9f8c69b53 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -16,6 +16,11 @@ namespace HandBrakeWPF { #region Constants and Fields + /// + /// HandBrakes build + /// + public const string HandBrakeBuild = "HandBrakeBuild"; + /// /// Add Only One Per Langage /// @@ -301,6 +306,10 @@ namespace HandBrakeWPF /// public const string SaveLogCopyDirectory = "SaveLogCopyDirectory"; + /// + /// The clear completed from queue. + /// + public const string ClearCompletedFromQueue = "ClearCompletedFromQueue"; #endregion } diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 61c2d4a22..296b1faa4 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -26,6 +26,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Commands; using HandBrakeWPF.Model; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// diff --git a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs index 6344e262b..b8f2a265b 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs @@ -22,6 +22,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; using LumenWorks.Framework.IO.Csv; diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index de08398bb..e5d825ba4 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -19,6 +19,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Utilities; using HandBrake.Interop.Model.Encoding; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index d20657728..dc87292d9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1258,7 +1258,7 @@ namespace HandBrakeWPF.ViewModels // Check if we already have jobs, and if we do, just start the queue. if (this.queueProcessor.Count != 0) { - this.queueProcessor.Start(); + this.queueProcessor.Start(UserSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue)); return; } @@ -1287,7 +1287,7 @@ namespace HandBrakeWPF.ViewModels // Create the Queue Task and Start Processing QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create()); this.queueProcessor.Add(task); - this.queueProcessor.Start(); + this.queueProcessor.Start(UserSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue)); this.IsEncoding = true; } @@ -1572,8 +1572,7 @@ namespace HandBrakeWPF.ViewModels PlistUtility.Export( savefiledialog.FileName, this.selectedPreset, - this.userSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild) - .ToString(CultureInfo.InvariantCulture)); + this.userSettingService.GetUserSetting(UserSettingConstants.HandBrakeBuild).ToString(CultureInfo.InvariantCulture)); } } else diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 122914d13..f8a86494e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -1953,7 +1953,7 @@ namespace HandBrakeWPF.ViewModels // Minimise to Tray this.MinimiseToTray = this.userSettingService.GetUserSetting(UserSettingConstants.MainWindowMinimize); this.DisablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting(UserSettingConstants.PresetNotification); - this.ClearQueueOnEncodeCompleted = userSettingService.GetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue); + this.ClearQueueOnEncodeCompleted = userSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue); this.ShowAdvancedTab = userSettingService.GetUserSetting(UserSettingConstants.ShowAdvancedTab); // Set the preview count @@ -2052,7 +2052,7 @@ namespace HandBrakeWPF.ViewModels /* Advanced */ userSettingService.SetUserSetting(UserSettingConstants.MainWindowMinimize, this.MinimiseToTray); userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification); - userSettingService.SetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue, this.ClearQueueOnEncodeCompleted); + userSettingService.SetUserSetting(UserSettingConstants.ClearCompletedFromQueue, this.ClearQueueOnEncodeCompleted); userSettingService.SetUserSetting(UserSettingConstants.PreviewScanCount, this.SelectedPreviewCount); userSettingService.SetUserSetting(UserSettingConstants.X264Step, double.Parse(this.SelectedGranulairty, CultureInfo.InvariantCulture)); userSettingService.SetUserSetting(UserSettingConstants.ShowAdvancedTab, this.ShowAdvancedTab); diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index aa390eaa6..59ce20942 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -22,6 +22,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.Interop.Model.Encoding; using HandBrakeWPF.Helpers; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; using Size = System.Drawing.Size; diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 972c46d94..e89ecc4cd 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -304,7 +304,7 @@ namespace HandBrakeWPF.ViewModels this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.Count); this.IsEncoding = true; - this.queueProcessor.Start(); + this.queueProcessor.Start(UserSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue)); } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs index a40e76a46..d12798fef 100644 --- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs @@ -30,6 +30,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Commands.Interfaces; using HandBrakeWPF.Properties; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// @@ -983,53 +984,53 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.Task); - if (preset.Task != null) - { - this.SetEncoder(preset.Task.VideoEncoder); - - // applies to both x264 and QSV - if (preset.Task.VideoEncoder == VideoEncoder.X264 || - preset.Task.VideoEncoder == VideoEncoder.QuickSync) - { - this.H264Profile = preset.Task.H264Profile; - this.H264Level = preset.Task.H264Level; - } - else - { - this.H264Profile = x264Profile.None; - this.H264Level = "Auto"; - } - - // x264 Only - if (preset.Task.VideoEncoder == VideoEncoder.X264) - { - this.X264PresetValue = (int)preset.Task.X264Preset; - this.X264Tune = preset.Task.X264Tune; - this.FastDecode = preset.Task.FastDecode; - } - else - { - this.X264PresetValue = (int)x264Preset.Medium; - this.X264Tune = x264Tune.None; - this.FastDecode = false; - } - - // QSV Only - if (preset.Task.VideoEncoder == VideoEncoder.QuickSync) - { - this.QsvPresetValue = (int)preset.Task.QsvPreset; - } - else - { - this.QsvPresetValue = SystemInfo.IsHswOrNewer - ? (int)QsvPreset.Quality - : (int)QsvPreset.Balanced; - } - - this.ExtraArguments = preset.Task.ExtraAdvancedArguments; - this.UseAdvancedTab = !string.IsNullOrEmpty(preset.Task.AdvancedEncoderOptions) && this.ShowAdvancedTab; - } - } + if (preset.Task != null) + { + this.SetEncoder(preset.Task.VideoEncoder); + + // applies to both x264 and QSV + if (preset.Task.VideoEncoder == VideoEncoder.X264 || + preset.Task.VideoEncoder == VideoEncoder.QuickSync) + { + this.H264Profile = preset.Task.H264Profile; + this.H264Level = preset.Task.H264Level; + } + else + { + this.H264Profile = x264Profile.None; + this.H264Level = "Auto"; + } + + // x264 Only + if (preset.Task.VideoEncoder == VideoEncoder.X264) + { + this.X264PresetValue = (int)preset.Task.X264Preset; + this.X264Tune = preset.Task.X264Tune; + this.FastDecode = preset.Task.FastDecode; + } + else + { + this.X264PresetValue = (int)x264Preset.Medium; + this.X264Tune = x264Tune.None; + this.FastDecode = false; + } + + // QSV Only + if (preset.Task.VideoEncoder == VideoEncoder.QuickSync) + { + this.QsvPresetValue = (int)preset.Task.QsvPreset; + } + else + { + this.QsvPresetValue = SystemInfo.IsHswOrNewer + ? (int)QsvPreset.Quality + : (int)QsvPreset.Balanced; + } + + this.ExtraArguments = preset.Task.ExtraAdvancedArguments; + this.UseAdvancedTab = !string.IsNullOrEmpty(preset.Task.AdvancedEncoderOptions) && this.ShowAdvancedTab; + } + } /// /// Update all the UI controls based on the encode task passed in. diff --git a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs index 7a13881dc..301e161dd 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs @@ -14,6 +14,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Services.Interfaces; using HandBrakeWPF.Helpers; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs index 0347bc647..fbf700b4a 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs @@ -22,6 +22,7 @@ namespace HandBrakeWPF.Views using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Commands; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; using Application = System.Windows.Application; -- cgit v1.2.3