diff --git a/TextLocator/Enums/FileType.cs b/TextLocator/Enums/FileType.cs
index 4abc2ea120db9e400edb9aefaced6ebaff99abc3..98180969a36899ed7d4eae8006b22111514bba89 100644
--- a/TextLocator/Enums/FileType.cs
+++ b/TextLocator/Enums/FileType.cs
@@ -40,7 +40,7 @@ namespace TextLocator.Enums
///
/// 代码
///
- [Description("cs,java,js,css,md,py,c,cpp,lua,sql,jsp,json,php,rs,rb,yml,yaml,bat")]
+ [Description("cs,java,js,css,md,py,c,h,cpp,lua,sql,jsp,json,php,rs,rb,yml,yaml,bat")]
代码,
///
/// 纯文本
diff --git a/TextLocator/Index/IndexCore.cs b/TextLocator/Index/IndexCore.cs
index 7977be696feaafa8aa880df23c14270fec9f265c..22b6b7ff449085da8b0f3bef3645c62df90665e0 100644
--- a/TextLocator/Index/IndexCore.cs
+++ b/TextLocator/Index/IndexCore.cs
@@ -58,7 +58,6 @@ namespace TextLocator.Index
{
_callback = callback;
-
// 判断是创建索引还是增量索引(如果索引目录不存在,重建)
bool create = !Directory.Exists(AppConst.APP_INDEX_DIR);
// 入参为true,表示重建
diff --git a/TextLocator/MainWindow.xaml.cs b/TextLocator/MainWindow.xaml.cs
index a8fccb53fca5369f888ec199e2751bf2f9b59314..27869df4d1a4b8007c889708867bc28b1802f6dc 100644
--- a/TextLocator/MainWindow.xaml.cs
+++ b/TextLocator/MainWindow.xaml.cs
@@ -37,6 +37,10 @@ namespace TextLocator
/// 索引文件夹列表
///
private List _indexFolders = new List();
+ ///
+ /// 时间戳
+ ///
+ private long _timestamp;
///
/// 索引构建中
@@ -78,7 +82,7 @@ namespace TextLocator
}
// 软件每次启动时执行索引更新逻辑?
-
+ CheckingIndexUpdates();
}
#region 初始化
@@ -268,7 +272,7 @@ namespace TextLocator
/// 排序类型
/// 仅文件名
/// 匹配全词
- private void Search(List keywords, string fileType, SortType sortType, bool onlyFileName = false, bool matchWords = false)
+ private void Search(List keywords, string fileType, SortType sortType, long timestamp, bool onlyFileName = false, bool matchWords = false)
{
if (!CheckIndexExist())
{
@@ -403,6 +407,10 @@ namespace TextLocator
// 获取并显示列表
for (int i = start; i < end; i++)
{
+ if (_timestamp != timestamp)
+ {
+ continue;
+ }
// 该文件的在索引里的文档号,Doc是该文档进入索引时Lucene的编号,默认按照顺序编的
int docId = scores[i].Doc;
// 获取文档对象
@@ -816,6 +824,20 @@ namespace TextLocator
#endregion
#region 辅助方法
+ ///
+ /// 检查索引是否需要更新
+ ///
+ private void CheckingIndexUpdates()
+ {
+ string lastIndexTime = AppUtil.ReadValue("AppConfig", "LastIndexTime", "");
+ // 时间不存在 或 已经超过7天
+ if (string.IsNullOrEmpty(lastIndexTime) || (DateTime.Now - DateTime.Parse(lastIndexTime)).TotalDays > 7)
+ {
+ // 执行索引更新,扫描新文件。
+ BuildIndex(false);
+ }
+ }
+
///
/// 检查索引是否存在
///
@@ -843,7 +865,6 @@ namespace TextLocator
{
var taskMark = TaskTime.StartNew();
-
var fileMark = TaskTime.StartNew();
// 定义文件列表
List filePaths = new List();
@@ -880,6 +901,8 @@ namespace TextLocator
Message.ShowSuccess("MessageContainer", msg);
}));
+ AppUtil.WriteValue("AppConfig", "LastIndexTime", DateTime.Now.ToString());
+
// 构建结束
build = false;
});
@@ -1022,11 +1045,15 @@ namespace TextLocator
PreviewImage.Source = null;
PreviewFileTypeIcon.Source = null;
+ // 记录时间戳
+ _timestamp = Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);
+
// 搜索
Search(
keywords,
filter == null ? null : filter + "",
(SortType)SortOptions.SelectedValue,
+ _timestamp,
(bool)OnlyFileName.IsChecked,
(bool)MatchWords.IsChecked
);
diff --git a/TextLocator/Properties/AssemblyInfo.cs b/TextLocator/Properties/AssemblyInfo.cs
index e32b67f3362cdfefd314e38b35ddc8c6955f034a..e169e29256bd63477d2c1bd49ebd7f9ca589e0c3 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.2")]
-[assembly: AssemblyFileVersion("1.2.1.0")]
+[assembly: AssemblyVersion("1.2.3")]
+[assembly: AssemblyFileVersion("1.2.3.0")]
// log4net
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
\ No newline at end of file
diff --git a/TextLocator/Util/FileTypeUtil.cs b/TextLocator/Util/FileTypeUtil.cs
index 01b05155a08e73fd1faaa942ffef529501c12e3a..9ad6104e8b23e72db8ef2e5cea81d0c4c1165d67 100644
--- a/TextLocator/Util/FileTypeUtil.cs
+++ b/TextLocator/Util/FileTypeUtil.cs
@@ -40,10 +40,12 @@ namespace TextLocator.Util
{
// 获取描述
string description = ft.GetDescription();
- if (description.Contains(fileExt.Replace(".", "")))
+ foreach(var ext in description.Split(','))
{
- fileType = ft;
- break;
+ if (ext.Equals(fileExt.Replace(".", ""))) {
+ fileType = ft;
+ break;
+ }
}
}
diff --git a/TextLocator/Util/FileUtil.cs b/TextLocator/Util/FileUtil.cs
index 9dc85757899063ad86af917f106154e7023bad8e..df30fe02a8206f3f750603c1d7d705d09eff6443 100644
--- a/TextLocator/Util/FileUtil.cs
+++ b/TextLocator/Util/FileUtil.cs
@@ -20,6 +20,14 @@ namespace TextLocator.Util
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ ///
+ /// 程序员节,文件大小单位换算常量
+ ///
+ private const long PROGRAMMERS_SECTION = 1024;
+ ///
+ /// 文件大小单位
+ ///
+ private static readonly string[] suffixes = new string[] { " B", " KB", " MB", " GB", " TB", " PB" };
///
/// 根据文件类型获取文件图标
///
@@ -83,27 +91,39 @@ namespace TextLocator.Util
///
/// 获取文件大小友好显示
///
- ///
+ ///
///
- public static string GetFileSizeFriendly(long fileSize)
+ public static string GetFileSizeFriendly(long number)
{
- string fileSizeUnit = "b";
- if (fileSize > 1024)
+ /*string sizeUnit = "B";
+ if (fileSize > PROGRAMMERS_SECTION)
{
- fileSize = fileSize / 1024;
- fileSizeUnit = "KB";
+ fileSize = fileSize / PROGRAMMERS_SECTION;
+ sizeUnit = "KB";
}
- if (fileSize > 1024)
+ if (fileSize > PROGRAMMERS_SECTION)
{
- fileSize = fileSize / 1024;
- fileSizeUnit = "MB";
+ fileSize = fileSize / PROGRAMMERS_SECTION;
+ sizeUnit = "MB";
}
- if (fileSize > 1024)
+ if (fileSize > PROGRAMMERS_SECTION)
{
- fileSize = fileSize / 1024;
- fileSizeUnit = "GB";
+ fileSize = fileSize / PROGRAMMERS_SECTION;
+ sizeUnit = "GB";
+ }
+ return fileSize + "" + sizeUnit;*/
+ double last = 1;
+ for (int i = 0; i < suffixes.Length; i++)
+ {
+ var current = Math.Pow(1024, i + 1);
+ var temp = number / current;
+ if (temp < 1)
+ {
+ return (number / last).ToString("n2") + suffixes[i];
+ }
+ last = current;
}
- return fileSize + "" + fileSizeUnit;
+ return number.ToString();
}
///