コード例 #1
0
        public static bool TrySetSetting(OrderedDictionary <SettingCategory, OrderedDictionary <string, Setting> > settings, SettingCategory category, string name, string value)
        {
            bool isLauncherSetting = IsLauncherSettings(settings);

            if (isLauncherSetting && !AreLauncherSettingsInitialized)
            {
                return(false);
            }

            if (!isLauncherSetting && !AreModSettingsInitialized)
            {
                return(false);
            }

            if (settings[category][name].AllowedValues.Count > 0)
            {
                foreach (var allowedValue in settings[category][name].AllowedValues)
                {
                    if (allowedValue.Value.Key.Equals(value))
                    {
                        settings[category][name].Value = allowedValue.Key;
                        break;
                    }
                }
            }
            else
            {
                settings[category][name].Value = value;
            }

            if (isLauncherSetting)
            {
                DelayedStoreLauncherSettings();
            }
            else
            {
                DelayedStoreModSettings();
            }

            return(true);
        }
コード例 #2
0
        public static bool TrySetSetting(OrderedDictionary <SettingCategory, OrderedDictionary <string, Setting> > settings, SettingCategory category, string name, bool value)
        {
            bool isLauncherSetting = IsLauncherSettings(settings);

            if (isLauncherSetting && !AreLauncherSettingsInitialized)
            {
                return(false);
            }

            if (!isLauncherSetting && !AreModSettingsInitialized)
            {
                return(false);
            }

            settings[category][name].Value = value ? "1" : "0";

            if (isLauncherSetting)
            {
                DelayedStoreLauncherSettings();
                Application.Current?.Dispatcher?.BeginInvoke((Action)(() => (Application.Current?.MainWindow as MainWindow)?.UpdateState()));
            }
            else
            {
                DelayedStoreModSettings();
            }

            return(true);
        }