Esempio n. 1
0
 public GlobalFuncs()
 {
     applicationDirectory = System.Environment.CurrentDirectory;
     localization         = new ScoutLocalization();
     logging    = new Logging(applicationDirectory);
     scoutTimer = new ScoutTimer();
 }
Esempio n. 2
0
        public void setLanguage()
        {
            if (!initScout)
            {
                if (curPreferencesSettings.language.Equals(currentLanguage))
                {
                    return;
                }
            }

            ScoutLocalization sl = globalFuncs.localization;

            FieldInfo[] slfieldInfos = typeof(ScoutLocalization).GetFields();
            Language    l            = null;

            for (int i = 0; i < languages.Count; ++i)
            {
                if (curPreferencesSettings.language.Equals(languages[i].name))
                {
                    l = languages[i];
                    break;
                }
            }
            if (l != null)
            {
                FieldInfo[]   lfieldInfos = typeof(Language).GetFields();
                List <String> toAddEmpty  = new List <String>()
                {
                    "YesNoEmpty",
                    "contractStatuses",
                    "regions",
                    "bestcrs",
                    "bestprs",
                    "ownerShips",
                    "roles",
                    "bestcrs",
                    "teamtypes",
                    "reputations"
                };

                changingLanguage = true;
                //int j = 0;
                for (int i = 0; i < lfieldInfos.Length; ++i)
                {
                    FieldInfo lfieldInfo = lfieldInfos[i];
                    if (lfieldInfo != null)
                    {
                        if (lfieldInfo.FieldType.Name.Contains("List"))
                        {
                            //++j;
                            //if (slfieldInfo.Name.Equals("YesNoEmpty")) --j;
                            FieldInfo slfieldInfo = null;
                            for (int j = 0; j < slfieldInfos.Length; ++j)
                            {
                                if (slfieldInfos[j].Name.ToLower().Equals(lfieldInfo.Name.ToLower()))
                                {
                                    slfieldInfo = slfieldInfos[j];
                                    break;
                                }
                            }
                            if (slfieldInfo != null)
                            {
                                ObservableCollection <String> sllist = (ObservableCollection <String>)slfieldInfo.GetValue(sl);
                                List <String> llist = (List <String>)lfieldInfo.GetValue(l);
                                //sllist.Clear();
                                int index = -1;

                                if (toAddEmpty.Contains(slfieldInfo.Name))
                                {
                                    ++index;
                                }

                                for (int k = 0; k < llist.Count; ++k)
                                {
                                    sllist[++index] = llist[k];
                                }

                                if (lfieldInfo.Name.ToLower().Equals("yesno"))
                                {
                                    FieldInfo slfieldInfo2 = typeof(ScoutLocalization).GetField("YesNoEmpty");
                                    ObservableCollection <String> sllist2 = (ObservableCollection <String>)slfieldInfo2.GetValue(sl);
                                    for (int k = 0; k < llist.Count; ++k)
                                    {
                                        sllist2[k + 1] = llist[k];
                                    }
                                }
                            }
                            else
                            {
                                globalFuncs.logging.update("Error: Language " + curPreferencesSettings.language + " Reason: Could not apply " + slfieldInfo.Name);
                            }
                        }
                    }
                    else
                    {
                        globalFuncs.logging.update("Error: Language " + curPreferencesSettings.language + " Reason: Could not apply " + lfieldInfo.Name);
                    }
                }
                globalFuncs.windowMain.changeLanguage();
                changingLanguage = false;
                currentLanguage  = curPreferencesSettings.language;
            }
            else
            {
                globalFuncs.logging.update("Error: Language " + curPreferencesSettings.language + " Reason: Could not be applied");
            }
        }