PowerToys/Wox.Infrastructure/MFTSearch/MFTSearcherCache.cs

61 lines
1.6 KiB
C#
Raw Normal View History

2014-10-22 18:36:49 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace Wox.Infrastructure.MFTSearch
{
internal class MFTSearcherCache
{
2014-10-23 18:39:11 +08:00
private Dictionary<ulong, USNRecord> records = new Dictionary<ulong, USNRecord>(100000);
private Lookup<string, string> recordsLookup;
2014-10-22 18:36:49 +08:00
public MFTSearcherCache() { }
2014-10-23 18:39:11 +08:00
public void AddRecord(List<USNRecord> record)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
record.ForEach(AddRecord);
2014-10-22 18:36:49 +08:00
}
2014-10-23 18:39:11 +08:00
public void AddRecord(USNRecord record)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
if(!records.ContainsKey(record.FRN)) records.Add(record.FRN, record);
2014-10-22 18:36:49 +08:00
}
2014-10-23 18:39:11 +08:00
public bool DeleteRecord(ulong frn)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
return records.Remove(frn);
2014-10-22 18:36:49 +08:00
}
2014-10-23 18:39:11 +08:00
public void UpdateRecord(USNRecord record)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
USNRecord firstOrDefault = records[record.FRN];
if (firstOrDefault != null)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
firstOrDefault.Name = record.Name;
firstOrDefault.FullPath = record.FullPath;
firstOrDefault.VolumeName = record.VolumeName;
2014-10-22 18:36:49 +08:00
}
}
2014-10-23 18:39:11 +08:00
public List<USNRecord> FindByName(string filename)
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
filename = filename.ToLower();
var query = from file in records.Values
where file.Name.ToLower().Contains(filename)
select file;
return query.ToList();
2014-10-22 18:36:49 +08:00
}
2014-10-23 18:39:11 +08:00
public long RecordsCount
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
get { return records.Count; }
2014-10-22 18:36:49 +08:00
}
2014-10-23 18:39:11 +08:00
public Dictionary<ulong, USNRecord> GetAllRecords()
2014-10-22 18:36:49 +08:00
{
2014-10-23 18:39:11 +08:00
return records;
2014-10-22 18:36:49 +08:00
}
}
}