summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-03-25 18:14:10 +0000
committersr55 <[email protected]>2012-03-25 18:14:10 +0000
commit479f2a8da44ee1237acdf187892e0bf2e77c5663 (patch)
tree7afe479dcc484fe8319019c2216e954c3e30a6cd /win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
parent970ae1ed9f3c05fa4a8a4bc454892ef63278c721 (diff)
WinGuWinGui:(WPF) Remove some legacy queue code with the queue models and fix up some issues with the quality slider on the new video tab. Improve the User settings service code.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4542 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs123
1 files changed, 50 insertions, 73 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
index d8e537bdc..c36b5ec49 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
@@ -6,9 +6,9 @@
namespace HandBrake.ApplicationServices.Services
{
using System;
- using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
+ using System.Linq;
using System.Windows.Forms;
using System.Xml.Serialization;
@@ -44,7 +44,7 @@ namespace HandBrake.ApplicationServices.Services
this.Load();
if (userSettings == null || userSettings.Count == 0)
{
- this.LoadDefaults();
+ this.userSettings = this.GetDefaults();
}
}
@@ -104,15 +104,25 @@ namespace HandBrake.ApplicationServices.Services
/// </summary>
private void Save()
{
- string directory = Path.GetDirectoryName(this.settingsFile);
- if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+ try
{
- Directory.CreateDirectory(directory);
- }
+ 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))
+ using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))
+ {
+ serializer.Serialize(strm, this.userSettings);
+ }
+ }
+ catch (Exception exc)
{
- serializer.Serialize(strm, this.userSettings);
+ 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);
}
}
@@ -129,7 +139,16 @@ namespace HandBrake.ApplicationServices.Services
{
SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
this.userSettings = data;
+
+ // Add any new settings
+ SerializableDictionary<string, object> 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)
@@ -144,76 +163,34 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// Load Default Settings
/// </summary>
- private void LoadDefaults()
+ /// <returns>
+ /// The get defaults.
+ /// </returns>
+ private SerializableDictionary<string, object> GetDefaults()
{
- string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");
- if (File.Exists(defaults))
+ try
{
- using (StreamReader reader = new StreamReader(defaults))
+ string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");
+ if (File.Exists(defaults))
{
- SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
- this.userSettings = data;
+ using (StreamReader reader = new StreamReader(defaults))
+ {
+ return (SerializableDictionary<string, object>)serializer.Deserialize(reader);
+ }
}
- }
- }
- /// <summary>
- /// This is just a utility method for creating a defaults xml file. Don't use this!!!
- /// </summary>
- private void SetAllDefaults()
- {
- userSettings = new SerializableDictionary<string, object>();
- userSettings[ASUserSettingConstants.X264Step] = 0.25;
- userSettings[ASUserSettingConstants.Verbosity] = 1;
- userSettings[ASUserSettingConstants.WhenCompleteAction] = "Do Nothing";
- userSettings[ASUserSettingConstants.GrowlEncode] = false;
- userSettings[ASUserSettingConstants.GrowlQueue] = false;
- userSettings[ASUserSettingConstants.ProcessPriority] = "Below Normal";
- userSettings[ASUserSettingConstants.PreventSleep] = true;
- userSettings[ASUserSettingConstants.ShowCLI] = false;
- userSettings[ASUserSettingConstants.SaveLogToCopyDirectory] = false;
- userSettings[ASUserSettingConstants.SaveLogWithVideo] = false;
- userSettings[ASUserSettingConstants.DisableLibDvdNav] = false;
- userSettings[ASUserSettingConstants.SendFile] = false;
- userSettings[ASUserSettingConstants.MinScanDuration] = 10;
- userSettings[ASUserSettingConstants.HandBrakeBuild] = 0;
- userSettings[ASUserSettingConstants.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_i686"] = "http://handbrake.fr/appcast.i386.xml";
- userSettings["appcast_x64"] = "http://handbrake.fr/appcast_unstable.x86_64.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["HandBrakeExeHash"] = string.Empty;
- userSettings["previewScanCount"] = 10;
- userSettings["clearOldLogs"] = true;
- userSettings["AutoNameTitleCase"] = true;
- userSettings["AutoNameRemoveUnderscore"] = true;
- userSettings["ActivityWindowLastMode"] = 0;
- userSettings["useClosedCaption"] = false;
- userSettings["batchMinDuration"] = "00:18:00";
- userSettings["batchMaxDuration"] = "02:30:00";
- userSettings["defaultPlayer"] = false;
- userSettings["SelectedLanguages"] = new StringCollection();
- userSettings["DubModeAudio"] = 0;
- userSettings["DubModeSubtitle"] = 0;
- userSettings["addOnlyOneAudioPerLanguage"] = true;
- userSettings["MinTitleLength"] = 10;
- userSettings["ShowAdvancedAudioPassthruOpts"] = false;
+ throw new GeneralApplicationException(
+ "User default settings file is missing. This install of HandBrake may be corrupted.",
+ "Try re-installing HandBrake.",
+ null);
+ }
+ catch (Exception exc)
+ {
+ throw new GeneralApplicationException(
+ "User default settings file is missing or inaccessible. This install of HandBrake may be corrupted.",
+ "Try re-installing HandBrake.",
+ exc);
+ }
}
}
}