public static SettingBase Load(SettingBase defaultSettings, string fileName) { defaultSettings.m_fileName = fileName; if (!File.Exists(fileName)) { return(defaultSettings); } SettingBase settings = defaultSettings; try { XmlSerializer serializer = new XmlSerializer(defaultSettings.GetType()); using (TextReader reader = new StreamReader(fileName)) { settings = (SettingBase)serializer.Deserialize(reader); settings.m_fileName = fileName; } } catch (Exception ex) { throw new Exception(string.Format("Loading settings from file '{1}' to {0} failed.", defaultSettings.GetType().ToString(), fileName), ex); } if (File.Exists(fileName + ".tmp")) { File.Delete(fileName + ".tmp"); } return(settings); }
public static SettingBase Load(SettingBase defaultSettings, LocationType locationType, string name) { string fileName = Path.Combine(DefaultLocation(locationType), name); return(Load(defaultSettings, fileName)); }
public static SettingBase Load(SettingBase defaultSettings, LocationType locationType) { return(Load(defaultSettings, locationType, defaultSettings.DefaultName())); }
public static SettingBase LoadFromPath(SettingBase defaultSettings, string path) { string fileName = Path.Combine(path, defaultSettings.DefaultName()); return(Load(defaultSettings, fileName)); }