Ejemplo 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));
     }
 }
Ejemplo n.º 2
0
        private static void WatcherNotice(object sender, FileSystemEventArgs e)
        {
            object noticeLock = TextTranslator.NoticeLock;

            Monitor.Enter(noticeLock);
            try
            {
                if (!(TextTranslator.lastraisedfile == e.FullPath) || !(DateTime.Now < TextTranslator.lastraisedtime))
                {
                    TextTranslator.lastraisedfile = e.FullPath;
                    TextTranslator.lastraisedtime = DateTime.Now.AddSeconds(1);
                    if (e.FullPath.EndsWith(".noregex.txt"))
                    {
                        if (!IniSettings.UseRegEx)
                        {
                            TextTranslator.LoadTranslations(e.FullPath, true);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (e.FullPath.EndsWith(".regex.txt"))
                    {
                        if (IniSettings.UseRegEx)
                        {
                            TextTranslator.LoadTranslations(e.FullPath, true);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (e.FullPath != TextTranslator.MainFileFullPath)
                    {
                        string str = e.FullPath.Substring(0, e.FullPath.Length - ".txt".Length);
                        str = string.Concat(str, (IniSettings.UseRegEx ? ".regex.txt" : ".noregex.txt"));
                        if (!File.Exists(str))
                        {
                            TextTranslator.LoadTranslations(e.FullPath, true);
                        }
                        else
                        {
                            TextTranslator.LoadTranslations(e.FullPath, false);
                            TextTranslator.LoadTranslations(str, true);
                        }
                    }
                    else
                    {
                        TextTranslator.LoadTranslations(e.FullPath, true);
                    }
                    TextTranslator.WatchTextFiles();
                }
            }
            finally
            {
                Monitor.Exit(noticeLock);
            }
        }
Ejemplo n.º 3
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);
            }
        }