mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 12:09:18 +08:00
Reduce memory usage.
This commit is contained in:
parent
0b3d028c2f
commit
3045611452
@ -1,9 +1,4 @@
|
|||||||
using System;
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch
|
|
||||||
{
|
{
|
||||||
public class MFTSearchRecord
|
public class MFTSearchRecord
|
||||||
{
|
{
|
||||||
|
@ -2,29 +2,24 @@
|
|||||||
* Thanks to the https://github.com/yiwenshengmei/MyEverything, we can bring MFT search to Wox
|
* Thanks to the https://github.com/yiwenshengmei/MyEverything, we can bring MFT search to Wox
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using MyEverything;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
{
|
{
|
||||||
|
|
||||||
public class MFTSearcher
|
public class MFTSearcher
|
||||||
{
|
{
|
||||||
private static MFTSearcherCache cache = new MFTSearcherCache();
|
private static MFTSearcherCache cache = new MFTSearcherCache();
|
||||||
|
|
||||||
public static void IndexVolume(string volume)
|
private static void IndexVolume(string volume)
|
||||||
{
|
{
|
||||||
List<USNRecord> files;
|
cache.CheckHashTableKey(volume);
|
||||||
List<USNRecord> folders;
|
EnumerateVolume(volume,cache.VolumeRecords[volume]);
|
||||||
EnumerateVolume(volume, out files, out folders);
|
|
||||||
cache.AddRecord(volume, files, USNRecordType.File);
|
|
||||||
cache.AddRecord(volume, folders, USNRecordType.Folder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IndexAllVolumes()
|
public static void IndexAllVolumes()
|
||||||
@ -37,11 +32,7 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
|
|
||||||
public static long IndexedFileCount
|
public static long IndexedFileCount
|
||||||
{
|
{
|
||||||
get { return cache.FileCount; }
|
get { return cache.RecordsCount; }
|
||||||
}
|
|
||||||
public static long IndexedFolderCount
|
|
||||||
{
|
|
||||||
get { return cache.FolderCount; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MFTSearchRecord> Search(string item)
|
public static List<MFTSearchRecord> Search(string item)
|
||||||
@ -53,7 +44,7 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
return found.ConvertAll(o => new MFTSearchRecord(o));
|
return found.ConvertAll(o => new MFTSearchRecord(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddVolumeRootRecord(string volumeName, ref List<USNRecord> folders)
|
private static void AddVolumeRootRecord(string volumeName, Dictionary<ulong, USNRecord> files)
|
||||||
{
|
{
|
||||||
string rightVolumeName = string.Concat("\\\\.\\", volumeName);
|
string rightVolumeName = string.Concat("\\\\.\\", volumeName);
|
||||||
rightVolumeName = string.Concat(rightVolumeName, Path.DirectorySeparatorChar);
|
rightVolumeName = string.Concat(rightVolumeName, Path.DirectorySeparatorChar);
|
||||||
@ -74,7 +65,7 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
UInt64 fileIndexHigh = (UInt64)fi.FileIndexHigh;
|
UInt64 fileIndexHigh = (UInt64)fi.FileIndexHigh;
|
||||||
UInt64 indexRoot = (fileIndexHigh << 32) | fi.FileIndexLow;
|
UInt64 indexRoot = (fileIndexHigh << 32) | fi.FileIndexLow;
|
||||||
|
|
||||||
folders.Add(new USNRecord
|
files.Add(indexRoot,new USNRecord
|
||||||
{
|
{
|
||||||
FRN = indexRoot,
|
FRN = indexRoot,
|
||||||
Name = volumeName,
|
Name = volumeName,
|
||||||
@ -96,20 +87,19 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error()));
|
throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void EnumerateVolume(string volumeName, out List<USNRecord> files, out List<USNRecord> flds)
|
|
||||||
|
private static void EnumerateVolume(string volumeName, Dictionary<ulong, USNRecord> files)
|
||||||
{
|
{
|
||||||
files = new List<USNRecord>();
|
|
||||||
flds = new List<USNRecord>();
|
|
||||||
IntPtr medBuffer = IntPtr.Zero;
|
IntPtr medBuffer = IntPtr.Zero;
|
||||||
IntPtr pVolume = IntPtr.Zero;
|
IntPtr pVolume = IntPtr.Zero;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AddVolumeRootRecord(volumeName, ref flds);
|
AddVolumeRootRecord(volumeName,files);
|
||||||
pVolume = GetVolumeJournalHandle(volumeName);
|
pVolume = GetVolumeJournalHandle(volumeName);
|
||||||
EnableVomuleJournal(pVolume);
|
EnableVomuleJournal(pVolume);
|
||||||
|
|
||||||
SetupMFTEnumInBuffer(ref medBuffer, pVolume);
|
SetupMFTEnumInBuffer(ref medBuffer, pVolume);
|
||||||
EnumerateFiles(volumeName, pVolume, medBuffer, ref files, ref flds);
|
EnumerateFiles(volumeName, pVolume, medBuffer, files);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -134,6 +124,7 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IntPtr GetVolumeJournalHandle(string volumeName)
|
internal static IntPtr GetVolumeJournalHandle(string volumeName)
|
||||||
{
|
{
|
||||||
string vol = string.Concat("\\\\.\\", volumeName);
|
string vol = string.Concat("\\\\.\\", volumeName);
|
||||||
@ -210,7 +201,8 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
throw new IOException("DeviceIoControl() returned false", new Win32Exception(Marshal.GetLastWin32Error()));
|
throw new IOException("DeviceIoControl() returned false", new Win32Exception(Marshal.GetLastWin32Error()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe private static void EnumerateFiles(string volumeName, IntPtr pVolume, IntPtr medBuffer, ref List<USNRecord> files, ref List<USNRecord> folders)
|
|
||||||
|
unsafe private static void EnumerateFiles(string volumeName, IntPtr pVolume, IntPtr medBuffer, Dictionary<ulong, USNRecord> files)
|
||||||
{
|
{
|
||||||
IntPtr pData = Marshal.AllocHGlobal(sizeof(UInt64) + 0x10000);
|
IntPtr pData = Marshal.AllocHGlobal(sizeof(UInt64) + 0x10000);
|
||||||
PInvokeWin32.ZeroMemory(pData, sizeof(UInt64) + 0x10000);
|
PInvokeWin32.ZeroMemory(pData, sizeof(UInt64) + 0x10000);
|
||||||
@ -225,28 +217,14 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
{
|
{
|
||||||
PInvokeWin32.USN_RECORD usn = new PInvokeWin32.USN_RECORD(pUsnRecord);
|
PInvokeWin32.USN_RECORD usn = new PInvokeWin32.USN_RECORD(pUsnRecord);
|
||||||
|
|
||||||
if (usn.IsFolder)
|
files.Add(usn.FRN,new USNRecord
|
||||||
{
|
|
||||||
folders.Add(new USNRecord
|
|
||||||
{
|
{
|
||||||
Name = usn.FileName,
|
Name = usn.FileName,
|
||||||
ParentFrn = usn.ParentFRN,
|
ParentFrn = usn.ParentFRN,
|
||||||
FRN = usn.FRN,
|
FRN = usn.FRN,
|
||||||
IsFolder = true,
|
IsFolder = usn.IsFolder,
|
||||||
VolumeName = volumeName
|
VolumeName = volumeName
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
files.Add(new USNRecord
|
|
||||||
{
|
|
||||||
Name = usn.FileName,
|
|
||||||
ParentFrn = usn.ParentFRN,
|
|
||||||
FRN = usn.FRN,
|
|
||||||
IsFolder = false,
|
|
||||||
VolumeName = volumeName
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pUsnRecord = new IntPtr(pUsnRecord.ToInt32() + usn.RecordLength);
|
pUsnRecord = new IntPtr(pUsnRecord.ToInt32() + usn.RecordLength);
|
||||||
outBytesReturned -= usn.RecordLength;
|
outBytesReturned -= usn.RecordLength;
|
||||||
@ -255,14 +233,16 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
}
|
}
|
||||||
Marshal.FreeHGlobal(pData);
|
Marshal.FreeHGlobal(pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void FillPath(string volume, USNRecord record, MFTSearcherCache db)
|
internal static void FillPath(string volume, USNRecord record, MFTSearcherCache db)
|
||||||
{
|
{
|
||||||
if (record == null) return;
|
if (record == null) return;
|
||||||
var fdSource = db.GetFolderSource(volume);
|
var fdSource = db.GetVolumeRecords(volume);
|
||||||
string fullpath = record.Name;
|
string fullpath = record.Name;
|
||||||
FindRecordPath(record, ref fullpath, fdSource);
|
FindRecordPath(record, ref fullpath, fdSource);
|
||||||
record.FullPath = fullpath;
|
record.FullPath = fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FindRecordPath(USNRecord curRecord, ref string fullpath, Dictionary<ulong, USNRecord> fdSource)
|
private static void FindRecordPath(USNRecord curRecord, ref string fullpath, Dictionary<ulong, USNRecord> fdSource)
|
||||||
{
|
{
|
||||||
if (curRecord.IsVolumeRoot) return;
|
if (curRecord.IsVolumeRoot) return;
|
||||||
|
@ -1,59 +1,45 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MyEverything;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
{
|
{
|
||||||
internal class MFTSearcherCache
|
internal class MFTSearcherCache
|
||||||
{
|
{
|
||||||
private Dictionary<string, Dictionary<ulong, USNRecord>> _volumes_files = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
public Dictionary<string, Dictionary<ulong, USNRecord>> VolumeRecords = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
||||||
private Dictionary<string, Dictionary<ulong, USNRecord>> _volumes_folders = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
|
||||||
|
|
||||||
public MFTSearcherCache() { }
|
public MFTSearcherCache() { }
|
||||||
|
|
||||||
public bool ContainsVolume(string volume)
|
public bool ContainsVolume(string volume)
|
||||||
{
|
{
|
||||||
return _volumes_files.ContainsKey(volume) && _volumes_folders.ContainsKey(volume);
|
return VolumeRecords.ContainsKey(volume);
|
||||||
}
|
}
|
||||||
public void AddRecord(string volume, List<USNRecord> r, USNRecordType type)
|
|
||||||
|
public void AddRecord(string volume, List<USNRecord> r)
|
||||||
{
|
{
|
||||||
if (type == USNRecordType.File)
|
CheckHashTableKey(volume);
|
||||||
|
r.ForEach(x => VolumeRecords[volume].Add(x.FRN, x));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRecord(string volume, USNRecord record)
|
||||||
{
|
{
|
||||||
CheckHashTableKey(_volumes_files, volume);
|
CheckHashTableKey(volume);
|
||||||
r.ForEach(x => _volumes_files[volume].Add(x.FRN, x));
|
VolumeRecords[volume].Add(record.FRN, record);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
public void CheckHashTableKey(string volume)
|
||||||
{
|
{
|
||||||
CheckHashTableKey(_volumes_folders, volume);
|
if (!VolumeRecords.ContainsKey(volume))
|
||||||
r.ForEach(x => _volumes_folders[volume].Add(x.FRN, x));
|
VolumeRecords.Add(volume, new Dictionary<ulong, USNRecord>());
|
||||||
}
|
|
||||||
}
|
|
||||||
public void AddRecord(string volume, USNRecord record, USNRecordType type)
|
|
||||||
{
|
|
||||||
if (type == USNRecordType.File)
|
|
||||||
{
|
|
||||||
CheckHashTableKey(_volumes_files, volume);
|
|
||||||
_volumes_files[volume].Add(record.FRN, record);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CheckHashTableKey(_volumes_folders, volume);
|
|
||||||
_volumes_folders[volume].Add(record.FRN, record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void CheckHashTableKey(Dictionary<string, Dictionary<ulong, USNRecord>> hashtable, string key)
|
|
||||||
{
|
|
||||||
if (!hashtable.ContainsKey(key))
|
|
||||||
hashtable.Add(key, new Dictionary<ulong, USNRecord>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeleteRecord(string volume, ulong frn)
|
public bool DeleteRecord(string volume, ulong frn)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
result = DeleteRecordHashTableItem(_volumes_files, volume, frn);
|
result = DeleteRecordHashTableItem(VolumeRecords, volume, frn);
|
||||||
if (!result) result = DeleteRecordHashTableItem(_volumes_folders, volume, frn);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DeleteRecordHashTableItem(Dictionary<string, Dictionary<ulong, USNRecord>> hashtable, string volume, ulong frn)
|
private bool DeleteRecordHashTableItem(Dictionary<string, Dictionary<ulong, USNRecord>> hashtable, string volume, ulong frn)
|
||||||
{
|
{
|
||||||
if (hashtable.ContainsKey(volume) && hashtable[volume].ContainsKey(frn))
|
if (hashtable.ContainsKey(volume) && hashtable[volume].ContainsKey(frn))
|
||||||
@ -66,13 +52,12 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void UpdateRecord(string volume, USNRecord record, USNRecordType type)
|
|
||||||
|
public void UpdateRecord(string volume, USNRecord record)
|
||||||
{
|
{
|
||||||
if (type == USNRecordType.File)
|
RealUpdateRecord(volume, VolumeRecords, record);
|
||||||
RealUpdateRecord(volume, _volumes_files, record);
|
|
||||||
else
|
|
||||||
RealUpdateRecord(volume, _volumes_folders, record);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RealUpdateRecord(string volume, Dictionary<string, Dictionary<ulong, USNRecord>> source, USNRecord record)
|
private bool RealUpdateRecord(string volume, Dictionary<string, Dictionary<ulong, USNRecord>> source, USNRecord record)
|
||||||
{
|
{
|
||||||
if (source.ContainsKey(volume) && source[volume].ContainsKey(record.FRN))
|
if (source.ContainsKey(volume) && source[volume].ContainsKey(record.FRN))
|
||||||
@ -85,48 +70,40 @@ namespace Wox.Infrastructure.MFTSearch
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<USNRecord> FindByName(string filename)
|
public List<USNRecord> FindByName(string filename)
|
||||||
{
|
{
|
||||||
filename = filename.ToLower();
|
filename = filename.ToLower();
|
||||||
var fileQuery = from filesInVolumeDic in _volumes_files.Values
|
var fileQuery = from filesInVolumeDic in VolumeRecords.Values
|
||||||
from eachFilePair in filesInVolumeDic
|
from eachFilePair in filesInVolumeDic
|
||||||
where eachFilePair.Value.Name.ToLower().Contains(filename)
|
where eachFilePair.Value.Name.ToLower().Contains(filename)
|
||||||
select eachFilePair.Value;
|
select eachFilePair.Value;
|
||||||
|
|
||||||
var folderQuery = from fldsInVolumeDic in _volumes_folders.Values
|
|
||||||
from eachFldPair in fldsInVolumeDic
|
|
||||||
where eachFldPair.Value.Name.ToLower().Contains(filename)
|
|
||||||
select eachFldPair.Value;
|
|
||||||
|
|
||||||
List<USNRecord> result = new List<USNRecord>();
|
List<USNRecord> result = new List<USNRecord>();
|
||||||
|
|
||||||
result.AddRange(fileQuery);
|
result.AddRange(fileQuery);
|
||||||
result.AddRange(folderQuery);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public USNRecord FindByFrn(string volume, ulong frn)
|
public USNRecord FindByFrn(string volume, ulong frn)
|
||||||
{
|
{
|
||||||
if ((!_volumes_files.ContainsKey(volume)) || (!_volumes_folders.ContainsKey(volume)))
|
if ((!VolumeRecords.ContainsKey(volume)))
|
||||||
throw new Exception(string.Format("DB not contain the volume: {0}", volume));
|
throw new Exception(string.Format("DB not contain the volume: {0}", volume));
|
||||||
USNRecord result = null;
|
USNRecord result = null;
|
||||||
_volumes_files[volume].TryGetValue(frn, out result);
|
VolumeRecords[volume].TryGetValue(frn, out result);
|
||||||
if (result != null) return result;
|
|
||||||
_volumes_folders[volume].TryGetValue(frn, out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public long FileCount
|
|
||||||
|
public long RecordsCount
|
||||||
{
|
{
|
||||||
get { return _volumes_files.Sum(x => x.Value.Count); }
|
get { return VolumeRecords.Sum(x => x.Value.Count); }
|
||||||
}
|
}
|
||||||
public long FolderCount
|
|
||||||
{
|
public Dictionary<ulong, USNRecord> GetVolumeRecords(string volume)
|
||||||
get { return _volumes_folders.Sum(x => x.Value.Count); }
|
|
||||||
}
|
|
||||||
public Dictionary<ulong, USNRecord> GetFolderSource(string volume)
|
|
||||||
{
|
{
|
||||||
Dictionary<ulong, USNRecord> result = null;
|
Dictionary<ulong, USNRecord> result = null;
|
||||||
_volumes_folders.TryGetValue(volume, out result);
|
VolumeRecords.TryGetValue(volume, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch {
|
namespace Wox.Plugin.FindFile.MFTSearch {
|
||||||
public class PInvokeWin32
|
public class PInvokeWin32
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
{
|
{
|
||||||
internal class USNChangeReason
|
internal class USNChangeReason
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using MyEverything;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.MFTSearch
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
{
|
{
|
||||||
public class USNRecord
|
public class USNRecord
|
||||||
{
|
{
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
namespace Wox.Infrastructure.MFTSearch
|
|
||||||
{
|
|
||||||
internal enum USNRecordType
|
|
||||||
{
|
|
||||||
File,
|
|
||||||
Folder
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using Wox.Infrastructure.MFTSearch;
|
|
||||||
|
|
||||||
namespace MyEverything
|
namespace Wox.Plugin.FindFile.MFTSearch
|
||||||
{
|
{
|
||||||
internal class VolumeMonitor
|
internal class VolumeMonitor
|
||||||
{
|
{
|
||||||
|
|
||||||
public Action<USNRecord> RecordAddedEvent;
|
public Action<USNRecord> RecordAddedEvent;
|
||||||
public Action<USNRecord> RecordDeletedEvent;
|
public Action<USNRecord> RecordDeletedEvent;
|
||||||
public Action<USNRecord, USNRecord> RecordRenameEvent;
|
public Action<USNRecord, USNRecord> RecordRenameEvent;
|
||||||
@ -32,7 +27,7 @@ namespace MyEverything
|
|||||||
IntPtr pMonitorVolume = MFTSearcher.GetVolumeJournalHandle(volume);
|
IntPtr pMonitorVolume = MFTSearcher.GetVolumeJournalHandle(volume);
|
||||||
uint bytesReturned = 0;
|
uint bytesReturned = 0;
|
||||||
PInvokeWin32.USN_JOURNAL_DATA ujd = new PInvokeWin32.USN_JOURNAL_DATA();
|
PInvokeWin32.USN_JOURNAL_DATA ujd = new PInvokeWin32.USN_JOURNAL_DATA();
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.QueryUSNJournal(pMonitorVolume, out ujd, out bytesReturned);
|
MFTSearcher.QueryUSNJournal(pMonitorVolume, out ujd, out bytesReturned);
|
||||||
|
|
||||||
// 构建输入参数
|
// 构建输入参数
|
||||||
PInvokeWin32.READ_USN_JOURNAL_DATA rujd = new PInvokeWin32.READ_USN_JOURNAL_DATA();
|
PInvokeWin32.READ_USN_JOURNAL_DATA rujd = new PInvokeWin32.READ_USN_JOURNAL_DATA();
|
||||||
@ -62,7 +57,7 @@ namespace MyEverything
|
|||||||
Marshal.StructureToPtr(rujd, prujd, true);
|
Marshal.StructureToPtr(rujd, prujd, true);
|
||||||
|
|
||||||
Debug.WriteLine(string.Format("\nMoniting on {0}......", volume));
|
Debug.WriteLine(string.Format("\nMoniting on {0}......", volume));
|
||||||
IntPtr pVolume = Wox.Infrastructure.MFTSearch.MFTSearcher.GetVolumeJournalHandle(volume);
|
IntPtr pVolume = MFTSearcher.GetVolumeJournalHandle(volume);
|
||||||
|
|
||||||
bool fok = PInvokeWin32.DeviceIoControl(pVolume,
|
bool fok = PInvokeWin32.DeviceIoControl(pVolume,
|
||||||
PInvokeWin32.FSCTL_READ_USN_JOURNAL,
|
PInvokeWin32.FSCTL_READ_USN_JOURNAL,
|
||||||
@ -89,7 +84,7 @@ namespace MyEverything
|
|||||||
private void ProcessUSN(PInvokeWin32.USN_RECORD usn, string volume, MFTSearcherCache db)
|
private void ProcessUSN(PInvokeWin32.USN_RECORD usn, string volume, MFTSearcherCache db)
|
||||||
{
|
{
|
||||||
var dbCached = db.FindByFrn(volume, usn.FRN);
|
var dbCached = db.FindByFrn(volume, usn.FRN);
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.FillPath(volume, dbCached, db);
|
MFTSearcher.FillPath(volume, dbCached, db);
|
||||||
Debug.WriteLine(string.Format("------USN[frn={0}]------", usn.FRN));
|
Debug.WriteLine(string.Format("------USN[frn={0}]------", usn.FRN));
|
||||||
Debug.WriteLine(string.Format("FileName={0}, USNChangeReason={1}", usn.FileName, USNChangeReason.ReasonPrettyFormat(usn.Reason)));
|
Debug.WriteLine(string.Format("FileName={0}, USNChangeReason={1}", usn.FileName, USNChangeReason.ReasonPrettyFormat(usn.Reason)));
|
||||||
Debug.WriteLine(string.Format("FileName[Cached]={0}", dbCached == null ? "NoCache" : dbCached.FullPath));
|
Debug.WriteLine(string.Format("FileName[Cached]={0}", dbCached == null ? "NoCache" : dbCached.FullPath));
|
||||||
@ -111,7 +106,7 @@ namespace MyEverything
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.FillPath(volume, cached, db);
|
MFTSearcher.FillPath(volume, cached, db);
|
||||||
var deleteok = db.DeleteRecord(volume, usn.FRN);
|
var deleteok = db.DeleteRecord(volume, usn.FRN);
|
||||||
Debug.WriteLine(string.Format(">>>> File {0} deleted {1}.", cached.FullPath, deleteok ? "successful" : "fail"));
|
Debug.WriteLine(string.Format(">>>> File {0} deleted {1}.", cached.FullPath, deleteok ? "successful" : "fail"));
|
||||||
if (RecordDeletedEvent != null)
|
if (RecordDeletedEvent != null)
|
||||||
@ -122,14 +117,13 @@ namespace MyEverything
|
|||||||
{
|
{
|
||||||
USNRecord newRecord = USNRecord.ParseUSN(volume, usn);
|
USNRecord newRecord = USNRecord.ParseUSN(volume, usn);
|
||||||
//string fullpath = newRecord.Name;
|
//string fullpath = newRecord.Name;
|
||||||
//db.FindRecordPath(newRecord, ref fullpath, db.GetFolderSource(volume));
|
//db.FindRecordPath(newRecord, ref fullpath, db.GetVolumeRecords(volume));
|
||||||
//newRecord.FullPath = fullpath;
|
//newRecord.FullPath = fullpath;
|
||||||
var oldRecord = db.FindByFrn(volume, usn.FRN);
|
var oldRecord = db.FindByFrn(volume, usn.FRN);
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.FillPath(volume, oldRecord, db);
|
MFTSearcher.FillPath(volume, oldRecord, db);
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.FillPath(volume, newRecord, db);
|
MFTSearcher.FillPath(volume, newRecord, db);
|
||||||
Debug.WriteLine(string.Format(">>>> RenameFile {0} to {1}", oldRecord.FullPath, newRecord.FullPath));
|
Debug.WriteLine(string.Format(">>>> RenameFile {0} to {1}", oldRecord.FullPath, newRecord.FullPath));
|
||||||
db.UpdateRecord(volume, newRecord,
|
db.UpdateRecord(volume, newRecord);
|
||||||
usn.IsFolder ? USNRecordType.Folder : USNRecordType.File);
|
|
||||||
if (RecordRenameEvent != null) RecordRenameEvent(oldRecord, newRecord);
|
if (RecordRenameEvent != null) RecordRenameEvent(oldRecord, newRecord);
|
||||||
if (newRecord.FullPath.Contains("$RECYCLE.BIN"))
|
if (newRecord.FullPath.Contains("$RECYCLE.BIN"))
|
||||||
{
|
{
|
||||||
@ -140,10 +134,10 @@ namespace MyEverything
|
|||||||
{
|
{
|
||||||
USNRecord record = USNRecord.ParseUSN(volume, usn);
|
USNRecord record = USNRecord.ParseUSN(volume, usn);
|
||||||
//string fullpath = record.Name;
|
//string fullpath = record.Name;
|
||||||
//db.FindRecordPath(record, ref fullpath, db.GetFolderSource(volume));
|
//db.FindRecordPath(record, ref fullpath, db.GetVolumeRecords(volume));
|
||||||
//record.FullPath = fullpath;
|
//record.FullPath = fullpath;
|
||||||
db.AddRecord(volume, record, usn.IsFolder ? USNRecordType.Folder : USNRecordType.File);
|
db.AddRecord(volume, record);
|
||||||
Wox.Infrastructure.MFTSearch.MFTSearcher.FillPath(volume, record, db);
|
MFTSearcher.FillPath(volume, record, db);
|
||||||
Debug.WriteLine(string.Format(">>>> NewFile: {0}", record.FullPath));
|
Debug.WriteLine(string.Format(">>>> NewFile: {0}", record.FullPath));
|
||||||
if (RecordAddedEvent != null)
|
if (RecordAddedEvent != null)
|
||||||
RecordAddedEvent(record);
|
RecordAddedEvent(record);
|
||||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
|||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.MFTSearch;
|
using Wox.Plugin.FindFile.MFTSearch;
|
||||||
|
|
||||||
namespace Wox.Plugin.FindFile
|
namespace Wox.Plugin.FindFile
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
<Compile Include="MFTSearch\PInvokeWin32.cs" />
|
<Compile Include="MFTSearch\PInvokeWin32.cs" />
|
||||||
<Compile Include="MFTSearch\USNChangeReason.cs" />
|
<Compile Include="MFTSearch\USNChangeReason.cs" />
|
||||||
<Compile Include="MFTSearch\USNRecord.cs" />
|
<Compile Include="MFTSearch\USNRecord.cs" />
|
||||||
<Compile Include="MFTSearch\USNRecordType.cs" />
|
|
||||||
<Compile Include="MFTSearch\VolumeMonitor.cs" />
|
<Compile Include="MFTSearch\VolumeMonitor.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Wox.Infrastructure.MFTSearch;
|
using Wox.Plugin.FindFile.MFTSearch;
|
||||||
|
|
||||||
namespace Wox.Test
|
namespace Wox.Test
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user