Exemplo n.º 1
0
        public void SaveSettingsToIni()
        {
            var iniFile = new IniFileHandler(ConstantsEnums.IniFilename);

            foreach (var setting in _settings)
            {
                iniFile.Write(setting.Name, setting.GetValueAsString(), "CameraSettings");
            }

            foreach (ISetting binding in _keyBindings)
            {
                iniFile.Write(binding.Name, binding.GetValueAsString(), "KeyBindings");
            }

            // other settings
            iniFile.Write("PreferredRenderAPI", ((int)_preferredRenderApiKind).ToString(), "MiscSettings");
        }
        public void LoadFromIni()
        {
            var iniFile = new IniFileHandler(ConstantsEnums.IniFilename);

            if (iniFile.FileExists())
            {
                foreach (var setting in _settings.Where(s => s.PersistToIniFile))
                {
                    setting.SetValueFromString(iniFile.Read(setting.Name, "CameraSettings"));
                }

                foreach (var binding in _keyBindings.Where(s => s.PersistToIniFile))
                {
                    binding.SetValueFromString(iniFile.Read(binding.Name, "KeyBindings"));
                }

                // other settings
                var themeID = Convert.ToInt32(iniFile.Read("ThemeID", "MiscSettings"));
                if (themeID >= 0)
                {
                    ThemeManager.Current.ApplicationTheme = (ApplicationTheme)themeID;
                }

                var accentColor = iniFile.Read("AccentColor", "MiscSettings");
                if (!string.IsNullOrWhiteSpace(accentColor))
                {
                    ThemeManager.Current.AccentColor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(accentColor);
                }

                for (int i = 0; i < ConstantsEnums.NumberOfResolutionsToKeep; i++)
                {
                    string keyName = "Resolution" + i;
                    if (!iniFile.KeyExists(keyName, "RecentlyUsedResolutions"))
                    {
                        break;
                    }

                    var resolutionAsString = iniFile.Read(keyName, "RecentlyUsedResolutions");
                    if (!string.IsNullOrEmpty(resolutionAsString))
                    {
                        _recentlyUsedResolutions.Add(Resolution.FromString(resolutionAsString));
                    }
                }
            }
        }
        public void SaveSettingsToIni()
        {
            var iniFile = new IniFileHandler(ConstantsEnums.IniFilename);

            foreach (var setting in _settings.Where(s => s.PersistToIniFile))
            {
                iniFile.Write(setting.Name, setting.GetValueAsString(), "CameraSettings");
            }

            foreach (ISetting binding in _keyBindings.Where(s => s.PersistToIniFile))
            {
                iniFile.Write(binding.Name, binding.GetValueAsString(), "KeyBindings");
            }

            // other settings
            ApplicationTheme?currentTheme = ThemeManager.Current.ApplicationTheme;
            int themeID = -1;                   // not defined, so use default.

            if (currentTheme != null)
            {
                themeID = (int)currentTheme.Value;
            }
            iniFile.Write("ThemeID", themeID.ToString(), "MiscSettings");
            System.Windows.Media.Color?accentColor = ThemeManager.Current.AccentColor;
            if (accentColor == null)
            {
                iniFile.DeleteKey("AccentColor", "MiscSettings");
            }
            else
            {
                iniFile.Write("AccentColor", accentColor.ToString(), "MiscSettings");
            }

            int counter = 0;

            foreach (var r in _recentlyUsedResolutions)
            {
                // Format: resolution|aspect ratio
                // resulution: widthxheight
                // aspect ratio: width:height
                iniFile.Write("Resolution" + counter, r.ToStringForIniFile(), "RecentlyUsedResolutions");
                counter++;
            }
        }
Exemplo n.º 4
0
        public void LoadFromIni()
        {
            var iniFile = new IniFileHandler(ConstantsEnums.IniFilename);

            if (iniFile.FileExists())
            {
                foreach (var setting in _settings)
                {
                    setting.SetValueFromString(iniFile.Read(setting.Name, "CameraSettings"));
                }

                foreach (var binding in _keyBindings)
                {
                    binding.SetValueFromString(iniFile.Read(binding.Name, "KeyBindings"));
                }

                // other settings
                _preferredRenderApiKind = (RenderAPIKind)Convert.ToInt32(iniFile.Read("PreferredRenderAPI", "MiscSettings"));
            }
        }