/// <summary> /// Load settings /// </summary> public static void Load() { _needSave = false; FileStream file = FileHelper.LoadGameContentFile(SettingsFilename); if (file == null) { // We need a save, but wait to create the file after quitting. _needSave = true; return; } // If the file is empty, just create a new file with the default // settings. if (file.Length == 0) { // Close the file first. file.Close(); // Check if there is a file in the game directory // to load the default game settings. file = FileHelper.LoadGameContentFile(SettingsFilename); if (file != null) { // Load everything into this class. GameSettings loadedGameSetting = (GameSettings)new XmlSerializer(typeof(GameSettings)).Deserialize(file); if (loadedGameSetting != null) _defaultInstance = loadedGameSetting; // Close the file. file.Close(); } // Save the user settings. _needSave = true; Save(); } else { // Else load everything into this class with help of the // XmlSerializer. GameSettings loadedGameSetting = (GameSettings)new XmlSerializer(typeof(GameSettings)).Deserialize(file); if (loadedGameSetting != null) _defaultInstance = loadedGameSetting; // Close the file. file.Close(); } }
/// <summary> /// Create game settings. This constructor helps us to only load the /// GameSetting once, not again if GameSetting is recreated by /// the Deserialization process. /// </summary> public static void Initialize() { _defaultInstance = new GameSettings(); Load(); }