Exemple #1
0
 internal static void Initialize()
 {
     try
     {
         if (!TextTranslator.Initialized)
         {
             double totalMilliseconds = TimeSpan.FromSeconds((double)IniSettings.LogWriterTime).TotalMilliseconds;
             TextTranslator.writerdata  = new Dictionary <string, StringBuilder>();
             TextTranslator.writertimer = new System.Timers.Timer(totalMilliseconds)
             {
                 AutoReset = false
             };
             TextTranslator.writertimer.Elapsed += new ElapsedEventHandler(TextTranslator.WriterTimerElapsed);
             TextTranslator.Load();
             IniSettings.LanguageDirChanged += new Action <string>((string value) => {
                 TextTranslator.Load();
                 MaskableGraphicText.Retranslate();
             });
             IniSettings.ProcessPathDirChanged += new Action <string>((string value) => {
                 TextTranslator.Load();
                 MaskableGraphicText.Retranslate();
             });
             IniSettings.UseRegExChanged += new Action <bool>((bool value) => TextTranslator.Load());
             TextTranslator.Initialized   = true;
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         TextTranslator.Initialized = false;
         IniSettings.Error(string.Concat("TextTranslator::Initialize:\n", exception.ToString()));
     }
 }
Exemple #2
0
 static MaskableGraphicText()
 {
     IniSettings.FindTextChanged += new Action <bool>((bool value) => MaskableGraphicText.Retranslate());
     MaskableGraphicText.cpy2clip = new List <Text>();
 }
Exemple #3
0
        private static void LoadTranslations(string file, bool retranslate = false)
        {
            string str             = file;
            object translationLock = TextTranslator.TranslationLock;

            Monitor.Enter(translationLock);
            try
            {
                try
                {
                    if (Path.GetExtension(str).ToLower() == ".txt")
                    {
                        if (!Path.GetFileName(str).StartsWith("."))
                        {
                            if (str.StartsWith(Environment.CurrentDirectory))
                            {
                                str = str.Remove(0, Environment.CurrentDirectory.Length);
                                if (!str.StartsWith("\\"))
                                {
                                    str = string.Concat("\\", str);
                                }
                                str = string.Concat(".", str);
                            }
                            int  fileLevel = TextTranslator.GetFileLevel(str);
                            bool flag      = fileLevel > -1;
                            OrderedDictionary           orderedDictionaries   = null;
                            List <RegexTranslationData> regexTranslationDatas = null;
                            if (!flag)
                            {
                                TextTranslator.RemoveAllTranslation(TextTranslator.translations, str);
                                TextTranslator.translationsR.RemoveAll((RegexTranslationData x) => x.Path == str);
                            }
                            else
                            {
                                TextTranslator.translationsLv.TryGetValue(fileLevel, out orderedDictionaries);
                                TextTranslator.translationsLvR.TryGetValue(fileLevel, out regexTranslationDatas);
                                if (orderedDictionaries != null)
                                {
                                    TextTranslator.RemoveAllTranslation(orderedDictionaries, str);
                                }
                                if (regexTranslationDatas != null)
                                {
                                    regexTranslationDatas.RemoveAll((RegexTranslationData x) => x.Path == str);
                                }
                            }
                            using (StreamReader streamReader = new StreamReader(str, Encoding.UTF8))
                            {
                                RegexOptions regexOption = RegexOptions.None;
                                regexOption = regexOption | RegexOptions.Singleline;
                                regexOption = regexOption | RegexOptions.IgnoreCase;
                                while (!streamReader.EndOfStream)
                                {
                                    string str1 = streamReader.ReadLine();
                                    if (str1.Length == 0 || str1.StartsWith("//"))
                                    {
                                        continue;
                                    }
                                    string[] strArrays = str1.Split(new char[] { '=' }, StringSplitOptions.None);
                                    if ((int)strArrays.Length != 2)
                                    {
                                        if (!IniSettings.FindText)
                                        {
                                            continue;
                                        }
                                        try
                                        {
                                            if (!Directory.Exists(IniSettings.LogFileDir))
                                            {
                                                Directory.CreateDirectory(IniSettings.LogFileDir);
                                            }
                                            if ((int)strArrays.Length <= 2)
                                            {
                                                IniSettings.Log(string.Concat(new string[] { "Error_On__File: ", str, Environment.NewLine, "Unknown__Value: ", str1, Environment.NewLine, Environment.NewLine, Environment.NewLine }));
                                            }
                                            else
                                            {
                                                string[] newLine = new string[] { "Error_On__File: ", str, Environment.NewLine, "SeparatorError: ", str1, Environment.NewLine, "  -> Replace the \"=\" after the first \"=\" by \"", null, null, null, null };
                                                char     chr     = '=';
                                                newLine[7]  = TextTranslator.HexEncode(chr.ToString(), true);
                                                newLine[8]  = "\"";
                                                newLine[9]  = Environment.NewLine;
                                                newLine[10] = Environment.NewLine;
                                                IniSettings.Log(string.Concat(newLine));
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    else
                                    {
                                        TranslationDataBase item = null;
                                        bool   flag1             = false;
                                        string value             = TextTranslator.Decode(strArrays[0].Trim());
                                        if (string.IsNullOrEmpty(value))
                                        {
                                            continue;
                                        }
                                        string str2 = TextTranslator.Decode(strArrays[1].Trim());
                                        if (value[0].ToString().ToUpper() == "R")
                                        {
                                            Match match = Regex.Match(value, "^R\\s*\\((.+)\\)$", regexOption);
                                            if (match.Success)
                                            {
                                                if (!IniSettings.UseRegEx)
                                                {
                                                    continue;
                                                }
                                                flag1 = true;
                                                value = match.Groups[1].Value;
                                            }
                                        }
                                        if (flag1)
                                        {
                                            if (!flag)
                                            {
                                                item = TextTranslator.translationsR.Find((RegexTranslationData t) => t.Key == value);
                                            }
                                            else if (regexTranslationDatas != null)
                                            {
                                                item = regexTranslationDatas.Find((RegexTranslationData t) => t.Key == value);
                                            }
                                        }
                                        else if (!flag)
                                        {
                                            item = TextTranslator.translations[value] as TranslationDataBase;
                                        }
                                        else if (orderedDictionaries != null)
                                        {
                                            item = orderedDictionaries[value] as TranslationDataBase;
                                        }
                                        if (item != null)
                                        {
                                            if (flag1)
                                            {
                                                if (!flag)
                                                {
                                                    TextTranslator.translationsR.Remove((RegexTranslationData)item);
                                                }
                                                else
                                                {
                                                    regexTranslationDatas.Remove((RegexTranslationData)item);
                                                }
                                            }
                                            else if (!flag)
                                            {
                                                TextTranslator.translations.Remove(value);
                                            }
                                            else
                                            {
                                                orderedDictionaries.Remove(value);
                                            }
                                            if (IniSettings.FindText)
                                            {
                                                try
                                                {
                                                    if (!Directory.Exists(IniSettings.LogFileDir))
                                                    {
                                                        Directory.CreateDirectory(IniSettings.LogFileDir);
                                                    }
                                                    string[] value1 = new string[] { "Replacing__Key: ", value, "=", item.Value, Environment.NewLine, "FromLoadedFile: ", item.Path, Environment.NewLine, "By__Next___Key: ", value, "=", str2, Environment.NewLine, "From_Next_File: ", str, Environment.NewLine, "These__Keys_Do: ", null, null, null };
                                                    value1[17] = (item.Value != str2 ? "Not Match" : "Match");
                                                    value1[18] = Environment.NewLine;
                                                    value1[19] = Environment.NewLine;
                                                    IniSettings.Log(string.Concat(value1));
                                                }
                                                catch
                                                {
                                                }
                                            }
                                        }
                                        if (!flag1)
                                        {
                                            item = new TranslationDataBase(str, str2);
                                            if (!flag)
                                            {
                                                TextTranslator.translations.Add(value, item);
                                            }
                                            else
                                            {
                                                if (orderedDictionaries == null)
                                                {
                                                    orderedDictionaries = new OrderedDictionary();
                                                    TextTranslator.translationsLv.Add(fileLevel, orderedDictionaries);
                                                }
                                                orderedDictionaries.Add(value, item);
                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                try
                                                {
                                                    item = new RegexTranslationData(str, value, str2);
                                                    TextTranslator.UpdateRegexCacheSize();
                                                    Regex.Replace("A", value, str2);
                                                }
                                                catch (Exception exception1)
                                                {
                                                    Exception exception = exception1;
                                                    item = null;
                                                    if (IniSettings.FindText)
                                                    {
                                                        try
                                                        {
                                                            IniSettings.Log(string.Concat(new string[] { "Error_On__File: ", str, Environment.NewLine, "Regex____Error: ", str1, Environment.NewLine, "  ", exception.Message, Environment.NewLine, Environment.NewLine, Environment.NewLine }));
                                                        }
                                                        catch
                                                        {
                                                        }
                                                    }
                                                }
                                            }
                                            finally
                                            {
                                                if (item != null)
                                                {
                                                    if (!flag)
                                                    {
                                                        TextTranslator.translationsR.Add((RegexTranslationData)item);
                                                    }
                                                    else
                                                    {
                                                        if (regexTranslationDatas == null)
                                                        {
                                                            regexTranslationDatas = new List <RegexTranslationData>();
                                                            TextTranslator.translationsLvR.Add(fileLevel, regexTranslationDatas);
                                                        }
                                                        regexTranslationDatas.Add((RegexTranslationData)item);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (retranslate)
                            {
                                MaskableGraphicText.Retranslate();
                            }
                            if (IniSettings.DebugMode || IniSettings.FindText)
                            {
                                IniSettings.Log(string.Concat("Loaded: ", str));
                            }
                        }
                    }
                }
                catch (Exception exception2)
                {
                    IniSettings.Error(string.Concat("LoadTranslations:\n", exception2.ToString()));
                }
            }
            finally
            {
                Monitor.Exit(translationLock);
            }
        }