Exemplo n.º 1
0
 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));
     }
 }
Exemplo n.º 2
0
 internal static void Error(object obj = null)
 {
     if (IniSettings.DebugMode)
     {
         IniSettings.Log(obj);
     }
 }
        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);
        }
        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);
        }
Exemplo n.º 5
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 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);
 }
Exemplo n.º 7
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()));
     }
 }
Exemplo n.º 8
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()));
     }
 }
 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()));
     }
 }
        static SubtitleSettings()
        {
#if UNITY4
            IniSettings.LoadSettings += new Action <IniFile>(SubtitleSettings.LoadIni);
            IniSettings.LoadIni();
#else
            Load();
#endif
        }
Exemplo n.º 11
0
 private static void WatcherNotice(object sender, FileSystemEventArgs e)
 {
     if (IniSettings.lastraisedfile == e.FullPath && DateTime.Now < IniSettings.lastraisedtime)
     {
         return;
     }
     IniSettings.lastraisedfile = e.FullPath;
     IniSettings.lastraisedtime = DateTime.Now.AddSeconds(1);
     IniSettings.Load();
 }
 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()));
     }
 }
Exemplo n.º 13
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());
     }
 }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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);
            }
        }
        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 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);
            }
        }
        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);
        }
 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());
         }
     }
 }
Exemplo n.º 22
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 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());
     }
 }
Exemplo n.º 24
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()));
     }
 }
Exemplo n.º 25
0
 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 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()));
     }
 }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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()));
     }
 }
Exemplo n.º 29
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);
            }
        }
Exemplo n.º 30
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);
            }
        }