ReactOS  0.4.15-dev-1397-g19779b3
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_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 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 LPITEMIDLIST _ILCreate (LPCWSTR lpszPath)
 
static LPCWSTR _ILGetPath (LPCITEMIDLIST pidl)
 
static LPCITEMIDLIST _ILGetFSPidl (LPCITEMIDLIST pidl)
 
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 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_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_ANSI 
ENCODING_UTF8 
ENCODING_UTF16LE 
ENCODING_UTF16BE 

Definition at line 191 of file CFindFolder.cpp.

Function Documentation

◆ _ILCreate()

static LPITEMIDLIST _ILCreate ( LPCWSTR  lpszPath)
static

Definition at line 99 of file CFindFolder.cpp.

100 {
101  CComHeapPtr<ITEMIDLIST> lpFSPidl(ILCreateFromPathW(lpszPath));
102  if (!lpFSPidl)
103  {
104  ERR("Failed to create pidl from path\n");
105  return NULL;
106  }
107  LPITEMIDLIST lpLastFSPidl = ILFindLastID(lpFSPidl);
108 
109  int pathLen = (PathFindFileNameW(lpszPath) - lpszPath) * sizeof(WCHAR);
110  int cbData = sizeof(WORD) + pathLen + lpLastFSPidl->mkid.cb;
111  LPITEMIDLIST pidl = (LPITEMIDLIST) SHAlloc(cbData + sizeof(WORD));
112  if (!pidl)
113  return NULL;
114 
115  LPBYTE p = (LPBYTE) pidl;
116  *((WORD *) p) = cbData;
117  p += sizeof(WORD);
118 
119  memcpy(p, lpszPath, pathLen);
120  p += pathLen - sizeof(WCHAR);
121  *((WCHAR *) p) = '\0';
122  p += sizeof(WCHAR);
123 
124  memcpy(p, lpLastFSPidl, lpLastFSPidl->mkid.cb);
125  p += lpLastFSPidl->mkid.cb;
126 
127  *((WORD *) p) = 0;
128 
129  return pidl;
130 }
unsigned char * LPBYTE
Definition: typedefs.h:53
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned short WORD
Definition: ntddk_ex.h:93
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
GLfloat GLfloat p
Definition: glext.h:8902
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:309

Referenced by CFindFolder::AddResult().

◆ _ILGetFSPidl()

static LPCITEMIDLIST _ILGetFSPidl ( LPCITEMIDLIST  pidl)
static

Definition at line 139 of file CFindFolder.cpp.

140 {
141  if (!pidl || !pidl->mkid.cb)
142  return pidl;
143  return (LPCITEMIDLIST) ((LPBYTE) pidl->mkid.abID
144  + ((wcslen((LPCWSTR) pidl->mkid.abID) + 1) * sizeof(WCHAR)));
145 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
unsigned char * LPBYTE
Definition: typedefs.h:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by CFindFolder::CompareIDs(), CFindFolder::GetAttributesOf(), CFindFolder::GetDetailsOf(), CFindFolder::GetDisplayNameOf(), CFindFolder::GetUIObjectOf(), and CFindFolderContextMenu::InvokeCommand().

◆ _ILGetPath()

static LPCWSTR _ILGetPath ( LPCITEMIDLIST  pidl)
static

Definition at line 132 of file CFindFolder.cpp.

133 {
134  if (!pidl || !pidl->mkid.cb)
135  return NULL;
136  return (LPCWSTR) pidl->mkid.abID;
137 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define NULL
Definition: types.h:112

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

◆ _InsertMenuItemW()

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

Definition at line 40 of file CFindFolder.cpp.

48 {
49  MENUITEMINFOW mii;
50  WCHAR wszText[100];
51 
52  ZeroMemory(&mii, sizeof(mii));
53  mii.cbSize = sizeof(mii);
54  if (fType == MFT_SEPARATOR)
55  mii.fMask = MIIM_ID | MIIM_TYPE;
56  else if (fType == MFT_STRING)
57  {
59  if (IS_INTRESOURCE(dwTypeData))
60  {
61  if (LoadStringW(_AtlBaseModule.GetResourceInstance(), LOWORD((ULONG_PTR)dwTypeData), wszText, _countof(wszText)))
62  mii.dwTypeData = wszText;
63  else
64  {
65  ERR("failed to load string %p\n", dwTypeData);
66  return;
67  }
68  }
69  else
70  mii.dwTypeData = (LPWSTR)dwTypeData;
71  mii.fState = fState;
72  }
73 
74  mii.wID = wID;
75  mii.fType = fType;
76  InsertMenuItemW(hMenu, indexMenu, fByPosition, &mii);
77 }
#define MFT_STRING
Definition: winuser.h:741
#define ZeroMemory
Definition: winbase.h:1648
LPWSTR dwTypeData
Definition: winuser.h:3244
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MIIM_STATE
Definition: winuser.h:716
#define MIIM_ID
Definition: winuser.h:717
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MFT_SEPARATOR
Definition: winuser.h:739
#define MIIM_TYPE
Definition: winuser.h:720
#define ERR(fmt,...)
Definition: debug.h:110
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LOWORD(l)
Definition: pedump.c:82

Referenced by CFindFolderContextMenu::QueryContextMenu().

◆ AttribHiddenMatch()

static BOOL AttribHiddenMatch ( DWORD  FileAttributes,
_SearchData pSearchData 
)
static

Definition at line 392 of file CFindFolder.cpp.

393 {
394  if (!(FileAttributes & FILE_ATTRIBUTE_HIDDEN) || (pSearchData->SearchHidden))
395  {
396  return TRUE;
397  }
398  return FALSE;
399 }
#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:1230
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703

Referenced by RecursiveFind().

◆ ContentsMatch()

static BOOL ContentsMatch ( LPCWSTR  szPath,
_SearchData pSearchData 
)
static

Definition at line 383 of file CFindFolder.cpp.

384 {
385  if (pSearchData->szQueryA.IsEmpty() || SearchFile(szPath, pSearchData))
386  {
387  return TRUE;
388  }
389  return FALSE;
390 }
CStringA szQueryA
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
bool IsEmpty() const
Definition: atlsimpstr.h:379
static BOOL SearchFile(LPCWSTR lpFilePath, _SearchData *pSearchData)
LPCWSTR szPath
Definition: env.c:35

Referenced by RecursiveFind().

◆ FileNameMatch()

static BOOL FileNameMatch ( LPCWSTR  FindDataFileName,
_SearchData pSearchData 
)
static

Definition at line 374 of file CFindFolder.cpp.

375 {
376  if (pSearchData->szFileName.IsEmpty() || PathMatchSpecW(FindDataFileName, pSearchData->szFileName))
377  {
378  return TRUE;
379  }
380  return FALSE;
381 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
CStringW szFileName
bool IsEmpty() const
Definition: atlsimpstr.h:379
BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
Definition: path.c:1943

Referenced by RecursiveFind().

◆ IsDataUnicode()

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

Definition at line 200 of file CFindFolder.cpp.

205 {
206  PBYTE pBytes = (PBYTE)Buffer;
207  ENCODING encFile = ENCODING_ANSI;
208  DWORD dwPos = 0;
209 
210  /*
211  * See http://archives.miloush.net/michkap/archive/2007/04/22/2239345.html
212  * for more details about the algorithm and the pitfalls behind it.
213  * Of course it would be actually great to make a nice function that
214  * would work, once and for all, and put it into a library.
215  */
216 
217  /* Look for Byte Order Marks */
218  if ((BufferSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
219  {
220  encFile = ENCODING_UTF16LE;
221  dwPos = 2;
222  }
223  else if ((BufferSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
224  {
225  encFile = ENCODING_UTF16BE;
226  dwPos = 2;
227  }
228  else if ((BufferSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
229  {
230  encFile = ENCODING_UTF8;
231  dwPos = 3;
232  }
233  else
234  {
235  /*
236  * Try using statistical analysis. Do not rely on the return value of
237  * IsTextUnicode as we can get FALSE even if the text is in UTF-16 BE
238  * (i.e. we have some of the IS_TEXT_UNICODE_REVERSE_MASK bits set).
239  * Instead, set all the tests we want to perform, then just check
240  * the passed tests and try to deduce the string properties.
241  */
242 
243 /*
244  * This mask contains the 3 highest bits from IS_TEXT_UNICODE_NOT_ASCII_MASK
245  * and the 1st highest bit from IS_TEXT_UNICODE_NOT_UNICODE_MASK.
246  */
247 #define IS_TEXT_UNKNOWN_FLAGS_MASK ((7 << 13) | (1 << 11))
248 
249  /* Flag out the unknown flags here, the passed tests will not have them either */
254  INT Results;
255 
257  Results = Tests;
258 
259  /*
260  * As the IS_TEXT_UNICODE_NULL_BYTES or IS_TEXT_UNICODE_ILLEGAL_CHARS
261  * flags are expected to be potentially present in the result without
262  * modifying our expectations, filter them out now.
263  */
265 
266  /*
267  * NOTE: The flags IS_TEXT_UNICODE_ASCII16 and
268  * IS_TEXT_UNICODE_REVERSE_ASCII16 are not reliable.
269  *
270  * NOTE2: Check for potential "bush hid the facts" effect by also
271  * checking the original results (in 'Tests') for the absence of
272  * the IS_TEXT_UNICODE_NULL_BYTES flag, as we may presumably expect
273  * that in UTF-16 text there will be at some point some NULL bytes.
274  * If not, fall back to ANSI. This shows the limitations of using the
275  * IsTextUnicode API to perform such tests, and the usage of a more
276  * improved encoding detection algorithm would be really welcome.
277  */
278  if (!(Results & IS_TEXT_UNICODE_NOT_UNICODE_MASK) &&
279  !(Results & IS_TEXT_UNICODE_REVERSE_MASK) &&
280  (Results & IS_TEXT_UNICODE_UNICODE_MASK) &&
282  {
283  encFile = ENCODING_UTF16LE;
284  dwPos = (Results & IS_TEXT_UNICODE_SIGNATURE) ? 2 : 0;
285  }
286  else
287  if (!(Results & IS_TEXT_UNICODE_NOT_UNICODE_MASK) &&
288  !(Results & IS_TEXT_UNICODE_UNICODE_MASK) &&
289  (Results & IS_TEXT_UNICODE_REVERSE_MASK) &&
291  {
292  encFile = ENCODING_UTF16BE;
293  dwPos = (Results & IS_TEXT_UNICODE_REVERSE_SIGNATURE) ? 2 : 0;
294  }
295  else
296  {
297  /*
298  * Either 'Results' has neither of those masks set, as it can be
299  * the case for UTF-8 text (or ANSI), or it has both as can be the
300  * case when analysing pure binary data chunk. This is therefore
301  * invalid and we fall back to ANSI encoding.
302  * FIXME: In case of failure, assume ANSI (as long as we do not have
303  * correct tests for UTF8, otherwise we should do them, and at the
304  * very end, assume ANSI).
305  */
306  encFile = ENCODING_ANSI; // ENCODING_UTF8;
307  dwPos = 0;
308  }
309  }
310 
311  if (Encoding)
312  *Encoding = encFile;
313  if (SkipBytes)
314  *SkipBytes = dwPos;
315 
316  return (encFile != ENCODING_ANSI);
317 }
#define IS_TEXT_UNICODE_NOT_ASCII_MASK
Definition: winnt_old.h:934
int32_t INT
Definition: typedefs.h:58
#define IS_TEXT_UNICODE_SIGNATURE
Definition: winnt_old.h:925
Definition: bufpool.h:45
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS SkipBytes
Definition: mmfuncs.h:226
#define IS_TEXT_UNICODE_REVERSE_SIGNATURE
Definition: winnt_old.h:926
#define IS_TEXT_UNKNOWN_FLAGS_MASK
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
#define IS_TEXT_UNICODE_ILLEGAL_CHARS
Definition: winnt_old.h:927
ENCODING
Definition: more.c:168
#define IS_TEXT_UNICODE_REVERSE_MASK
Definition: winnt_old.h:932
#define IS_TEXT_UNICODE_NULL_BYTES
Definition: winnt_old.h:930
BYTE * PBYTE
Definition: pedump.c:66
#define IS_TEXT_UNICODE_UNICODE_MASK
Definition: winnt_old.h:931
struct test_data Tests[]
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define IS_TEXT_UNICODE_NOT_UNICODE_MASK
Definition: winnt_old.h:933

Referenced by SearchFile().

◆ RecursiveFind()

static UINT RecursiveFind ( LPCWSTR  lpPath,
_SearchData pSearchData 
)
static

Definition at line 401 of file CFindFolder.cpp.

402 {
403  if (WaitForSingleObject(pSearchData->hStopEvent, 0) != WAIT_TIMEOUT)
404  return 0;
405 
407  WIN32_FIND_DATAW FindData;
408  HANDLE hFindFile;
409  BOOL bMoreFiles = TRUE;
410  UINT uTotalFound = 0;
411 
412  PathCombineW(szPath, lpPath, L"*");
413 
414  for (hFindFile = FindFirstFileW(szPath, &FindData);
415  bMoreFiles && hFindFile != INVALID_HANDLE_VALUE;
416  bMoreFiles = FindNextFileW(hFindFile, &FindData))
417  {
418 #define IS_DOTS(psz) ((psz)[0] == L'.' && ((psz)[1] == 0 || ((psz)[1] == L'.' && (psz)[2] == 0)))
419  if (IS_DOTS(FindData.cFileName))
420  continue;
421 
422  PathCombineW(szPath, lpPath, FindData.cFileName);
423 
424  if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
425  {
427  if (pSearchData->szQueryW.IsEmpty() &&
428  FileNameMatch(FindData.cFileName, pSearchData) &&
429  AttribHiddenMatch(FindData.dwFileAttributes, pSearchData))
430  {
432  uTotalFound++;
433  }
434  status.Format(IDS_SEARCH_FOLDER, FindData.cFileName);
435  PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer()));
436 
437  uTotalFound += RecursiveFind(szPath, pSearchData);
438  }
439  else if (FileNameMatch(FindData.cFileName, pSearchData)
440  && AttribHiddenMatch(FindData.dwFileAttributes, pSearchData)
441  && ContentsMatch(szPath, pSearchData))
442  {
443  uTotalFound++;
445  }
446  }
447 
448  if (hFindFile != INVALID_HANDLE_VALUE)
449  FindClose(hFindFile);
450 
451  return uTotalFound;
452 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define WM_SEARCH_ADD_RESULT
Definition: shellfind.h:31
CStringW szQueryW
#define TRUE
Definition: types.h:120
static BOOL ContentsMatch(LPCWSTR szPath, _SearchData *pSearchData)
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define IDS_SEARCH_FOLDER
Definition: resource.h:173
LPWSTR WINAPI StrDupW(LPCWSTR lpszStr)
Definition: string.c:1089
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static BOOL AttribHiddenMatch(DWORD FileAttributes, _SearchData *pSearchData)
static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG_PTR LPARAM
Definition: windef.h:208
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
static BOOL FileNameMatch(LPCWSTR FindDataFileName, _SearchData *pSearchData)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
#define IS_DOTS(psz)
#define WAIT_TIMEOUT
Definition: dderror.h:14
static const WCHAR L[]
Definition: oid.c:1250
bool IsEmpty() const
Definition: atlsimpstr.h:379
LPCWSTR szPath
Definition: env.c:35
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_SEARCH_UPDATE_STATUS
Definition: shellfind.h:32
LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
Definition: path.c:189
static SERVICE_STATUS status
Definition: service.c:31
HANDLE hStopEvent
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
Definition: ps.c:97

Referenced by CFindFolder::SearchThreadProc().

◆ SearchFile()

static BOOL SearchFile ( LPCWSTR  lpFilePath,
_SearchData pSearchData 
)
static

Definition at line 319 of file CFindFolder.cpp.

320 {
323  return FALSE;
324 
325  // FIXME: support large file
327  if (size == 0 || size == INVALID_FILE_SIZE)
328  {
330  return FALSE;
331  }
332 
335  if (hFileMap == INVALID_HANDLE_VALUE)
336  return FALSE;
337 
338  LPBYTE pbContents = (LPBYTE)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, size);
339  CloseHandle(hFileMap);
340  if (!pbContents)
341  return FALSE;
342 
344  IsDataUnicode(pbContents, size, &encoding, NULL);
345 
346  BOOL bFound;
347  switch (encoding)
348  {
349  case ENCODING_UTF16LE:
350  // UTF-16
351  bFound = StrFindNIW((LPCWSTR)pbContents, pSearchData->szQueryW, size / sizeof(WCHAR));
352  break;
353  case ENCODING_UTF16BE:
354  // UTF-16 BE
355  bFound = StrFindNIW((LPCWSTR)pbContents, pSearchData->szQueryU16BE, size / sizeof(WCHAR));
356  break;
357  case ENCODING_UTF8:
358  // UTF-8
359  bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryU8, size / sizeof(CHAR));
360  break;
361  case ENCODING_ANSI:
362  default:
363  // ANSI or UTF-8 without BOM
364  bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryA, size / sizeof(CHAR));
365  if (!bFound && pSearchData->szQueryA != pSearchData->szQueryU8)
366  bFound = StrFindNIA((LPCSTR)pbContents, pSearchData->szQueryU8, size / sizeof(CHAR));
367  break;
368  }
369 
370  UnmapViewOfFile(pbContents);
371  return bFound;
372 }
static BOOL IsDataUnicode(IN PVOID Buffer, IN DWORD BufferSize, OUT ENCODING *Encoding OPTIONAL, OUT PDWORD SkipBytes OPTIONAL)
CStringW szQueryW
#define CloseHandle
Definition: compat.h:598
CStringA szQueryA
#define MapViewOfFile
Definition: compat.h:604
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define INVALID_FILE_SIZE
Definition: winbase.h:529
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_MAP_READ
Definition: compat.h:635
const char * LPCSTR
Definition: xmlstorage.h:183
#define OPEN_EXISTING
Definition: compat.h:634
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:603
static BOOL StrFindNIW(const WCHAR *lpFirst, const CStringW &lpSrch, UINT cchMax)
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
static BOOL StrFindNIA(const CHAR *lpFirst, const CStringA &lpSrch, UINT cchMax)
#define GENERIC_READ
Definition: compat.h:135
_In_ HANDLE hFile
Definition: mswsock.h:90
ed encoding
Definition: write.c:2825
ENCODING
Definition: more.c:168
CStringW szQueryU16BE
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define CreateFileW
Definition: compat.h:600
#define UnmapViewOfFile
Definition: compat.h:605
CStringA szQueryU8

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 13 of file CFindFolder.cpp.

15 {
16  HRESULT hr;
17  CComPtr<IShellFolder> pShellFolder;
18 
20  if (FAILED(hr))
21  return hr;
22 
23  LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
26 
27  if (ppfti && SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3))))
28  {
29  ppf3->InitializeEx(NULL, pidlAbsolute, ppfti);
30  }
31  else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))
32  {
33  ppf->Initialize(pidlAbsolute);
34  }
35  ILFree (pidlAbsolute);
36 
37  return pShellFolder->QueryInterface(riid, ppvOut);
38 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
REFIID riid
Definition: precomp.h:44
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
#define IID_PPV_ARG(Itype, ppType)
if SUCCEEDED(hr)
HRESULT WINAPI SHCoCreateInstance(LPCWSTR aclsid, const CLSID *clsid, LPUNKNOWN pUnkOuter, REFIID refiid, LPVOID *ppv)
Definition: shellole.c:105
LONG HRESULT
Definition: typedefs.h:79
REFCLSID clsid
Definition: msctf.c:82
#define NULL
Definition: types.h:112
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

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

◆ StrFindNIA()

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

Definition at line 177 of file CFindFolder.cpp.

178 {
179  return StrStrN<CHAR, CStringA, _strnicmp>(lpFirst, lpSrch, cchMax) != NULL;
180 }
UINT cchMax
#define NULL
Definition: types.h:112

Referenced by SearchFile().

◆ StrFindNIW()

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

Definition at line 183 of file CFindFolder.cpp.

184 {
185  return StrStrN<WCHAR, CStringW, _wcsnicmp>(lpFirst, lpSrch, cchMax) != NULL;
186 }
UINT cchMax
#define NULL
Definition: types.h:112

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 162 of file CFindFolder.cpp.

163 {
164  if (!lpFirst || lpSrch.IsEmpty() || !cchMax)
165  return NULL;
166 
167  for (UINT i = cchMax; i > 0 && *lpFirst; i--, lpFirst++)
168  {
169  if (!StrNCmp(lpFirst, lpSrch, lpSrch.GetLength()))
170  return (const TChar*)lpFirst;
171  }
172 
173  return NULL;
174 }
UINT cchMax
#define StrNCmp
Definition: shlwapi.h:1524
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
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shellfind  )

Variable Documentation

◆ g_ColumnDefs