protected Texture2D GetTexture()
        {
            if (base.GetType() != typeof(Sprite))
            {
                return(null);
            }
            Texture2D textured = ((Sprite)this)._get_texture();

            try
            {
                if (textured == null)
                {
                    return(textured);
                }
                if (this.overrideData.OriginalTexture2D != null)
                {
                    return(this.overrideData.OverrideTexture2D);
                }
                Texture2DOverride.LoadTexture2D(((Sprite)this).name, textured, out this.overrideData);
                if (this.overrideData.OverrideTexture2D != null)
                {
                    textured = this.overrideData.OverrideTexture2D;
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error("SpriteOverride:\n" + exception.ToString());
            }
            return(textured);
        }
 private static U::UnityEngine.Texture2D FlipTextureY(U::UnityEngine.Texture2D original)
 {
     U::UnityEngine.Texture2D texture2D;
     try
     {
         texture2D = new U::UnityEngine.Texture2D(original.width, original.height, original.format, false);
         int num  = original.width;
         int num1 = original.height;
         for (int i = 0; i < num1; i++)
         {
             for (int j = 0; j < num; j++)
             {
                 texture2D.SetPixel(j, num1 - i - 1, original.GetPixel(j, i));
             }
         }
         texture2D.Apply();
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         texture2D = original;
         IniSettings.Error(string.Concat("FlipTextureY:\n", exception.ToString()));
     }
     return(texture2D);
 }
Ejemplo n.º 3
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()));
     }
 }
Ejemplo n.º 4
0
        static IniSettings()
        {
            IniSettings.initialized    = false;
            IniSettings.writetime      = 3;
            IniSettings.LoadLock       = new object();
            IniSettings.LogLock        = new object();
            IniSettings.processname    = Process.GetCurrentProcess().ProcessName;
            IniSettings.processfile    = string.Concat(IniSettings.processname, ".exe");
            IniSettings.PROCESSPATHKEY = string.Concat(IniSettings.processname, "_Folder");
            IniSettings.sb             = new StringBuilder();
            TimeSpan timeSpan = TimeSpan.FromSeconds((double)IniSettings.LogWriterTime);

            IniSettings.timer = new System.Timers.Timer(timeSpan.TotalMilliseconds)
            {
                AutoReset = false
            };
            IniSettings.timer.Elapsed += new ElapsedEventHandler(IniSettings.timer_Elapsed);
            try
            {
                if (File.Exists(IniSettings.LogFilePath))
                {
                    File.Delete(IniSettings.LogFilePath);
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error(string.Concat("IniSettings:\n", exception.ToString()));
            }
#if UNITY4
            LoadIni();
#else
            IniSettings.Load();
#endif
            IniSettings.WatchTextFiles();
        }
        private static Dictionary <string, Texture2DData> ParseIniData(IniFile ini)
        {
            Dictionary <string, Texture2DData> strs = new Dictionary <string, Texture2DData>();

            try
            {
                string[] sections = ini.GetSections();
                for (int i = 0; i < (int)sections.Length; i++)
                {
                    string str    = sections[i];
                    bool   flag   = false;
                    string value  = ini.GetValue(str, "sPath", "");
                    string value1 = ini.GetValue(str, "bFlipTexture", null);
                    if (!string.IsNullOrEmpty(value1) && !bool.TryParse(value1, out flag))
                    {
                        flag = true;
                    }
                    Texture2DData texture2DDatum = new Texture2DData(value, flag);
                    strs.Remove(str);
                    strs.Add(str, texture2DDatum);
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error(string.Concat("LoadIniData:\n", exception.ToString()));
            }
            return(strs);
        }
Ejemplo n.º 6
0
 private static void WatchSubtitleFiles()
 {
     try
     {
         if (SubtitleTranslator.GlobalSubtitleDir != SubtitleTranslator.SubtitleDir && SubtitleTranslator.gfsw == null && Directory.Exists(SubtitleTranslator.GlobalSubtitleDir))
         {
             SubtitleTranslator.gfsw = new FileSystemWatcher(SubtitleTranslator.GlobalSubtitleDir, SubtitleTranslator.GlobalSubtitleDirFiles)
             {
                 NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime,
                 IncludeSubdirectories = false
             };
             SubtitleTranslator.gfsw.Changed            += new FileSystemEventHandler(SubtitleTranslator.WatcherNotice);
             SubtitleTranslator.gfsw.Created            += new FileSystemEventHandler(SubtitleTranslator.WatcherNotice);
             SubtitleTranslator.gfsw.Error              += new ErrorEventHandler((object sender, ErrorEventArgs e) => IniSettings.Error(e.GetException().ToString()));
             SubtitleTranslator.gfsw.EnableRaisingEvents = true;
         }
         if (SubtitleTranslator.sfsw == null && Directory.Exists(SubtitleTranslator.SubtitleDir))
         {
             SubtitleTranslator.sfsw = new FileSystemWatcher(SubtitleTranslator.SubtitleDir, SubtitleTranslator.SubtitleDirFiles)
             {
                 NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime,
                 IncludeSubdirectories = false
             };
             SubtitleTranslator.sfsw.Changed            += new FileSystemEventHandler(SubtitleTranslator.WatcherNotice);
             SubtitleTranslator.sfsw.Created            += new FileSystemEventHandler(SubtitleTranslator.WatcherNotice);
             SubtitleTranslator.sfsw.Error              += new ErrorEventHandler((object sender, ErrorEventArgs e) => IniSettings.Error(e.GetException().ToString()));
             SubtitleTranslator.sfsw.EnableRaisingEvents = true;
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("WatchSubtitleFiles:\n", exception.ToString()));
     }
 }
 private void LateUpdate()
 {
     try
     {
         if (this.subtitles.Count != 0)
         {
             foreach (KeyValuePair <TextPosition, StringBuilder> keyValuePair in this.content)
             {
                 if (keyValuePair.Value.Length <= 0)
                 {
                     continue;
                 }
                 keyValuePair.Value.Length = 0;
             }
             for (int i = this.subtitles.Count - 1; i >= 0; i--)
             {
                 Subtitle item = this.subtitles[i] as Subtitle;
                 if (item == null)
                 {
                     this.subtitles.RemoveAt(i);
                 }
                 else if (item.Source != null)
                 {
                     if (this.reloadsubtitles)
                     {
                         item.Reload();
                     }
                     item.LateUpdate();
                     foreach (TextPosition anchor in SubtitleUserInterfaceBase <SubtitleCanvas> .Instance.Anchors)
                     {
                         string str = item[anchor];
                         if (str.Length <= 0)
                         {
                             continue;
                         }
                         if (this.content[anchor].Length > 0)
                         {
                             this.content[anchor].Append('\n');
                         }
                         this.content[anchor].Append(str);
                     }
                 }
                 else
                 {
                     this.subtitles.RemoveAt(i);
                 }
             }
             this.reloadsubtitles = false;
             foreach (TextPosition textPosition in SubtitleUserInterfaceBase <SubtitleCanvas> .Instance.Anchors)
             {
                 SubtitleUserInterfaceBase <SubtitleCanvas> .Instance[textPosition] = this.content[textPosition].ToString();
             }
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("AudioSourceSubtitle::LateUpdate:\n", exception.ToString()));
     }
 }
 public void Add(U::UnityEngine.AudioSource source)
 {
     try
     {
         this.subtitles.Remove(source);
         this.subtitles.Insert(0, source, new Subtitle(SubtitleUserInterfaceBase <SubtitleCanvas> .Instance.Anchors, source));
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("AudioSourceSubtitle::Load:\n", exception.ToString()));
     }
 }
Ejemplo n.º 9
0
 public void LateUpdate()
 {
     try
     {
         if (((this.Source != null) && (this.Clip != null)) && (this.Source.clip == this.Clip))
         {
             int   num  = (this.Clip.frequency == 0) ? 0xac44 : this.Clip.frequency;
             float num2 = this.Source.timeSamples * (1f / ((float)num));
             foreach (LineData data in this.subtitles)
             {
                 if (data != null)
                 {
                     if ((this.Source.isPlaying && ((data.Line.EndTime == 0f) || (num2 < data.Line.EndTime))) && (num2 >= data.Line.StartTime))
                     {
                         this.invalid |= data.Show();
                     }
                     else
                     {
                         this.invalid |= data.Hide();
                     }
                 }
             }
             if (this.invalid)
             {
                 foreach (KeyValuePair <TextPosition, HashSet <SubtitleLine> > pair in this.display)
                 {
                     StringBuilder builder = this.ClearContent(this.content[pair.Key]);
                     foreach (SubtitleLine line2 in pair.Value)
                     {
                         if (builder.Length > 0)
                         {
                             builder.Append('\n');
                         }
                         builder.Append(line2.Text);
                     }
                 }
                 this.invalid = false;
             }
         }
         else if (this.loaded)
         {
             this.Unload();
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error("Subtitle::LateUpdate:\n" + exception.ToString());
     }
 }
Ejemplo n.º 10
0
        private static void WriterTimerElapsed(object sender, ElapsedEventArgs e)
        {
            object writerLock = TextTranslator.WriterLock;

            Monitor.Enter(writerLock);
            try
            {
                TextTranslator.StopWatchTextFiles();
                try
                {
                    foreach (KeyValuePair <string, StringBuilder> writerdatum in TextTranslator.writerdata)
                    {
                        string key           = writerdatum.Key;
                        string directoryName = Path.GetDirectoryName(key);
                        if (!Directory.Exists(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }
                        if (!File.Exists(key) && key != TextTranslator.MainFilePath)
                        {
                            string   str       = key.Substring(0, key.Length - ".txt".Length);
                            string[] strArrays = new string[] { string.Concat(str, ".noregex.txt"), string.Concat(str, ".regex.txt") };
                            for (int i = 0; i < (int)strArrays.Length; i++)
                            {
                                string str1 = strArrays[i];
                                if (!File.Exists(str1))
                                {
                                    File.Create(str1).Dispose();
                                }
                            }
                        }
                        using (StreamWriter streamWriter = new StreamWriter(key, true, Encoding.UTF8))
                        {
                            streamWriter.Write(writerdatum.Value.ToString());
                        }
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("TextTranslator::DumpText:\n", exception.ToString()));
                }
                TextTranslator.writerdata.Clear();
                TextTranslator.WatchTextFiles();
            }
            finally
            {
                Monitor.Exit(writerLock);
            }
        }
Ejemplo n.º 11
0
        internal static void Load()
        {
            int    num;
            bool   flag;
            object loadLock = IniSettings.LoadLock;

            Monitor.Enter(loadLock);
            try
            {
                try
                {
                    if (IniSettings.iniw != null)
                    {
                        IniSettings.iniw.Dispose();
                        IniSettings.iniw = null;
                    }
                    if (!Directory.Exists(IniSettings.SettingsFileDir))
                    {
                        Directory.CreateDirectory(IniSettings.SettingsFileDir);
                    }
                    TranslationConfig config = IniSettings.GetJsonConfig();
                    IniSettings.DebugMode          = config.DebugMode;
                    IniSettings.Language           = config.Language;
                    IniSettings.FindImage          = config.FindImage;
                    IniSettings.FindAudio          = config.FindAudio;
                    IniSettings.DumpAudioByLevel   = config.DumpAudioByLevel;
                    IniSettings.FindText           = config.FindText;
                    IniSettings.DumpTextByLevel    = config.DumpTextByLevel;
                    IniSettings.UseRegEx           = config.UseRegEx;
                    IniSettings.UseTextPrediction  = config.UseTextPrediction;
                    IniSettings.UseCopy2Clipboard  = config.UseCopy2Clipboard;
                    IniSettings.Copy2ClipboardTime = config.Copy2ClipboardTimeMs;

                    IniSettings.initialized = true;
                    IniSettings.WatchTextFiles();
                }
                catch (Exception exception1)
                {
                    IniSettings.Error(string.Concat("LoadSettings:\n", exception1.ToString()));
                }
            }
            finally
            {
                Monitor.Exit(loadLock);
            }
        }
        private static Dictionary <string, string> GetUniqueImageFiles(string dir)
        {
            Dictionary <string, string> strs = new Dictionary <string, string>();

            try
            {
                if (Texture2DData.ValidExtensions.Count > 0 && dir != null && Directory.Exists(dir))
                {
                    HashSet <string> strs1 = new HashSet <string>();
                    foreach (Texture2DData value in Texture2DOverride.inidata.Values)
                    {
                        if (strs1.Contains(value.Path) || !value.Exists)
                        {
                            continue;
                        }
                        strs1.Add(value.Path);
                    }
                    string[]         files     = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
                    HashSet <string> strs2     = new HashSet <string>(Texture2DData.ValidExtensions);
                    string[]         strArrays = files;
                    for (int i = 0; i < (int)strArrays.Length; i++)
                    {
                        string str = strArrays[i];
                        if (strs2.Contains(Path.GetExtension(str).ToLower()))
                        {
                            string str1 = str;
                            if (str1.StartsWith(dir))
                            {
                                str1 = str1.Remove(0, dir.Length);
                            }
                            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str);
                            if (!strs.ContainsKey(fileNameWithoutExtension) && !strs1.Contains(str1))
                            {
                                strs.Add(fileNameWithoutExtension, str1);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error(string.Concat("GetUniqueImageFiles:\n", exception.ToString()));
            }
            return(strs);
        }
        private static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            object dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                try
                {
                    List <int> nums = new List <int>();
                    foreach (KeyValuePair <int, DateTime> keyValuePair in Texture2DOverride.unused)
                    {
                        if (DateTime.Now <= keyValuePair.Value.AddSeconds(15))
                        {
                            continue;
                        }
                        nums.Add(keyValuePair.Key);
                        if (Texture2DOverride.loaded[keyValuePair.Key].OverrideData.OriginalTexture2D == null)
                        {
                            continue;
                        }
                        int key = keyValuePair.Key;
                        Texture2DOverride.loaded.Remove(key);
                    }
                    if (nums.Count > 0)
                    {
                        Dictionary <int, DateTime> nums1 = Texture2DOverride.unused;
                        foreach (int num in nums)
                        {
                            nums1.Remove(num);
                        }
                        Texture2DOverride.unused = nums1;
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("timer_Elapsed:\n", exception.ToString()));
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
        }
        private static void WriterTimerElapsed(object sender, ElapsedEventArgs e)
        {
            object writerLock = Texture2DOverride.WriterLock;

            Monitor.Enter(writerLock);
            try
            {
                Texture2DOverride.StopWatchTextFiles();
                try
                {
                    if (!Directory.Exists(Texture2DOverride.TranslationImageIniFileDir))
                    {
                        Directory.CreateDirectory(Texture2DOverride.TranslationImageIniFileDir);
                    }
                    if (!File.Exists(Texture2DOverride.TranslationImageIniFilePath))
                    {
                        Texture2DOverride.LoadMainIniFile();
                    }
                    if (!Directory.Exists(Texture2DOverride.TranslationImageDir))
                    {
                        Directory.CreateDirectory(Texture2DOverride.TranslationImageDir);
                    }
                    foreach (Texture2DDumpData writerdatum in Texture2DOverride.writerdata)
                    {
                        Texture2DOverride.mainini.WriteValue(writerdatum.Section, "sPath", writerdatum.Path);
                        if (writerdatum.Format != TextureFormat.DXT1 && writerdatum.Format != TextureFormat.DXT5)
                        {
                            continue;
                        }
                        Texture2DOverride.mainini.WriteValue(writerdatum.Section, "bFlipTexture", true);
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("DumpTexture2D:\n", exception.ToString()));
                }
                Texture2DOverride.writerdata.Clear();
                Texture2DOverride.WatchTextFiles();
            }
            finally
            {
                Monitor.Exit(writerLock);
            }
        }
        internal static void UnloadTexture2D(ref Texture2DOverrideData overrideData)
        {
            Texture2DCacheData texture2DCacheDatum;
            object             dataLock = Texture2DOverride.DataLock;

            Monitor.Enter(dataLock);
            try
            {
                try
                {
                    try
                    {
                        if (overrideData.OriginalTexture2D != null)
                        {
                            int instanceID = overrideData.InstanceID;
                            if (Texture2DOverride.loaded.TryGetValue(instanceID, out texture2DCacheDatum))
                            {
                                if (texture2DCacheDatum.Count <= (long)0)
                                {
                                    Texture2DOverride.unused.Add(instanceID, DateTime.Now);
                                }
                                else
                                {
                                    texture2DCacheDatum.DecreaseAmount((long)1);
                                }
                            }
                        }
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        IniSettings.Error(string.Concat(new object[] { "UnloadTexture2D[", overrideData.InstanceID, "]:\n", exception.ToString() }));
                    }
                }
                finally
                {
                    overrideData = new Texture2DOverrideData();
                }
            }
            finally
            {
                Monitor.Exit(dataLock);
            }
        }
        private static bool LoadTextureData(string path, out U::UnityEngine.Texture2D texture2D)
        {
            bool flag;

            texture2D = null;
            try
            {
                path = string.Concat(Texture2DOverride.TranslationImageDir, path);
                string extension = Path.GetExtension(path);
                if (extension == ".dds")
                {
                    flag = DXTLoader.LoadDXT(path, out texture2D);
                }
                else if (extension == ".jpeg" || extension == ".jpg")
                {
                    texture2D = new Texture2D(2, 2, TextureFormat.RGB24, false);
                    flag      = texture2D.LoadImage(File.ReadAllBytes(path));
                }
                else if (extension == ".png")
                {
                    texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                    flag      = texture2D.LoadImage(File.ReadAllBytes(path));
                }
                else if (extension == ".psd")
                {
                    flag = PSDLoader.LoadPSD(path, out texture2D);
                }
                else if (extension == ".tga")
                {
                    flag = TGALoader.LoadTGA(path, out texture2D);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception exception)
            {
                IniSettings.Error(string.Concat("LoadImage:\n", exception.ToString()));
                return(false);
            }
            return(flag);
        }
Ejemplo n.º 17
0
 private void SetOurOverrideTexture(ref U::UnityEngine.Texture value)
 {
     if (base.GetType() == typeof(RawImage))
     {
         try
         {
             if (value == null)
             {
                 if (this.overrideData.OriginalTexture2D != null)
                 {
                     Texture2DOverride.UnloadTexture2D(ref this.overrideData);
                 }
             }
             else
             {
                 U::UnityEngine.Texture2D textured = value as U::UnityEngine.Texture2D;
                 if (textured != null)
                 {
                     if (this.overrideData.OriginalTexture2D != null)
                     {
                         int instanceID = textured.GetInstanceID();
                         if ((this.overrideData.InstanceID == instanceID) || (this.overrideData.OverrideID == instanceID))
                         {
                             value = this.overrideData.OverrideTexture2D;
                             return;
                         }
                         Texture2DOverride.UnloadTexture2D(ref this.overrideData);
                     }
                     Texture2DOverride.LoadTexture2D(((RawImage)this).name, textured, out this.overrideData);
                     if (this.overrideData.OverrideTexture2D != null)
                     {
                         value = this.overrideData.OverrideTexture2D;
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             IniSettings.Error("RawImageOverride:\n" + exception.ToString());
         }
     }
 }
 protected void Swap(ref Texture value)
 {
     if (base.GetType() == typeof(Material))
     {
         try
         {
             if (value == null)
             {
                 if (this.overrideData.OriginalTexture2D != null)
                 {
                     Texture2DOverride.UnloadTexture2D(ref this.overrideData);
                 }
             }
             else
             {
                 Texture2D textured = value as Texture2D;
                 if (textured != null)
                 {
                     if (this.overrideData.OriginalTexture2D != null)
                     {
                         int instanceID = textured.GetInstanceID();
                         if ((this.overrideData.InstanceID == instanceID) || (this.overrideData.OverrideID == instanceID))
                         {
                             value = this.overrideData.OverrideTexture2D;
                             return;
                         }
                         Texture2DOverride.UnloadTexture2D(ref this.overrideData);
                     }
                     Texture2DOverride.LoadTexture2D(((Material)this).name, textured, out this.overrideData);
                     if (this.overrideData.OverrideTexture2D != null)
                     {
                         value = this.overrideData.OverrideTexture2D;
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             IniSettings.Error("MaterialOverride:\n" + exception.ToString());
         }
     }
 }
 protected static void Swap(ref Texture2D texture)
 {
     try
     {
         if (texture == null)
         {
             if (overrideData.OriginalTexture2D != null)
             {
                 Texture2DOverride.UnloadTexture2D(ref overrideData);
             }
         }
         else
         {
             if (overrideData.OriginalTexture2D != null)
             {
                 int instanceID = texture.GetInstanceID();
                 if (overrideData.InstanceID == instanceID)
                 {
                     texture = overrideData.OverrideTextureCache;
                     return;
                 }
                 Texture2DOverride.UnloadTexture2D(ref overrideData);
             }
             Texture2DOverride.LoadTexture2D(texture.name, texture, out overrideData);
             if (overrideData.OverrideTexture2D != null)
             {
                 if ((texture.width != overrideData.OverrideTexture2D.width) || (texture.height != overrideData.OverrideTexture2D.height))
                 {
                     texture.Resize(overrideData.OverrideTexture2D.width, overrideData.OverrideTexture2D.height);
                 }
                 texture.SetPixels32(overrideData.OverrideTexture2D.GetPixels32());
                 texture.Apply();
                 overrideData.OverrideTextureCache = texture;
             }
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error("CursorOverride:\n" + exception.ToString());
     }
 }
Ejemplo n.º 20
0
 private static void WatchTextFiles()
 {
     try
     {
         if (IniSettings.iniw == null && Directory.Exists(IniSettings.SettingsFileDir))
         {
             IniSettings.iniw = new FileSystemWatcher(IniSettings.SettingsFileDir, IniSettings.SettingsFileName)
             {
                 NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime,
                 IncludeSubdirectories = false
             };
             IniSettings.iniw.Changed            += new FileSystemEventHandler(IniSettings.WatcherNotice);
             IniSettings.iniw.Created            += new FileSystemEventHandler(IniSettings.WatcherNotice);
             IniSettings.iniw.Error              += new ErrorEventHandler((object sender, ErrorEventArgs e) => IniSettings.Error(e.GetException().ToString()));
             IniSettings.iniw.EnableRaisingEvents = true;
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("WatchTextFiles:\n", exception.ToString()));
     }
 }
 private static void LoadMainIniFile()
 {
     try
     {
         Texture2DOverride.mainini = new IniFile(Texture2DOverride.TranslationImageIniFilePath);
         if (File.Exists(Texture2DOverride.TranslationImageIniFilePath))
         {
             string mainFolderSection = Texture2DOverride.MainFolderSection;
             string mAINFOLDERKEY     = Texture2DOverride.MAINFOLDERKEY;
             string value             = Texture2DOverride.mainini.GetValue(mainFolderSection, mAINFOLDERKEY, null);
             Texture2DOverride.MainFolder = value;
             if (value != Texture2DOverride.MainFolder)
             {
                 Texture2DOverride.mainini.WriteValue(mainFolderSection, mAINFOLDERKEY, Texture2DOverride.MainFolder);
             }
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("Texture2D::LoadIniFile:", exception.ToString()));
     }
 }
Ejemplo n.º 22
0
        public static KeyTranslationData[] FindPredictions(string text, KeyTranslationData[] predictions = null)
        {
            OrderedDictionary orderedDictionaries;
            Dictionary <string, KeyTranslationData> strs = new Dictionary <string, KeyTranslationData>();

            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    if (predictions == null)
                    {
                        if (TextTranslator.translationsLv.TryGetValue(Application.loadedLevel, out orderedDictionaries))
                        {
                            TextTranslator.MakePredictions(text, orderedDictionaries, strs);
                        }
                        TextTranslator.MakePredictions(text, TextTranslator.translations, strs);
                    }
                    else
                    {
                        OrderedDictionary    orderedDictionaries1    = new OrderedDictionary();
                        KeyTranslationData[] keyTranslationDataArray = predictions;
                        for (int i = 0; i < (int)keyTranslationDataArray.Length; i++)
                        {
                            KeyTranslationData keyTranslationDatum = keyTranslationDataArray[i];
                            orderedDictionaries1.Add(keyTranslationDatum.Key, keyTranslationDatum);
                        }
                        TextTranslator.MakePredictions(text, orderedDictionaries1, strs);
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("TextTranslator::PredictTranslation:\n", exception.ToString()));
                }
            }
            KeyTranslationData[] keyTranslationDataArray1 = new KeyTranslationData[strs.Count];
            strs.Values.CopyTo(keyTranslationDataArray1, 0);
            return(keyTranslationDataArray1);
        }
Ejemplo n.º 23
0
 internal static void Initialize()
 {
     try
     {
         if (!SubtitleTranslator.Initialized)
         {
             double totalMilliseconds = TimeSpan.FromSeconds((double)IniSettings.LogWriterTime).TotalMilliseconds;
             SubtitleTranslator.writerdata  = new Dictionary <string, StringBuilder>();
             SubtitleTranslator.writertimer = new System.Timers.Timer(totalMilliseconds)
             {
                 AutoReset = false
             };
             SubtitleTranslator.writertimer.Elapsed += new ElapsedEventHandler(SubtitleTranslator.WriterTimerElapsed);
             SubtitleTranslator.Load();
             SubtitleSettings.AnchorChanged += new Action <TextPosition>((TextPosition value) => {
                 SubtitleTranslator.Load();
                 AudioSourceSubtitle.Instance.Reload();
             });
             IniSettings.LanguageDirChanged += new Action <string>((string value) => {
                 SubtitleTranslator.Load();
                 AudioSourceSubtitle.Instance.Reload();
             });
             IniSettings.ProcessPathDirChanged += new Action <string>((string value) => {
                 SubtitleTranslator.Load();
                 AudioSourceSubtitle.Instance.Reload();
             });
             IniSettings.FindAudioChanged  += new Action <bool>((bool value) => AudioSourceSubtitle.Instance.Reload());
             SubtitleTranslator.Initialized = true;
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         SubtitleTranslator.Initialized = false;
         IniSettings.Error(string.Concat("SubtitleTranslator::Initialize:\n", exception.ToString()));
     }
 }
Ejemplo n.º 24
0
        private static void WriterTimerElapsed(object sender, ElapsedEventArgs e)
        {
            object writerLock = SubtitleTranslator.WriterLock;

            Monitor.Enter(writerLock);
            try
            {
                SubtitleTranslator.StopWatchSubtitleFiles();
                try
                {
                    foreach (KeyValuePair <string, StringBuilder> writerdatum in SubtitleTranslator.writerdata)
                    {
                        string key           = writerdatum.Key;
                        string directoryName = Path.GetDirectoryName(key);
                        if (!Directory.Exists(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }
                        using (StreamWriter streamWriter = new StreamWriter(key, true, Encoding.UTF8))
                        {
                            streamWriter.Write(writerdatum.Value.ToString());
                        }
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("SubtitleTranslator::DumpText:\n", exception.ToString()));
                }
                SubtitleTranslator.writerdata.Clear();
                SubtitleTranslator.WatchSubtitleFiles();
            }
            finally
            {
                Monitor.Exit(writerLock);
            }
        }
Ejemplo n.º 25
0
        internal static void LoadIni()
        {
            int    num;
            bool   flag;
            object loadLock = IniSettings.LoadLock;

            Monitor.Enter(loadLock);
            try
            {
                try
                {
                    if (IniSettings.iniw != null)
                    {
                        IniSettings.iniw.Dispose();
                        IniSettings.iniw = null;
                    }
                    if (!Directory.Exists(IniSettings.SettingsFileDir))
                    {
                        Directory.CreateDirectory(IniSettings.SettingsFileDir);
                    }
                    IniFile nIFile         = IniSettings.GetINIFile();
                    string  pROCESSPATHKEY = "bDebugMode";
                    string  value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = false;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.DebugMode = flag;
                    pROCESSPATHKEY        = "sLanguage";
                    value = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    IniSettings.Language = value;
                    if (value != IniSettings.Language)
                    {
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, IniSettings.Language);
                    }
                    pROCESSPATHKEY = "bFindImage";
                    value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = false;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.FindImage = flag;
                    pROCESSPATHKEY        = "bFindAudio";
                    value = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = false;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.FindAudio = flag;
                    pROCESSPATHKEY        = "bDumpAudioByLevel";
                    value = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = true;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.DumpAudioByLevel = flag;
                    pROCESSPATHKEY = "bFindText";
                    value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = false;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.FindText = flag;
                    pROCESSPATHKEY       = "bDumpTextByLevel";
                    value = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = true;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.DumpTextByLevel = flag;
                    pROCESSPATHKEY = "bUseRegEx";
                    value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = true;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.UseRegEx = flag;
                    pROCESSPATHKEY       = "bUseTextPrediction";
                    value = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = true;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.UseTextPrediction = flag;
                    pROCESSPATHKEY = "bUseCopy2Clipboard";
                    value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !bool.TryParse(value, out flag))
                    {
                        flag = false;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, flag);
                    }
                    IniSettings.UseCopy2Clipboard = flag;
                    pROCESSPATHKEY = "iCopy2ClipboardTime(ms)";
                    value          = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    if (value == null || !int.TryParse(value, out num))
                    {
                        num = 250;
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, num);
                    }
                    IniSettings.Copy2ClipboardTime = num;
                    pROCESSPATHKEY          = IniSettings.PROCESSPATHKEY;
                    value                   = nIFile.GetValue("Translation", pROCESSPATHKEY, null);
                    IniSettings.ProcessPath = value;
                    if (value != IniSettings.ProcessPath)
                    {
                        nIFile.WriteValue("Translation", pROCESSPATHKEY, IniSettings.ProcessPath);
                    }
                    IniSettings.initialized = true;
                    try
                    {
                        Action <IniFile> action = IniSettings.LoadSettings;
                        if (action != null)
                        {
                            action(nIFile);
                        }
                    }
                    catch (Exception exception)
                    {
                        IniSettings.Error(string.Concat("LoadSettings:\n", exception.ToString()));
                    }
                    IniSettings.WatchTextFiles();
                }
                catch (Exception exception1)
                {
                    IniSettings.Error(string.Concat("LoadSettings:\n", exception1.ToString()));
                }
            }
            finally
            {
                Monitor.Exit(loadLock);
            }
        }
Ejemplo n.º 26
0
        public static bool Translate(string audio, out SubtitleLine[] lines)
        {
            OrderedDictionary orderedDictionaries;
            OrderedDictionary orderedDictionaries1;
            bool   count;
            object translationLock = SubtitleTranslator.TranslationLock;

            Monitor.Enter(translationLock);
            try
            {
                try
                {
                    List <SubtitleLine> value = null;
                    if (SubtitleTranslator.translationsLv.TryGetValue(Application.loadedLevel, out orderedDictionaries))
                    {
                        SubtitleDataBase item = orderedDictionaries[audio] as SubtitleDataBase;
                        if (item == null)
                        {
                            goto Label2;
                        }
                        value = item.Value;
                        goto Label1;
                    }
Label2:
                    SubtitleDataBase subtitleDataBase = SubtitleTranslator.translations[audio] as SubtitleDataBase;
                    if (subtitleDataBase != null)
                    {
                        value = subtitleDataBase.Value;
                    }
Label1:
                    if (value == null)
                    {
                        value = new List <SubtitleLine>();
                        if (IniSettings.FindAudio)
                        {
                            if (!IniSettings.DumpAudioByLevel)
                            {
                                string filePath = SubtitleTranslator.FilePath;
                                SubtitleTranslator.translations.Add(audio, new SubtitleDataBase(filePath, value));
                                SubtitleTranslator.DumpSubtitle(filePath, audio);
                            }
                            else
                            {
                                if (!SubtitleTranslator.translationsLv.TryGetValue(Application.loadedLevel, out orderedDictionaries1))
                                {
                                    orderedDictionaries1 = new OrderedDictionary();
                                    SubtitleTranslator.translationsLv.Add(Application.loadedLevel, orderedDictionaries1);
                                }
                                string lvFilePath = SubtitleTranslator.LvFilePath;
                                orderedDictionaries1.Add(audio, new SubtitleDataBase(lvFilePath, value));
                                SubtitleTranslator.DumpSubtitle(lvFilePath, audio);
                            }
                        }
                    }
                    List <SubtitleLine> subtitleLines = new List <SubtitleLine>();
                    foreach (SubtitleLine subtitleLine in value)
                    {
                        if (string.IsNullOrEmpty(subtitleLine.Text))
                        {
                            continue;
                        }
                        subtitleLines.Add(subtitleLine);
                    }
                    if (subtitleLines.Count == 0 && IniSettings.FindAudio)
                    {
                        SubtitleLine subtitleLine1 = new SubtitleLine()
                        {
                            Position = SubtitleSettings.Anchor,
                            Text     = audio
                        };
                        subtitleLines.Add(subtitleLine1);
                    }
                    lines = subtitleLines.ToArray();
                    count = subtitleLines.Count > 0;
                    return(count);
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("TextTranslator::Translate:\n", exception.ToString()));
                }
                lines = null;
                count = false;
            }
            finally
            {
                Monitor.Exit(translationLock);
            }
            return(count);
        }
Ejemplo n.º 27
0
        private void LateUpdate()
        {
            TimeSpan timeSpan;

            if (!TextTranslator.Initialized)
            {
                return;
            }
            if (base.GetType() == typeof(Text))
            {
                try
                {
                    if (MaskableGraphicText.cpy2clip.Count > 0 && (U::UnityEngine.Time.time >= MaskableGraphicText.cliptime || U::UnityEngine.Time.time >= MaskableGraphicText.idlecliptime))
                    {
                        if (MaskableGraphicText.NativeMethods.OpenClipboard(IntPtr.Zero))
                        {
                            if (MaskableGraphicText.NativeMethods.EmptyClipboard())
                            {
                                string empty = string.Empty;
                                foreach (Text text in MaskableGraphicText.cpy2clip)
                                {
                                    if (string.IsNullOrEmpty(text.text4translate))
                                    {
                                        continue;
                                    }
                                    empty = string.Concat(empty, text.text4translate, Environment.NewLine);
                                }
                                uint   length = (uint)((empty.Length + 1) * 2);
                                IntPtr intPtr = MaskableGraphicText.NativeMethods.GlobalAlloc(66, new UIntPtr(length));
                                if (intPtr != IntPtr.Zero)
                                {
                                    IntPtr hGlobalUni = Marshal.StringToHGlobalUni(empty);
                                    IntPtr intPtr1    = MaskableGraphicText.NativeMethods.GlobalLock(intPtr);
                                    if (intPtr1 != IntPtr.Zero)
                                    {
                                        MaskableGraphicText.NativeMethods.CopyMemory(intPtr1, hGlobalUni, length);
                                        MaskableGraphicText.NativeMethods.GlobalUnlock(intPtr1);
                                        MaskableGraphicText.NativeMethods.SetClipboardData(13, intPtr);
                                    }
                                    Marshal.FreeHGlobal(hGlobalUni);
                                    MaskableGraphicText.NativeMethods.GlobalFree(intPtr);
                                }
                            }
                            MaskableGraphicText.NativeMethods.CloseClipboard();
                        }
                        MaskableGraphicText.idlecliptime = 0f;
                        MaskableGraphicText.cliptime     = 0f;
                        MaskableGraphicText.cpy2clip.Clear();
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MaskableGraphicText.idlecliptime = 0f;
                    MaskableGraphicText.cliptime     = 0f;
                    MaskableGraphicText.cpy2clip.Clear();
                    IniSettings.Error(string.Concat("MaskableGraphicText::LateUpdate::Copy2Clipboard:\n", exception.ToString()));
                }
                try
                {
                    if (this.textchanged)
                    {
                        this.textchanged = false;
                        this.textcached  = null;
                        if (!TextTranslator.IsNotValidString(this.text4translate))
                        {
                            if (IniSettings.UseCopy2Clipboard)
                            {
                                timeSpan = (IniSettings.Copy2ClipboardTime >= 1 ? TimeSpan.FromMilliseconds((double)IniSettings.Copy2ClipboardTime) : TimeSpan.FromMilliseconds(1));
                                float single = U::UnityEngine.Time.time + Convert.ToSingle(timeSpan.TotalSeconds);
                                MaskableGraphicText.cliptime = single;
                                if (MaskableGraphicText.idlecliptime == 0f)
                                {
                                    MaskableGraphicText.idlecliptime = single + 3f;
                                }
                                if (!MaskableGraphicText.cpy2clip.Contains((Text)this))
                                {
                                    MaskableGraphicText.cpy2clip.Add((Text)this);
                                }
                            }
                            string value = this.text4translate;
                            if (this.txtpredictions != null || this.firstprediction)
                            {
                                if (this.firstprediction)
                                {
                                    this.firstprediction = false;
                                    this.txtpredictions  = TextTranslator.FindPredictions(this.text4translate, null);
                                }
                                else if ((int)this.txtpredictions.Length > 1)
                                {
                                    this.txtpredictions = TextTranslator.FindPredictions(this.text4translate, this.txtpredictions);
                                }
                                if (this.txtpredictions.Length == 0)
                                {
                                    this.predictionsfailed = true;
                                    this.txtpredictions    = null;
                                    TextTranslator.Translate(ref value);
                                }
                                else if ((int)this.txtpredictions.Length != 1)
                                {
                                    value = this.InitialPrediction();
                                }
                                else if (this.txtpredictions[0].Key.Length > this.text4translate.Length && this.txtpredictions[0].Key.StartsWith(this.text4translate))
                                {
                                    if (!string.IsNullOrEmpty(this.txtpredictions[0].Value))
                                    {
                                        float length1 = (float)this.text4translate.Length / (float)this.txtpredictions[0].Key.Length;
                                        int   num     = Convert.ToInt32((float)this.txtpredictions[0].Value.Length * length1);
                                        value = this.txtpredictions[0].Value.Substring(0, num);
                                        Text text1 = this as Text;
                                        TextTranslator.ApplyFontSettings(text1);
                                        U::UnityEngine.TextGenerationSettings generationSettings = text1.GetGenerationSettings(text1.rectTransform.rect.size);
                                        U::UnityEngine.TextGenerator          textGenerator      = new U::UnityEngine.TextGenerator();
                                        textGenerator.Populate(this.txtpredictions[0].Value, generationSettings);
                                        if (textGenerator.lineCount > 1)
                                        {
                                            int num1 = textGenerator.lineCount - 1;
                                            while (num1 >= 1)
                                            {
                                                U::UnityEngine.UILineInfo item = textGenerator.lines[num1];
                                                if (value.Length < item.startCharIdx)
                                                {
                                                    num1--;
                                                }
                                                else
                                                {
                                                    if (value.Length == item.startCharIdx || value == this.txtpredictions[0].Value || value[item.startCharIdx - 1] == '\n')
                                                    {
                                                        goto Label1;
                                                    }
                                                    value = value.Insert(item.startCharIdx, "\n");
                                                    goto Label1;
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (this.txtpredictions[0].Key != this.text4translate)
                                {
                                    this.predictionsfailed = true;
                                    this.txtpredictions    = null;
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(this.txtpredictions[0].Value))
                                    {
                                        value = this.txtpredictions[0].Value;
                                    }
                                    this.txtpredictions = null;
                                }
                            }
                            else if (!TextTranslator.Translate(ref value) && IniSettings.UseTextPrediction && !this.predictionsfailed)
                            {
                                this.firstprediction = true;
                            }
Label1:
                            if (value != this.text4translate)
                            {
                                value = string.Concat(this.text4translatetag1, value, this.text4translatetag2);
                                this.texttranslated = value;
                                ((Text)this).text   = value;
                                TextTranslator.ApplyFontSettings((Text)this);
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (this.retranslatetext)
                    {
                        this.retranslatetext = false;
                        if (!string.IsNullOrEmpty(this.text4translate))
                        {
                            string str  = this.text4translate;
                            string str1 = this.text2translate;
                            this.ResetTextPredictions();
                            this.text2translate = null;
                            this.text4translate = null;
                            this.texttranslated = null;
                            ((Text)this).text   = str;
                            ((Text)this).text   = str1;
                            this.LateUpdate();
                        }
                    }
                }
                catch (Exception exception3)
                {
                    Exception exception2 = exception3;
                    this.textchanged = false;
                    this.textcached  = null;
                    IniSettings.Error(string.Concat("MaskableGraphicText::LateUpdate:\n", exception2.ToString()));
                }
            }
        }
Ejemplo n.º 28
0
        public static bool Translate(ref string text)
        {
            OrderedDictionary           orderedDictionaries;
            List <RegexTranslationData> regexTranslationDatas;
            bool flag;
            OrderedDictionary orderedDictionaries1;
            object            translationLock = TextTranslator.TranslationLock;

            Monitor.Enter(translationLock);
            try
            {
                try
                {
                    string value = null;
                    if (TextTranslator.translationsLv.TryGetValue(Application.loadedLevel, out orderedDictionaries))
                    {
                        TranslationDataBase item = orderedDictionaries[text] as TranslationDataBase;
                        if (item == null)
                        {
                            goto Label2;
                        }
                        value = item.Value;
                        goto Label1;
                    }
Label2:
                    if (IniSettings.UseRegEx)
                    {
                        TextTranslator.UpdateRegexCacheSize();
                        if (TextTranslator.translationsLvR.TryGetValue(Application.loadedLevel, out regexTranslationDatas))
                        {
                            foreach (RegexTranslationData regexTranslationDatum in regexTranslationDatas)
                            {
                                Match match = Regex.Match(text, regexTranslationDatum.Key);
                                if (!match.Success || !(match.Groups[0].Value == text))
                                {
                                    continue;
                                }
                                value = match.Result(regexTranslationDatum.Value);
                                goto Label1;
                            }
                        }
                    }
                    TranslationDataBase translationDataBase = TextTranslator.translations[text] as TranslationDataBase;
                    if (translationDataBase != null)
                    {
                        value = translationDataBase.Value;
                    }
                    else if (IniSettings.UseRegEx)
                    {
                        TextTranslator.UpdateRegexCacheSize();
                        foreach (RegexTranslationData regexTranslationDatum1 in TextTranslator.translationsR)
                        {
                            Match match1 = Regex.Match(text, regexTranslationDatum1.Key);
                            if (!match1.Success || !(match1.Groups[0].Value == text))
                            {
                                continue;
                            }
                            value = match1.Result(regexTranslationDatum1.Value);
                            goto Label1;
                        }
                    }
Label1:
                    if (value != null)
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            text = value;
                            flag = true;
                            return(flag);
                        }
                    }
                    else if (IniSettings.FindText)
                    {
                        if (!IniSettings.DumpTextByLevel)
                        {
                            string mainFilePath = TextTranslator.MainFilePath;
                            TextTranslator.translations.Add(text, new TranslationDataBase(mainFilePath));
                            TextTranslator.DumpText(mainFilePath, text);
                        }
                        else
                        {
                            if (!TextTranslator.translationsLv.TryGetValue(Application.loadedLevel, out orderedDictionaries1))
                            {
                                orderedDictionaries1 = new OrderedDictionary();
                                TextTranslator.translationsLv.Add(Application.loadedLevel, orderedDictionaries1);
                            }
                            string lvFilePath = TextTranslator.LvFilePath;
                            orderedDictionaries1.Add(text, new TranslationDataBase(lvFilePath));
                            TextTranslator.DumpText(lvFilePath, text);
                        }
                    }
                }
                catch (Exception exception)
                {
                    IniSettings.Error(string.Concat("TextTranslator::Translate:\n", exception.ToString()));
                }
                flag = false;
            }
            finally
            {
                Monitor.Exit(translationLock);
            }
            return(flag);
        }
Ejemplo n.º 29
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);
            }
        }
Ejemplo n.º 30
0
 private static void LoadAllFromTranslationDir(string[] files)
 {
     try
     {
         if (files != null && files.Length != 0)
         {
             HashSet <string> strs      = new HashSet <string>();
             bool             useRegEx  = IniSettings.UseRegEx;
             string[]         strArrays = files;
             for (int i = 0; i < (int)strArrays.Length; i++)
             {
                 string str = strArrays[i];
                 if (!strs.Contains(str))
                 {
                     string str1 = null;
                     if (str.EndsWith(".noregex.txt"))
                     {
                         if (useRegEx)
                         {
                             continue;
                         }
                         str1 = string.Concat(str.Substring(0, str.Length - ".noregex.txt".Length), ".txt");
                     }
                     else if (str.EndsWith(".regex.txt"))
                     {
                         if (!useRegEx)
                         {
                             continue;
                         }
                         str1 = string.Concat(str.Substring(0, str.Length - ".regex.txt".Length), ".txt");
                     }
                     if (!string.IsNullOrEmpty(str1))
                     {
                         if (!strs.Contains(str1) && File.Exists(str1))
                         {
                             TextTranslator.LoadTranslations(str1, false);
                             strs.Add(str1);
                         }
                         TextTranslator.LoadTranslations(str, false);
                         strs.Add(str);
                     }
                     else
                     {
                         TextTranslator.LoadTranslations(str, false);
                         strs.Add(str);
                         str1 = (!useRegEx ? string.Concat(str.Substring(0, str.Length - ".txt".Length), ".noregex.txt") : string.Concat(str.Substring(0, str.Length - ".txt".Length), ".regex.txt"));
                         if (!strs.Contains(str1) && File.Exists(str1))
                         {
                             TextTranslator.LoadTranslations(str1, false);
                             strs.Add(str1);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         IniSettings.Error(string.Concat("TextTranslator::LoadFromTranslationDir:\n", exception.ToString()));
     }
 }