|
@@ -25,6 +25,7 @@
|
|
|
#include "../util/CritSect.h"
|
|
|
#include "../util/Dictionary.h"
|
|
|
#include "../util/HashSet.h"
|
|
|
+#include "../../third_party/putty/wildcard.h"
|
|
|
|
|
|
#include "util/AllocDebug.h"
|
|
|
|
|
@@ -3485,6 +3486,7 @@ struct BfpFindFileData
|
|
|
{
|
|
|
BfpFindFileFlags mFlags;
|
|
|
WIN32_FIND_DATA mFindData;
|
|
|
+ Beefy::String mWildcard;
|
|
|
HANDLE mHandle;
|
|
|
};
|
|
|
|
|
@@ -3496,29 +3498,43 @@ static bool BfpFindFileData_CheckFilter(BfpFindFileData* findData)
|
|
|
bool isDir = (findData->mFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
|
if (isDir)
|
|
|
{
|
|
|
- if ((findData->mFlags & BfpFindFileFlag_Directories) != 0)
|
|
|
- {
|
|
|
- if ((wcscmp(findData->mFindData.cFileName, L".") == 0) || (wcscmp(findData->mFindData.cFileName, L"..") == 0))
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if ((findData->mFlags & BfpFindFileFlag_Directories) == 0)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if ((wcscmp(findData->mFindData.cFileName, L".") == 0) || (wcscmp(findData->mFindData.cFileName, L"..") == 0))
|
|
|
+ return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if ((findData->mFlags & BfpFindFileFlag_Files) != 0)
|
|
|
- return true;
|
|
|
+ if ((findData->mFlags & BfpFindFileFlag_Files) == 0)
|
|
|
+ return false;
|
|
|
}
|
|
|
- return false;
|
|
|
+
|
|
|
+ Beefy::String fileName = UTF8Encode(findData->mFindData.cFileName);
|
|
|
+ if (!wc_match(findData->mWildcard.c_str(), fileName.c_str()))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
BFP_EXPORT BfpFindFileData* BFP_CALLTYPE BfpFindFileData_FindFirstFile(const char* path, BfpFindFileFlags flags, BfpFileResult* outResult)
|
|
|
{
|
|
|
- UTF16String wPath = UTF8Decode(path);
|
|
|
+ Beefy::String findStr = path;
|
|
|
+ Beefy::String wildcard;
|
|
|
+
|
|
|
+ int lastSlashPos = std::max((int)findStr.LastIndexOf('/'), (int)findStr.LastIndexOf('\\'));
|
|
|
+ if (lastSlashPos != -1)
|
|
|
+ {
|
|
|
+ wildcard = findStr.Substring(lastSlashPos + 1);
|
|
|
+ findStr = findStr.Substring(0, lastSlashPos + 1);
|
|
|
+ findStr.Append("*");
|
|
|
+ }
|
|
|
+ if (wildcard == "*.*")
|
|
|
+ wildcard = "*";
|
|
|
|
|
|
BfpFindFileData* findData = new BfpFindFileData();
|
|
|
findData->mFlags = flags;
|
|
|
+ findData->mWildcard = wildcard;
|
|
|
|
|
|
FINDEX_SEARCH_OPS searchOps;
|
|
|
if ((flags & BfpFindFileFlag_Files) == 0)
|
|
@@ -3526,6 +3542,7 @@ BFP_EXPORT BfpFindFileData* BFP_CALLTYPE BfpFindFileData_FindFirstFile(const cha
|
|
|
else
|
|
|
searchOps = FindExSearchNameMatch;
|
|
|
|
|
|
+ UTF16String wPath = UTF8Decode(findStr);
|
|
|
findData->mHandle = ::FindFirstFileExW(wPath.c_str(), FindExInfoBasic, &findData->mFindData, searchOps, NULL, 0);
|
|
|
if (findData->mHandle == INVALID_HANDLE_VALUE)
|
|
|
{
|