diff options
author | sr55 <[email protected]> | 2015-01-25 19:13:54 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2015-01-25 19:13:54 +0000 |
commit | caed9f1d774a7f64ff0e71f247cd19ce7e3f6b89 (patch) | |
tree | 1e687c7993c0367d79ef8d3d8ed94e99ac104802 /win/CS/HandBrakeWPF/Services/Presets/PresetService.cs | |
parent | 7e55e64f9478bf0cc5b4f05516936e019a3c3812 (diff) |
WinGui:
- Change the internal presets.dat file which stores built-in presets to JSON.
- Starting to remove the CLI handling code.
- Some assembly info updates.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6812 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Services/Presets/PresetService.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Presets/PresetService.cs | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 09fcc4a50..c20af5ddc 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -281,58 +281,42 @@ namespace HandBrakeWPF.Services.Presets {
using (StreamReader reader = new StreamReader(stream))
{
- StringBuilder contents = new StringBuilder();
-
- string category = String.Empty;
-
- while (!reader.EndOfStream)
+ // New Preset Format.
+ try
{
- string line = reader.ReadLine();
- contents.AppendLine(line);
+ string json = reader.ReadToEnd();
+ var presetList = JsonConvert.DeserializeObject<List<Preset>>(json);
- // Found the beginning of a preset block )
- if (line != null && line.Contains("<") && !line.Contains("<<"))
+ foreach (Preset preset in presetList)
{
- category = line.Replace("<", string.Empty).Trim();
- }
+ preset.Version = VersionHelper.GetVersion();
+ preset.UsePictureFilters = true;
+ preset.IsBuildIn = true; // Older versions did not have this flag so explicitly make sure it is set.
- // Found a preset
- if (line != null && line.Contains("+"))
- {
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(line);
-
- Preset newPreset = new Preset
- {
- Category = category,
- Name = presetName[0].Replace("+", string.Empty).Trim(),
- Version = VersionHelper.GetVersion(),
- Description = string.Empty, // Maybe one day we will populate this.
- IsBuildIn = true,
- UsePictureFilters = true,
- Task = QueryParserUtility.Parse(presetName[2])
- };
-
- if (newPreset.Name == "iPod")
+ if (preset.Name == "iPod")
{
- newPreset.Task.KeepDisplayAspect = true;
+ preset.Task.KeepDisplayAspect = true;
}
- newPreset.Task.AllowedPassthruOptions = new AllowedPassthru(true); // We don't want to override the built-in preset
+ preset.Task.AllowedPassthruOptions = new AllowedPassthru(true); // We don't want to override the built-in preset
- if (newPreset.Name == "Normal")
+ if (preset.Name == "Normal")
{
- newPreset.IsDefault = true;
+ preset.IsDefault = true;
}
- this.presets.Add(newPreset);
+ this.presets.Add(preset);
}
- }
- // Verify we have presets.
- if (this.presets.Count == 0)
+ // Verify we have presets.
+ if (this.presets.Count == 0)
+ {
+ throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", new Exception(json));
+ }
+ }
+ catch (Exception exc)
{
- throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", new Exception(contents.ToString()));
+ // Do Nothing.
}
}
}
@@ -571,8 +555,10 @@ namespace HandBrakeWPF.Services.Presets Directory.CreateDirectory(directory);
}
+ JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };
+
// Built-in Presets
- JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore };
+
using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write))
{
string presetsJson = JsonConvert.SerializeObject(this.presets.Where(p => p.IsBuildIn).ToList(), Formatting.Indented, settings);
@@ -583,14 +569,13 @@ namespace HandBrakeWPF.Services.Presets }
// User Presets
- JsonSerializerSettings userPresetSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };
using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write))
{
List<Preset> userPresets = this.presets.Where(p => p.IsBuildIn == false).ToList();
- string presetsJson = JsonConvert.SerializeObject(userPresets, Formatting.Indented, userPresetSettings);
+ string presetsJson = JsonConvert.SerializeObject(userPresets, Formatting.Indented, settings);
PresetContainer container = new PresetContainer(CurrentPresetVersion, presetsJson);
- string containerJson = JsonConvert.SerializeObject(container, Formatting.Indented, userPresetSettings);
+ string containerJson = JsonConvert.SerializeObject(container, Formatting.Indented, settings);
using (StreamWriter writer = new StreamWriter(strm))
{
|