private void btnOK_Click(object sender, EventArgs e)
 {
     foreach (var subtitleFile in SubtitleFiles)
     {
         //File.Copy(subtitleFile.Key,subtitleFile.Key+".bak");
         FileOperationHelper.WriteFile(subtitleFile.Key, Encoding.UTF8,
                                       stOperator.Subtitle2String(subtitleFile.Value));
     }
     MessageBox.Show("完成");
 }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var lines = new List <SubtitleLine>();

            foreach (var subtitleLine in subtitle.Bodies)
            {
                if (removeChinese)
                {
                    subtitleLine.Text = subtitleLine.EnglishTextWithMeans;
                }
                else
                {
                    subtitleLine.Text = subtitleLine.Text.Replace(subtitleLine.EnglishText,
                                                                  subtitleLine.EnglishTextWithMeans);
                }
                lines.Add(subtitleLine);
            }
            subtitle.Bodies = lines;
            var path    = txbSubtitleFilePath.Text;
            var bakFile = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "_bak" + Path.GetExtension(path);

            if (!File.Exists(bakFile))
            {
                File.Copy(txbSubtitleFilePath.Text, bakFile);
            }
            var str = stOperator.Subtitle2String(subtitle);

            FileOperationHelper.WriteFile(txbSubtitleFilePath.Text, Encoding.UTF8, str);
            ShowMessage("保存成功");
        }
        private void btnPreview_Click(object sender, EventArgs e)
        {
            var filePaths = txbFilePath.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            if (filePaths.Length == 0)
            {
                MessageBox.Show("未选择字幕文件");
                return;
            }
            SubtitleFiles.Clear();

            stOperator = SubtitleHelper.GetOperatorByFileName(filePaths[0]);
            foreach (var filePath in filePaths)
            {
                var content = FileOperationHelper.ReadFile(filePath);
                var srts    = stOperator.Parse(content);
                SubtitleFiles.Add(filePath, srts);
            }
            richTextBox1.Clear();
            foreach (var subtitleFile in SubtitleFiles)
            {
                richTextBox1.AppendText("----" + subtitleFile.Key + "----\r\n");
                richTextBox1.AppendText(stOperator.Subtitle2String(subtitleFile.Value));
            }
        }
Esempio n. 4
0
        //private  void ClearCache()
        //{
        //    userVocabularies.Clear();
        //    cachedDict.Clear();
        //}

        private void btnSave_Click(object sender, EventArgs e)
        {
            var nsubtitle = BuildSubtitleFromGrid();

            if (nsubtitle == null || nsubtitle.Bodies.Count == 0)
            {
                MessageBox.Show("请先点击“载入字幕”按钮打开字幕文件");
                return;
            }
            if (meanColor != default(Color))
            {
                Regex r          = new Regex(@"\(([^\)]+)\)");
                var   fontFormat = "(<font color='#" + meanColor.R.ToString("x2") + meanColor.G.ToString("x2") +
                                   meanColor.B.ToString("x2") + "'>$1</font>)";
                foreach (var kv in nsubtitle.Bodies)
                {
                    var line = kv.Value;
                    if (r.IsMatch(line.Text))
                    {
                        line.Text = r.Replace(line.Text, fontFormat);
                    }
                }
            }
            var path    = txbSubtitleFilePath.Text;
            var newFile = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "_new" + Path.GetExtension(path);
            //if(!File.Exists(newFile))
            //{
            //    File.Copy(txbSubtitleFilePath.Text, newFile);
            //}
            var str = stOperator.Subtitle2String(nsubtitle);

            FileOperationHelper.WriteFile(newFile, Encoding.UTF8, str);
            ShowMessage("保存成功");
            MessageBox.Show("保存成功,文件名:" + Path.GetFileName(newFile));
        }
        private void btnPreview_Click(object sender, EventArgs e)
        {
            var filePaths = txbFilePath.Text.Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
            if (filePaths.Length == 0)
            {
                MessageBox.Show("未选择字幕文件");
                return;
            }
            SubtitleFiles.Clear();

            stOperator = SubtitleHelper.GetOperatorByFileName(filePaths[0]);
            foreach (var filePath in filePaths)
            {
                var content = FileOperationHelper.ReadFile(filePath);
                var srts = stOperator.Parse(content);
                SubtitleFiles.Add(filePath, srts);
            }
            richTextBox1.Clear();
            foreach (var subtitleFile in SubtitleFiles)
            {
                richTextBox1.AppendText("----"+subtitleFile.Key+"----\r\n");
                richTextBox1.AppendText(stOperator.Subtitle2String(subtitleFile.Value));
            }
        }