Add find file plugin.

This commit is contained in:
qianlifeng
2014-10-22 22:49:34 +08:00
parent 581423a87c
commit 80e38fc430
23 changed files with 478 additions and 203 deletions

View File

@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@@ -30,13 +31,26 @@ namespace Wox.Infrastructure.MFTSearch
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
IndexVolume(drive.VolumeLabel);
IndexVolume(drive.Name.Replace("\\", ""));
}
}
public static long IndexedFileCount
{
get { return cache.FileCount; }
}
public static long IndexedFolderCount
{
get { return cache.FolderCount; }
}
public static List<MFTSearchRecord> Search(string item)
{
return null;
if (string.IsNullOrEmpty(item)) return new List<MFTSearchRecord>();
List<USNRecord> found = cache.FindByName(item);
found.ForEach(x => FillPath(x.VolumeName, x, cache));
return found.ConvertAll(o => new MFTSearchRecord(o));
}
private static void AddVolumeRootRecord(string volumeName, ref List<USNRecord> folders)

View File

@@ -85,22 +85,19 @@ namespace Wox.Infrastructure.MFTSearch
return false;
}
}
public List<USNRecord> FindByName(string filename, out long foundFileCnt, out long fountFolderCnt)
public List<USNRecord> FindByName(string filename)
{
filename = filename.ToLower();
var fileQuery = from filesInVolumeDic in _volumes_files.Values
from eachFilePair in filesInVolumeDic
where eachFilePair.Value.Name.Contains(filename)
where eachFilePair.Value.Name.ToLower().Contains(filename)
select eachFilePair.Value;
var folderQuery = from fldsInVolumeDic in _volumes_folders.Values
from eachFldPair in fldsInVolumeDic
where eachFldPair.Value.Name.Contains(filename)
where eachFldPair.Value.Name.ToLower().Contains(filename)
select eachFldPair.Value;
foundFileCnt = fileQuery.Count();
fountFolderCnt = folderQuery.Count();
List<USNRecord> result = new List<USNRecord>();
result.AddRange(fileQuery);