ReactOS  0.4.14-dev-368-gfa26425
CFindFolder.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Search Shell Extension
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Search results folder
5  * COPYRIGHT: Copyright 2019 Brock Mammen
6  */
7 
8 #include "CFindFolder.h"
9 #include <exdispid.h>
10 
12 
13 // FIXME: Remove this declaration after the function has been fully implemented
15 WINAPI
17  UINT cidl,
19  DWORD dwFlags);
20 
21 static HRESULT SHELL32_CoCreateInitSF(LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO* ppfti,
22  LPCITEMIDLIST pidlChild, const GUID* clsid, REFIID riid, LPVOID *ppvOut)
23 {
24  HRESULT hr;
25  CComPtr<IShellFolder> pShellFolder;
26 
28  if (FAILED(hr))
29  return hr;
30 
31  LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
34 
35  if (ppfti && SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3))))
36  {
37  ppf3->InitializeEx(NULL, pidlAbsolute, ppfti);
38  }
39  else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))
40  {
41  ppf->Initialize(pidlAbsolute);
42  }
43  ILFree (pidlAbsolute);
44 
45  return pShellFolder->QueryInterface(riid, ppvOut);
46 }
47 
49  HMENU hMenu,
50  UINT indexMenu,
51  BOOL fByPosition,
52  UINT wID,
53  UINT fType,
54  LPCWSTR dwTypeData,
55  UINT fState)
56 {
57  MENUITEMINFOW mii;
58  WCHAR wszText[100];
59 
60  ZeroMemory(&mii, sizeof(mii));
61  mii.cbSize = sizeof(mii);
62  if (fType == MFT_SEPARATOR)
63  mii.fMask = MIIM_ID | MIIM_TYPE;
64  else if (fType == MFT_STRING)
65  {
67  if (IS_INTRESOURCE(dwTypeData))
68  {
69  if (LoadStringW(_AtlBaseModule.GetResourceInstance(), LOWORD((ULONG_PTR)dwTypeData), wszText, _countof(wszText)))
70  mii.dwTypeData = wszText;
71  else
72  {
73  ERR("failed to load string %p\n", dwTypeData);
74  return;
75  }
76  }
77  else
78  mii.dwTypeData = (LPWSTR)dwTypeData;
79  mii.fState = fState;
80  }
81 
82  mii.wID = wID;
83  mii.fType = fType;
84  InsertMenuItemW(hMenu, indexMenu, fByPosition, &mii);
85 }
86 
87 struct FolderViewColumns
88 {
89  int iResource;
91  int fmt;
92  int cxChar;
93 };
94 
96 {
100 };
101 
103  m_hStopEvent(NULL)
104 {
105 }
106 
108 {
109  CComHeapPtr<ITEMIDLIST> lpFSPidl(ILCreateFromPathW(lpszPath));
110  if (!lpFSPidl)
111  {
112  ERR("Failed to create pidl from path\n");
113  return NULL;
114  }
115  LPITEMIDLIST lpLastFSPidl = ILFindLastID(lpFSPidl);
116 
117  int pathLen = (PathFindFileNameW(lpszPath) - lpszPath) * sizeof(WCHAR);
118  int cbData = sizeof(WORD) + pathLen + lpLastFSPidl->mkid.cb;
119  LPITEMIDLIST pidl = (LPITEMIDLIST) SHAlloc(cbData + sizeof(WORD));
120  if (!pidl)
121  return NULL;
122 
123  LPBYTE p = (LPBYTE) pidl;
124  *((WORD *) p) = cbData;
125  p += sizeof(WORD);
126 
127  memcpy(p, lpszPath, pathLen);
128  p += pathLen - sizeof(WCHAR);
129  *((WCHAR *) p) = '\0';
130  p += sizeof(WCHAR);
131 
132  memcpy(p, lpLastFSPidl, lpLastFSPidl->mkid.cb);
133  p += lpLastFSPidl->mkid.cb;
134 
135  *((WORD *) p) = 0;
136 
137  return pidl;
138 }
139 
141 {
142  if (!pidl || !pidl->mkid.cb)
143  return NULL;
144  return (LPCWSTR) pidl->mkid.abID;
145 }
146 
148 {
149  if (!pidl || !pidl->mkid.cb)
150  return pidl;
151  return (LPCITEMIDLIST) ((LPBYTE) pidl->mkid.abID
152  + ((wcslen((LPCWSTR) pidl->mkid.abID) + 1) * sizeof(WCHAR)));
153 }
154 
156 {
165 };
166 
167 template<typename TChar, typename TString, int (&StrNCmp)(const TChar *, const TChar *, size_t)>
168 static const TChar* StrStrN(const TChar *lpFirst, const TString &lpSrch, UINT cchMax)
169 {
170  if (!lpFirst || lpSrch.IsEmpty() || !cchMax)
171  return NULL;
172 
173  for (UINT i = cchMax; i > 0 && *lpFirst; i--, lpFirst++)
174  {
175  if (!StrNCmp(lpFirst, lpSrch, lpSrch.GetLength()))
176  return (const TChar*)lpFirst;
177  }
178 
179  return NULL;
180 }
181 
182 template<typename TChar, typename TString, int (&StrNCmp)(const TChar *, const TChar *, size_t)>
183 static UINT StrStrNCount(const TChar *lpFirst, const TString &lpSrch, UINT cchMax)
184 {
185  const TChar *lpSearchEnd = lpFirst + cchMax;
186  UINT uCount = 0;
187  while (lpFirst < lpSearchEnd && (lpFirst = StrStrN<TChar, TString, StrNCmp>(lpFirst, lpSrch, cchMax)))
188  {
189  uCount++;
190  lpFirst += lpSrch.GetLength();
191  cchMax = lpSearchEnd - lpFirst;
192  }
193  return uCount;
194 }
195 
196 static UINT StrStrCountNIA(const CHAR *lpFirst, const CStringA &lpSrch, UINT cchMax)
197 {
198  return StrStrNCount<CHAR, CStringA, _strnicmp>(lpFirst, lpSrch, cchMax);
199 }
200 
201 static UINT StrStrCountNIW(const WCHAR *lpFirst, const CStringW &lpSrch, UINT cchMax)
202 {
203  return StrStrNCount<WCHAR, CStringW, _wcsnicmp>(lpFirst, lpSrch, cchMax);
204 }
205 
206 static UINT SearchFile(LPCWSTR lpFilePath, _SearchData *pSearchData)
207 {
210  return 0;
211 
213  HANDLE hFileMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
215  if (hFileMap == INVALID_HANDLE_VALUE)
216  return 0;
217 
218  LPBYTE lpFileContent = (LPBYTE) MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
219  CloseHandle(hFileMap);
220  if (!lpFileContent)
221  return 0;
222 
223  UINT uMatches = 0;
224  // Check for UTF-16 BOM
225  if (size >= 2 && lpFileContent[0] == 0xFF && lpFileContent[1] == 0xFE)
226  {
227  uMatches = StrStrCountNIW((LPCWSTR) lpFileContent, pSearchData->szQueryW, size / sizeof(WCHAR));
228  }
229  else
230  {
231  uMatches = StrStrCountNIA((LPCSTR) lpFileContent, pSearchData->szQueryA, size / sizeof(CHAR));
232  }
233 
234  UnmapViewOfFile(lpFileContent);
235 
236  return uMatches;
237 }
238 
239 static BOOL FileNameMatch(LPCWSTR FindDataFileName, _SearchData *pSearchData)
240 {
241  if (pSearchData->szFileName.IsEmpty() || PathMatchSpecW(FindDataFileName, pSearchData->szFileName))
242  {
243  return TRUE;
244  }
245  return FALSE;
246 }
247 
249 {
250  if (pSearchData->szQueryA.IsEmpty() || SearchFile(szPath, pSearchData))
251  {
252  return TRUE;
253  }
254  return FALSE;
255 }
256 
258 {
259  if (!(FileAttributes & FILE_ATTRIBUTE_HIDDEN) || (pSearchData->SearchHidden))
260  {
261  return TRUE;
262  }
263  return FALSE;
264 }
265 
266 static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
267 {
268  if (WaitForSingleObject(pSearchData->hStopEvent, 0) != WAIT_TIMEOUT)
269  return 0;
270 
272  WIN32_FIND_DATAW FindData;
273  HANDLE hFindFile;
274  BOOL bMoreFiles = TRUE;
275  UINT uTotalFound = 0;
276 
277  PathCombineW(szPath, lpPath, L"*.*");
278 
279  for (hFindFile = FindFirstFileW(szPath, &FindData);
280  bMoreFiles && hFindFile != INVALID_HANDLE_VALUE;
281  bMoreFiles = FindNextFileW(hFindFile, &FindData))
282  {
283  if (!wcscmp(FindData.cFileName, L".") || !wcscmp(FindData.cFileName, L".."))
284  continue;
285 
286  PathCombineW(szPath, lpPath, FindData.cFileName);
287 
288  if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
289  {
291  if (FileNameMatch(FindData.cFileName, pSearchData)
292  && AttribHiddenMatch(FindData.dwFileAttributes, pSearchData))
293  {
295  uTotalFound++;
296  }
297  status.Format(IDS_SEARCH_FOLDER, FindData.cFileName);
298  PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer()));
299 
300  uTotalFound += RecursiveFind(szPath, pSearchData);
301  }
302  else if (FileNameMatch(FindData.cFileName, pSearchData)
303  && AttribHiddenMatch(FindData.dwFileAttributes, pSearchData)
304  && ContentsMatch(szPath, pSearchData))
305  {
306  uTotalFound++;
308  }
309  }
310 
311  if (hFindFile != INVALID_HANDLE_VALUE)
312  FindClose(hFindFile);
313 
314  return uTotalFound;
315 }
316 
318 {
319  _SearchData *data = static_cast<_SearchData*>(lpParameter);
320 
321  data->pFindFolder->NotifyConnections(DISPID_SEARCHSTART);
322 
323  UINT uTotalFound = RecursiveFind(data->szPath, data);
324 
325  data->pFindFolder->NotifyConnections(DISPID_SEARCHCOMPLETE);
326 
328  status.Format(IDS_SEARCH_FILES_FOUND, uTotalFound);
329  ::PostMessageW(data->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer()));
330  ::SendMessageW(data->hwnd, WM_SEARCH_STOP, 0, 0);
331 
332  CloseHandle(data->hStopEvent);
333  delete data;
334 
335  return 0;
336 }
337 
339 {
340  DISPPARAMS dispatchParams = {0};
341  CComDynamicUnkArray &subscribers =
343  for (IUnknown** pSubscriber = subscribers.begin(); pSubscriber < subscribers.end(); pSubscriber++)
344  {
345  if (!*pSubscriber)
346  continue;
347 
348  CComPtr<IDispatch> pDispatch;
349  HRESULT hResult = (*pSubscriber)->QueryInterface(IID_PPV_ARG(IDispatch, &pDispatch));
350  if (!FAILED_UNEXPECTEDLY(hResult))
351  pDispatch->Invoke(id, GUID_NULL, 0, DISPATCH_METHOD, &dispatchParams, NULL, NULL, NULL);
352  }
353 }
354 
356 {
357  HKEY hkey;
358  DWORD size = sizeof(DWORD);
359  DWORD result;
360  DWORD SearchHiddenValue = 0;
361 
362  if (!lParam)
363  return 0;
364 
365  // Clear all previous search results
366  UINT uItemIndex;
367  m_shellFolderView->RemoveObject(NULL, &uItemIndex);
368 
369  _SearchData* pSearchData = new _SearchData();
370  pSearchData->pFindFolder = this;
371  pSearchData->hwnd = m_hWnd;
372 
373  SearchStart *pSearchParams = (SearchStart *) lParam;
374  pSearchData->szPath = pSearchParams->szPath;
375  pSearchData->szFileName = pSearchParams->szFileName;
376  pSearchData->szQueryA = pSearchParams->szQuery;
377  pSearchData->szQueryW = pSearchParams->szQuery;
378  pSearchData->SearchHidden = pSearchParams->SearchHidden;
379  SHFree(pSearchParams);
380 
381  TRACE("pSearchParams->SearchHidden is '%d'.\n", pSearchData->SearchHidden);
382 
383  if (pSearchData->SearchHidden)
384  SearchHiddenValue = 1;
385  else
386  SearchHiddenValue = 0;
387 
388  /* Placing the code to save the changed settings to the registry here has the effect of not saving any changes */
389  /* to the registry unless the user clicks on the "Search" button. This is the same as what we see in Windows. */
390  result = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", 0, KEY_SET_VALUE, &hkey);
391  if (result == ERROR_SUCCESS)
392  {
393  if (RegSetValueExW(hkey, L"SearchHidden", NULL, REG_DWORD, (const BYTE*)&SearchHiddenValue, size) == ERROR_SUCCESS)
394  {
395  TRACE("SearchHidden is '%d'.\n", SearchHiddenValue);
396  }
397  else
398  {
399  ERR("RegSetValueEx for \"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SearchHidden\" Failed.\n");
400  }
401  RegCloseKey(hkey);
402  }
403  else
404  {
405  ERR("RegOpenKey for \"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\" Failed.\n");
406  }
407 
408  if (m_hStopEvent)
410  pSearchData->hStopEvent = m_hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
411 
412  if (!SHCreateThread(SearchThreadProc, pSearchData, NULL, NULL))
413  {
414  SHFree(pSearchData);
415  return 0;
416  }
417 
418  return 0;
419 }
420 
422 {
423  if (m_hStopEvent)
424  {
426  m_hStopEvent = NULL;
427  }
428  return 0;
429 }
430 
432 {
433  if (!lParam)
434  return 0;
435 
436  CComHeapPtr<WCHAR> lpPath((LPWSTR) lParam);
437 
438  CComHeapPtr<ITEMIDLIST> lpSearchPidl(_ILCreate(lpPath));
439  if (lpSearchPidl)
440  {
441  UINT uItemIndex;
442  m_shellFolderView->AddObject(lpSearchPidl, &uItemIndex);
443  }
444 
445  return 0;
446 }
447 
449 {
451  if (m_shellBrowser)
452  {
453  m_shellBrowser->SetStatusTextSB(status);
454  }
455 
456  return 0;
457 }
458 
459 // *** IShellFolder2 methods ***
461 {
463  return E_NOTIMPL;
464 }
465 
467 {
469  return E_NOTIMPL;
470 }
471 
473 {
474  if (pSort)
475  *pSort = 0;
476  if (pDisplay)
477  *pDisplay = 0;
478  return S_OK;
479 }
480 
482 {
483  if (!pcsFlags)
484  return E_INVALIDARG;
485  if (iColumn >= _countof(g_ColumnDefs))
486  return m_pisfInner->GetDefaultColumnState(iColumn - _countof(g_ColumnDefs) + 1, pcsFlags);
487  *pcsFlags = g_ColumnDefs[iColumn].dwDefaultState;
488  return S_OK;
489 }
490 
492 {
493  return m_pisfInner->GetDetailsEx(pidl, pscid, pv);
494 }
495 
497 {
498  if (iColumn >= _countof(g_ColumnDefs))
499  return m_pisfInner->GetDetailsOf(_ILGetFSPidl(pidl), iColumn - _countof(g_ColumnDefs) + 1, pDetails);
500 
501  pDetails->cxChar = g_ColumnDefs[iColumn].cxChar;
502  pDetails->fmt = g_ColumnDefs[iColumn].fmt;
503 
504  if (!pidl)
505  return SHSetStrRet(&pDetails->str, _AtlBaseModule.GetResourceInstance(), g_ColumnDefs[iColumn].iResource);
506 
507  if (iColumn == 1)
508  {
509  return SHSetStrRet(&pDetails->str, _ILGetPath(pidl));
510  }
511 
512  return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);
513 }
514 
516 {
518  return E_NOTIMPL;
519 }
520 
521 // *** IShellFolder methods ***
522 STDMETHODIMP CFindFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, ULONG *pchEaten,
523  PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
524 {
526  return E_NOTIMPL;
527 }
528 
529 STDMETHODIMP CFindFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
530 {
531  *ppEnumIDList = NULL;
532  return S_FALSE;
533 }
534 
536 {
538  return E_NOTIMPL;
539 }
540 
542 {
544  return E_NOTIMPL;
545 }
546 
548 {
549  return m_pisfInner->CompareIDs(lParam, _ILGetFSPidl(pidl1), _ILGetFSPidl(pidl2));
550 }
551 
553 {
554  if (riid == IID_IShellView)
555  {
556  SFV_CREATE sfvparams = {};
557  sfvparams.cbSize = sizeof(SFV_CREATE);
558  sfvparams.pshf = this;
559  sfvparams.psfvcb = this;
560  HRESULT hr = SHCreateShellFolderView(&sfvparams, (IShellView **) ppvOut);
561  if (FAILED_UNEXPECTEDLY(hr))
562  {
563  return hr;
564  }
565 
566  return ((IShellView * ) * ppvOut)->QueryInterface(IID_PPV_ARG(IShellFolderView, &m_shellFolderView));
567  }
568  return E_NOINTERFACE;
569 }
570 
572 {
574  aFSPidl.Allocate(cidl);
575  for (UINT i = 0; i < cidl; i++)
576  {
577  aFSPidl[i] = _ILGetFSPidl(apidl[i]);
578  }
579 
580  return m_pisfInner->GetAttributesOf(cidl, aFSPidl, rgfInOut);
581 }
582 
584  public IContextMenu,
585  public CComObjectRootEx<CComMultiThreadModelNoCS>
586 {
590  static const UINT ADDITIONAL_MENU_ITEMS = 2;
591 
593  STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
594  {
595  m_firstCmdId = indexMenu;
597  _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst++, MFT_SEPARATOR, NULL, 0);
598  return m_pInner->QueryContextMenu(hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
599  }
600 
602  {
603  if (!IS_INTRESOURCE(lpcmi->lpVerb))
604  {
605  return m_pInner->InvokeCommand(lpcmi);
606  }
607 
609  {
610  PCUITEMID_CHILD *apidl;
611  UINT cidl;
612  HRESULT hResult = m_shellFolderView->GetSelectedObjects(&apidl, &cidl);
613  if (FAILED_UNEXPECTEDLY(hResult))
614  return hResult;
615 
616  for (UINT i = 0; i < cidl; i++)
617  {
619  if (!folderPidl)
620  return E_OUTOFMEMORY;
621  CComHeapPtr<ITEMIDLIST> filePidl(ILCombine(folderPidl, _ILGetFSPidl(apidl[i])));
622  if (!filePidl)
623  return E_OUTOFMEMORY;
624  SHOpenFolderAndSelectItems(folderPidl, 1, &filePidl, 0);
625  }
626  return S_OK;
627  }
628 
629  CMINVOKECOMMANDINFOEX actualCmdInfo;
630  memcpy(&actualCmdInfo, lpcmi, lpcmi->cbSize);
631  actualCmdInfo.lpVerb -= ADDITIONAL_MENU_ITEMS;
632  return m_pInner->InvokeCommand((CMINVOKECOMMANDINFO *)&actualCmdInfo);
633  }
634 
635  STDMETHODIMP GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen)
636  {
637  return m_pInner->GetCommandString(idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
638  }
639 
640 public:
641  static HRESULT Create(IShellFolderView *pShellFolderView, IContextMenu *pInnerContextMenu, IContextMenu **pContextMenu)
642  {
645  if (FAILED_UNEXPECTEDLY(hResult))
646  return hResult;
647  pObj->m_shellFolderView = pShellFolderView;
648  pObj->m_pInner = pInnerContextMenu;
649  return pObj->QueryInterface(IID_PPV_ARG(IContextMenu, pContextMenu));
650  }
651 
653  COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
654  END_COM_MAP()
655 };
656 
658  UINT *prgfInOut, LPVOID *ppvOut)
659 {
660  if (cidl <= 0)
661  {
662  return m_pisfInner->GetUIObjectOf(hwndOwner, cidl, apidl, riid, prgfInOut, ppvOut);
663  }
664 
666  aFSPidl.Allocate(cidl);
667  for (UINT i = 0; i < cidl; i++)
668  {
669  aFSPidl[i] = _ILGetFSPidl(apidl[i]);
670  }
671 
672  if (riid == IID_IContextMenu)
673  {
675  if (!folderPidl)
676  return E_OUTOFMEMORY;
677  CComPtr<IShellFolder> pDesktopFolder;
678  HRESULT hResult = SHGetDesktopFolder(&pDesktopFolder);
679  if (FAILED_UNEXPECTEDLY(hResult))
680  return hResult;
681  CComPtr<IShellFolder> pShellFolder;
682  hResult = pDesktopFolder->BindToObject(folderPidl, NULL, IID_PPV_ARG(IShellFolder, &pShellFolder));
683  if (FAILED_UNEXPECTEDLY(hResult))
684  return hResult;
685  CComPtr<IContextMenu> pContextMenu;
686  hResult = pShellFolder->GetUIObjectOf(hwndOwner, cidl, aFSPidl, riid, prgfInOut, (LPVOID *)&pContextMenu);
687  if (FAILED_UNEXPECTEDLY(hResult))
688  return hResult;
689  return CFindFolderContextMenu::Create(m_shellFolderView, pContextMenu, (IContextMenu **)ppvOut);
690  }
691 
692  return m_pisfInner->GetUIObjectOf(hwndOwner, cidl, aFSPidl, riid, prgfInOut, ppvOut);
693 }
694 
696 {
697  return m_pisfInner->GetDisplayNameOf(_ILGetFSPidl(pidl), dwFlags, pName);
698 }
699 
701  PITEMID_CHILD *pPidlOut)
702 {
704  return E_NOTIMPL;
705 }
706 
709 {
710  switch (uMsg)
711  {
712  case SFVM_DEFVIEWMODE:
713  {
714  FOLDERVIEWMODE *pViewMode = (FOLDERVIEWMODE *) lParam;
715  *pViewMode = FVM_DETAILS;
716  return S_OK;
717  }
718  case SFVM_WINDOWCREATED:
719  {
720  // Subclass window to receive window messages
722 
723  // Get shell browser for updating status bar text
724  CComPtr<IServiceProvider> pServiceProvider;
725  HRESULT hr = m_shellFolderView->QueryInterface(IID_PPV_ARG(IServiceProvider, &pServiceProvider));
726  if (FAILED_UNEXPECTEDLY(hr))
727  return hr;
728  hr = pServiceProvider->QueryService(SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &m_shellBrowser));
729  if (FAILED_UNEXPECTEDLY(hr))
730  return hr;
731 
732  // Open search bar
733  CComPtr<IWebBrowser2> pWebBrowser2;
734  hr = m_shellBrowser->QueryInterface(IID_PPV_ARG(IWebBrowser2, &pWebBrowser2));
735  if (FAILED_UNEXPECTEDLY(hr))
736  return hr;
737  WCHAR pwszGuid[MAX_PATH];
738  StringFromGUID2(CLSID_FileSearchBand, pwszGuid, _countof(pwszGuid));
739  CComVariant searchBar(pwszGuid);
740  return pWebBrowser2->ShowBrowserBar(&searchBar, NULL, NULL);
741  }
742  }
743  return E_NOTIMPL;
744 }
745 
748 {
749  *pidl = ILClone(m_pidl);
750  return S_OK;
751 }
752 
753 // *** IPersistFolder methods ***
755 {
756  m_pidl = ILClone(pidl);
757  if (!m_pidl)
758  return E_OUTOFMEMORY;
759 
761  NULL,
762  NULL,
763  &CLSID_ShellFSFolder,
765 }
766 
767 // *** IPersist methods ***
769 {
770  if (pClassId == NULL)
771  return E_INVALIDARG;
772  *pClassId = CLSID_FindFolder;
773  return S_OK;
774 }
#define CreateEvent
Definition: winbase.h:3572
STDMETHODIMP BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
DWORD dwDefaultState
Definition: CFontExt.cpp:17
#define WM_SEARCH_ADD_RESULT
Definition: shellfind.h:31
IUnknown ** begin()
Definition: atlcom.h:1064
#define MFT_STRING
Definition: winuser.h:741
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
CStringW szQueryW
#define CloseHandle
Definition: compat.h:406
STDMETHODIMP GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
#define E_NOINTERFACE
Definition: winerror.h:2364
CStringA szQueryA
CComPtr< CFindFolder > pFindFolder
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MapViewOfFile
Definition: compat.h:410
STDMETHODIMP GetDefaultSearchGUID(GUID *pguid)
HRESULT hr
Definition: shlfolder.c:183
#define KEY_SET_VALUE
Definition: nt_native.h:1017
IShellFolderViewCB * psfvcb
Definition: shlobj.h:1276
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HANDLE m_hStopEvent
Definition: CFindFolder.h:70
LPITEMIDLIST m_pidl
Definition: CFindFolder.h:66
interface IBindCtx * LPBC
Definition: objfwd.h:18
REFIID riid
Definition: precomp.h:44
static UINT StrStrCountNIW(const WCHAR *lpFirst, const CStringW &lpSrch, UINT cchMax)
static BOOL ContentsMatch(LPCWSTR szPath, _SearchData *pSearchData)
#define _countof(array)
Definition: fontsub.cpp:30
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
_In_ LPCSTR lpName
Definition: winbase.h:2736
#define IDS_COL_NAME
Definition: resource.h:6
#define LVCFMT_LEFT
Definition: commctrl.h:2594
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
#define IDS_COL_LOCATION
Definition: resource.h:170
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define ZeroMemory
Definition: winbase.h:1642
LPWSTR dwTypeData
Definition: winuser.h:3243
#define IDS_SEARCH_FOLDER
Definition: resource.h:173
LRESULT StartSearch(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
UINT_PTR WPARAM
Definition: windef.h:207
UINT uFlags
Definition: api.c:59
char * LPSTR
Definition: xmlstorage.h:182
static DWORD WINAPI SearchThreadProc(LPVOID lpParameter)
static void WINAPI _InsertMenuItemW(HMENU hMenu, UINT indexMenu, BOOL fByPosition, UINT wID, UINT fType, LPCWSTR dwTypeData, UINT fState)
Definition: CFindFolder.cpp:48
static LPOLESTR
Definition: stg_prop.c:27
LRESULT StopSearch(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pcsfv, IShellView **ppsv)
Definition: CDefView.cpp:3456
#define IID_PPV_ARG(Itype, ppType)
LPWSTR WINAPI StrDupW(LPCWSTR lpszStr)
Definition: string.c:1089
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define DWORD
Definition: nt_native.h:44
STRRET str
Definition: shtypes.idl:108
static LPCWSTR _ILGetPath(LPCITEMIDLIST pidl)
WPARAM wParam
Definition: combotst.c:138
#define DISPATCH_METHOD
Definition: oleauto.h:1006
STDMETHODIMP GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
uint32_t ULONG_PTR
Definition: typedefs.h:63
STDMETHODIMP GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen)
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static BOOL AttribHiddenMatch(DWORD FileAttributes, _SearchData *pSearchData)
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
Definition: dwarf.h:133
STDMETHODIMP MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define MFS_ENABLED
Definition: winuser.h:745
WCHAR szQuery[MAX_PATH]
Definition: shellfind.h:38
static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
CStringW szFileName
#define MIIM_STATE
Definition: winuser.h:716
unsigned int BOOL
Definition: ntddk_ex.h:94
CStringW szPath
WINE_DEFAULT_DEBUG_CHANNEL(shellfind)
STDMETHODIMP GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *pDetails)
#define IDS_COL_RELEVANCE
Definition: resource.h:171
bool Allocate(_In_ size_t nElements=1)
Definition: atlalloc.h:143
STDMETHODIMP GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET pName)
#define DISPID_SEARCHSTART
Definition: exdispid.h:172
#define STDMETHODIMP
Definition: basetyps.h:43
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
STDMETHODIMP BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
smooth NULL
Definition: ftsmooth.c:416
static const UINT ADDITIONAL_MENU_ITEMS
STDMETHODIMP GetClassID(CLSID *pClassId)
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
LONG_PTR LPARAM
Definition: windef.h:208
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
#define DISPID_SEARCHCOMPLETE
Definition: exdispid.h:173
static UINT StrStrNCount(const TChar *lpFirst, const TString &lpSrch, UINT cchMax)
STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
#define FILE_MAP_READ
Definition: compat.h:435
FOLDERVIEWMODE
Definition: shobjidl.idl:658
static HRESULT Create(IShellFolderView *pShellFolderView, IContextMenu *pInnerContextMenu, IContextMenu **pContextMenu)
const char * LPCSTR
Definition: xmlstorage.h:183
struct _SFV_CREATE SFV_CREATE
_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
HRESULT WINAPI SHCoCreateInstance(LPCWSTR aclsid, const CLSID *clsid, LPUNKNOWN pUnkOuter, REFIID refiid, LPVOID *ppv)
Definition: shellole.c:105
WCHAR szFileName[MAX_PATH]
Definition: shellfind.h:37
#define OPEN_EXISTING
Definition: compat.h:434
CComPtr< IShellFolder2 > m_pisfInner
Definition: CFindFolder.h:67
#define MIIM_ID
Definition: winuser.h:717
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:541
#define IDS_SEARCH_OPEN_FOLDER
Definition: resource.h:174
#define IDS_SEARCH_FILES_FOUND
Definition: resource.h:172
#define TRACE(s)
Definition: solgame.cpp:4
static LPSTR pName
Definition: security.c:75
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
STDMETHODIMP GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
GLsizeiptr size
Definition: glext.h:5919
static BOOL FileNameMatch(LPCWSTR FindDataFileName, _SearchData *pSearchData)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
LRESULT UpdateStatus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SFVM_WINDOWCREATED
Definition: shlobj.h:1226
LONG HRESULT
Definition: typedefs.h:77
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:409
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
static UINT StrStrCountNIA(const CHAR *lpFirst, const CStringA &lpSrch, UINT cchMax)
#define WINAPI
Definition: msvc.h:8
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
STDMETHODIMP GetCurFolder(PIDLIST_ABSOLUTE *pidl)
STDMETHODIMP GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
STDMETHODIMP CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
STDMETHODIMP GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT *prgfInOut, LPVOID *ppvOut)
#define WAIT_TIMEOUT
Definition: dderror.h:14
UINT cchMax
static LPCITEMIDLIST _ILGetFSPidl(LPCITEMIDLIST pidl)
#define MFT_SEPARATOR
Definition: winuser.h:739
STDMETHODIMP CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
void NotifyConnections(DISPID id)
REFCLSID clsid
Definition: msctf.c:82
#define SFVM_DEFVIEWMODE
Definition: shlobj.h:1236
static const WCHAR L[]
Definition: oid.c:1250
static LPITEMIDLIST _ILCreate(LPCWSTR lpszPath)
STDMETHODIMP EnumSearches(IEnumExtraSearch **ppenum)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MIIM_TYPE
Definition: winuser.h:720
LPVOID lpParameter
Definition: kernel32.h:241
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define GUID_NULL
Definition: ks.h:106
#define StrNCmp
Definition: shlwapi.h:1524
HWND m_hWnd
Definition: atlwin.h:268
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
STDMETHOD() QueryInterface(REFIID iid, void **ppvObject)
Definition: atlcom.h:160
#define ERR(fmt,...)
Definition: debug.h:109
bool IsEmpty() const
Definition: atlsimpstr.h:379
IShellFolder * pshf
Definition: shlobj.h:1274
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define S_OK
Definition: intsafe.h:59
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define RegOpenKeyEx
Definition: winreg.h:520
IUnknown ** end()
Definition: atlcom.h:1069
EXTERN_C HRESULT WINAPI SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD dwFlags)
Definition: shlfolder.cpp:389
CComPtr< IShellFolderView > m_shellFolderView
UINT cbSize
Definition: shlobj.h:1273
LPCWSTR szPath
Definition: env.c:35
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:228
WCHAR szPath[MAX_PATH]
Definition: shellfind.h:36
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:561
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define E_NOTIMPL
Definition: ddrawi.h:99
CComPtr< IShellBrowser > m_shellBrowser
Definition: CFindFolder.h:69
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
STDMETHODIMP Initialize(PCIDLIST_ABSOLUTE pidl)
unsigned int UINT
Definition: ndis.h:50
BOOL SearchHidden
Definition: shellfind.h:39
#define PAGE_READONLY
Definition: compat.h:127
static const TChar * StrStrN(const TChar *lpFirst, const TString &lpSrch, UINT cchMax)
CComPtr< IShellFolderView > m_shellFolderView
Definition: CFindFolder.h:68
STDMETHODIMP ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, ULONG *pchEaten, PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
#define CreateFileW
Definition: compat.h:408
#define WM_SEARCH_STOP
Definition: shellfind.h:30
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
const ITEMIDLIST_RELATIVE UNALIGNED * PCUIDLIST_RELATIVE
Definition: shtypes.idl:57
BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
Definition: path.c:1943
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static HRESULT SHELL32_CoCreateInitSF(LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO *ppfti, LPCITEMIDLIST pidlChild, const GUID *clsid, REFIID riid, LPVOID *ppvOut)
Definition: CFindFolder.cpp:21
struct stdole::DISPPARAMS DISPPARAMS
STDMETHODIMP SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
unsigned int ULONG
Definition: retypes.h:1
STDMETHODIMP MapColumnToSCID(UINT iColumn, SHCOLUMNID *pscid)
#define UNIMPLEMENTED
Definition: debug.h:114
STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
STDMETHODIMP EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define END_COM_MAP()
Definition: atlcom.h:552
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
#define SID_SShellBrowser
Definition: shlguid.h:125
CComPtr< IContextMenu > m_pInner
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define WM_SEARCH_UPDATE_STATUS
Definition: shellfind.h:32
LONG_PTR LRESULT
Definition: windef.h:209
#define EXTERN_C
Definition: basetyps.h:12
LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
Definition: path.c:189
LRESULT AddResult(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define UnmapViewOfFile
Definition: compat.h:411
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE pfnThreadProc, VOID *pData, DWORD dwFlags, LPTHREAD_START_ROUTINE pfnCallback)
Definition: thread.c:356
GLuint64EXT * result
Definition: glext.h:11304
#define REG_DWORD
Definition: sdbapi.c:596
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
static SERVICE_STATUS status
Definition: service.c:31
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
HANDLE hStopEvent
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:309
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static UINT SearchFile(LPCWSTR lpFilePath, _SearchData *pSearchData)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
static FolderViewColumns g_ColumnDefs[]
Definition: CFindFolder.cpp:95
Definition: ps.c:97