Example #1
0
        public static ElasticComboBox PopulateLanguageList(ElasticComboBox myCboLanguage, string myStrSelectedSheet)
        {
            if (myCboLanguage == null)
            {
                throw new ArgumentNullException(nameof(myCboLanguage));
            }
            string strDefaultSheetLanguage        = GlobalOptions.Language;
            int?   intLastIndexDirectorySeparator = myStrSelectedSheet?.LastIndexOf(Path.DirectorySeparatorChar);

            if (intLastIndexDirectorySeparator.HasValue && (intLastIndexDirectorySeparator != -1))
            {
                string strSheetLanguage = myStrSelectedSheet.Substring(0, intLastIndexDirectorySeparator.Value);
                if (strSheetLanguage.Length == 5)
                {
                    strDefaultSheetLanguage = strSheetLanguage;
                }
            }

            myCboLanguage.BeginUpdate();
            myCboLanguage.ValueMember   = "Value";
            myCboLanguage.DisplayMember = "Name";
            myCboLanguage.DataSource    = LstLanguages;
            myCboLanguage.SelectedValue = strDefaultSheetLanguage;
            if (myCboLanguage.SelectedIndex == -1)
            {
                myCboLanguage.SelectedValue = GlobalOptions.DefaultLanguage;
            }
            myCboLanguage.EndUpdate();
            return(myCboLanguage);
        }
Example #2
0
        public static ElasticComboBox PopulateLanguageList(ElasticComboBox myCboLanguage, string myStrSelectedSheet)
        {
            List <ListItem> lstLanguages          = new List <ListItem>();
            string          languageDirectoryPath = Path.Combine(Utils.GetStartupPath, "lang");

            string[] languageFilePaths = Directory.GetFiles(languageDirectoryPath, "*.xml");

            foreach (string filePath in languageFilePaths)
            {
                XmlDocument xmlDocument = new XmlDocument();

                try
                {
                    using (StreamReader objStreamReader = new StreamReader(filePath, Encoding.UTF8, true))
                    {
                        xmlDocument.Load(objStreamReader);
                    }
                }
                catch (IOException)
                {
                    continue;
                }
                catch (XmlException)
                {
                    continue;
                }

                XmlNode node = xmlDocument.SelectSingleNode("/chummer/name");

                if (node == null)
                {
                    continue;
                }

                string strLanguageCode = Path.GetFileNameWithoutExtension(filePath);
                if (GetXslFilesFromLocalDirectory(strLanguageCode).Count > 0)
                {
                    lstLanguages.Add(new ListItem(strLanguageCode, node.InnerText));
                }
            }

            lstLanguages.Sort(CompareListItems.CompareNames);

            string strDefaultSheetLanguage        = GlobalOptions.Language;
            int?   intLastIndexDirectorySeparator = myStrSelectedSheet?.LastIndexOf(Path.DirectorySeparatorChar);

            if (intLastIndexDirectorySeparator.HasValue && (intLastIndexDirectorySeparator != -1))
            {
                string strSheetLanguage = myStrSelectedSheet.Substring(0, intLastIndexDirectorySeparator.Value);
                if (strSheetLanguage.Length == 5)
                {
                    strDefaultSheetLanguage = strSheetLanguage;
                }
            }

            myCboLanguage.BeginUpdate();
            myCboLanguage.ValueMember   = "Value";
            myCboLanguage.DisplayMember = "Name";
            myCboLanguage.DataSource    = lstLanguages;
            myCboLanguage.SelectedValue = strDefaultSheetLanguage;
            if (myCboLanguage.SelectedIndex == -1)
            {
                myCboLanguage.SelectedValue = GlobalOptions.DefaultLanguage;
            }
            myCboLanguage.EndUpdate();
            return(myCboLanguage);
        }