public override void Execute() { var settingsSerializer = new DataContractJsonSerializer(typeof(SettingsData), new DataContractJsonSerializerSettings { UseSimpleDictionaryFormat = true }); if (File.Exists(Constants.SettingsPath)) { _settingsContainer.InitializeSettings(settingsSerializer.ReadObject(new MemoryStream(Encoding.Unicode.GetBytes(File.ReadAllText(Constants.SettingsPath)))) as SettingsData); } else { _settingsContainer.InitializeSettings(new SettingsData { MasterVolume = Constants.DefaultMasterVolume, MusicVolume = Constants.DefaultMusicVolume, SFXVolume = Constants.DefaultSFXVolume, Language = _localizationManager.GetPreferredLanguage(), AutoSave = Constants.AutoSaveDefault }); settingsSerializer.WriteObject(new FileStream(Constants.SettingsPath, FileMode.Create), _settingsContainer); } }
public static void ResetToDefaultSettings(this SettingsData settingsData, ILocalizationManager localizationManager) { settingsData.MasterVolume = Constants.DefaultMasterVolume; settingsData.MusicVolume = Constants.DefaultMusicVolume; settingsData.SFXVolume = Constants.DefaultSFXVolume; settingsData.Language = localizationManager.GetPreferredLanguage(); settingsData.AutoSave = Constants.AutoSaveDefault; settingsData.AutoLogin = Constants.AutoLoginDefault; }