diff options
-rw-r--r-- | win/C#/Presets/PresetsHandler.cs | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/win/C#/Presets/PresetsHandler.cs b/win/C#/Presets/PresetsHandler.cs index 8d1da12d6..05c0243ab 100644 --- a/win/C#/Presets/PresetsHandler.cs +++ b/win/C#/Presets/PresetsHandler.cs @@ -168,7 +168,8 @@ namespace Handbrake.Presets string[] presetName = r.Split(line);
Preset newPreset = new Preset
- { Category = category,
+ {
+ Category = category,
Name = presetName[0].Replace("+", "").Trim(),
Query = presetName[2],
Version = Properties.Settings.Default.hb_version,
@@ -195,37 +196,69 @@ namespace Handbrake.Presets _presets.Clear();
_userPresets.Clear();
- // Load in the users _presets from _userPresets.xml
- if (File.Exists(_hbPresetFile))
+ try
{
- using (FileStream strm = new FileStream(_hbPresetFile, FileMode.Open, FileAccess.Read))
+ // Load in the users _presets from _userPresets.xml
+ if (File.Exists(_hbPresetFile))
{
- if (strm.Length != 0)
+ using (FileStream strm = new FileStream(_hbPresetFile, FileMode.Open, FileAccess.Read))
{
- List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
-
- if (list != null)
- foreach (Preset preset in list)
- _presets.Add(preset);
+ if (strm.Length != 0)
+ {
+ List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
+
+ if (list != null)
+ foreach (Preset preset in list)
+ _presets.Add(preset);
+ }
}
}
}
+ catch (Exception)
+ {
+ MessageBox.Show(
+ "HandBrakes preset file appears to have been corrupted. This file will now be re-generated!\n" +
+ "If the problem presists, please delete the file: \n\n" + _hbPresetFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ UpdateBuiltInPresets();
+ }
- // Load in the users _presets from _userPresets.xml
- if (File.Exists(_userPresetFile))
+ try
{
- using (FileStream strm = new FileStream(_userPresetFile, FileMode.Open, FileAccess.Read))
+ // Load in the users _presets from _userPresets.xml
+ if (File.Exists(_userPresetFile))
{
- if (strm.Length != 0)
+ using (FileStream strm = new FileStream(_userPresetFile, FileMode.Open, FileAccess.Read))
{
- List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
-
- if (list != null)
- foreach (Preset preset in list)
- _userPresets.Add(preset);
+ if (strm.Length != 0)
+ {
+ List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
+
+ if (list != null)
+ foreach (Preset preset in list)
+ _userPresets.Add(preset);
+ }
}
}
}
+ catch (Exception)
+ {
+ MessageBox.Show(
+ "Your User presets file appears to have been corrupted.\n" +
+ "Your presets will not be loaded. You may need to re-create your presets.\n\n" +
+ "Your user presets file has been renamed to 'user_presets.xml.old' and is located in:\n " +
+ Path.GetDirectoryName(_userPresetFile) + "\n" +
+ "You may be able to recover some presets if you know the XML language.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ // Recover from Error.
+ if (File.Exists(_userPresetFile))
+ {
+ string disabledFile = _userPresetFile + ".old";
+ if (File.Exists(disabledFile))
+ File.Delete(disabledFile);
+ File.Move(_userPresetFile, disabledFile);
+ }
+
+ }
}
/// <summary>
@@ -241,7 +274,7 @@ namespace Handbrake.Presets if (_presets.Count != 0) // Built In Presets
{
-
+
foreach (Preset preset in _presets)
{
if (preset.Category != category)
|