Example #1
0
        internal void Init(string fileName)
        {
            try
            {
                List <string> schemeNames = new List <string>();
                foreach (IMControlScheme controlScheme in this.ParentWindow.SelectedConfig.ControlSchemes)
                {
                    schemeNames.Add(controlScheme.Name);
                }
                this.mSchemesStackPanel.Children.Clear();
                JObject  jobject1      = JObject.Parse(File.ReadAllText(fileName));
                int?     configVersion = ConfigConverter.GetConfigVersion(jobject1);
                int      num1          = 14;
                IMConfig deserializedImConfigObject;
                if (configVersion.GetValueOrDefault() < num1 & configVersion.HasValue)
                {
                    JObject jobject2 = ConfigConverter.Convert(jobject1, "14", false, true);
                    JsonSerializerSettings serializerSettings = Utils.GetSerializerSettings();
                    serializerSettings.Formatting = Formatting.Indented;
                    JsonSerializerSettings settings = serializerSettings;
                    deserializedImConfigObject = KMManager.GetDeserializedIMConfigObject(JsonConvert.SerializeObject((object)jobject2, settings), false);
                }
                else
                {
                    configVersion = ConfigConverter.GetConfigVersion(jobject1);
                    int num2 = 16;
                    if (configVersion.GetValueOrDefault() < num2 & configVersion.HasValue && Utils.CheckIfImagesArrayPresentInCfg(jobject1))
                    {
                        JObject jobject2 = jobject1;
                        foreach (JObject scheme in (IEnumerable <JToken>)jobject1["ControlSchemes"])
                        {
                            scheme["Images"] = (JToken)ConfigConverter.ConvertImagesArrayForPV16(scheme);
                        }
                        jobject2["MetaData"][(object)"Comment"]       = (JToken)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Generated automatically from ver {0}", (object)(int)jobject2["MetaData"][(object)"ParserVersion"]);
                        jobject2["MetaData"][(object)"ParserVersion"] = (JToken)16;
                        JsonSerializerSettings serializerSettings = Utils.GetSerializerSettings();
                        serializerSettings.Formatting = Formatting.Indented;
                        deserializedImConfigObject    = KMManager.GetDeserializedIMConfigObject(JsonConvert.SerializeObject((object)jobject2, serializerSettings), false);
                    }
                    else
                    {
                        deserializedImConfigObject = KMManager.GetDeserializedIMConfigObject(fileName, true);
                    }
                }
                this.mStringsToImport = deserializedImConfigObject.Strings;
                this.mNumberOfSchemesSelectedForImport = 0;
                deserializedImConfigObject.ControlSchemes.Where <IMControlScheme>((Func <IMControlScheme, bool>)(scheme => scheme.BuiltIn)).ToList <IMControlScheme>().ForEach((System.Action <IMControlScheme>)(scheme => AddSchemeToImportCheckbox(scheme)));
                deserializedImConfigObject.ControlSchemes.Where <IMControlScheme>((Func <IMControlScheme, bool>)(scheme => !scheme.BuiltIn)).ToList <IMControlScheme>().ForEach((System.Action <IMControlScheme>)(scheme =>
                {
                    if (this.dict.Keys.Contains <string>(scheme.Name.ToLower(CultureInfo.InvariantCulture).Trim()))
                    {
                        scheme.Name += " (Edited)";
                        scheme.Name  = KMManager.GetUniqueName(scheme.Name, (IEnumerable <string>)schemeNames);
                    }
                    AddSchemeToImportCheckbox(scheme);
                }));

                void AddSchemeToImportCheckbox(IMControlScheme scheme)
                {
                    this.dict.Add(scheme.Name.ToLower(CultureInfo.InvariantCulture).Trim(), scheme);
                    ImportSchemesWindowControl schemesWindowControl1 = new ImportSchemesWindowControl(this, this.ParentWindow);

                    schemesWindowControl1.Width = this.mSchemesStackPanel.Width;
                    ImportSchemesWindowControl schemesWindowControl2 = schemesWindowControl1;

                    schemesWindowControl2.mContent.Content = (object)scheme.Name;
                    schemesWindowControl2.Margin           = new Thickness(0.0, 1.0, 0.0, 1.0);
                    foreach (string key in this.ParentWindow.SelectedConfig.ControlSchemesDict.Keys)
                    {
                        if (string.Equals(key.Trim(), schemesWindowControl2.mContent.Content.ToString().Trim(), StringComparison.InvariantCultureIgnoreCase))
                        {
                            schemesWindowControl2.mBlock.Visibility = Visibility.Visible;
                            schemesWindowControl2.mImportName.Text  = KMManager.GetUniqueName(schemesWindowControl2.mContent.Content.ToString().Trim(), (IEnumerable <string>)schemeNames);
                            break;
                        }
                    }
                    this.mSchemesStackPanel.Children.Add((UIElement)schemesWindowControl2);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in import window init err: " + ex.ToString());
            }
        }