Exemple #1
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));
     }
 }
Exemple #2
0
        private static void WatcherNotice(object sender, FileSystemEventArgs e)
        {
            object noticeLock = SubtitleTranslator.NoticeLock;

            Monitor.Enter(noticeLock);
            try
            {
                if (!(SubtitleTranslator.lastraisedfile == e.FullPath) || !(DateTime.Now < SubtitleTranslator.lastraisedtime))
                {
                    SubtitleTranslator.lastraisedfile = e.FullPath;
                    SubtitleTranslator.lastraisedtime = DateTime.Now.AddSeconds(1);
                    if (e.FullPath.EndsWith(".txt"))
                    {
                        SubtitleTranslator.LoadTranslations(e.FullPath, true);
                    }
                    SubtitleTranslator.WatchSubtitleFiles();
                }
            }
            finally
            {
                Monitor.Exit(noticeLock);
            }
        }
Exemple #3
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);
            }
        }