コード例 #1
0
 /// <summary>
 /// Saves the settings to file.
 /// </summary>
 public void SaveSettings()
 {
     GlobalSettings.SetPostProcessingEffect();
     GlobalSettings.SetGraphicsSettings();
     GlobalSettings.SetLanguage();
     settingsManager.Save();
 }
コード例 #2
0
        public void SaveLoad_PropertiesMatch()
        {
            FileInfo file = new FileInfo(Path.Combine(Path.GetTempPath(), $"{nameof(SettingsFileManagerTests)}.{nameof(this.SaveLoad_PropertiesMatch)}.xml"));

            try {
                SettingsFileManager <FakeSettings> settingsManager = new SettingsFileManager <FakeSettings>(file);
                settingsManager.Settings.NewProperty = "foo";
                settingsManager.Settings.IsAwesome   = true;
                settingsManager.Settings.Title       = "hello";
                FakeSettings savedSettings = settingsManager.Settings;
                settingsManager.Save();

                FakeSettings loadedSettings = new SettingsFileManager <FakeSettings>(file).Settings;

                Assert.AreEqual(savedSettings.NewProperty, loadedSettings.NewProperty);
                Assert.AreEqual(savedSettings.IsAwesome, loadedSettings.IsAwesome);
                Assert.AreEqual(savedSettings.Title, loadedSettings.Title);
            } finally {
                try { file.Delete(); } catch { }
            }
        }
コード例 #3
0
        public void LoadOldSettings_NewPropertyHasCorrectDefault()
        {
            FileInfo file = new FileInfo(Path.Combine(Path.GetTempPath(), $"{nameof(SettingsFileManagerTests)}.{nameof(this.LoadOldSettings_NewPropertyHasCorrectDefault)}.xml"));

            try {
                SettingsFileManager <OldFakeSettings> oldSettingsManager = new SettingsFileManager <OldFakeSettings>(file);
                oldSettingsManager.Settings.IsAwesome = true;
                oldSettingsManager.Save();
                string serialized;
                using (StreamReader reader = file.OpenText())
                    serialized = reader.ReadToEnd();
                using (StreamWriter writer = file.CreateText())
                    writer.Write(serialized.Replace(nameof(OldFakeSettings), nameof(FakeSettings)));

                FakeSettings settings = new SettingsFileManager <FakeSettings>(file).Settings;

                Assert.AreEqual(NEW_PROPERTY_DEFAULT, settings.NewProperty);
            } finally {
                try { file.Delete(); } catch { }
            }
        }