Пример #1
0
 private bool EditedNameIsAllowed(string text, ImportSchemesWindowControl item)
 {
     if (string.IsNullOrEmpty(text.Trim()))
     {
         BlueStacksUIBinding.Bind(item.mWarningMsg, LocaleStrings.GetLocalizedString("STRING_INVALID_SCHEME_NAME", ""), "");
         return(false);
     }
     if (text.Trim().IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
     {
         BlueStacksUIBinding.Bind(item.mWarningMsg, LocaleStrings.GetLocalizedString("STRING_INVALID_SCHEME_NAME", ""), "");
         return(false);
     }
     foreach (IMControlScheme controlScheme in this.ParentWindow.SelectedConfig.ControlSchemes)
     {
         if (controlScheme.Name.ToLower(CultureInfo.InvariantCulture).Trim() == text.ToLower(CultureInfo.InvariantCulture).Trim())
         {
             return(false);
         }
     }
     foreach (ImportSchemesWindowControl child in this.mSchemesStackPanel.Children)
     {
         bool?isChecked = child.mContent.IsChecked;
         bool flag1     = true;
         if (isChecked.GetValueOrDefault() == flag1 & isChecked.HasValue && child.mBlock.Visibility == Visibility.Visible && (child.mImportName.Text.ToLower(CultureInfo.InvariantCulture).Trim() == text.ToLower(CultureInfo.InvariantCulture).Trim() && child.mContent.Content.ToString().Trim().ToLower(CultureInfo.InvariantCulture) != item.mContent.Content.ToString().Trim().ToLower(CultureInfo.InvariantCulture)))
         {
             return(false);
         }
         isChecked = child.mContent.IsChecked;
         bool flag2 = true;
         if (isChecked.GetValueOrDefault() == flag2 & isChecked.HasValue && child.mContent.Content.ToString().ToLower(CultureInfo.InvariantCulture).Trim() == text.ToLower(CultureInfo.InvariantCulture).Trim())
         {
             return(false);
         }
     }
     return(true);
 }
Пример #2
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());
            }
        }
Пример #3
0
 private void ImportBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int  index = 0;
         bool flag1 = true;
         List <IMControlScheme> imControlSchemeList = new List <IMControlScheme>();
         foreach (ImportSchemesWindowControl child in this.mSchemesStackPanel.Children)
         {
             bool?isChecked = child.mContent.IsChecked;
             bool flag2     = true;
             if (isChecked.GetValueOrDefault() == flag2 & isChecked.HasValue)
             {
                 imControlSchemeList.Add(this.dict.ElementAt <KeyValuePair <string, IMControlScheme> >(index).Value);
                 if (this.ParentWindow.SelectedConfig.ControlSchemesDict.Keys.Select <string, string>((Func <string, string>)(key => key.ToLower(CultureInfo.InvariantCulture).Trim())).Contains <string>(child.mContent.Content.ToString().ToLower(CultureInfo.InvariantCulture).Trim()))
                 {
                     if (!this.EditedNameIsAllowed(child.mImportName.Text, child))
                     {
                         child.mImportName.InputTextValidity = TextValidityOptions.Error;
                         if (!string.IsNullOrEmpty(child.mImportName.Text) && child.mImportName.Text.Trim().IndexOfAny(Path.GetInvalidFileNameChars()) < 0)
                         {
                             BlueStacksUIBinding.Bind(child.mWarningMsg, LocaleStrings.GetLocalizedString("STRING_DUPLICATE_SCHEME_NAME_WARNING", ""), "");
                         }
                         child.mWarningMsg.Visibility = Visibility.Visible;
                         flag1 = false;
                     }
                     else
                     {
                         child.mImportName.InputTextValidity = TextValidityOptions.Success;
                         child.mWarningMsg.Visibility        = Visibility.Collapsed;
                     }
                 }
             }
             ++index;
         }
         if (imControlSchemeList.Count == 0)
         {
             this.ParentWindow.mCommonHandler.AddToastPopup((Window)this, LocaleStrings.GetLocalizedString("STRING_NO_SCHEME_SELECTED", ""), 1.3, false);
         }
         else
         {
             if (!flag1)
             {
                 return;
             }
             foreach (IMControlScheme scheme in imControlSchemeList)
             {
                 ImportSchemesWindowControl controlFromScheme = this.GetControlFromScheme(scheme);
                 if (this.ParentWindow.SelectedConfig.ControlSchemesDict.Keys.Select <string, string>((Func <string, string>)(key => key.ToLower(CultureInfo.InvariantCulture))).Contains <string>(controlFromScheme.mContent.Content.ToString().ToLower(CultureInfo.InvariantCulture).Trim()))
                 {
                     scheme.Name = controlFromScheme.mImportName.Text.Trim();
                 }
             }
             this.mStringsToImport = KMManager.CleanupGuidanceAccordingToSchemes(imControlSchemeList, this.mStringsToImport);
             this.ImportSchemes(imControlSchemeList, this.mStringsToImport);
             KeymapCanvasWindow.sIsDirty = true;
             KMManager.SaveIMActions(this.ParentWindow, false, false);
             this.CanvasWindow.SidebarWindow.FillProfileCombo();
             this.CanvasWindow.SidebarWindow.ProfileChanged();
             KMManager.SendSchemeChangedStats(this.ParentWindow, "import_scheme");
             this.ParentWindow.mCommonHandler.AddToastPopup((Window)this.CanvasWindow.SidebarWindow, LocaleStrings.GetLocalizedString("STRING_CONTROLS_IMPORTED", ""), 1.3, false);
             this.CloseWindow();
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Error while importing script. err:" + ex.ToString());
     }
 }