internal static void Error(object obj = null) { if (IniSettings.DebugMode) { IniSettings.Log(obj); } }
private static void Load() { TextTranslator.StopWatchTextFiles(); TextTranslator.mainfilefullpath = null; TextTranslator.translationsLv.Clear(); TextTranslator.translationsLvR.Clear(); TextTranslator.translations.Clear(); TextTranslator.translationsR.Clear(); if (File.Exists(TextTranslator.MainFilePath)) { TextTranslator.LoadTranslations(TextTranslator.MainFilePath, false); } if (TextTranslator.GlobalTextDir != TextTranslator.TextDir) { TextTranslator.LoadAllFromGlobalTranslationDir(); } TextTranslator.LoadAllFromTranslationDir(); TextTranslator.WatchTextFiles(); if (IniSettings.DebugMode || IniSettings.FindText) { int count = 0; foreach (OrderedDictionary value in TextTranslator.translationsLv.Values) { count = count + value.Count; } foreach (List <RegexTranslationData> regexTranslationDatas in TextTranslator.translationsLvR.Values) { count = count + regexTranslationDatas.Count; } count = count + TextTranslator.translations.Count; count = count + TextTranslator.translationsR.Count; IniSettings.Log(string.Format("Translations Loaded: {0}", count)); } }
private static void Load() { SubtitleTranslator.StopWatchSubtitleFiles(); SubtitleTranslator.translations.Clear(); SubtitleTranslator.translationsLv.Clear(); if (SubtitleTranslator.GlobalSubtitleDir != SubtitleTranslator.SubtitleDir) { SubtitleTranslator.LoadAllFromGlobalTranslationDir(); } SubtitleTranslator.LoadAllFromTranslationDir(); SubtitleTranslator.WatchSubtitleFiles(); if (IniSettings.DebugMode || IniSettings.FindAudio) { int count = 0; count = count + SubtitleTranslator.translations.Count; foreach (OrderedDictionary value in SubtitleTranslator.translationsLv.Values) { count = count + value.Count; } IniSettings.Log(string.Format("Subtitles Loaded: {0}", count)); } }
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); } }
private static void LoadTranslations(string file, bool retranslate = false) { object translationLock = SubtitleTranslator.TranslationLock; Monitor.Enter(translationLock); try { try { if (Path.GetExtension(file).ToLower() == ".txt") { if (!Path.GetFileName(file).StartsWith(".")) { if (file.StartsWith(Environment.CurrentDirectory)) { file = file.Remove(0, Environment.CurrentDirectory.Length); if (!file.StartsWith("\\")) { file = string.Concat("\\", file); } file = string.Concat(".", file); } int fileLevel = SubtitleTranslator.GetFileLevel(file); bool flag = fileLevel > -1; OrderedDictionary orderedDictionaries = null; if (!flag) { SubtitleTranslator.RemoveAllTranslation(SubtitleTranslator.translations, file); } else { SubtitleTranslator.translationsLv.TryGetValue(fileLevel, out orderedDictionaries); if (orderedDictionaries != null) { SubtitleTranslator.RemoveAllTranslation(orderedDictionaries, file); } } using (StreamReader streamReader = new StreamReader(file, Encoding.UTF8)) { bool flag1 = false; bool flag2 = true; List <SubtitleLine> subtitleLines = null; string empty = string.Empty; while (!streamReader.EndOfStream) { string str = streamReader.ReadLine(); if (str.StartsWith("//") || empty.Length == 0 && str.Length == 0) { continue; } Match match = Regex.Match(str.TrimEnd(new char[0]), "^#sub[ ]+\"(.+?)\"(?:[ ]+(?:{\\\\a([\\d]+)})?(.*))?$", RegexOptions.IgnoreCase); if (!match.Success) { if (empty.Length <= 0) { continue; } if (!flag1) { if (str.Length == 0) { continue; } Match match1 = Regex.Match(str, "^([\\d]*\\.?[\\d]+)[ ]+-->[ ]+([\\d]*\\.?[\\d]+)$", RegexOptions.None); if (!match1.Success) { flag1 = true; subtitleLines.Add(new SubtitleLine()); } else { if (streamReader.EndOfStream) { continue; } flag1 = true; SubtitleLine subtitleLine = new SubtitleLine() { StartTime = float.Parse(match1.Groups[1].Value, CultureInfo.InvariantCulture), EndTime = float.Parse(match1.Groups[2].Value, CultureInfo.InvariantCulture) }; subtitleLines.Add(subtitleLine); continue; } } if (flag2) { int count = subtitleLines.Count - 1; if (str.Length > 0) { Match match2 = Regex.Match(str, "^(?:{\\\\a([\\d]+)})?(.*)$", RegexOptions.None); if (match2.Success) { string str1 = match2.Groups[2].Value.Trim(); if (str1.Length != 0 || !streamReader.EndOfStream) { SubtitleLine item = subtitleLines[count]; item.Position = (match2.Groups[1].Success ? item.Position.Parse(match2.Groups[1].Value, SubtitleSettings.Anchor) : SubtitleSettings.Anchor); item.Text = str1; subtitleLines[count] = item; continue; } } } flag1 = false; flag2 = true; subtitleLines.RemoveAt(count); } else if (str.Length <= 0) { flag1 = false; flag2 = true; int num = subtitleLines.Count - 1; if (subtitleLines[num].Text.Length != 0) { continue; } subtitleLines.RemoveAt(num); } else { string str2 = str.Trim(); int count1 = subtitleLines.Count - 1; SubtitleLine item1 = subtitleLines[count1]; if (str2.Length <= 0) { if (!streamReader.EndOfStream || item1.Text.Length != 0) { continue; } subtitleLines.RemoveAt(count1); } else { if (item1.Text.Length > 0) { item1.Text = string.Concat(item1.Text, "\n"); } item1.Text = string.Concat(item1.Text, str2); subtitleLines[count1] = item1; } } } else { flag1 = false; flag2 = true; SubtitleDataBase subtitleDataBase = null; empty = match.Groups[1].Value; subtitleLines = new List <SubtitleLine>(); if (match.Groups[3].Success) { string str3 = match.Groups[3].Value.Trim(); if (str3.Length > 0) { SubtitleLine subtitleLine1 = new SubtitleLine() { Text = str3 }; subtitleLine1.Position = (match.Groups[2].Success ? subtitleLine1.Position.Parse(match.Groups[2].Value, SubtitleSettings.Anchor) : SubtitleSettings.Anchor); subtitleLines.Add(subtitleLine1); } } if (!flag) { subtitleDataBase = SubtitleTranslator.translations[empty] as SubtitleDataBase; } else if (orderedDictionaries != null) { subtitleDataBase = orderedDictionaries[empty] as SubtitleDataBase; } if (subtitleDataBase != null) { if (!flag) { SubtitleTranslator.translations.Remove(empty); } else { orderedDictionaries.Remove(empty); } } subtitleDataBase = new SubtitleDataBase(file, subtitleLines); if (!flag) { SubtitleTranslator.translations.Add(empty, subtitleDataBase); } else { if (orderedDictionaries == null) { orderedDictionaries = new OrderedDictionary(); SubtitleTranslator.translationsLv.Add(fileLevel, orderedDictionaries); } orderedDictionaries.Add(empty, subtitleDataBase); } } } } if (retranslate) { AudioSourceSubtitle.Instance.Reload(); } if (IniSettings.DebugMode || IniSettings.FindAudio) { IniSettings.Log(string.Concat("Loaded: ", file)); } } } } catch (Exception exception) { IniSettings.Error(string.Concat("LoadSubtitles:\n", exception.ToString())); } } finally { Monitor.Exit(translationLock); } }
private static void Load() { Texture2DCacheData texture2DCacheDatum; object dataLock = Texture2DOverride.DataLock; Monitor.Enter(dataLock); try { Texture2DOverride.StopWatchTextFiles(); Dictionary <int, Texture2DCacheData> nums = new Dictionary <int, Texture2DCacheData>(Texture2DOverride.loaded); Texture2DOverride.unused.Clear(); Texture2DOverride.loaded.Clear(); Texture2DOverride.LoadMainIniFile(); Texture2DOverride.inidata = Texture2DOverride.ParseIniData(Texture2DOverride.mainini); Texture2DOverride.uniqueimagesdata = Texture2DOverride.GetUniqueImageFiles(Texture2DOverride.TranslationImageDir); if (Texture2DOverride.GlobalTranslationImageIniFilePath != Texture2DOverride.TranslationImageDir) { Dictionary <string, Texture2DData> strs = Texture2DOverride.ParseIniData(new IniFile(Texture2DOverride.GlobalTranslationImageIniFilePath)); foreach (KeyValuePair <string, Texture2DData> keyValuePair in strs) { if (Texture2DOverride.inidata.ContainsKey(keyValuePair.Key)) { continue; } Texture2DOverride.inidata.Add(keyValuePair.Key, keyValuePair.Value); } strs.Clear(); strs = null; Dictionary <string, string> uniqueImageFiles = Texture2DOverride.GetUniqueImageFiles(Texture2DOverride.GlobalTranslationImageDir); foreach (KeyValuePair <string, string> uniqueImageFile in uniqueImageFiles) { if (Texture2DOverride.uniqueimagesdata.ContainsKey(uniqueImageFile.Key)) { continue; } Texture2DOverride.uniqueimagesdata.Add(uniqueImageFile.Key, uniqueImageFile.Value); } uniqueImageFiles.Clear(); uniqueImageFiles = null; } Texture2DOverride.WatchTextFiles(); foreach (KeyValuePair <int, Texture2DCacheData> num in nums) { Texture2DOverrideData overrideData = num.Value.OverrideData; Texture2DOverride.LoadTexture2D(num.Value.ObjectName, overrideData.OriginalTexture2D, out overrideData); if (!Texture2DOverride.loaded.TryGetValue(overrideData.InstanceID, out texture2DCacheDatum)) { continue; } texture2DCacheDatum.IncreaseAmount(num.Value.Count); } if (IniSettings.DebugMode || IniSettings.FindImage) { int count = Texture2DOverride.inidata.Count; IniSettings.Log(string.Concat("ImageSettingsLoaded: ", count.ToString())); } } finally { Monitor.Exit(dataLock); } }