From 2d578cdda12daa524d7466d5681e35f2b9443bf0 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 26 May 2014 14:54:30 +0100 Subject: [PATCH] Handle IO errors while reading/writing config file - crash report fix --- renderdocui/Code/AppMain.cs | 4 ++++ renderdocui/Code/PersistantConfig.cs | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/renderdocui/Code/AppMain.cs b/renderdocui/Code/AppMain.cs index c9465dedf..eb316d38a 100644 --- a/renderdocui/Code/AppMain.cs +++ b/renderdocui/Code/AppMain.cs @@ -96,6 +96,10 @@ namespace renderdocui.Code { MessageBox.Show(String.Format("Error loading config file\n{0}\nA default config is loaded and will be saved out.", Core.ConfigFilename)); } + catch (System.IO.IOException ex) + { + MessageBox.Show(String.Format("Error loading config file: {1}\n{0}\nA default config is loaded and will be saved out.", Core.ConfigFilename, ex.Message)); + } } // propogate float formatting settings to the Formatter class used globally to format float values diff --git a/renderdocui/Code/PersistantConfig.cs b/renderdocui/Code/PersistantConfig.cs index cca8be6cf..303a3a0e7 100644 --- a/renderdocui/Code/PersistantConfig.cs +++ b/renderdocui/Code/PersistantConfig.cs @@ -31,6 +31,7 @@ using System.IO; using System.Xml; using System.Xml.Serialization; using renderdoc; +using System.Windows.Forms; namespace renderdocui.Code { @@ -125,15 +126,23 @@ namespace renderdocui.Code public void Serialize(string file) { - ReplayHostKeyValues.Clear(); - foreach(var kv in ReplayHosts) - ReplayHostKeyValues.Add(new SerializableKeyValuePair(kv.Key, kv.Value)); + try + { + ReplayHostKeyValues.Clear(); + foreach (var kv in ReplayHosts) + ReplayHostKeyValues.Add(new SerializableKeyValuePair(kv.Key, kv.Value)); - XmlSerializer xs = new XmlSerializer(this.GetType()); - StreamWriter writer = File.CreateText(file); - xs.Serialize(writer, this); - writer.Flush(); - writer.Close(); + XmlSerializer xs = new XmlSerializer(this.GetType()); + StreamWriter writer = File.CreateText(file); + xs.Serialize(writer, this); + writer.Flush(); + writer.Close(); + } + catch (System.IO.IOException ex) + { + // Can't recover, but let user know that we couldn't save their settings. + MessageBox.Show(String.Format("Error saving config file: {1}\n{0}\nA default config is loaded and will be saved out.", file, ex.Message)); + } } public static PersistantConfig Deserialize(string file)