Beispiel #1
0
 // load settings from specified location using default name
 public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType)
 {
     return(Load(defaultSettings, locationType, defaultSettings.DefaultName()));
 }
Beispiel #2
0
 // load settings from default file
 public static SettingsBase Load(SettingsBase defaultSettings)
 {
     return(Load(defaultSettings, LocationType.Application));
 }
Beispiel #3
0
        // Load settings from specified location using specified path and default filename
        public static SettingsBase LoadFromPath(SettingsBase defaultSettings, string path)
        {
            string fileName = Path.Combine(path, defaultSettings.DefaultName());

            return(Load(defaultSettings, fileName));
        }
Beispiel #4
0
        // Load settings from specified location using specified name
        public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType, string name)
        {
            string fileName = Path.Combine(DefaultLocation(locationType), name);

            return(Load(defaultSettings, fileName));
        }
Beispiel #5
0
		// load settings from default file
		public static SettingsBase Load(SettingsBase defaultSettings) 
		{
			return Load(defaultSettings, LocationType.User);
		}
Beispiel #6
0
		// load settings from specified location using default name
		public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType)
		{
			return Load(defaultSettings, locationType, defaultSettings.DefaultName());
		}
Beispiel #7
0
		// Load settings from specified location using specified name
		public static SettingsBase Load(SettingsBase defaultSettings, LocationType locationType, string name)
		{
			string fileName = Path.Combine(DefaultLocation(locationType), name);
			return Load(defaultSettings, fileName);
		}
Beispiel #8
0
		// Load settings from specified location using specified path and default filename
		public static SettingsBase LoadFromPath(SettingsBase defaultSettings, string path)
		{
			string fileName = Path.Combine(path, defaultSettings.DefaultName());
			return Load(defaultSettings, fileName);
		}
Beispiel #9
0
		// load settings from a given file (full path and name)
		public static SettingsBase Load(SettingsBase defaultSettings, string fileName) 
		{
			// remember where we loaded from for a later save
			defaultSettings.m_fileName = fileName;

			// return the default instance if the file does not exist
			if(!File.Exists(fileName)) 
			{
				return defaultSettings;
			}

			// start out with the default instance
			SettingsBase settings = defaultSettings;
			try 
			{
				XmlSerializer ser = new XmlSerializer(defaultSettings.GetType());

				using(TextReader tr = new StreamReader(fileName)) 
				{
					settings = (SettingsBase)ser.Deserialize(tr);
					settings.m_fileName = fileName; // remember where we loaded from for a later save
				}
			}
			catch(Exception ex) 
			{
				throw new System.Exception(String.Format("Loading settings from file '{1}' to {0} failed", 
					defaultSettings.GetType().ToString(), fileName), ex);
			}
         
			return settings;
		}