Exemple #1
0
		} // GameSettings()

		/// <summary>
		/// Create game settings. This constructor helps us to only load the
		/// GameSettings once, not again if GameSettings is recreated by
		/// the Deserialization process.
		/// </summary>
		/// <param name="loadSettings">Load settings</param>
		static GameSettings()
		{
			defaultInstance = new GameSettings();
			Load();
		} // GameSettings(loadSettings)
Exemple #2
0
		} // GameSettings(loadSettings)
		#endregion

		#region Load
		/// <summary>
		/// Load
		/// </summary>
		public static void Load()
		{
			needSave = false;

			FileStream file =
				FileHelper.LoadGameContentFile(SettingsFilename);
			if (file == null)
				return;

			// If the file is empty, just create a new file with the default
			// settings.
			if (file.Length == 0)
			{
				// Close the file
				file.Close();

				// But first check if there is maybe a file in the game directory
				// to load the default game settings from.
				file = FileHelper.LoadGameContentFile(SettingsFilename);
				if (file != null)
				{
					// Load everything into this class
					GameSettings loadedGameSettings =
						(GameSettings)new XmlSerializer(typeof(GameSettings)).
						Deserialize(file);
					if (loadedGameSettings != null)
						defaultInstance = loadedGameSettings;

					// Close the file
					file.Close();
				} // if (file)

				// Save user settings file
				needSave = true;
				Save();
			} // if (file.Length)
			else
			{
				// Else load everything into this class with help of the
				// XmlSerializer.
				GameSettings loadedGameSettings =
					(GameSettings)new XmlSerializer(typeof(GameSettings)).
					Deserialize(file);
				if (loadedGameSettings != null)
					defaultInstance = loadedGameSettings;

				// Close the file
				file.Close();
			} // else
		} // Load()