Skip to content

Commit

Permalink
Merge pull request studyzy#13 from cabbage89/master
Browse files Browse the repository at this point in the history
修改命令行的bug,支持通配符
  • Loading branch information
studyzy authored Jul 27, 2016
2 parents 8996a95 + 84553df commit 563c0b0
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions IME WL Converter/IME WL Converter/MainBody.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand All @@ -7,6 +7,7 @@
using Studyzy.IMEWLConverter.Generaters;
using Studyzy.IMEWLConverter.Helpers;
using Studyzy.IMEWLConverter.Language;
using System.Linq;

namespace Studyzy.IMEWLConverter
{
Expand Down Expand Up @@ -116,6 +117,31 @@ public int Count

public IList<IBatchFilter> BatchFilters { get; set; }


public List<string> GetRealPath(IList<string> filePathes)
{
var list = new List<string>();

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;
}

/// <summary>
/// 转换多个文件成一个文件
/// </summary>
Expand All @@ -125,11 +151,15 @@ public string Convert(IList<string> 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)
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -202,8 +232,12 @@ private void GenerateDestinationCode(WordLibraryList wordLibraryList, CodeType c
public void Convert(IList<string> 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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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("简繁转换时转换失败,请更改简繁转换设置");
Expand All @@ -297,4 +332,4 @@ private WordLibraryList ConvertChinese(WordLibraryList wordLibraryList)
return wordLibraryList;
}
}
}
}

0 comments on commit 563c0b0

Please sign in to comment.