ReactOS  0.4.15-dev-509-g96a357b
CFileSysEnum Class Reference
Inheritance diagram for CFileSysEnum:
Collaboration diagram for CFileSysEnum:

Public Member Functions

 CFileSysEnum ()
 
 ~CFileSysEnum ()
 
HRESULT WINAPI Initialize (LPWSTR sPathTarget, DWORD dwFlags)
 
- Public Member Functions inherited from CEnumIDListBase
 CEnumIDListBase ()
 
virtual ~CEnumIDListBase ()
 
BOOL AddToEnumList (LPITEMIDLIST pidl)
 
BOOL DeleteList ()
 
BOOL HasItemWithCLSID (LPITEMIDLIST pidl)
 
HRESULT AppendItemsFromEnumerator (IEnumIDList *pEnum)
 
virtual HRESULT STDMETHODCALLTYPE Next (ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched)
 
virtual HRESULT STDMETHODCALLTYPE Skip (ULONG celt)
 
virtual HRESULT STDMETHODCALLTYPE Reset ()
 
virtual HRESULT STDMETHODCALLTYPE Clone (IEnumIDList **ppenum)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 
- Public Member Functions inherited from IEnumIDList
HRESULT Next ([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] PITEMID_CHILD *rgelt, [out] ULONG *pceltFetched)
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Private Member Functions

HRESULT _AddFindResult (LPWSTR sParentDir, const WIN32_FIND_DATAW &FindData, DWORD dwFlags)
 

Additional Inherited Members

- Public Types inherited from IEnumIDList
typedef IEnumIDListLPENUMIDLIST
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 

Detailed Description

Definition at line 350 of file CFSFolder.cpp.

Constructor & Destructor Documentation

◆ CFileSysEnum()

CFileSysEnum::CFileSysEnum ( )
inline

Definition at line 448 of file CFSFolder.cpp.

449  {
450 
451  }

◆ ~CFileSysEnum()

CFileSysEnum::~CFileSysEnum ( )
inline

Definition at line 453 of file CFSFolder.cpp.

454  {
455  }

Member Function Documentation

◆ _AddFindResult()

HRESULT CFileSysEnum::_AddFindResult ( LPWSTR  sParentDir,
const WIN32_FIND_DATAW FindData,
DWORD  dwFlags 
)
inlineprivate

Definition at line 354 of file CFSFolder.cpp.

355  {
356 #define SUPER_HIDDEN (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)
357 
358  // Does it need special handling because it is hidden?
359  if (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
360  {
361  DWORD dwHidden = FindData.dwFileAttributes & SUPER_HIDDEN;
362 
363  // Is it hidden, but are we not asked to include hidden?
364  if (dwHidden == FILE_ATTRIBUTE_HIDDEN && !(dwFlags & SHCONTF_INCLUDEHIDDEN))
365  return S_OK;
366 
367  // Is it a system file, but are we not asked to include those?
368  if (dwHidden == SUPER_HIDDEN && !(dwFlags & SHCONTF_INCLUDESUPERHIDDEN))
369  return S_OK;
370  }
371 
372  BOOL bDirectory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
373 
374  HRESULT hr;
375  if (bDirectory)
376  {
377  // Skip the current and parent directory nodes
378  if (!strcmpW(FindData.cFileName, L".") || !strcmpW(FindData.cFileName, L".."))
379  return S_OK;
380 
381  // Does this directory need special handling?
382  if ((FindData.dwFileAttributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)) != 0)
383  {
384  WCHAR Tmp[MAX_PATH];
385  CLSID clsidFolder;
386 
387  PathCombineW(Tmp, sParentDir, FindData.cFileName);
388 
389  hr = SHELL32_GetCLSIDForDirectory(Tmp, L"CLSID", &clsidFolder);
390  if (SUCCEEDED(hr))
391  {
392  ERR("SHOULD DO SOMETHING WITH CLSID?\n");
393  }
394  }
395  }
396  else
397  {
398  CLSID clsidFile;
399  LPWSTR pExtension = PathFindExtensionW(FindData.cFileName);
400  if (pExtension)
401  {
402  // FIXME: Cache this?
403  hr = GetCLSIDForFileTypeFromExtension(pExtension, L"CLSID", &clsidFile);
404  if (hr == S_OK)
405  {
406  HKEY hkey;
407  hr = SHRegGetCLSIDKeyW(clsidFile, L"ShellFolder", FALSE, FALSE, &hkey);
408  if (SUCCEEDED(hr))
409  {
410  ::RegCloseKey(hkey);
411 
412  // This should be presented as directory!
413  bDirectory = TRUE;
414  TRACE("Treating '%S' as directory!\n", FindData.cFileName);
415  }
416  }
417  }
418  }
419 
420  LPITEMIDLIST pidl = NULL;
421  if (bDirectory)
422  {
423  if (dwFlags & SHCONTF_FOLDERS)
424  {
425  TRACE("(%p)-> (folder=%s)\n", this, debugstr_w(FindData.cFileName));
426  pidl = _ILCreateFromFindDataW(&FindData);
427  }
428  }
429  else
430  {
431  if (dwFlags & SHCONTF_NONFOLDERS)
432  {
433  TRACE("(%p)-> (file =%s)\n", this, debugstr_w(FindData.cFileName));
434  pidl = _ILCreateFromFindDataW(&FindData);
435  }
436  }
437 
438  if (pidl && !AddToEnumList(pidl))
439  {
441  return E_FAIL;
442  }
443 
444  return S_OK;
445  }
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
BOOL AddToEnumList(LPITEMIDLIST pidl)
static HRESULT SHELL32_GetCLSIDForDirectory(LPCWSTR pwszDir, LPCWSTR KeyName, CLSID *pclsidFolder)
Definition: CFSFolder.cpp:586
#define E_FAIL
Definition: ddrawi.h:102
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SUPER_HIDDEN
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:442
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID, LPCWSTR, BOOL, BOOL, PHKEY)
Definition: reg.c:2422
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HRESULT GetCLSIDForFileTypeFromExtension(LPWSTR pExtension, LPCWSTR KeyName, CLSID *pclsid)
Definition: CFSFolder.cpp:72
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:59
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
LPITEMIDLIST _ILCreateFromFindDataW(const WIN32_FIND_DATAW *wfd)
Definition: pidl.c:1735
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
Definition: path.c:189
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by Initialize().

◆ Initialize()

HRESULT WINAPI CFileSysEnum::Initialize ( LPWSTR  sPathTarget,
DWORD  dwFlags 
)
inline

Definition at line 457 of file CFSFolder.cpp.

458  {
459  TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(sPathTarget), dwFlags);
460 
461  if (!sPathTarget || !sPathTarget[0])
462  {
463  WARN("No path for CFileSysEnum, empty result!\n");
464  return S_FALSE;
465  }
466 
467  WCHAR szFindPattern[MAX_PATH];
468  HRESULT hr = StringCchCopyW(szFindPattern, _countof(szFindPattern), sPathTarget);
469  if (FAILED_UNEXPECTEDLY(hr))
470  return hr;
471 
472  /* FIXME: UNSAFE CRAP */
473  PathAddBackslashW(szFindPattern);
474 
475  hr = StringCchCatW(szFindPattern, _countof(szFindPattern), L"*.*");
476  if (FAILED_UNEXPECTEDLY(hr))
477  return hr;
478 
479 
480  WIN32_FIND_DATAW FindData;
481  HANDLE hFind = FindFirstFileW(szFindPattern, &FindData);
482  if (hFind == INVALID_HANDLE_VALUE)
484 
485  do
486  {
487  hr = _AddFindResult(sPathTarget, FindData, dwFlags);
488 
489  if (FAILED_UNEXPECTEDLY(hr))
490  break;
491 
492  } while(FindNextFileW(hFind, &FindData));
493 
494  if (SUCCEEDED(hr))
495  {
496  DWORD dwError = GetLastError();
497  if (dwError != ERROR_NO_MORE_FILES)
498  {
499  hr = HRESULT_FROM_WIN32(dwError);
501  }
502  }
503  TRACE("(%p)->(hr=0x%08x)\n", this, hr);
504  FindClose(hFind);
505  return hr;
506  }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define debugstr_w
Definition: kernel32.h:32
#define S_FALSE
Definition: winerror.h:2357
HRESULT _AddFindResult(LPWSTR sParentDir, const WIN32_FIND_DATAW &FindData, DWORD dwFlags)
Definition: CFSFolder.cpp:354
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define _countof(array)
Definition: sndvol32.h:68
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define SUCCEEDED(hr)
Definition: intsafe.h:57
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

The documentation for this class was generated from the following file: