diff --git a/Plugins/PluginFileView/PluginFileView.cpp b/Plugins/PluginFileView/PluginFileView.cpp index 6df03db8..573b394e 100644 --- a/Plugins/PluginFileView/PluginFileView.cpp +++ b/Plugins/PluginFileView/PluginFileView.cpp @@ -44,6 +44,7 @@ typedef struct // 22 bytes #pragma pack(pop) unsigned __stdcall SystemThreadProc(void* pParam); +void EscapeRegex(std::wstring& regex); void GetFolderInfo(std::queue& folderQueue, std::wstring& folder, ParentMeasure* parent, RecursiveType rType); void GetIcon(std::wstring filePath, std::wstring iconPath, IconSize iconSize); HRESULT SaveIcon(HICON hIcon, FILE* fp); @@ -729,6 +730,11 @@ 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()) @@ -893,10 +899,41 @@ unsigned __stdcall SystemThreadProc(void* pParam) return 0; } +void EscapeRegex(std::wstring& regex) +{ + auto replace = [®ex](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& folderQueue, std::wstring& folder, ParentMeasure* parent, RecursiveType rType) { std::wstring path = folder; - folder += (rType == RECURSIVE_PARTIAL) ? L"*" : parent->wildcardSearch; + folder += (rType == RECURSIVE_NONE) ? parent->wildcardSearch : L"*"; WIN32_FIND_DATA fd; HANDLE find = FindFirstFileEx(folder.c_str(), FindExInfoStandard, &fd, FindExSearchNameMatch, nullptr, 0); @@ -917,6 +954,15 @@ void GetFolderInfo(std::queue& folderQueue, std::wstring& folder, bool isHidden = (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) > 0; bool isSystem = (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) > 0; + 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)) + { + continue; + } + } + if ((rType != RECURSIVE_PARTIAL) && ((rType != RECURSIVE_FULL && !parent->showFile && !file.isFolder) || (rType != RECURSIVE_FULL && !parent->showFolder && file.isFolder) || diff --git a/Plugins/PluginFileView/PluginFileView.rc b/Plugins/PluginFileView/PluginFileView.rc index 7a8759f2..ce8d03c8 100644 --- a/Plugins/PluginFileView/PluginFileView.rc +++ b/Plugins/PluginFileView/PluginFileView.rc @@ -7,7 +7,7 @@ // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,0,0,0 + FILEVERSION 2,0,1,0 PRODUCTVERSION PRODUCTVER FILEFLAGSMASK 0x17L #ifdef _DEBUG @@ -23,7 +23,7 @@ VS_VERSION_INFO VERSIONINFO { BLOCK "040904E4" { - VALUE "FileVersion", "2.0.0.0" + VALUE "FileVersion", "2.0.1.0" VALUE "LegalCopyright", "© 2012 - Brian Ferguson" VALUE "ProductName", "Rainmeter" #ifdef _WIN64 diff --git a/Plugins/PluginFileView/StdAfx.h b/Plugins/PluginFileView/StdAfx.h index ef133e4d..cd0b274b 100644 --- a/Plugins/PluginFileView/StdAfx.h +++ b/Plugins/PluginFileView/StdAfx.h @@ -29,6 +29,7 @@ #include #include #include +#include #include // Rainmeter API