FileView: Change wildcard matching to use PathMatchSpec

This commit is contained in:
Birunthan Mohanathas 2013-06-03 18:40:37 +03:00
parent 7cdd6853aa
commit 68dce478d5
3 changed files with 14 additions and 40 deletions

View File

@ -44,7 +44,6 @@ typedef struct // 22 bytes
#pragma pack(pop)
unsigned __stdcall SystemThreadProc(void* pParam);
void EscapeRegex(std::wstring& regex);
void GetFolderInfo(std::queue<std::wstring>& folderQueue, std::wstring& folder, ParentMeasure* parent, RecursiveType rType);
void GetIcon(std::wstring filePath, const std::wstring& iconPath, IconSize iconSize);
HRESULT SaveIcon(HICON hIcon, FILE* fp);
@ -741,11 +740,6 @@ unsigned __stdcall SystemThreadProc(void* pParam)
std::wstring folder = tmp->path;
RecursiveType rType = tmp->recursiveType;
if (rType == RECURSIVE_FULL && tmp->wildcardSearch != L"*")
{
EscapeRegex(tmp->wildcardSearch);
}
GetFolderInfo(folderQueue, folder, tmp, (rType == RECURSIVE_PARTIAL) ? RECURSIVE_NONE : rType);
while (rType != RECURSIVE_NONE && !folderQueue.empty())
@ -912,37 +906,6 @@ unsigned __stdcall SystemThreadProc(void* pParam)
return 0;
}
void EscapeRegex(std::wstring& regex)
{
auto replace = [&regex](std::wstring from, std::wstring to)
{
size_t start = 0;
while ((start = regex.find(from, start)) != std::wstring::npos)
{
regex.replace(start, from.size(), to);
start += to.size();
}
};
replace(L"\\", L"\\\\");
replace(L"^", L"\\^");
replace(L"$", L"\\$");
replace(L"|", L"\\|");
replace(L"(", L"\\(");
replace(L")", L"\\)");
replace(L"[", L"\\[");
replace(L"]", L"\\]");
replace(L".", L"\\.");
replace(L"+", L"\\+");
replace(L"/", L"\\/");
replace(L"&", L"\\&");
replace(L"{", L"\\{");
replace(L"}", L"\\}");
replace(L"*", L".*");
replace(L"?", L".");
}
void GetFolderInfo(std::queue<std::wstring>& folderQueue, std::wstring& folder, ParentMeasure* parent, RecursiveType rType)
{
std::wstring path = folder;
@ -969,8 +932,7 @@ void GetFolderInfo(std::queue<std::wstring>& folderQueue, std::wstring& folder,
if (rType == RECURSIVE_FULL && parent->wildcardSearch != L"*" && !file.isFolder)
{
std::wregex pattern(parent->wildcardSearch, std::wregex::icase | std::wregex::optimize);
if (!std::regex_match(file.fileName, pattern))
if (!PathMatchSpec(file.fileName.c_str(), parent->wildcardSearch.c_str()))
{
continue;
}

View File

@ -23,6 +23,9 @@
</ClCompile>
<Link>
</Link>
<Link>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -31,6 +34,9 @@
</ClCompile>
<Link>
</Link>
<Link>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -39,6 +45,9 @@
</ClCompile>
<Link>
</Link>
<Link>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@ -47,6 +56,9 @@
</ClCompile>
<Link>
</Link>
<Link>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="PluginFileView.h" />

View File

@ -24,12 +24,12 @@
#include <commctrl.h>
#include <commoncontrols.h>
#include <process.h>
#include <Shlwapi.h>
// STL
#include <string>
#include <vector>
#include <queue>
#include <regex>
#include <algorithm>
// Rainmeter API