diff --git a/TextLocator/App.xaml.cs b/TextLocator/App.xaml.cs index aeec4417afc01cbddcdd1d41936bfc0a6756bf41..75750fd0f3b73ab52ce097521d1d4d1000f3ec92 100644 --- a/TextLocator/App.xaml.cs +++ b/TextLocator/App.xaml.cs @@ -119,7 +119,13 @@ namespace TextLocator /// </summary> private void InitAppConfig() { - // 保存文件读取超时时间 + // 保存缓存池容量 + AppUtil.WriteValue("AppConfig", "CachePoolCapacity", AppConst.CACHE_POOL_CAPACITY + ""); + + // 每页显示条数 + AppUtil.WriteValue("AppConfig", "ResultListPageSize", AppConst.MRESULT_LIST_PAGE_SIZE + ""); + + // 文件读取超时时间 AppUtil.WriteValue("AppConfig", "FileReadTimeout", AppConst.FILE_READ_TIMEOUT + ""); } #endregion diff --git a/TextLocator/Core/AppConst.cs b/TextLocator/Core/AppConst.cs index 6ebd20c4c331c1547d9938c5dabe2a0ea95d58e6..ad8d23a8db7dd8c27b92d7941e69aaaa772d7ca4 100644 --- a/TextLocator/Core/AppConst.cs +++ b/TextLocator/Core/AppConst.cs @@ -31,11 +31,7 @@ namespace TextLocator.Core /// <summary> /// 文件大小限制 /// </summary> - public static int FILE_SIZE_LIMIT = int.Parse(AppUtil.ReadValue("AppConfig", "FileSizeLimit", "500000000")); - /// <summary> - /// 压缩包解析大小 - /// </summary> - public static int ZIP_FILE_SIZE_LIMIT = int.Parse(AppUtil.ReadValue("AppConfig", "ZipFileSizeLimit", "20000000")); + public static int FILE_SIZE_LIMIT = int.Parse(AppUtil.ReadValue("AppConfig", "FileSizeLimit", "200000000")); /// <summary> /// 缓存池容量 /// </summary> @@ -47,6 +43,10 @@ namespace TextLocator.Core /// </summary> public static readonly string APP_INDEX_DIR = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Index"); /// <summary> + /// 临时目录:_AppDir\\_AppName\\Temp\\ + /// </summary> + public static readonly string APP_TEMP_DIR = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp"); + /// <summary> /// 分词器 /// new Lucene.Net.Analysis.Cn.ChineseAnalyzer(); /// new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);// 用standardAnalyzer分词器 @@ -71,7 +71,7 @@ namespace TextLocator.Core /// <summary> /// 匹配空白和换行 /// </summary> - public static readonly Regex REGEX_LINE_BREAKS_AND_WHITESPACE = new Regex(" |\r|\n|\\s"); + public static readonly Regex REGEX_LINE_BREAKS_AND_WHITESPACE = new Regex(" |\r|\n|┄|\\s"); /// <summary> /// 匹配HTML和XML标签 /// </summary> diff --git a/TextLocator/Core/TaskTime.cs b/TextLocator/Core/TaskTime.cs index 5bbfa4bff3d52c4e3b9f8c839336f3a8cef88f44..068f9c2397e83d7f816b508f8e5bcfa3e4a88171 100644 --- a/TextLocator/Core/TaskTime.cs +++ b/TextLocator/Core/TaskTime.cs @@ -7,6 +7,11 @@ namespace TextLocator.Core /// </summary> public class TaskTime { + /// <summary> + /// 文件大小单位 + /// </summary> + private static readonly string[] suffixes = new string[] { " 秒", " 分", " 时" }; + /// <summary> /// 开始时间 /// </summary> @@ -21,14 +26,28 @@ namespace TextLocator.Core } /// <summary> - /// 消耗时间 + /// 消耗时间(友好显示) /// </summary> - /// <returns></returns> - public double ConsumeTime + public string ConsumeTime { - get - { - return (DateTime.Now - beginTime).TotalSeconds; + get { + double time = (DateTime.Now - beginTime).TotalMilliseconds; + if (time > 1000) + { + if (time / 1000 < 60) + { + return time / 1000 + " 秒"; + } + else if (time / 1000 / 60 < 60) + { + return time / 1000 / 60 + " 分"; + } + else if (time / 1000 / 60 / 60 < 24) + { + return time / 1000 / 60 / 60 + " 时"; + } + } + return time + " 毫秒"; } } diff --git a/TextLocator/Index/IndexCore.cs b/TextLocator/Index/IndexCore.cs index 826cb2fbdd9455e7346a7df61f220ec687260836..996586a32bbfdc669b95c60a57002b24e1750f47 100644 --- a/TextLocator/Index/IndexCore.cs +++ b/TextLocator/Index/IndexCore.cs @@ -41,10 +41,6 @@ namespace TextLocator.Index /// </summary> private static volatile int _totalCount = 0; /// <summary> - /// 是否是创建 - /// </summary> - private static volatile bool _create = false; - /// <summary> /// 回调函数 /// </summary> private static volatile Callback _callback; @@ -58,7 +54,8 @@ namespace TextLocator.Index /// <summary> /// 创建索引写入器 /// </summary> - private static void CreateIndexWriter() + /// <param name="create">是否是创建</param> + private static void CreateIndexWriter(bool create = false) { if (_indexWriter == null) { @@ -69,7 +66,7 @@ namespace TextLocator.Index // 分词器 AppConst.INDEX_ANALYZER, // 是否创建 - _create, + create, // 字段限制 IndexWriter.MaxFieldLength.UNLIMITED); @@ -114,22 +111,22 @@ namespace TextLocator.Index _finishCount = 0; // 判断是创建索引还是增量索引(如果索引目录不存在,重建) - _create = !Directory.Exists(AppConst.APP_INDEX_DIR); + bool create = !Directory.Exists(AppConst.APP_INDEX_DIR); // 入参为true,表示重建 if (rebuild) { - _create = rebuild; + create = rebuild; } // 创建还是更新? - if (_create) + if (create) { // 重建时,删除全部已建索引的标记 AppUtil.DeleteSection("FileIndex"); } // 创建索引写入器 - CreateIndexWriter(); + CreateIndexWriter(create); using (MutipleThreadResetEvent resetEvent = new MutipleThreadResetEvent(_totalCount)) { @@ -138,7 +135,7 @@ namespace TextLocator.Index { string filePath = filePaths[i]; // 忽略已存在索引的文件 - if (SkipFile(_create, filePath, resetEvent)) + if (SkipFile(create, filePath, resetEvent)) { continue; } @@ -248,7 +245,7 @@ namespace TextLocator.Index // 文件内容 string content = FileInfoServiceFactory.GetFileContent(filePath); - msg.Append(",解析:" + taskMark.ConsumeTime + "秒"); + msg.Append(",解析:" + taskMark.ConsumeTime); // 判断文件内容 if (!string.IsNullOrEmpty(content)) { @@ -284,7 +281,7 @@ namespace TextLocator.Index // 执行删除、添加逻辑 AddDocument(filePath, doc); } - msg.Append(",索引:" + taskMark.ConsumeTime + "秒"); + msg.Append(",索引:" + taskMark.ConsumeTime); } else { diff --git a/TextLocator/MainWindow.xaml.cs b/TextLocator/MainWindow.xaml.cs index 9bf6ab472008614285dbb1159ad01ee7c711f61a..f9d796e47c0c5a6e6dae922ac21cb1c3ec24c183 100644 --- a/TextLocator/MainWindow.xaml.cs +++ b/TextLocator/MainWindow.xaml.cs @@ -176,7 +176,7 @@ namespace TextLocator { SortOptions.Items.Add(sort); } - log.Debug("InitializeSortType 耗时:" + taskTime.ConsumeTime + "秒"); + log.Debug("InitializeSortType 耗时:" + taskTime.ConsumeTime + "。"); } /// <summary> @@ -231,7 +231,7 @@ namespace TextLocator Background = Brushes.DarkGray }); } - log.Debug("InitializeFileTypeFilters 耗时:" + taskTime.ConsumeTime + "秒"); + log.Debug("InitializeFileTypeFilters 耗时:" + taskTime.ConsumeTime + "。"); } /// <summary> @@ -275,7 +275,7 @@ namespace TextLocator ExclusionPaths.Text = exclusionPaths; ExclusionPaths.ToolTip = ExclusionPaths.Text; - log.Debug("InitializeAppConfig 耗时:" + taskTime.ConsumeTime + "秒"); + log.Debug("InitializeAppConfig 耗时:" + taskTime.ConsumeTime + "。"); } #endregion @@ -587,7 +587,7 @@ namespace TextLocator this.SwitchPreview.Visibility = totalHits > 0 ? Visibility.Visible : Visibility.Hidden; })); - string msg = "检索完成。分词:( " + text + " ),结果:" + totalHits + "个符合条件的结果 (第 " + pageNow + " 页),耗时:" + taskMark.ConsumeTime + "秒。"; + string msg = "检索完成。分词:( " + text + " ),结果:" + totalHits + "个符合条件的结果 (第 " + pageNow + " 页),耗时:" + taskMark.ConsumeTime + "。"; log.Debug(msg); @@ -1162,7 +1162,7 @@ namespace TextLocator // 获取文件信息列表 FileUtil.GetAllFiles(filePaths, s, _regexExclusionFolder); } - log.Debug("GetFiles 耗时:" + fileMark.ConsumeTime + "秒"); + log.Debug("GetFiles 耗时:" + fileMark.ConsumeTime + "。"); ShowStatus("文件扫描完成,开始" + tips + "索引..."); // 验证扫描文件列表是否为空 @@ -1189,7 +1189,7 @@ namespace TextLocator // 创建索引方法 IndexCore.CreateIndex(filePaths, rebuild, ShowStatus); - string msg = "索引" + tips + "完成。共用时:" + taskMark.ConsumeTime + "秒"; + string msg = "索引" + tips + "完成。共用时:" + taskMark.ConsumeTime + "。"; // 显示状态 ShowStatus(msg); diff --git a/TextLocator/Properties/AssemblyInfo.cs b/TextLocator/Properties/AssemblyInfo.cs index 666cd99530fb84c218beae01cab722fa47d4a069..90a184a2a44ec1ae3da446f288198301005ea4f2 100644 --- a/TextLocator/Properties/AssemblyInfo.cs +++ b/TextLocator/Properties/AssemblyInfo.cs @@ -49,8 +49,8 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.11")] -[assembly: AssemblyFileVersion("1.2.11.0")] +[assembly: AssemblyVersion("1.2.12")] +[assembly: AssemblyFileVersion("1.2.12.0")] // log4net [assembly: log4net.Config.XmlConfigurator(Watch = true)] \ No newline at end of file diff --git a/TextLocator/Service/DevelopFileService.cs b/TextLocator/Service/DevelopFileService.cs index 2e3d6b377b199f88e7adcc13aa29496aa7c24a91..eb57d5a84818473dfd2faa52f6df323332d4c475 100644 --- a/TextLocator/Service/DevelopFileService.cs +++ b/TextLocator/Service/DevelopFileService.cs @@ -22,12 +22,15 @@ namespace TextLocator.Service StringBuilder builder = new StringBuilder(); try { - using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read), Encoding.UTF8)) + using (FileStream fs = File.OpenRead(filePath)) { - string line; - while ((line = reader.ReadLine()) != null) + using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { - builder.Append(AppConst.REGEX_TAG.Replace(line, "")); + string line; + while ((line = reader.ReadLine()) != null) + { + builder.AppendLine(AppConst.REGEX_TAG.Replace(line, "")); + } } } } diff --git a/TextLocator/Service/DomFileService.cs b/TextLocator/Service/DomFileService.cs index 30c6d104f81a7da2547788c1e80bc8ff67119d8f..350c00dae9696c07b61d2ccd9916f516ea66c97d 100644 --- a/TextLocator/Service/DomFileService.cs +++ b/TextLocator/Service/DomFileService.cs @@ -22,12 +22,15 @@ namespace TextLocator.Service StringBuilder builder = new StringBuilder(); try { - using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read), Encoding.UTF8)) + using (FileStream fs = File.OpenRead(filePath)) { - string line; - while((line = reader.ReadLine()) != null) + using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { - builder.Append(AppConst.REGEX_TAG.Replace(line, "")); + string line; + while ((line = reader.ReadLine()) != null) + { + builder.AppendLine(AppConst.REGEX_TAG.Replace(line, "")); + } } } } diff --git a/TextLocator/Service/ExcelFileService.cs b/TextLocator/Service/ExcelFileService.cs index d2e1d06aeddae45e6cd517ce5fdf13540832550b..ac333ffd46d7d730d3e261c1476f6c91cc0796f4 100644 --- a/TextLocator/Service/ExcelFileService.cs +++ b/TextLocator/Service/ExcelFileService.cs @@ -28,7 +28,7 @@ namespace TextLocator.Service { // =========== NPIO =========== // 文件流 - using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (FileStream fs = File.OpenRead(filePath)) { // 获取扩展名 string extName = Path.GetExtension(filePath); @@ -38,11 +38,11 @@ namespace TextLocator.Service { // 把xls写入workbook中 2003版本 case ".xls": - readWorkbook = new HSSFWorkbook(fileStream); + readWorkbook = new HSSFWorkbook(fs); break; // 把xlsx 写入workbook中 2007版本 case ".xlsx": - readWorkbook = new XSSFWorkbook(fileStream); + readWorkbook = new XSSFWorkbook(fs); break; default: break; @@ -97,40 +97,43 @@ namespace TextLocator.Service try { // =========== Spire.XLS =========== - // 创建Workbook对象 - using (Spire.Xls.Workbook workbook = new Spire.Xls.Workbook()) + using (FileStream fs = File.OpenRead(filePath)) { - // 加载Excel文档 - workbook.LoadFromFile(filePath); - StringBuilder builder = new StringBuilder(); - if (workbook != null) + // 创建Workbook对象 + using (Spire.Xls.Workbook workbook = new Spire.Xls.Workbook()) { - WorksheetsCollection sheets = workbook.Worksheets; - if (sheets != null && sheets.Count > 0) + // 加载Excel文档 + workbook.LoadFromStream(fs); + StringBuilder builder = new StringBuilder(); + if (workbook != null) { - // 获取工作表 - for (int i = 0; i < sheets.Count; i++) + WorksheetsCollection sheets = workbook.Worksheets; + if (sheets != null && sheets.Count > 0) { - using (Spire.Xls.Worksheet sheet = sheets[i]) + // 获取工作表 + for (int i = 0; i < sheets.Count; i++) { - // 行 - for (int j = sheet.FirstRow; j < sheet.LastRow; j++) + using (Spire.Xls.Worksheet sheet = sheets[i]) { - using (Spire.Xls.CellRange row = sheet.Rows[j]) + // 行 + for (int j = sheet.FirstRow; j < sheet.LastRow; j++) { - // 列 - for (int k = 0; k < row.Columns.Length; k++) + using (Spire.Xls.CellRange row = sheet.Rows[j]) { - builder.Append(row.Columns[k].Value2.ToString() + " "); + // 列 + for (int k = 0; k < row.Columns.Length; k++) + { + builder.Append(row.Columns[k].Value2.ToString() + " "); + } } + builder.AppendLine(); } - builder.AppendLine(); } } } } + content = builder.ToString(); } - content = builder.ToString(); } } catch (Exception ex) diff --git a/TextLocator/Service/NoTextFileService.cs b/TextLocator/Service/NoTextFileService.cs index c4deb201a17403caab962d9a4f45df7329e1f5ca..59990a08201bb0becfff1e2c5f5ebb9b1622a915 100644 --- a/TextLocator/Service/NoTextFileService.cs +++ b/TextLocator/Service/NoTextFileService.cs @@ -17,7 +17,7 @@ namespace TextLocator.Service try { System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); - string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1); + string fileName = fileInfo.Name; StringBuilder builder = new StringBuilder(); builder.Append("文件名称:" + fileName); builder.Append(";更新时间:" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")); diff --git a/TextLocator/Service/PdfFileService.cs b/TextLocator/Service/PdfFileService.cs index 3d3434df9ccccc4472656061db4255952ca307a8..0efb24a5ca69af2ddba34cb4ecfc20d3b19e5556 100644 --- a/TextLocator/Service/PdfFileService.cs +++ b/TextLocator/Service/PdfFileService.cs @@ -24,20 +24,23 @@ namespace TextLocator.Service { try { - - // 实例化一个PdfDocument对象 - using (PdfDocument doc = new PdfDocument(new FileStream(filePath, FileMode.Open, FileAccess.Read))) + using (FileStream fs = File.OpenRead(filePath)) { - PdfPageCollection pages = doc.Pages; - if (pages != null && pages.Count > 0) + // 实例化一个PdfDocument对象 + using (PdfDocument doc = new PdfDocument(fs)) { - //提取PDF所有页面的文本 - foreach (PdfPageBase page in pages) + PdfPageCollection pages = doc.Pages; + if (pages != null && pages.Count > 0) { - try + //提取PDF所有页面的文本 + foreach (PdfPageBase page in pages) { - builder.Append(page.ExtractText().Replace("Evaluation Warning : The document was created with Spire.PDF for .NET.", "")); - } catch { } + try + { + builder.Append(page.ExtractText().Replace("Evaluation Warning : The document was created with Spire.PDF for .NET.", "")); + } + catch { } + } } } } diff --git a/TextLocator/Service/PowerPointFileService.cs b/TextLocator/Service/PowerPointFileService.cs index d51408f703c66751c73b5079ef99ad324558d263..0df7d63de10db4a4c4f6ee6f5a13e497f6ef7359 100644 --- a/TextLocator/Service/PowerPointFileService.cs +++ b/TextLocator/Service/PowerPointFileService.cs @@ -24,40 +24,43 @@ namespace TextLocator.Service { try { - using (Presentation presentation = new Presentation(new FileStream(filePath, FileMode.Open, FileAccess.Read), FileFormat.Auto)) + using (FileStream fs = File.OpenRead(filePath)) { - SlideCollection slides = presentation.Slides; - if (slides != null && slides.Count > 0) + using (Presentation presentation = new Presentation(fs, FileFormat.Auto)) { - foreach (ISlide slide in presentation.Slides) + SlideCollection slides = presentation.Slides; + if (slides != null && slides.Count > 0) { - ShapeCollection shapes = slide.Shapes; - if (shapes != null && shapes.Count > 0) + foreach (ISlide slide in presentation.Slides) { - foreach (IShape shape in shapes) + ShapeCollection shapes = slide.Shapes; + if (shapes != null && shapes.Count > 0) { - if (shape != null && shape is IAutoShape) + foreach (IShape shape in shapes) { - ITextFrameProperties textFrame; - if ((textFrame = (shape as IAutoShape).TextFrame) != null) + if (shape != null && shape is IAutoShape) { - ParagraphCollection paragraph = textFrame.Paragraphs; - if (paragraph != null && paragraph.Count > 0) + ITextFrameProperties textFrame; + if ((textFrame = (shape as IAutoShape).TextFrame) != null) { - foreach (TextParagraph tp in paragraph) + ParagraphCollection paragraph = textFrame.Paragraphs; + if (paragraph != null && paragraph.Count > 0) { - builder.Append(tp.Text + Environment.NewLine); + foreach (TextParagraph tp in paragraph) + { + builder.Append(tp.Text + Environment.NewLine); + } } } } + shape.Dispose(); } - shape.Dispose(); } + slide.Dispose(); } - slide.Dispose(); } + } - } } catch (Exception ex) diff --git a/TextLocator/Service/TxtFileService.cs b/TextLocator/Service/TxtFileService.cs index ebce22592f79b2906c36fd298f67fd91e7ae8401..8bce107cc0bd87d98bd28960e1dd4938758b2dbc 100644 --- a/TextLocator/Service/TxtFileService.cs +++ b/TextLocator/Service/TxtFileService.cs @@ -20,12 +20,15 @@ namespace TextLocator.Service StringBuilder builder = new StringBuilder(); try { - using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read), Encoding.UTF8)) + using (FileStream fs = File.OpenRead(filePath)) { - string line; - while((line = reader.ReadLine()) != null) + using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { - builder.Append(line); + string line; + while ((line = reader.ReadLine()) != null) + { + builder.AppendLine(line); + } } } } diff --git a/TextLocator/Service/WordFileService.cs b/TextLocator/Service/WordFileService.cs index d355ad404c431a76b4d798bcfd0e701b1cf20356..461660a872b4a3b60de716427c9d8eb3b43de22e 100644 --- a/TextLocator/Service/WordFileService.cs +++ b/TextLocator/Service/WordFileService.cs @@ -28,22 +28,25 @@ namespace TextLocator.Service try { // =========== Spire.XLS =========== - using (Spire.Doc.Document document = new Spire.Doc.Document(new FileStream(filePath, FileMode.Open, FileAccess.Read))) + using (FileStream fs = File.OpenRead(filePath)) { - if (document != null) + using (Spire.Doc.Document document = new Spire.Doc.Document(fs)) { - SectionCollection sections = document.Sections; - if (sections != null && sections.Count > 0) + if (document != null) { - // 提取每个段落的文本 - foreach (Section section in sections) + SectionCollection sections = document.Sections; + if (sections != null && sections.Count > 0) { - ParagraphCollection paragraphs = section.Paragraphs; - if (paragraphs != null && paragraphs.Count > 0) + // 提取每个段落的文本 + foreach (Section section in sections) { - foreach (Paragraph paragraph in paragraphs) + ParagraphCollection paragraphs = section.Paragraphs; + if (paragraphs != null && paragraphs.Count > 0) { - builder.AppendLine(paragraph.Text); + foreach (Paragraph paragraph in paragraphs) + { + builder.AppendLine(paragraph.Text); + } } } } @@ -57,9 +60,9 @@ namespace TextLocator.Service XWPFDocument document = null; try { - using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (FileStream fs = File.OpenRead(filePath)) { - document = new XWPFDocument(file); + document = new XWPFDocument(fs); if (document != null) { diff --git a/TextLocator/Service/ZipFileService.cs b/TextLocator/Service/ZipFileService.cs index fda4e9d45dd46ec249db5508258d3fba3d5922e9..9d659310833ea43415b2d6c677181732ae79561e 100644 --- a/TextLocator/Service/ZipFileService.cs +++ b/TextLocator/Service/ZipFileService.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TextLocator.Core; +using TextLocator.Enums; using TextLocator.Exceptions; using TextLocator.Factory; using TextLocator.Util; @@ -31,19 +32,29 @@ namespace TextLocator.Service { try { + // 文件信息 + FileInfo fileInfo = new FileInfo(filePath); + // 文件名称 + string fileName = fileInfo.Name; + // 文件大小 + long fileSize = fileInfo.Length; + // 压缩包解压 - builder.Append("名称:" + filePath.Substring(filePath.LastIndexOf("\\") + 1)); - builder.Append(" 大小:" + FileUtil.GetFileSizeFriendly(new FileInfo(filePath).Length) + " =>\r\n"); + builder.Append("名称:" + fileName); + builder.Append(" 大小:" + FileUtil.GetFileSizeFriendly(fileInfo.Length)); + builder.Append(" 列表:=> \r\n"); - builder.Append(" 列表:=>\r\n"); - using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + // 解析列表 + using (FileStream file = File.OpenRead(filePath)) { - using (var archive = ArchiveFactory.Open(file)) { + using (var archive = ArchiveFactory.Open(file)) + { foreach (var entry in archive.Entries) { if (!entry.IsDirectory) { - builder.Append(String.Format(" {0}, {1}\r\n", entry.Key, FileUtil.GetFileSizeFriendly(entry.Size))); + builder.Append("┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\r\n"); + builder.Append(string.Format("{0}, {1}\r\n", entry.Key, FileUtil.GetFileSizeFriendly(entry.Size))); } } } diff --git a/TextLocator/SettingWindow.xaml b/TextLocator/SettingWindow.xaml index 53a033cc22972ff105733e18350101500e620e11..05b8fa0ad49eef6271d29e28426ab6ae1e8dd3fc 100644 --- a/TextLocator/SettingWindow.xaml +++ b/TextLocator/SettingWindow.xaml @@ -19,50 +19,51 @@ <Grid Margin="20,20,20,0"> <Grid HorizontalAlignment="Left"> <TextBlock Text="最小数量:" HorizontalAlignment="Left"/> - <TextBox x:Name="MinThreads" Text="32" ToolTip="建议:CPU核心数" HorizontalAlignment="Left" Margin="70,0,0,0" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> + <TextBox x:Name="MinThreads" Text="32" ToolTip="默认:32,建议:CPU核心数" HorizontalAlignment="Left" Margin="70,0,0,0" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> </Grid> </Grid> <Grid Margin="20,20,20,0"> <Grid HorizontalAlignment="Left"> <TextBlock Text="最大数量:" HorizontalAlignment="Left"/> - <TextBox x:Name="MaxThreads" Text="64" ToolTip="建议:2倍CPU核心数 + 1" HorizontalAlignment="Left" Margin="70,0,0,0" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> + <TextBox x:Name="MaxThreads" Text="64" ToolTip="默认:64,建议:2倍CPU核心数 + 1" HorizontalAlignment="Left" Margin="70,0,0,0" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> </Grid> </Grid> </StackPanel> </Grid> + <!-- 分割线 --> <Line X1="0" Y1="0" X2="480" Y2="0" Margin="0,10,0,10" Stroke="Gray" StrokeThickness="1"></Line> - <!-- 结果列表每页显示条数 --> + <!-- 缓存池容量 --> <Grid> - <TextBlock Text="结果列表分页条数:" VerticalAlignment="Top" HorizontalAlignment="Left"/> + <TextBlock Text="缓存池容量:" VerticalAlignment="Top" HorizontalAlignment="Left"/> <Grid Margin="20,30,20,0"> <Grid HorizontalAlignment="Left"> - <TextBox x:Name="ResultListPageSize" Text="100" ToolTip="建议:大于50,小于300" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> - <TextBlock Text="(分页条数太多每页显示太多可能会卡顿)" HorizontalAlignment="Left" Margin="110,0,0,0" /> + <TextBox x:Name="CachePoolCapacity" Text="100000" ToolTip="建议:根据自己CPU使用率和内存决定吧" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> + <TextBlock Text="默认:100000(缓存:被索引标记、文件内容等)" HorizontalAlignment="Left" Margin="110,0,0,0" /> </Grid> </Grid> </Grid> <!-- 分割线 --> <Line X1="0" Y1="0" X2="480" Y2="0" Margin="0,10,0,10" Stroke="Gray" StrokeThickness="1"></Line> - <!-- 结果列表每页显示条数 --> + <!-- 结果列表分页条数 --> <Grid> - <TextBlock Text="文件读取超时时间:" VerticalAlignment="Top" HorizontalAlignment="Left"/> + <TextBlock Text="列表分页条数:" VerticalAlignment="Top" HorizontalAlignment="Left"/> <Grid Margin="20,30,20,0"> <Grid HorizontalAlignment="Left"> - <TextBox x:Name="FileReadTimeout" Text="600" ToolTip="建议:大于5分钟,小于15分钟" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> - <TextBlock Text="单位:秒(太短正常文件未返回,太长影响速度)" HorizontalAlignment="Left" Margin="110,0,0,0" /> + <TextBox x:Name="ResultListPageSize" Text="100" ToolTip="建议:大于50,小于300" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> + <TextBlock Text="默认:100(每页显示太多可能会卡顿)" HorizontalAlignment="Left" Margin="110,0,0,0" /> </Grid> </Grid> </Grid> <!-- 分割线 --> <Line X1="0" Y1="0" X2="480" Y2="0" Margin="0,10,0,10" Stroke="Gray" StrokeThickness="1"></Line> - <!-- 结果列表每页显示条数 --> + <!-- 文件读取超时时间 --> <Grid> - <TextBlock Text="缓存池容量:" VerticalAlignment="Top" HorizontalAlignment="Left"/> + <TextBlock Text="文件读取超时时间:" VerticalAlignment="Top" HorizontalAlignment="Left"/> <Grid Margin="20,30,20,0"> <Grid HorizontalAlignment="Left"> - <TextBox x:Name="CachePoolCapacity" Text="100000" ToolTip="建议:根据自己CPU使用率和内存决定吧" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> - <TextBlock Text="程序运行中缓存(文件被索引标记、文件内容预览等)" HorizontalAlignment="Left" Margin="110,0,0,0" /> + <TextBox x:Name="FileReadTimeout" Text="600" ToolTip="建议:大于5分钟,小于15分钟" HorizontalAlignment="Left" Width="100" input:InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Number_TextBox_PreviewTextInput"/> + <TextBlock Text="单位:秒(太短正常文件未返回,太长影响速度)" HorizontalAlignment="Left" Margin="110,0,0,0" /> </Grid> </Grid> </Grid> diff --git a/TextLocator/SettingWindow.xaml.cs b/TextLocator/SettingWindow.xaml.cs index 947127b7ddda1433e4963ab387ec66ca897e28b2..4321b695c4bc2d4207705f310c774452d7e2dde4 100644 --- a/TextLocator/SettingWindow.xaml.cs +++ b/TextLocator/SettingWindow.xaml.cs @@ -81,17 +81,6 @@ namespace TextLocator // 线程池 string minThreadsText = this.MinThreads.Text; string maxThreadsText = this.MaxThreads.Text; - - // 每页显示条数 - string ResultListPageSizeText = this.ResultListPageSize.Text; - - // 文件读取超时时间 - string fileReadTimeoutText = this.FileReadTimeout.Text; - - // 缓存池容量 - string cachePoolCapacityText = this.CachePoolCapacity.Text; - - // 转换,验证 int minThreads = 0; try { @@ -126,6 +115,26 @@ namespace TextLocator } } + // 缓存池容量 + string cachePoolCapacityText = this.CachePoolCapacity.Text; + int cachePoolCapacity = 0; + try + { + cachePoolCapacity = int.Parse(cachePoolCapacityText); + } + catch + { + Message.ShowWarning("MessageContainer", "缓存池容量设置错误"); + return; + } + if (cachePoolCapacity < 50000 || cachePoolCapacity > 500000) + { + Message.ShowWarning("MessageContainer", "建议设置在5-50W范围内"); + return; + } + + // 每页显示条数 + string ResultListPageSizeText = this.ResultListPageSize.Text; int ResultListPageSize = 0; try { @@ -142,6 +151,8 @@ namespace TextLocator return; } + // 文件读取超时时间 + string fileReadTimeoutText = this.FileReadTimeout.Text; int fileReadTimeout = 0; try { @@ -158,39 +169,23 @@ namespace TextLocator return; } - int cachePoolCapacity = 0; - try - { - cachePoolCapacity = int.Parse(cachePoolCapacityText); - } catch - { - Message.ShowWarning("MessageContainer", "缓存池容量设置错误"); - return; - } - if (cachePoolCapacity < 50000 || cachePoolCapacity > 500000) - { - Message.ShowWarning("MessageContainer", "建议设置在5-50w范围内"); - return; - } - // 刷新、保存 AppConst.THREAD_POOL_MIN_SIZE = minThreads; AppConst.THREAD_POOL_MAX_SIZE = maxThreads; AppCore.SetThreadPoolSize(); + AppConst.CACHE_POOL_CAPACITY = cachePoolCapacity; + AppUtil.WriteValue("AppConfig", "CachePoolCapacity", AppConst.CACHE_POOL_CAPACITY + ""); + log.Debug("修改缓存池容量:" + AppConst.CACHE_POOL_CAPACITY); + AppConst.MRESULT_LIST_PAGE_SIZE = ResultListPageSize; AppUtil.WriteValue("AppConfig", "ResultListPageSize", AppConst.MRESULT_LIST_PAGE_SIZE + ""); log.Debug("修改结果列表分页条数:" + AppConst.MRESULT_LIST_PAGE_SIZE); - AppConst.FILE_READ_TIMEOUT = fileReadTimeout; AppUtil.WriteValue("AppConfig", "FileReadTimeout", AppConst.FILE_READ_TIMEOUT + ""); log.Debug("修改文件读取超时时间:" + AppConst.FILE_READ_TIMEOUT); - AppConst.CACHE_POOL_CAPACITY = cachePoolCapacity; - AppUtil.WriteValue("AppConfig", "CachePoolCapacity", AppConst.CACHE_POOL_CAPACITY + ""); - log.Debug("修改缓存池容量:" + AppConst.CACHE_POOL_CAPACITY); - this.Close(); } #endregion diff --git a/TextLocator/Util/FileUtil.cs b/TextLocator/Util/FileUtil.cs index 735106e6e37545be1ee306de53db1da7b795c996..bf1bc9ca78f2d6d34d0398294103766a2de7c71b 100644 --- a/TextLocator/Util/FileUtil.cs +++ b/TextLocator/Util/FileUtil.cs @@ -199,23 +199,13 @@ namespace TextLocator.Util { return; } - // 获取源文件夹中的所有文件完整路径 - FileInfo[] files = new DirectoryInfo(srcDir).GetFiles(); - foreach (FileInfo fileInfo in files) - { - try - { - File.Delete(fileInfo.FullName); - } - catch (Exception ex) - { - log.Error("文件删除失败:" + ex.Message, ex); - } - } try { - File.Delete(srcDir); - } catch { } + DirectoryInfo dirInfo = new DirectoryInfo(srcDir); + dirInfo.Delete(true); + } catch (Exception ex) { + log.Error(srcDir + " -> 目录删除失败:" + ex.Message, ex); + } } /// <summary> diff --git a/TextLocator/Util/RichTextBoxUtil.cs b/TextLocator/Util/RichTextBoxUtil.cs index aa4fa9b38885d1bb874085fbc7f4d23869185128..8753a42c64cbb2e064aaf7a8948d66567ebc3f4a 100644 --- a/TextLocator/Util/RichTextBoxUtil.cs +++ b/TextLocator/Util/RichTextBoxUtil.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; @@ -46,18 +49,18 @@ namespace TextLocator.Util TextPointer position = richTextBox.Document.ContentStart; while (position != null) { - //向前搜索,需要内容为Text + // 向前搜索,需要内容为Text if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text) { - //拿出Run的Text + // 拿出Run的Text string text = position.GetTextInRun(LogicalDirection.Forward); - //可能包含多个keyword,做遍历查找 - int index = text.IndexOf(keyword, 0); + // 可能包含多个keyword,做遍历查找 + int index = text.IndexOf(keyword, 0, StringComparison.CurrentCultureIgnoreCase); if (index != -1) { TextPointer start = position.GetPositionAtOffset(index); TextPointer end = start.GetPositionAtOffset(keyword.Length); - position = selecta(richTextBox, color, start, end, background); + position = Selecta(richTextBox, color, start, end, background); } } // 文字指针向前偏移 @@ -72,11 +75,10 @@ namespace TextLocator.Util /// </summary> /// <param name="richTextBox">元素</param> /// <param name="color">颜色</param> - /// <param name="selectLen">选择长度</param> /// <param name="tpStart">内容指针开始位置</param> /// <param name="tpEnd">内容指针结束位置</param> /// <returns></returns> - private static TextPointer selecta(RichTextBox richTextBox, Color color, TextPointer tpStart, TextPointer tpEnd, bool background) + private static TextPointer Selecta(RichTextBox richTextBox, Color color, TextPointer tpStart, TextPointer tpEnd, bool background) { TextRange range = richTextBox.Selection; range.Select(tpStart, tpEnd);