summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2009-12-08 15:12:12 +0000
committersr55 <[email protected]>2009-12-08 15:12:12 +0000
commit718c04e00317956ba14d2d5499410480847c2d62 (patch)
treef1656f04a3782aa4d03e4a158d1830640a4fa318
parent2e15889c325c6033d30debc810fd7639a6a01c52 (diff)
WinGui:
- Added some code to recover from corrupted preset files. This will hopefully fix at least 1 cause of the CLR20r3 .NET error git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3012 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/C#/Presets/PresetsHandler.cs73
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)