ReactOS 0.4.15-dev-6068-g8061a6f
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)
 
HRESULT Skip ([in] ULONG celt)
 
HRESULT Reset ()
 
HRESULT Clone ([out] IEnumIDList **ppenum)
 
- 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 343 of file CFSFolder.cpp.

Constructor & Destructor Documentation

◆ CFileSysEnum()

CFileSysEnum::CFileSysEnum ( )
inline

Definition at line 441 of file CFSFolder.cpp.

442 {
443
444 }

◆ ~CFileSysEnum()

CFileSysEnum::~CFileSysEnum ( )
inline

Definition at line 446 of file CFSFolder.cpp.

447 {
448 }

Member Function Documentation

◆ _AddFindResult()

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

Definition at line 347 of file CFSFolder.cpp.

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

Referenced by Initialize().

◆ Initialize()

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

Definition at line 450 of file CFSFolder.cpp.

451 {
452 TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(sPathTarget), dwFlags);
453
454 if (!sPathTarget || !sPathTarget[0])
455 {
456 WARN("No path for CFileSysEnum, empty result!\n");
457 return S_FALSE;
458 }
459
460 WCHAR szFindPattern[MAX_PATH];
461 HRESULT hr = StringCchCopyW(szFindPattern, _countof(szFindPattern), sPathTarget);
463 return hr;
464
465 /* FIXME: UNSAFE CRAP */
466 PathAddBackslashW(szFindPattern);
467
468 hr = StringCchCatW(szFindPattern, _countof(szFindPattern), L"*.*");
470 return hr;
471
472
473 WIN32_FIND_DATAW FindData;
474 HANDLE hFind = FindFirstFileW(szFindPattern, &FindData);
475 if (hFind == INVALID_HANDLE_VALUE)
477
478 do
479 {
480 hr = _AddFindResult(sPathTarget, FindData, dwFlags);
481
483 break;
484
485 } while(FindNextFileW(hFind, &FindData));
486
487 if (SUCCEEDED(hr))
488 {
489 DWORD dwError = GetLastError();
490 if (dwError != ERROR_NO_MORE_FILES)
491 {
492 hr = HRESULT_FROM_WIN32(dwError);
494 }
495 }
496 TRACE("(%p)->(hr=0x%08x)\n", this, hr);
497 FindClose(hFind);
498 return hr;
499 }
#define WARN(fmt,...)
Definition: debug.h:112
HRESULT _AddFindResult(LPWSTR sParentDir, const WIN32_FIND_DATAW &FindData, DWORD dwFlags)
Definition: CFSFolder.cpp:347
#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
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:294
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define S_FALSE
Definition: winerror.h:2357
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

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