/// <summary> /// Persists the settings to the specified filename /// </summary> /// <param name="file">The filename to use for saving</param> /// <param name="settings">The instance of the Settings class to persist</param> internal static void SaveSettingsToFile(string file, VESettings settings) { FileStream fs = null; XmlSerializer xs = new XmlSerializer(typeof(VESettings)); fs = File.Open(file, FileMode.Create, FileAccess.Write); try { xs.Serialize(fs, settings); } finally { fs.Close(); } }
/// <summary> /// Loads a serialized instance of the settings from the specified file /// returns default values if the file doesn't exist or an error occurs /// </summary> /// <returns>The persisted settings from the file</returns> internal static VESettings LoadSettingsFromFile(string filename) { VESettings settings; XmlSerializer xs = new XmlSerializer(typeof(VESettings)); if (File.Exists(filename)) { FileStream fs = null; try { fs = File.Open(filename, FileMode.Open, FileAccess.Read); } catch { return new VESettings(); } try { settings = (VESettings)xs.Deserialize(fs); } catch { settings = new VESettings(); } finally { fs.Close(); } } else { settings = new VESettings(); } return settings; }