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

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

            return(Load(defaultSettings, fileName));
        }