diff --git a/.gitignore b/.gitignore index 8796d56c7bb31d89be96e3d321e73ba8d984a4fe..9ac242371b55bf294aac29959dc8af1dbdbd8456 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /TextLocator/bin /TextLocator/obj /packages +/.vs/TextLocator/v16/*.suo +/.vs diff --git a/.vs/TextLocator/v16/.suo b/.vs/TextLocator/v16/.suo deleted file mode 100644 index 7ad29fa39e3143f141a24b0f9dae99ff35255bb1..0000000000000000000000000000000000000000 Binary files a/.vs/TextLocator/v16/.suo and /dev/null differ diff --git a/README.md b/README.md index dd157698c961d14882cffef8ec92e9670c43c6ed..b2d48e8a88eb5e40863249f48bfe5845b5f47dd6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 文本定位器 -![主界面](https://images.gitee.com/uploads/images/2021/0905/223251_9b563fce_995027.png "主界面") +![主界面](https://images.gitee.com/uploads/images/2021/0906/224436_07453e0f_995027.png "主界面") #### 介绍 基于.net实现的本地文档的全文索引定位器,根据关键词搜索定位本地文档内容。便于查找历史文档时节省时间。 diff --git a/TextLocator/Core/AppCore.cs b/TextLocator/Core/AppCore.cs new file mode 100644 index 0000000000000000000000000000000000000000..ad88dfbbb19b64c79211e81e321c7c67647b4c89 --- /dev/null +++ b/TextLocator/Core/AppCore.cs @@ -0,0 +1,46 @@ +using log4net; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TextLocator.Core +{ + /// + /// AppCore + /// + public class AppCore + { + private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + #region App退出或重启 + /// + /// 退出应用 + /// + public static void ExitProcess() + { + log.Debug("退出当前应用程序进程"); + Environment.Exit(Environment.ExitCode); //Application.Current.Shutdown(-1); + } + + /// + /// 重启应用 + /// + public static void RestartProcess() + { + log.Debug("重启当前应用程序"); + + // 启动新进程 + System.Reflection.Assembly.GetEntryAssembly(); + String processPath = Directory.GetCurrentDirectory(); + String processName = Process.GetCurrentProcess().ProcessName; + Process.Start(processPath + "/" + processName); + + ExitProcess(); + } + #endregion + } +} diff --git a/TextLocator/FileInfoItem.xaml.cs b/TextLocator/FileInfoItem.xaml.cs index f10c88ca4d1ec1355161e4dfd87aacbd19341883..510fe716f067ce528225068a750fb6c5ec1f7587 100644 --- a/TextLocator/FileInfoItem.xaml.cs +++ b/TextLocator/FileInfoItem.xaml.cs @@ -45,29 +45,12 @@ namespace TextLocator public void Refresh(Entity.FileInfo fileInfo) { // 根据文件类型显示图标 - this.FileTypeIcon.Source = FileUtil.GetFileTypeIcon(fileInfo.FileType); + this.FileTypeIcon.Source = FileUtil.GetFileIcon(fileInfo.FileType); // 显示文件信息 this.FileName.Text = fileInfo.FileName; this.FileFolder.Text = fileInfo.FilePath.Replace(fileInfo.FileName, ""); - long fileSize = fileInfo.FileSize; - string fileSizeUnit = "b"; - if (fileSize > 1024) - { - fileSize = fileSize / 1024; - fileSizeUnit = "KB"; - } - if (fileSize > 1024) - { - fileSize = fileSize / 1024; - fileSizeUnit = "MB"; - } - if (fileSize > 1024) - { - fileSize = fileSize / 1024; - fileSizeUnit = "GB"; - } - this.FileSize.Text = fileSize + "" + fileSizeUnit; + this.FileSize.Text = FileUtil.GetFileSizeFriendly(fileInfo.FileSize); this.CreateTime.Text = fileInfo.CreateTime; this.FileContent.Document.Blocks.Clear(); diff --git a/TextLocator/Index/LuceneIndexCore.cs b/TextLocator/Index/LuceneIndexCore.cs index f7af428567394c8b0a5615ebe94655661f371a0e..9c905ec48c541b2121a9dcc270ae0a54ed20c920 100644 --- a/TextLocator/Index/LuceneIndexCore.cs +++ b/TextLocator/Index/LuceneIndexCore.cs @@ -37,11 +37,12 @@ namespace TextLocator.Index if (rebuild) { create = rebuild; - } + } // 索引写入初始化(FSDirectory表示索引存放在硬盘上,RAMDirectory表示放在内存上) Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(AppConst.INDEX_DIRECTORY, AppConst.INDEX_ANALYZER, create, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); + // 文件总数 int count = filePaths.Count(); // 遍历读取文件,并创建索引 @@ -54,6 +55,13 @@ namespace TextLocator.Index { continue; } + if (!create && !string.IsNullOrEmpty(AppUtil.ReadIni("FileIndex", filePath, ""))) + { + continue; + } + + // 写入 + AppUtil.WriteIni("FileIndex", filePath, "1"); // 开始时间 DateTime beginMark = DateTime.Now; diff --git a/TextLocator/MainWindow.xaml b/TextLocator/MainWindow.xaml index 8647b2636963cd222a47ba1a17d0749329da8753..a3c069f7974f564f39ac97dc175c0f5d101fe161 100644 --- a/TextLocator/MainWindow.xaml +++ b/TextLocator/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:TextLocator" xmlns:rubyer="clr-namespace:Rubyer;assembly=Rubyer" mc:Ignorable="d" - Title="搜索文本定位" Width="1366" Height="768" WindowStartupLocation="CenterScreen" Icon="Resource/App.ico" Loaded="Window_Loaded"> + Title="文本搜索定位" Width="1366" Height="768" WindowStartupLocation="CenterScreen" Icon="Resource/App.ico" Loaded="Window_Loaded"> @@ -87,7 +87,7 @@ -