Exemple #1
0
        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);
        }
Exemple #2
0
        public static SettingBase Load(SettingBase defaultSettings, LocationType locationType, string name)
        {
            string fileName = Path.Combine(DefaultLocation(locationType), name);

            return(Load(defaultSettings, fileName));
        }
Exemple #3
0
 public static SettingBase Load(SettingBase defaultSettings, LocationType locationType)
 {
     return(Load(defaultSettings, locationType, defaultSettings.DefaultName()));
 }
Exemple #4
0
        public static SettingBase LoadFromPath(SettingBase defaultSettings, string path)
        {
            string fileName = Path.Combine(path, defaultSettings.DefaultName());

            return(Load(defaultSettings, fileName));
        }