From 84553df122649554997edbfb99127e442a408482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8F=9C?= Date: Wed, 27 Jul 2016 13:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E9=85=8D=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IME WL Converter/IME WL Converter/MainBody.cs | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/IME WL Converter/IME WL Converter/MainBody.cs b/IME WL Converter/IME WL Converter/MainBody.cs index 9914fc9c..40d4b23a 100644 --- a/IME WL Converter/IME WL Converter/MainBody.cs +++ b/IME WL Converter/IME WL Converter/MainBody.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -7,6 +7,7 @@ using Studyzy.IMEWLConverter.Generaters; using Studyzy.IMEWLConverter.Helpers; using Studyzy.IMEWLConverter.Language; +using System.Linq; namespace Studyzy.IMEWLConverter { @@ -116,6 +117,31 @@ public int Count public IList BatchFilters { get; set; } + + public List GetRealPath(IList filePathes) + { + var list = new List(); + + filePathes.ToList().ForEach(x => + { + var dic = Path.GetDirectoryName(x); + var filen = Path.GetFileName(x); + if (filen.Contains("*")) + { + var files = Directory.GetFiles(dic, filen, SearchOption.AllDirectories); + list.AddRange(files); + } + else + { + list.Add(x); + } + + }); + + + return list; + } + /// /// 转换多个文件成一个文件 /// @@ -125,11 +151,15 @@ public string Convert(IList filePathes) { allWlList.Clear(); isImportProgress = true; + + filePathes = GetRealPath(filePathes); + foreach (string file in filePathes) { WordLibraryList wlList = import.Import(file); wlList = Filter(wlList); allWlList.AddRange(wlList); + } isImportProgress = false; if (selectedTranslate != ChineseTranslate.NotTrans) @@ -189,8 +219,8 @@ private void GenerateDestinationCode(WordLibraryList wordLibraryList, CodeType c continue; } generater.GetCodeOfWordLibrary(wordLibrary); - if(codeType!=CodeType.Unknown) - wordLibrary.CodeType = codeType; + if (codeType != CodeType.Unknown) + wordLibrary.CodeType = codeType; } } @@ -202,8 +232,12 @@ private void GenerateDestinationCode(WordLibraryList wordLibraryList, CodeType c public void Convert(IList filePathes, string outputDir) { int c = 0; + + filePathes = GetRealPath(filePathes); + foreach (string file in filePathes) { + WordLibraryList wlList = import.Import(file); wlList = Filter(wlList); if (selectedTranslate != ChineseTranslate.NotTrans) @@ -244,10 +278,11 @@ private WordLibraryList Filter(WordLibraryList list) { if (IsKeep(wordLibrary)) { - foreach (IReplaceFilter replaceFilter in ReplaceFilters) - { - replaceFilter.Replace(wordLibrary); - } + if (ReplaceFilters != null) + foreach (IReplaceFilter replaceFilter in ReplaceFilters) + { + replaceFilter.Replace(wordLibrary); + } if (wordLibrary.Word != string.Empty) result.Add(wordLibrary); } @@ -284,7 +319,7 @@ private WordLibraryList ConvertChinese(WordLibraryList wordLibraryList) { result = selectedConverter.ToCht(sb.ToString()); } - string[] newList = result.Split(new[] {'\r'}, StringSplitOptions.RemoveEmptyEntries); + string[] newList = result.Split(new[] { '\r' }, StringSplitOptions.RemoveEmptyEntries); if (newList.Length != count) { throw new Exception("简繁转换时转换失败,请更改简繁转换设置"); @@ -297,4 +332,4 @@ private WordLibraryList ConvertChinese(WordLibraryList wordLibraryList) return wordLibraryList; } } -} \ No newline at end of file +}