private void btnConvert_Click(object sender, EventArgs e)
        {
            if (!CheckCanRun())
            {
                return;
            }
            richTextBox1.Clear();
            errorMessages = "";
            try
            {
                if (streamExport)
                {
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        exportPath = saveFileDialog1.FileName;
                    }
                    else
                    {
                        ShowStatusMessage("请选择词库保存的路径,否则将无法进行词库导出", true);
                        return;
                    }
                }

                if (!mergeTo1File)
                {
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        outputDir = folderBrowserDialog1.SelectedPath;
                    }
                    else
                    {
                        ShowStatusMessage("请选择词库保存的路径,否则将无法进行词库导出", true);
                        return;
                    }
                }
                mainBody = new MainBody();
                mainBody.SelectedWordRankGenerater = wordRankGenerater;
                mainBody.Import                        = import;
                mainBody.Export                        = export;
                mainBody.SelectedTranslate             = this.translate;
                mainBody.SelectedConverter             = this.chineseConverter;
                mainBody.Filters                       = GetFilters();
                mainBody.SortType                      = this.sortType;
                mainBody.SortDesc                      = this.sortDesc;
                mainBody.BatchFilters                  = GetBatchFilters();
                mainBody.ReplaceFilters                = GetReplaceFilters();
                mainBody.FilterConfig                  = filterConfig;
                mainBody.Import.ImportLineErrorNotice += WriteErrorMessage;
                mainBody.Export.ExportErrorNotice     += WriteErrorMessage;
                mainBody.ProcessNotice                += RichTextBoxShow;
                timer1.Enabled = true;
                backgroundWorker1.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        public void Run()
        {
            for (int i = 0; i < Args.Length; i++)
            {
                string arg = Args[i];
                type = RunCommand(arg);
            }
            if (!string.IsNullOrEmpty(format))
            {
                if ((!(wordLibraryExport is SelfDefining)) && (!(wordLibraryImport is SelfDefining)))
                {
                    Console.WriteLine("-f参数用于自定义格式时设置格式样式用,导入导出词库格式均不是自定义格式,该参数无效!");
                    return;
                }
            }
            if (!string.IsNullOrEmpty(codingFile))
            {
                if (!(wordLibraryExport is SelfDefining))
                {
                    Console.WriteLine("-f参数用于自定义格式输出时设置编码用,导出词库格式不是自定义格式,该参数无效!");
                    return;
                }
            }
            if (wordLibraryImport is SelfDefining)
            {
                ((SelfDefining)wordLibraryImport).UserDefiningPattern = pattern;
            }
            if (wordLibraryExport is SelfDefining)
            {
                ((SelfDefining)wordLibraryExport).UserDefiningPattern = pattern;
            }
            if (importPaths.Count > 0 && exportPath != "")
            {
                MainBody mainBody = new MainBody();
                mainBody.Export = wordLibraryExport;
                mainBody.Import = wordLibraryImport;

                Console.WriteLine("转换开始...");
                //foreach (string importPath in importPaths)
                //{
                //    Console.WriteLine("开始转换文件:" + importPath);
                //    wordLibraryList.AddWordLibraryList(wordLibraryImport.Import(importPath));
                //}
                //string str = wordLibraryExport.Export(wordLibraryList);
                string str = mainBody.Convert(importPaths);
                FileOperationHelper.WriteFile(exportPath, wordLibraryExport.Encoding, str);
                Console.WriteLine("转换完成,共转换" + mainBody.Count + "个");
                return;
            }
            else
            {
                Console.WriteLine("输入 -? 可获取帮助");
            }
        }
Beispiel #3
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            if (!CheckCanRun())
            {
                return;
            }
            richTextBox1.Clear();

            try
            {
                if (streamExport)
                {
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        exportPath = saveFileDialog1.FileName;
                    }
                    else
                    {
                        ShowStatusMessage("请选择词库保存的路径,否则将无法进行词库导出", true);
                        return;
                    }
                }

                if (!mergeTo1File)
                {
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        outputDir = folderBrowserDialog1.SelectedPath;
                    }
                }
                mainBody = new MainBody();
                mainBody.SelectedWordRankGenerater = wordRankGenerater;
                mainBody.Import            = import;
                mainBody.Export            = export;
                mainBody.SelectedTranslate = this.translate;
                mainBody.SelectedConverter = this.chineseConverter;
                mainBody.Filters           = GetFilters();
                mainBody.BatchFilters      = GetBatchFilters();
                mainBody.ReplaceFilters    = GetReplaceFilters();

                mainBody.ProcessNotice += new ProcessNotice((string notice) => {
                    richTextBox1.Invoke(new Action(() => richTextBox1.AppendText(notice + "\r\n")));
                });
                timer1.Enabled = true;
                backgroundWorker1.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        public void Run()
        {
            for (int i = 0; i < Args.Length; i++)
            {
                string arg = Args[i];
                type = RunCommand(arg);
            }
            if (!string.IsNullOrEmpty(format))
            {
                if ((!(wordLibraryExport is SelfDefining)) && (!(wordLibraryImport is SelfDefining)))
                {
                    Console.WriteLine("-f参数用于自定义格式时设置格式样式用,导入导出词库格式均不是自定义格式,该参数无效!");
                    return;
                }
            }
            if (!string.IsNullOrEmpty(codingFile))
            {
                if (!(wordLibraryExport is SelfDefining))
                {
                    Console.WriteLine("-f参数用于自定义格式输出时设置编码用,导出词库格式不是自定义格式,该参数无效!");
                    return;
                }
            }
            if (wordLibraryImport is SelfDefining)
            {
                ((SelfDefining) wordLibraryImport).UserDefiningPattern = pattern;
            }
            if (wordLibraryExport is SelfDefining)
            {
                ((SelfDefining) wordLibraryExport).UserDefiningPattern = pattern;
            }
            if (wordLibraryImport is LingoesLd2)
            {
                var ld2Import = ((LingoesLd2) wordLibraryImport);
                ld2Import.WordEncoding = wordEncoding;
                if (xmlEncoding != null)
                {
                    ld2Import.XmlEncoding = xmlEncoding;
                    ld2Import.IncludeMeaning = true;
                }
            }
            if (importPaths.Count > 0 && exportPath != "")
            {
                MainBody mainBody = new MainBody();
                mainBody.Export = wordLibraryExport;
                mainBody.Import = wordLibraryImport;

                Console.WriteLine("转换开始...");
                //foreach (string importPath in importPaths)
                //{
                //    Console.WriteLine("开始转换文件:" + importPath);
                //    wordLibraryList.AddWordLibraryList(wordLibraryImport.Import(importPath));
                //}
                //string str = wordLibraryExport.Export(wordLibraryList);
                string str = mainBody.Convert(importPaths);
                FileOperationHelper.WriteFile(exportPath, wordLibraryExport.Encoding, str);
                Console.WriteLine("转换完成,共转换" + mainBody.Count + "个");
                return;
            }
            else
            {
                Console.WriteLine("输入 -? 可获取帮助");
            }
        }
Beispiel #5
0
 public void Run()
 {
     if (Args.Length == 0)
     {
         Console.WriteLine("输入 -? 可获取帮助");
         return;
     }
     for (int i = 0; i < Args.Length; i++)
     {
         string arg = Args[i];
         type = RunCommand(arg);
     }
     if (!string.IsNullOrEmpty(format))
     {
         if ((!(wordLibraryExport is SelfDefining)) && (!(wordLibraryImport is SelfDefining)))
         {
             Console.WriteLine("-f参数用于自定义格式时设置格式样式用,导入导出词库格式均不是自定义格式,该参数无效!");
             return;
         }
     }
     if (!string.IsNullOrEmpty(codingFile))
     {
         if (!(wordLibraryExport is SelfDefining))
         {
             Console.WriteLine("-f参数用于自定义格式输出时设置编码用,导出词库格式不是自定义格式,该参数无效!");
             return;
         }
     }
     if (wordLibraryImport is SelfDefining)
     {
         ((SelfDefining)wordLibraryImport).UserDefiningPattern = pattern;
     }
     if (wordLibraryExport is SelfDefining)
     {
         ((SelfDefining)wordLibraryExport).UserDefiningPattern = pattern;
     }
     if (wordLibraryExport is Rime)
     {
         ((Rime)wordLibraryExport).CodeType = pattern.CodeType;
         ((Rime)wordLibraryExport).OS       = pattern.OS;
     }
     if (wordLibraryImport is LingoesLd2)
     {
         var ld2Import = ((LingoesLd2)wordLibraryImport);
         ld2Import.WordEncoding = wordEncoding;
         if (xmlEncoding != null)
         {
             ld2Import.XmlEncoding    = xmlEncoding;
             ld2Import.IncludeMeaning = true;
         }
     }
     if (importPaths.Count > 0 && exportPath != "")
     {
         var mainBody = new MainBody();
         mainBody.Export = wordLibraryExport;
         mainBody.Import = wordLibraryImport;
         mainBody.SelectedWordRankGenerater = this.wordRankGenerater;
         mainBody.Filters        = this.filters;
         mainBody.ProcessNotice += MainBody_ProcessNotice;
         Console.WriteLine("转换开始...");
         //foreach (string importPath in importPaths)
         //{
         //    Console.WriteLine("开始转换文件:" + importPath);
         //    wordLibraryList.AddWordLibraryList(wordLibraryImport.Import(importPath));
         //}
         //string str = wordLibraryExport.Export(wordLibraryList);
         if (exportPath.EndsWith("*"))
         {
             mainBody.Convert(importPaths, exportPath.Substring(0, exportPath.Length - 1));
         }
         else
         {
             string str = mainBody.Convert(importPaths);
             FileOperationHelper.WriteFile(exportPath, wordLibraryExport.Encoding, str);
         }
         Console.WriteLine("转换完成,共转换" + mainBody.Count + "个");
     }
     Console.WriteLine("输入 -? 可获取帮助");
 }