ReactOS 0.4.16-dev-1369-gd4d04c8
CFindFolder.cpp File Reference
#include "CFindFolder.h"
#include <exdispid.h>
Include dependency graph for CFindFolder.cpp:

Go to the source code of this file.

Classes

struct  FolderViewColumns
 
struct  _SearchData
 
class  CFindFolderContextMenu
 

Macros

#define IS_TEXT_UNKNOWN_FLAGS_MASK   ((7 << 13) | (1 << 11))
 
#define IS_DOTS(psz)   ((psz)[0] == L'.' && ((psz)[1] == 0 || ((psz)[1] == L'.' && (psz)[2] == 0)))
 

Enumerations

enum  ENCODING {
  ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 , ENCODING_UTF16BE = 2 , ENCODING_UTF8 = 3 ,
  ENCODING_AUTO = -1 , ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 , ENCODING_UTF16BE = 2 ,
  ENCODING_UTF8 = 3 , ENCODING_UTF8BOM = 4 , ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 ,
  ENCODING_UTF16BE = 2 , ENCODING_UTF8 = 3 , ENCODING_ANSI = 1 , ENCODING_UTF8 ,
  ENCODING_UTF16LE , ENCODING_UTF16BE
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shellfind)
 
static HRESULT WINAPI DisplayNameOfW (_In_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ DWORD dwFlags, _Out_ LPWSTR pszBuf, _In_ UINT cchBuf)
 
static HRESULT GetCommandStringA (_In_ IContextMenu *pCM, _In_ UINT_PTR Id, _In_ UINT GCS, _Out_writes_(cchMax) LPSTR Buf, _In_ UINT cchMax)
 
static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO *ppfti, LPCITEMIDLIST pidlChild, const GUID *clsid, REFIID riid, LPVOID *ppvOut)
 
static void WINAPI _InsertMenuItemW (HMENU hMenu, UINT indexMenu, BOOL fByPosition, UINT wID, UINT fType, LPCWSTR dwTypeData, UINT fState)
 
static HRESULT QueryActiveShellView (IUnknown *pUnkSite, REFGUID rService, IShellView **ppSV)
 
static HRESULT BeginRenameOfShellViewSelection (IUnknown *pUnkSite)
 
static LPITEMIDLIST _ILCreate (LPCWSTR lpszPath)
 
static LPCWSTR _ILGetPath (LPCITEMIDLIST pidl)
 
static LPCITEMIDLIST _ILGetFSPidl (LPCITEMIDLIST pidl)
 
static PIDLIST_ABSOLUTE _ILCreateAbsolute (LPCITEMIDLIST pidlChild)
 
static int CALLBACK ILFreeHelper (void *pItem, void *pCaller)
 
template<typename TChar , typename TString , int(&)(const TChar *, const TChar *, size_t) StrNCmp>
static const TChar * StrStrN (const TChar *lpFirst, const TString &lpSrch, UINT cchMax)
 
static BOOL StrFindNIA (const CHAR *lpFirst, const CStringA &lpSrch, UINT cchMax)
 
static BOOL StrFindNIW (const WCHAR *lpFirst, const CStringW &lpSrch, UINT cchMax)
 
static BOOL IsDataUnicode (IN PVOID Buffer, IN DWORD BufferSize, OUT ENCODING *Encoding OPTIONAL, OUT PDWORD SkipBytes OPTIONAL)
 
static BOOL SearchFile (LPCWSTR lpFilePath, _SearchData *pSearchData)
 
static BOOL FileNameMatch (LPCWSTR FindDataFileName, _SearchData *pSearchData)
 
static BOOL ContentsMatch (LPCWSTR szPath, _SearchData *pSearchData)
 
static BOOL AttribHiddenMatch (DWORD FileAttributes, _SearchData *pSearchData)
 
static UINT RecursiveFind (LPCWSTR lpPath, _SearchData *pSearchData)
 

Variables

static const FolderViewColumns g_ColumnDefs []
 

Macro Definition Documentation

◆ IS_DOTS

#define IS_DOTS (   psz)    ((psz)[0] == L'.' && ((psz)[1] == 0 || ((psz)[1] == L'.' && (psz)[2] == 0)))

◆ IS_TEXT_UNKNOWN_FLAGS_MASK

#define IS_TEXT_UNKNOWN_FLAGS_MASK   ((7 << 13) | (1 << 11))

Enumeration Type Documentation

◆ ENCODING

Enumerator
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_AUTO 
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_UTF8BOM 
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_ANSI 
ENCODING_UTF8 
ENCODING_UTF16LE 
ENCODING_UTF16BE 

Definition at line 321 of file CFindFolder.cpp.

322{
323 ENCODING_ANSI = 0,
326 ENCODING_UTF8 = 3
327} ENCODING;
ENCODING
@ ENCODING_UTF16BE
@ ENCODING_UTF8
@ ENCODING_UTF16LE
@ ENCODING_ANSI

Function Documentation

◆ _ILCreate()

static LPITEMIDLIST _ILCreate ( LPCWSTR  lpszPath)
static

Definition at line 150 of file CFindFolder.cpp.

151{
152 CComHeapPtr<ITEMIDLIST> lpFSPidl(ILCreateFromPathW(lpszPath));
153 if (!lpFSPidl)
154 {
155 ERR("Failed to create pidl from path\n");
156 return NULL;
157 }
158 LPITEMIDLIST lpLastFSPidl = ILFindLastID(lpFSPidl);
159
160 SIZE_T cbPath = (PathFindFileNameW(lpszPath) - lpszPath + 1) * sizeof(WCHAR);
161 SIZE_T cbData = sizeof(WORD) + cbPath + lpLastFSPidl->mkid.cb;
162 if (cbData > 0xffff)
163 return NULL;
164 LPITEMIDLIST pidl = (LPITEMIDLIST) SHAlloc(cbData + sizeof(WORD));
165 if (!pidl)
166 return NULL;
167
168 LPBYTE p = (LPBYTE) pidl;
169 p += sizeof(WORD); // mkid.cb
170
171 PWSTR path = (PWSTR)p;
172 memcpy(p, lpszPath, cbPath);
173 p += cbPath;
174 ((PWSTR)p)[-1] = UNICODE_NULL; // "C:\" not "C:" (required by ILCreateFromPathW and matches Windows)
175 if (!PathIsRootW(path))
176 {
177 p -= sizeof(WCHAR);
178 ((PWSTR)p)[-1] = UNICODE_NULL; // "C:\folder"
179 }
180
181 memcpy(p, lpLastFSPidl, lpLastFSPidl->mkid.cb);
182 p += lpLastFSPidl->mkid.cb;
183
184 pidl->mkid.cb = p - (LPBYTE)pidl;
185 ((LPITEMIDLIST)p)->mkid.cb = 0; // Terminator
186 return pidl;
187}
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
WCHAR *WINAPI PathFindFileNameW(const WCHAR *path)
Definition: path.c:1644
BOOL WINAPI PathIsRootW(const WCHAR *path)
Definition: path.c:1044
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:315
unsigned short WORD
Definition: ntddk_ex.h:93
GLfloat GLfloat p
Definition: glext.h:8902
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define UNICODE_NULL
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:199
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:1102
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ _ILCreateAbsolute()

static PIDLIST_ABSOLUTE _ILCreateAbsolute ( LPCITEMIDLIST  pidlChild)
static

Definition at line 204 of file CFindFolder.cpp.

205{
206 PIDLIST_ABSOLUTE pidl = NULL;
207 if (PIDLIST_ABSOLUTE pidlFolder = SHSimpleIDListFromPath(_ILGetPath(pidl))) // FIXME: SHELL32_CreateSimpleIDListFromPath(, DIRECTORY)
208 {
209 pidl = ILCombine(pidlFolder, _ILGetFSPidl(pidl));
210 ILFree(pidlFolder);
211 }
212 return pidl;
213}
static LPCWSTR _ILGetPath(LPCITEMIDLIST pidl)
static LPCITEMIDLIST _ILGetFSPidl(LPCITEMIDLIST pidl)
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1045
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:817
PIDLIST_ABSOLUTE WINAPI SHSimpleIDListFromPath(PCWSTR)

Referenced by CFindFolder::CreateAbsolutePidlArray().

◆ _ILGetFSPidl()

static LPCITEMIDLIST _ILGetFSPidl ( LPCITEMIDLIST  pidl)
static

Definition at line 196 of file CFindFolder.cpp.

197{
198 if (!pidl || !pidl->mkid.cb)
199 return pidl;
200 return (LPCITEMIDLIST) ((LPBYTE) pidl->mkid.abID
201 + ((wcslen((LPCWSTR) pidl->mkid.abID) + 1) * sizeof(WCHAR)));
202}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by _ILCreateAbsolute(), CFindFolder::CompareIDs(), CFindFolder::GetFSFolderAndChild(), CFindFolder::GetUIObjectOf(), and CFindFolderContextMenu::InvokeCommand().

◆ _ILGetPath()

static LPCWSTR _ILGetPath ( LPCITEMIDLIST  pidl)
static

◆ _InsertMenuItemW()

static void WINAPI _InsertMenuItemW ( HMENU  hMenu,
UINT  indexMenu,
BOOL  fByPosition,
UINT  wID,
UINT  fType,
LPCWSTR  dwTypeData,
UINT  fState 
)
static

Definition at line 68 of file CFindFolder.cpp.

76{
77 MENUITEMINFOW mii;
78 WCHAR wszText[100];
79
80 ZeroMemory(&mii, sizeof(mii));
81 mii.cbSize = sizeof(mii);
82 if (fType == MFT_SEPARATOR)
83 mii.fMask = MIIM_ID | MIIM_TYPE;
84 else if (fType == MFT_STRING)
85 {
87 if (IS_INTRESOURCE(dwTypeData))
88 {
89 if (LoadStringW(_AtlBaseModule.GetResourceInstance(), LOWORD((ULONG_PTR)dwTypeData), wszText, _countof(wszText)))
90 mii.dwTypeData = wszText;
91 else
92 {
93 ERR("failed to load string %p\n", dwTypeData);
94 return;
95 }
96 }
97 else
98 mii.dwTypeData = (LPWSTR)dwTypeData;
99 mii.fState = fState;
100 }
101
102 mii.wID = wID;
103 mii.fType = fType;
104 InsertMenuItemW(hMenu, indexMenu, fByPosition, &mii);
105}
#define IS_INTRESOURCE(x)
Definition: loader.c:613
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
#define LOWORD(l)
Definition: pedump.c:82
#define _countof(array)
Definition: sndvol32.h:70
LPWSTR dwTypeData
Definition: winuser.h:3345
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ZeroMemory
Definition: winbase.h:1753
#define MIIM_ID
Definition: winuser.h:733
#define MFT_SEPARATOR
Definition: winuser.h:755
#define MIIM_STATE
Definition: winuser.h:732
#define MFT_STRING
Definition: winuser.h:757
#define MIIM_TYPE
Definition: winuser.h:736
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CFindFolderContextMenu::QueryContextMenu().

◆ AttribHiddenMatch()

static BOOL AttribHiddenMatch ( DWORD  FileAttributes,
_SearchData pSearchData 
)
static

Definition at line 522 of file CFindFolder.cpp.

523{
524 if (!(FileAttributes & FILE_ATTRIBUTE_HIDDEN) || (pSearchData->SearchHidden))
525 {
526 return TRUE;
527 }
528 return FALSE;
529}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703

Referenced by RecursiveFind().

◆ BeginRenameOfShellViewSelection()

static HRESULT BeginRenameOfShellViewSelection ( IUnknown pUnkSite)
static

Definition at line 114 of file CFindFolder.cpp.

115{
118 if (FAILED(hr))
119 return hr;
121 if (SUCCEEDED(hr = pSV->QueryInterface(IID_PPV_ARG(IFolderView2, &pFV2))))
122 return pFV2->DoRename();
124 if (SUCCEEDED(hr = pSV->QueryInterface(IID_PPV_ARG(IShellView2, &pSV2))))
125 return pSV2->HandleRename(NULL);
126 return hr;
127}
static HRESULT QueryActiveShellView(IUnknown *pUnkSite, REFGUID rService, IShellView **ppSV)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183
#define SID_SShellBrowser
Definition: shlguid.h:128
#define IID_PPV_ARG(Itype, ppType)

Referenced by CFindFolderContextMenu::InvokeCommand().

◆ ContentsMatch()

static BOOL ContentsMatch ( LPCWSTR  szPath,
_SearchData pSearchData 
)
static

Definition at line 513 of file CFindFolder.cpp.

514{
515 if (pSearchData->szQueryA.IsEmpty() || SearchFile(szPath, pSearchData))
516 {
517 return TRUE;
518 }
519 return FALSE;
520}
static BOOL SearchFile(LPCWSTR lpFilePath, _SearchData *pSearchData)
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
LPCWSTR szPath
Definition: env.c:37
CStringA szQueryA

Referenced by RecursiveFind().

◆ DisplayNameOfW()

static HRESULT WINAPI DisplayNameOfW ( _In_ IShellFolder psf,
_In_ LPCITEMIDLIST  pidl,
_In_ DWORD  dwFlags,
_Out_ LPWSTR  pszBuf,
_In_ UINT  cchBuf 
)
static

Definition at line 15 of file CFindFolder.cpp.

17{
18 *pszBuf = UNICODE_NULL;
19 STRRET sr;
20 HRESULT hr = psf->GetDisplayNameOf(pidl, dwFlags, &sr);
21 return FAILED(hr) ? hr : StrRetToBufW(&sr, pidl, pszBuf, cchBuf);
22}
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by CFSDropTarget::_DoDrop(), CDefView::OnNotify(), and CFindFolder::SetNameOf().

◆ FileNameMatch()

static BOOL FileNameMatch ( LPCWSTR  FindDataFileName,
_SearchData pSearchData 
)
static

Definition at line 504 of file CFindFolder.cpp.

505{
506 if (pSearchData->szFileName.IsEmpty() || PathMatchSpecW(FindDataFileName, pSearchData->szFileName))
507 {
508 return TRUE;
509 }
510 return FALSE;
511}
BOOL WINAPI PathMatchSpecW(const WCHAR *path, const WCHAR *mask)
Definition: path.c:2464
CStringW szFileName

Referenced by RecursiveFind().

◆ GetCommandStringA()

static HRESULT GetCommandStringA ( _In_ IContextMenu pCM,
_In_ UINT_PTR  Id,
_In_ UINT  GCS,
_Out_writes_(cchMax) LPSTR  Buf,
_In_ UINT  cchMax 
)
static

Definition at line 25 of file CFindFolder.cpp.

27{
28 HRESULT hr = pCM->GetCommandString(Id, GCS & ~GCS_UNICODE, NULL, Buf, cchMax);
29 if (FAILED(hr))
30 {
32 hr = pCM->GetCommandString(Id, GCS | GCS_UNICODE, NULL, (LPSTR)buf, _countof(buf));
33 if (SUCCEEDED(hr))
34 hr = SHUnicodeToAnsi(buf, Buf, cchMax) > 0 ? S_OK : E_FAIL;
35 }
36 return hr;
37}
DWORD Id
UINT cchMax
#define E_FAIL
Definition: ddrawi.h:102
#define MAX_PATH
Definition: compat.h:34
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen)
Definition: string.c:2797
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define S_OK
Definition: intsafe.h:52
char * LPSTR
Definition: xmlstorage.h:182

Referenced by CFindFolderContextMenu::InvokeCommand().

◆ ILFreeHelper()

static int CALLBACK ILFreeHelper ( void pItem,
void pCaller 
)
static

Definition at line 240 of file CFindFolder.cpp.

241{
242 ILFree((LPITEMIDLIST)pItem);
243 return TRUE;
244}

Referenced by CFindFolder::FreePidlArray().

◆ IsDataUnicode()

static BOOL IsDataUnicode ( IN PVOID  Buffer,
IN DWORD  BufferSize,
OUT ENCODING *Encoding  OPTIONAL,
OUT PDWORD SkipBytes  OPTIONAL 
)
static

Definition at line 330 of file CFindFolder.cpp.

335{
336 PBYTE pBytes = (PBYTE)Buffer;
337 ENCODING encFile = ENCODING_ANSI;
338 DWORD dwPos = 0;
339
340 /*
341 * See http://archives.miloush.net/michkap/archive/2007/04/22/2239345.html
342 * for more details about the algorithm and the pitfalls behind it.
343 * Of course it would be actually great to make a nice function that
344 * would work, once and for all, and put it into a library.
345 */
346
347 /* Look for Byte Order Marks */
348 if ((BufferSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
349 {
350 encFile = ENCODING_UTF16LE;
351 dwPos = 2;
352 }
353 else if ((BufferSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
354 {
355 encFile = ENCODING_UTF16BE;
356 dwPos = 2;
357 }
358 else if ((BufferSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
359 {
360 encFile = ENCODING_UTF8;
361 dwPos = 3;
362 }
363 else
364 {
365 /*
366 * Try using statistical analysis. Do not rely on the return value of
367 * IsTextUnicode as we can get FALSE even if the text is in UTF-16 BE
368 * (i.e. we have some of the IS_TEXT_UNICODE_REVERSE_MASK bits set).
369 * Instead, set all the tests we want to perform, then just check
370 * the passed tests and try to deduce the string properties.
371 */
372
373/*
374 * This mask contains the 3 highest bits from IS_TEXT_UNICODE_NOT_ASCII_MASK
375 * and the 1st highest bit from IS_TEXT_UNICODE_NOT_UNICODE_MASK.
376 */
377#define IS_TEXT_UNKNOWN_FLAGS_MASK ((7 << 13) | (1 << 11))
378
379 /* Flag out the unknown flags here, the passed tests will not have them either */
384 INT Results;
385
387 Results = Tests;
388
389 /*
390 * As the IS_TEXT_UNICODE_NULL_BYTES or IS_TEXT_UNICODE_ILLEGAL_CHARS
391 * flags are expected to be potentially present in the result without
392 * modifying our expectations, filter them out now.
393 */
395
396 /*
397 * NOTE: The flags IS_TEXT_UNICODE_ASCII16 and
398 * IS_TEXT_UNICODE_REVERSE_ASCII16 are not reliable.
399 *
400 * NOTE2: Check for potential "bush hid the facts" effect by also
401 * checking the original results (in 'Tests') for the absence of
402 * the IS_TEXT_UNICODE_NULL_BYTES flag, as we may presumably expect
403 * that in UTF-16 text there will be at some point some NULL bytes.
404 * If not, fall back to ANSI. This shows the limitations of using the
405 * IsTextUnicode API to perform such tests, and the usage of a more
406 * improved encoding detection algorithm would be really welcome.
407 */
408 if (!(Results & IS_TEXT_UNICODE_NOT_UNICODE_MASK) &&
409 !(Results & IS_TEXT_UNICODE_REVERSE_MASK) &&
410 (Results & IS_TEXT_UNICODE_UNICODE_MASK) &&
412 {
413 encFile = ENCODING_UTF16LE;
414 dwPos = (Results & IS_TEXT_UNICODE_SIGNATURE) ? 2 : 0;
415 }
416 else
417 if (!(Results & IS_TEXT_UNICODE_NOT_UNICODE_MASK) &&
418 !(Results & IS_TEXT_UNICODE_UNICODE_MASK) &&
419 (Results & IS_TEXT_UNICODE_REVERSE_MASK) &&
421 {
422 encFile = ENCODING_UTF16BE;
423 dwPos = (Results & IS_TEXT_UNICODE_REVERSE_SIGNATURE) ? 2 : 0;
424 }
425 else
426 {
427 /*
428 * Either 'Results' has neither of those masks set, as it can be
429 * the case for UTF-8 text (or ANSI), or it has both as can be the
430 * case when analysing pure binary data chunk. This is therefore
431 * invalid and we fall back to ANSI encoding.
432 * FIXME: In case of failure, assume ANSI (as long as we do not have
433 * correct tests for UTF8, otherwise we should do them, and at the
434 * very end, assume ANSI).
435 */
436 encFile = ENCODING_ANSI; // ENCODING_UTF8;
437 dwPos = 0;
438 }
439 }
440
441 if (Encoding)
442 *Encoding = encFile;
443 if (SkipBytes)
444 *SkipBytes = dwPos;
445
446 return (encFile != ENCODING_ANSI);
447}
#define IS_TEXT_UNKNOWN_FLAGS_MASK
struct test_data Tests[]
Definition: bufpool.h:45
BOOL WINAPI IsTextUnicode(IN CONST VOID *lpv, IN INT iSize, IN OUT LPINT lpiResult OPTIONAL)
Definition: unicode.c:27
unsigned long DWORD
Definition: ntddk_ex.h:95
ENCODING
Definition: more.c:493
BYTE * PBYTE
Definition: pedump.c:66
int32_t INT
Definition: typedefs.h:58
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define IS_TEXT_UNICODE_ILLEGAL_CHARS
Definition: winnt_old.h:923
#define IS_TEXT_UNICODE_UNICODE_MASK
Definition: winnt_old.h:927
#define IS_TEXT_UNICODE_NOT_ASCII_MASK
Definition: winnt_old.h:930
#define IS_TEXT_UNICODE_NULL_BYTES
Definition: winnt_old.h:926
#define IS_TEXT_UNICODE_REVERSE_MASK
Definition: winnt_old.h:928
#define IS_TEXT_UNICODE_REVERSE_SIGNATURE
Definition: winnt_old.h:922
#define IS_TEXT_UNICODE_NOT_UNICODE_MASK
Definition: winnt_old.h:929
#define IS_TEXT_UNICODE_SIGNATURE
Definition: winnt_old.h:921
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS SkipBytes
Definition: mmfuncs.h:227

Referenced by SearchFile().

◆ QueryActiveShellView()

static HRESULT QueryActiveShellView ( IUnknown pUnkSite,
REFGUID  rService,
IShellView **  ppSV 
)
static

Definition at line 107 of file CFindFolder.cpp.

108{
110 HRESULT hr = IUnknown_QueryService(pUnkSite, rService, IID_PPV_ARG(IShellBrowser, &pSB));
111 return SUCCEEDED(hr) ? pSB->QueryActiveShellView(ppSV) : hr;
112}
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1501

Referenced by BeginRenameOfShellViewSelection().

◆ RecursiveFind()

static UINT RecursiveFind ( LPCWSTR  lpPath,
_SearchData pSearchData 
)
static

Definition at line 531 of file CFindFolder.cpp.

532{
533 if (WaitForSingleObject(pSearchData->hStopEvent, 0) != WAIT_TIMEOUT)
534 return 0;
535
537 WIN32_FIND_DATAW FindData;
538 HANDLE hFindFile;
539 BOOL bMoreFiles = TRUE;
540 UINT uTotalFound = 0;
541
542 PathCombineW(szPath, lpPath, L"*");
543
544 for (hFindFile = FindFirstFileW(szPath, &FindData);
545 bMoreFiles && hFindFile != INVALID_HANDLE_VALUE;
546 bMoreFiles = FindNextFileW(hFindFile, &FindData))
547 {
548#define IS_DOTS(psz) ((psz)[0] == L'.' && ((psz)[1] == 0 || ((psz)[1] == L'.' && (psz)[2] == 0)))
549 if (IS_DOTS(FindData.cFileName))
550 continue;
551
552 PathCombineW(szPath, lpPath, FindData.cFileName);
553
554 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
555 {
557 if (pSearchData->szQueryW.IsEmpty() &&
558 FileNameMatch(FindData.cFileName, pSearchData) &&
559 AttribHiddenMatch(FindData.dwFileAttributes, pSearchData))
560 {
561 LPWSTR pszPathDup;
562 SHStrDupW(szPath, &pszPathDup);
563 PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM)pszPathDup);
564 uTotalFound++;
565 }
566 status.Format(IDS_SEARCH_FOLDER, FindData.cFileName);
567 LPWSTR pszStatusDup;
568 SHStrDupW(status.GetBuffer(), &pszStatusDup);
569 PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM)pszStatusDup);
570
571 uTotalFound += RecursiveFind(szPath, pSearchData);
572 }
573 else if (FileNameMatch(FindData.cFileName, pSearchData)
574 && AttribHiddenMatch(FindData.dwFileAttributes, pSearchData)
575 && ContentsMatch(szPath, pSearchData))
576 {
577 uTotalFound++;
578 LPWSTR pszPathDup;
579 SHStrDupW(szPath, &pszPathDup);
580 PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM)pszPathDup);
581 }
582 }
583
584 if (hFindFile != INVALID_HANDLE_VALUE)
585 FindClose(hFindFile);
586
587 return uTotalFound;
588}
static BOOL AttribHiddenMatch(DWORD FileAttributes, _SearchData *pSearchData)
static BOOL FileNameMatch(LPCWSTR FindDataFileName, _SearchData *pSearchData)
static BOOL ContentsMatch(LPCWSTR szPath, _SearchData *pSearchData)
#define IS_DOTS(psz)
static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define IDS_SEARCH_FOLDER
Definition: resource.h:179
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR *dest)
Definition: string.c:2018
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define PathCombineW
Definition: pathcch.h:317
#define WM_SEARCH_ADD_RESULT
Definition: shellfind.h:31
#define WM_SEARCH_UPDATE_STATUS
Definition: shellfind.h:32
CStringW szQueryW
HANDLE hStopEvent
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by RecursiveFind(), and CFindFolder::SearchThreadProc().

◆ SearchFile()

static BOOL SearchFile ( LPCWSTR  lpFilePath,
_SearchData pSearchData 
)
static

Definition at line 449 of file CFindFolder.cpp.

450{
453 return FALSE;
454
455 // FIXME: support large file
457 if (size == 0 || size == INVALID_FILE_SIZE)
458 {
460 return FALSE;
461 }
462
465 if (hFileMap == INVALID_HANDLE_VALUE)
466 return FALSE;
467
468 LPBYTE pbContents = (LPBYTE)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, size);
469 CloseHandle(hFileMap);
470 if (!pbContents)
471 return FALSE;
472
474 IsDataUnicode(pbContents, size, &encoding, NULL);
475
476 BOOL bFound;
477 switch (encoding)
478 {
479 case ENCODING_UTF16LE:
480 // UTF-16
481 bFound = StrFindNIW((LPCWSTR)pbContents, pSearchData->szQueryW, size / sizeof(WCHAR));
482 break;
483 case ENCODING_UTF16BE:
484 // UTF-16 BE
485 bFound = StrFindNIW((LPCWSTR)pbContents, pSearchData->szQueryU16BE, size / sizeof(WCHAR));
486 break;
487 case ENCODING_UTF8:
488 // UTF-8
489 bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryU8, size / sizeof(CHAR));
490 break;
491 case ENCODING_ANSI:
492 default:
493 // ANSI or UTF-8 without BOM
494 bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryA, size / sizeof(CHAR));
495 if (!bFound && pSearchData->szQueryA != pSearchData->szQueryU8)
496 bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryU8, size / sizeof(CHAR));
497 break;
498 }
499
500 UnmapViewOfFile(pbContents);
501 return bFound;
502}
static BOOL StrFindNIW(const WCHAR *lpFirst, const CStringW &lpSrch, UINT cchMax)
static BOOL IsDataUnicode(IN PVOID Buffer, IN DWORD BufferSize, OUT ENCODING *Encoding OPTIONAL, OUT PDWORD SkipBytes OPTIONAL)
static BOOL StrFindNIA(const CHAR *lpFirst, const CStringA &lpSrch, UINT cchMax)
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define OPEN_EXISTING
Definition: compat.h:775
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
GLsizeiptr size
Definition: glext.h:5919
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
CStringW szQueryU16BE
CStringA szQueryU8
#define INVALID_FILE_SIZE
Definition: winbase.h:584
static char * encoding
Definition: xmllint.c:155
const char * LPCSTR
Definition: xmlstorage.h:183
char CHAR
Definition: xmlstorage.h:175

Referenced by ContentsMatch().

◆ SHELL32_CoCreateInitSF()

static HRESULT SHELL32_CoCreateInitSF ( LPCITEMIDLIST  pidlRoot,
PERSIST_FOLDER_TARGET_INFO *  ppfti,
LPCITEMIDLIST  pidlChild,
const GUID clsid,
REFIID  riid,
LPVOID ppvOut 
)
static

Definition at line 39 of file CFindFolder.cpp.

41{
42 HRESULT hr;
43 CComPtr<IShellFolder> pShellFolder;
44
46 if (FAILED(hr))
47 return hr;
48
49 LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
52
53 if (ppfti && SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3))))
54 {
55 ppf3->InitializeEx(NULL, pidlAbsolute, ppfti);
56 }
57 else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))
58 {
59 ppf->Initialize(pidlAbsolute);
60 }
61 ILFree (pidlAbsolute);
62
63 return pShellFolder->QueryInterface(riid, ppvOut);
64}
HRESULT WINAPI SHCoCreateInstance(LPCWSTR aclsid, const CLSID *clsid, LPUNKNOWN pUnkOuter, REFIID refiid, LPVOID *ppv)
Definition: shellole.c:105
REFIID riid
Definition: atlbase.h:39
REFCLSID clsid
Definition: msctf.c:82

Referenced by CMyDocsFolder::EnsureFolder(), CDesktopFolder::FinalConstruct(), CRecycleBin::GetFSFolderForItem(), CFindFolder::Initialize(), CAdminToolsFolder::Initialize(), and CFontsFolder::Initialize().

◆ StrFindNIA()

static BOOL StrFindNIA ( const CHAR lpFirst,
const CStringA lpSrch,
UINT  cchMax 
)
inlinestatic

Definition at line 307 of file CFindFolder.cpp.

308{
309 return StrStrN<CHAR, CStringA, _strnicmp>(lpFirst, lpSrch, cchMax) != NULL;
310}

Referenced by SearchFile().

◆ StrFindNIW()

static BOOL StrFindNIW ( const WCHAR lpFirst,
const CStringW lpSrch,
UINT  cchMax 
)
inlinestatic

Definition at line 313 of file CFindFolder.cpp.

314{
315 return StrStrN<WCHAR, CStringW, _wcsnicmp>(lpFirst, lpSrch, cchMax) != NULL;
316}

Referenced by SearchFile().

◆ StrStrN()

template<typename TChar , typename TString , int(&)(const TChar *, const TChar *, size_t) StrNCmp>
static const TChar * StrStrN ( const TChar *  lpFirst,
const TString lpSrch,
UINT  cchMax 
)
static

Definition at line 292 of file CFindFolder.cpp.

293{
294 if (!lpFirst || lpSrch.IsEmpty() || !cchMax)
295 return NULL;
296
297 for (UINT i = cchMax; i > 0 && *lpFirst; i--, lpFirst++)
298 {
299 if (!StrNCmp(lpFirst, lpSrch, lpSrch.GetLength()))
300 return (const TChar*)lpFirst;
301 }
302
303 return NULL;
304}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define StrNCmp
Definition: shlwapi.h:1570

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shellfind  )

Variable Documentation

◆ g_ColumnDefs

const FolderViewColumns g_ColumnDefs[]
static
Initial value:
=
{
}
#define IDS_COL_NAME
Definition: resource.h:17
#define IDS_COL_RELEVANCE
Definition: resource.h:177
#define IDS_COL_LOCATION
Definition: resource.h:176
#define LVCFMT_LEFT
Definition: commctrl.h:2603
@ SHCOLSTATE_TYPE_STR
Definition: shtypes.idl:121
@ SHCOLSTATE_ONBYDEFAULT
Definition: shtypes.idl:125

Definition at line 137 of file CFindFolder.cpp.