From d0f09817c3e2273d3d4f7b662a7c0031da8bc802 Mon Sep 17 00:00:00 2001 From: studyzy Date: Sun, 5 Apr 2020 17:49:51 +0800 Subject: [PATCH] enable export error message --- src/IME WL Converter Win/Forms/MainForm.cs | 3 ++- src/ImeWlConverterCore/IME/BaseImport.cs | 6 ++++++ src/ImeWlConverterCore/IME/Win10MsPinyin.cs | 5 +++-- src/ImeWlConverterCore/IME/Win10MsPinyinSelfStudy.cs | 7 ++++++- src/ImeWlConverterCore/IME/Win10MsWubi.cs | 4 ++-- src/ImeWlConverterCore/ImeWlConverterCore-net46.csproj | 2 +- src/ImeWlConverterCore/Interface.cs | 1 + 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/IME WL Converter Win/Forms/MainForm.cs b/src/IME WL Converter Win/Forms/MainForm.cs index 085d2667..c9549172 100644 --- a/src/IME WL Converter Win/Forms/MainForm.cs +++ b/src/IME WL Converter Win/Forms/MainForm.cs @@ -229,7 +229,8 @@ private void btnConvert_Click(object sender, EventArgs e) mainBody.Filters = GetFilters(); mainBody.BatchFilters = GetBatchFilters(); mainBody.ReplaceFilters = GetReplaceFilters(); - mainBody.Import.ImportLineErrorNotice += WriteErrorMessage; + mainBody.Import.ImportLineErrorNotice += WriteErrorMessage; + mainBody.Export.ExportErrorNotice += WriteErrorMessage; mainBody.ProcessNotice+=RichTextBoxShow; timer1.Enabled = true; backgroundWorker1.RunWorkerAsync(); diff --git a/src/ImeWlConverterCore/IME/BaseImport.cs b/src/ImeWlConverterCore/IME/BaseImport.cs index 5ca66496..d934023f 100644 --- a/src/ImeWlConverterCore/IME/BaseImport.cs +++ b/src/ImeWlConverterCore/IME/BaseImport.cs @@ -39,5 +39,11 @@ protected void SendImportLineErrorNotice(string msg) { ImportLineErrorNotice?.Invoke(msg); } + + public event Action ExportErrorNotice; + protected void SendExportErrorNotice(string msg) + { + ExportErrorNotice?.Invoke(msg); + } } } \ No newline at end of file diff --git a/src/ImeWlConverterCore/IME/Win10MsPinyin.cs b/src/ImeWlConverterCore/IME/Win10MsPinyin.cs index 13b627da..3982e5bf 100644 --- a/src/ImeWlConverterCore/IME/Win10MsPinyin.cs +++ b/src/ImeWlConverterCore/IME/Win10MsPinyin.cs @@ -170,13 +170,14 @@ public WordLibraryList ImportLine(string str) { throw new NotImplementedException("二进制文件不支持单个词汇的转换"); } - + public event Action ExportErrorNotice; + public IList Export(WordLibraryList wlList) { //Win10拼音只支持最多32个字符的编码 wlList = Filter(wlList); - string tempPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Win10微软拼音词库.dat"; + string tempPath = Path.Combine(FileOperationHelper.GetCurrentFolderPath(), "\\Win10微软拼音词库.dat"); if (File.Exists(tempPath)) { File.Delete(tempPath); } var fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); diff --git a/src/ImeWlConverterCore/IME/Win10MsPinyinSelfStudy.cs b/src/ImeWlConverterCore/IME/Win10MsPinyinSelfStudy.cs index d7af35ac..9a69c448 100644 --- a/src/ImeWlConverterCore/IME/Win10MsPinyinSelfStudy.cs +++ b/src/ImeWlConverterCore/IME/Win10MsPinyinSelfStudy.cs @@ -531,6 +531,11 @@ public WordLibraryList ImportLine(string str) throw new NotImplementedException("二进制文件不支持单个词汇的转换"); } public string ExportFilePath { get; set; } + public event Action ExportErrorNotice; + protected void SendExportErrorNotice(string msg) + { + ExportErrorNotice?.Invoke(msg); + } /// /// 最多支持2W条一个dat文件 /// @@ -543,7 +548,7 @@ public IList Export(WordLibraryList wlList) var list = new List(); if(wlList.Count>20000) { - throw new Exception("微软拼音自学习词库最多支持2万条记录的导入,当前词条数为:"+wlList.Count+",操过限制,请设置过滤条件或者更换词库源。"); + SendExportErrorNotice("微软拼音自学习词库最多支持2万条记录的导入,当前词条数为:"+wlList.Count+",超过限制,请设置过滤条件或者更换词库源。"); //以后微软拼音放开2W限制了,再把这个异常取消吧。 var item20000 = new WordLibraryList(); for(var i=0;i ExportErrorNotice; public IList Export(WordLibraryList wlList) { //Win10拼音只支持最多32个字符的编码 wlList = Filter(wlList); - string tempPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Win10微软五笔词库.dat"; + string tempPath = Path.Combine(FileOperationHelper.GetCurrentFolderPath(), "\\Win10微软五笔词库.dat"); if (File.Exists(tempPath)) { File.Delete(tempPath); } var fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); diff --git a/src/ImeWlConverterCore/ImeWlConverterCore-net46.csproj b/src/ImeWlConverterCore/ImeWlConverterCore-net46.csproj index 1db1374d..e61f2303 100644 --- a/src/ImeWlConverterCore/ImeWlConverterCore-net46.csproj +++ b/src/ImeWlConverterCore/ImeWlConverterCore-net46.csproj @@ -5,7 +5,7 @@ net46 ImeWlConverterCore ImeWlConverterCore - 2.7.0 + 2.8.0 diff --git a/src/ImeWlConverterCore/Interface.cs b/src/ImeWlConverterCore/Interface.cs index e5ff2e09..ef0f1355 100644 --- a/src/ImeWlConverterCore/Interface.cs +++ b/src/ImeWlConverterCore/Interface.cs @@ -27,6 +27,7 @@ public interface IWordLibraryTextImport : IWordLibraryImport public interface IWordLibraryExport { + event Action ExportErrorNotice; Encoding Encoding { get; } CodeType CodeType { get; } ///