Ejemplo n.º 1
0
 /// <summary>
 /// 双击选择要读取的翻译文本
 /// </summary>
 private void TransGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (sender != null)
     {
         DataGrid grid = sender as DataGrid;
         if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
         {
             FileData     info  = (FileData)grid.SelectedItem;
             StreamReader s     = new StreamReader(info.Fdata.OpenRead());
             string       start = s.ReadLine();
             if (start == null || !start.Contains("DMK"))
             {
                 s.Close();
                 MessageBoxResult result = MessageBox.Show("尝试打开一个非DM提取的文本文件!", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
             DialoguesData data = this.textmGird.DataContext as DialoguesData;
             data.InitData(start);
             data.ReadDialogues(s, TextType.Original);
             s.Close();
             //从翻译后文本文件读取文本
             if (!FileOperator.FileExist(info.Fdata.DirectoryName, (info.Fdata.Name.Replace(info.Fdata.Extension, "") + Const.FinishName), FileType.all))
             {
                 info.Fdata.CopyTo(info.Fdata.FullName.Replace(info.Fdata.Extension, "") + Const.FinishName);
             }
             FileInfo f = FileOperator.GetFile(info.Fdata.FullName.Replace(info.Fdata.Extension, "") + Const.FinishName);
             s = new StreamReader(f.OpenRead());
             data.ReadDialogues(s, TextType.Posttranslation);
             s.Close();
             this.SaveBtn.IsEnabled = true;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 文本保存到文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            DialoguesData data = this.textmGird.DataContext as DialoguesData;
            FileData      info = (FileData)this.transGrid.SelectedItem;
            FileInfo      f    = FileOperator.GetFile(info.Fdata.FullName.Replace(info.Fdata.Extension, "") + Const.FinishName);

            if (data.SaveDialogues(new StreamWriter(f.Create(), Encoding.UTF8)))
            {
                MessageBoxResult result = MessageBox.Show($"文件成功写入到{f.FullName}", "通知", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBoxResult result = MessageBox.Show($"文件写入失败!", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }