From 718c04e00317956ba14d2d5499410480847c2d62 Mon Sep 17 00:00:00 2001 From: sr55 Date: Tue, 8 Dec 2009 15:12:12 +0000 Subject: 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 --- win/C#/Presets/PresetsHandler.cs | 73 +++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 20 deletions(-) (limited to 'win/C#/Presets') 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 list = Ser.Deserialize(strm) as List; - - if (list != null) - foreach (Preset preset in list) - _presets.Add(preset); + if (strm.Length != 0) + { + List list = Ser.Deserialize(strm) as List; + + 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 list = Ser.Deserialize(strm) as List; - - if (list != null) - foreach (Preset preset in list) - _userPresets.Add(preset); + if (strm.Length != 0) + { + List list = Ser.Deserialize(strm) as List; + + 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); + } + + } } /// @@ -241,7 +274,7 @@ namespace Handbrake.Presets if (_presets.Count != 0) // Built In Presets { - + foreach (Preset preset in _presets) { if (preset.Category != category) -- cgit v1.2.3