Skip to content

Commit 73e5727

Browse files
author
JulesG10
committed
initial commit
0 parents  commit 73e5727

21 files changed

+1464
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/PyFFS/build
2+
/FastFileSearch/*.user
3+
*.pyd
4+
*.dll
5+
*.exe
6+
/.vscode

FastFileSearch.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33801.468
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FastFileSearch", "FastFileSearch\FastFileSearch.vcxproj", "{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Debug|x64.ActiveCfg = Debug|x64
17+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Debug|x64.Build.0 = Debug|x64
18+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Debug|x86.ActiveCfg = Debug|Win32
19+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Debug|x86.Build.0 = Debug|Win32
20+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Release|x64.ActiveCfg = Release|x64
21+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Release|x64.Build.0 = Release|x64
22+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Release|x86.ActiveCfg = Release|Win32
23+
{0702CC3B-EFA6-48B3-9F63-004BEC16DAEF}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {CBC3D6EE-F285-44F6-A961-947AE901D6BC}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{0702cc3b-efa6-48b3-9f63-004bec16daef}</ProjectGuid>
25+
<RootNamespace>FastFileSearch</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
<LanguageStandard>stdcpplatest</LanguageStandard>
80+
</ClCompile>
81+
<Link>
82+
<SubSystem>Console</SubSystem>
83+
<GenerateDebugInformation>true</GenerateDebugInformation>
84+
</Link>
85+
</ItemDefinitionGroup>
86+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
87+
<ClCompile>
88+
<WarningLevel>Level3</WarningLevel>
89+
<FunctionLevelLinking>true</FunctionLevelLinking>
90+
<IntrinsicFunctions>true</IntrinsicFunctions>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
<LanguageStandard>stdcpplatest</LanguageStandard>
95+
</ClCompile>
96+
<Link>
97+
<SubSystem>Console</SubSystem>
98+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
99+
<OptimizeReferences>true</OptimizeReferences>
100+
<GenerateDebugInformation>true</GenerateDebugInformation>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<ClCompile>
105+
<WarningLevel>Level3</WarningLevel>
106+
<SDLCheck>true</SDLCheck>
107+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108+
<ConformanceMode>true</ConformanceMode>
109+
<LanguageStandard>stdcpplatest</LanguageStandard>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Console</SubSystem>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
117+
<ClCompile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<FunctionLevelLinking>true</FunctionLevelLinking>
120+
<IntrinsicFunctions>true</IntrinsicFunctions>
121+
<SDLCheck>true</SDLCheck>
122+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123+
<ConformanceMode>true</ConformanceMode>
124+
<LanguageStandard>stdcpplatest</LanguageStandard>
125+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
126+
<Optimization>Full</Optimization>
127+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
128+
</ClCompile>
129+
<Link>
130+
<SubSystem>Console</SubSystem>
131+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
132+
<OptimizeReferences>true</OptimizeReferences>
133+
<GenerateDebugInformation>true</GenerateDebugInformation>
134+
</Link>
135+
</ItemDefinitionGroup>
136+
<ItemGroup>
137+
<ClCompile Include="main.cpp" />
138+
</ItemGroup>
139+
<ItemGroup>
140+
<ClInclude Include="cache.h" />
141+
<ClInclude Include="dfs.h" />
142+
<ClInclude Include="linear.h" />
143+
<ClInclude Include="stdafx.h" />
144+
<ClInclude Include="tree.h" />
145+
<ClInclude Include="util.h" />
146+
<ClInclude Include="index.h" />
147+
</ItemGroup>
148+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
149+
<ImportGroup Label="ExtensionTargets">
150+
</ImportGroup>
151+
</Project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="main.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="index.h">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
<ClInclude Include="util.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
<ClInclude Include="stdafx.h">
30+
<Filter>Header Files</Filter>
31+
</ClInclude>
32+
<ClInclude Include="cache.h">
33+
<Filter>Header Files</Filter>
34+
</ClInclude>
35+
<ClInclude Include="linear.h">
36+
<Filter>Header Files</Filter>
37+
</ClInclude>
38+
<ClInclude Include="tree.h">
39+
<Filter>Header Files</Filter>
40+
</ClInclude>
41+
<ClInclude Include="dfs.h">
42+
<Filter>Header Files</Filter>
43+
</ClInclude>
44+
</ItemGroup>
45+
</Project>

FastFileSearch/cache.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#pragma once
2+
3+
#include "stdafx.h"
4+
#include "util.h"
5+
6+
std::vector<uint8_t> Decode(const std::vector<uint8_t>& data, const size_t outBufferSize = DEFAULT_BUFFER_SIZE) {
7+
BrotliDecoderState* state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
8+
if (state == nullptr) {
9+
return {};
10+
}
11+
12+
std::vector<uint8_t> outputBuffer;
13+
BrotliDecoderResult result = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;
14+
15+
size_t available_in = data.size();
16+
const uint8_t* next_in = data.data();
17+
18+
uint8_t* output = new uint8_t[outBufferSize];
19+
20+
size_t available_out = outBufferSize;
21+
uint8_t* next_out = output;
22+
23+
size_t total_out = 0;
24+
25+
do {
26+
result = BrotliDecoderDecompressStream(state, &available_in, &next_in,
27+
&available_out, &next_out, 0);
28+
29+
if (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {
30+
size_t out_size = (size_t)(next_out - output);
31+
total_out += out_size;
32+
if (out_size == 0) break;
33+
34+
outputBuffer.insert(outputBuffer.end(), output, output + out_size);
35+
36+
available_out = outBufferSize;
37+
next_out = output;
38+
}
39+
else if (result == BROTLI_DECODER_RESULT_SUCCESS) {
40+
break;
41+
}
42+
else {
43+
return {};
44+
}
45+
46+
} while (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
47+
48+
if (output != nullptr) {
49+
delete[] output;
50+
}
51+
52+
return outputBuffer;
53+
}
54+
55+
std::vector<uint8_t> Encode(const std::vector<uint8_t>& data) {
56+
const size_t inputBufferSize = data.size();
57+
const uint8_t* inputBuffer = data.data();
58+
59+
size_t outBufferSize = data.size();
60+
std::vector<uint8_t> outBuffer(outBufferSize);
61+
62+
BrotliEncoderCompress(BROTLI_DEFAULT_QUALITY, BROTLI_DEFAULT_WINDOW,
63+
BrotliEncoderMode::BROTLI_MODE_TEXT, inputBufferSize,
64+
inputBuffer, &outBufferSize, outBuffer.data());
65+
66+
outBuffer.resize(outBufferSize);
67+
return outBuffer;
68+
}
69+
70+
bool ReadCache(const std::string& cache_path, std::vector<uint8_t>& out_cache)
71+
{
72+
std::ifstream ifs(cache_path, std::ios::binary);
73+
74+
if (!ifs.good()) return false;
75+
76+
ifs.seekg(0, std::ios::end);
77+
std::streampos fileSize = ifs.tellg();
78+
ifs.seekg(0, std::ios::beg);
79+
80+
std::vector<uint8_t> encodedData(fileSize);
81+
ifs.read(reinterpret_cast<char*>(encodedData.data()), fileSize);
82+
ifs.close();
83+
84+
out_cache = Decode(encodedData);
85+
encodedData.clear();
86+
87+
return true;
88+
}
89+
90+
bool WriteCache(const std::string& cache_path, std::vector<uint8_t>& in_cache)
91+
{
92+
std::ofstream outfile(cache_path, std::ios::binary);
93+
if (!outfile.good()) return false;
94+
95+
96+
std::vector<uint8_t> encodedData = Encode(in_cache);
97+
outfile.write(reinterpret_cast<const char*>(encodedData.data()), encodedData.size());
98+
outfile.close();
99+
100+
encodedData.clear();
101+
return true;
102+
}

0 commit comments

Comments
 (0)