Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,438 changes: 1,322 additions & 1,116 deletions FileSearch/CDriveIndex.cpp

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions FileSearch/CDriveIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Credits for original code this is based on: Jeffrey Cooperstein & Jeffrey Richte
#include <WinIoCtl.h>
#include <stdio.h>
#include <sstream>
#include <hash_map>
#include <unordered_map>
#include "tinyxml2.h"

using namespace std;

#define NO_WHERE 0
Expand Down Expand Up @@ -133,36 +135,41 @@ struct SearchResult
}
};
class CDriveIndex {
public:
enum ExportFormat {ExportFormatAdcXml, ExportFormatAdcXml_LZ4};

public:
CDriveIndex();
CDriveIndex(wstring &strPath);
~CDriveIndex();
BOOL Init(WCHAR cDrive);
int Find(wstring *strQuery, wstring *strPath, vector<SearchResultFile> *rgsrfResults, BOOL bSort = true, BOOL bEnhancedSearch = true, int maxResults = -1);
void PopulateIndex();
BOOL SaveToDisk(wstring &strPath);
DriveInfo GetInfo();
BOOL SaveToDisk(wstring &strPath) const;
BOOL ExportToFileListing(wstring &strPath, int format) const;
DriveInfo GetInfo() const;

protected:
BOOL Empty();
HANDLE Open(WCHAR cDriveLetter, DWORD dwAccess);
BOOL Create(DWORDLONG MaximumSize, DWORDLONG AllocationDelta);
BOOL Query(PUSN_JOURNAL_DATA pUsnJournalData);
BOOL Query(PUSN_JOURNAL_DATA pUsnJournalData) const;
void FindRecursively(wstring &strQuery, const WCHAR* &szQueryLower, DWORDLONG QueryFilter, DWORDLONG QueryLength, wstring * strQueryPath, vector<SearchResultFile> &rgsrfResults, BOOL bEnhancedSearch, int maxResults, int &nResults);
template <class T>
void FindInJournal(wstring &strQuery, const WCHAR* &szQueryLower, DWORDLONG QueryFilter, DWORDLONG QueryLength, wstring * strQueryPath, vector<T> &rgJournalIndex, vector<SearchResultFile> &rgsrfResults, unsigned int iOffset, BOOL bEnhancedSearch, int maxResults, int &nResults);
void FindInPreviousResults(wstring &strQuery, const WCHAR* &szQueryLower, DWORDLONG QueryFilter, DWORDLONG QueryLength, wstring * strQueryPath, vector<SearchResultFile> &rgsrfResults, unsigned int iOffset, BOOL bEnhancedSearch, int maxResults, int &nResults);
void attach(vector<tinyxml2::XMLHandle> &dirHandles, unordered_map<DWORDLONG, vector<tinyxml2::XMLHandle>::size_type> &umDirFrnToHandle, int NodeType, DWORDLONG Index) const;

INT64 FindOffsetByIndex(DWORDLONG Index);
INT64 FindDirOffsetByIndex(DWORDLONG Index);
DWORDLONG MakeFilter(wstring *szName);
USNEntry FRNToName(DWORDLONG FRN);
USNEntry FRNToName(DWORDLONG FRN) const;
void CleanUp();
BOOL Add(DWORDLONG Index, wstring *szName, DWORDLONG ParentIndex, DWORDLONG Address = 0);
BOOL AddDir(DWORDLONG Index, wstring *szName, DWORDLONG ParentIndex, DWORDLONG Address = 0);
BOOL Get(DWORDLONG Index, wstring *sz);
BOOL GetDir(DWORDLONG Index, wstring *sz);
unsigned int GetParentDirectory(DWORDLONG Index);
BOOL Get(DWORDLONG Index, wstring *sz) const;
BOOL GetDir(DWORDLONG Index, wstring *sz) const;
//unsigned int GetParentDirectory(DWORDLONG Index);
void ClearLastResult();
// Members used to enumerate journal records
HANDLE m_hVol; // handle to volume
Expand All @@ -184,4 +191,6 @@ WCHAR* _stdcall Search(CDriveIndex *di, WCHAR *szQuery, WCHAR *szPath, BOOL bSor
void _stdcall FreeResultsBuffer(WCHAR *szResults);
BOOL _stdcall SaveIndexToDisk(CDriveIndex *di, WCHAR *szPath);
CDriveIndex* _stdcall LoadIndexFromDisk(WCHAR *szPath);
void _stdcall GetDriveInfo(CDriveIndex *di, DriveInfo *driveInfo);
void _stdcall GetDriveInfo(CDriveIndex *di, DriveInfo *driveInfo);
BOOL _stdcall SaveIndexToDisk(CDriveIndex *di, WCHAR *szPath);
BOOL _stdcall ExportIndex(CDriveIndex *di, WCHAR *szPath, int format);
3 changes: 2 additions & 1 deletion FileSearch/FileSearch.def
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ EXPORTS
FreeResultsBuffer @4
LoadIndexFromDisk @5
SaveIndexToDisk @6
GetDriveInfo @7
GetDriveInfo @7
ExportIndex @8
30 changes: 28 additions & 2 deletions FileSearch/FileSearch.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -28,23 +28,27 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -73,6 +77,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -144,8 +149,11 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="CDriveIndex.h" />
<ClInclude Include="lz4.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="stxutif.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="tinyxml2.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -163,12 +171,30 @@
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="CDriveIndex.cpp" />
<ClCompile Include="gel.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="lz4.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="tinyxml2.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
18 changes: 18 additions & 0 deletions FileSearch/FileSearch.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<ClInclude Include="CDriveIndex.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="stxutif.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="tinyxml2.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="lz4.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand All @@ -41,5 +50,14 @@
<ClCompile Include="CDriveIndex.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="gel.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="tinyxml2.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="lz4.c">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>
22 changes: 17 additions & 5 deletions FileSearch/FileSearch.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>$(OutDir)Exportall.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\Program Files\Autohotkey\Autohotkey.exe</LocalDebuggerCommand>
<LocalDebuggerCommand>C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>$(OutDir)FileSearchTest.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>$(OutDir)Exportall.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Program Files\Autohotkey\AutoHotkey.exe</LocalDebuggerCommand>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommand>C:\Program Files\AutoHotkey\AutoHotkey.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>$(OutDir)Exportall.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommand>C:\Program Files\AutoHotkey\AutoHotkey.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>$(OutDir)FileSearchTest.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>$(OutDir)Exportall.ahk</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
</Project>
38 changes: 38 additions & 0 deletions FileSearch/gel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "stxutif.h"
#include <codecvt>

#ifdef __MINGW32_VERSION
#ifndef _GLIBCXX_USE_WCHAR_T

namespace std
{
//instantiate the codecvt facet id for the required types
locale::id codecvt<wchar_t,char,mbstate_t>::id;
}

#endif //_GLIBCXX_USE_WCHAR_T
#endif //__MINGW32_VERSION


namespace gel
{namespace stdx
{
#if 0
//instantiate the global locale
std::locale utf8_locale(std::locale(), new std::codecvt_utf8<wchar_t>()); // VS2010 and further

// convert wstring to UTF-8 string
std::string wstring_to_utf8 (const std::wstring& str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.to_bytes(str);
}
#else

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
std::string wstring_to_utf8(const std::wstring& str) {
return conversion.to_bytes(str);
}

#endif

}}
Loading