ReactOS 0.4.16-dev-2224-g3637fd8
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)
 
template<class T >
BOOL HasItemWithCLSIDImpl (LPCITEMIDLIST pidl)
 
STDMETHOD() Next (ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) override
 
STDMETHOD() Skip (ULONG celt) override
 
STDMETHOD() Reset () override
 
STDMETHOD() Clone (IEnumIDList **ppenum) override
 
- 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
 
- Protected Attributes inherited from CEnumIDListBase
ENUMLISTmpFirst
 
ENUMLISTmpLast
 
ENUMLISTmpCurrent
 

Detailed Description

Definition at line 410 of file CFSFolder.cpp.

Constructor & Destructor Documentation

◆ CFileSysEnum()

CFileSysEnum::CFileSysEnum ( )
inline

Definition at line 508 of file CFSFolder.cpp.

509 {
510
511 }

◆ ~CFileSysEnum()

CFileSysEnum::~CFileSysEnum ( )
inline

Definition at line 513 of file CFSFolder.cpp.

514 {
515 }

Member Function Documentation

◆ _AddFindResult()

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

Definition at line 414 of file CFSFolder.cpp.

415 {
416#define SUPER_HIDDEN (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)
417
418 // Does it need special handling because it is hidden?
420 {
421 DWORD dwHidden = FindData.dwFileAttributes & SUPER_HIDDEN;
422
423 // Is it hidden, but are we not asked to include hidden?
424 if (dwHidden == FILE_ATTRIBUTE_HIDDEN && !(dwFlags & SHCONTF_INCLUDEHIDDEN))
425 return S_OK;
426
427 // Is it a system file, but are we not asked to include those?
428 if (dwHidden == SUPER_HIDDEN && !(dwFlags & SHCONTF_INCLUDESUPERHIDDEN))
429 return S_OK;
430 }
431
432 BOOL bDirectory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
433
434 HRESULT hr;
435 if (bDirectory)
436 {
437 // Skip the current and parent directory nodes
438 if (!strcmpW(FindData.cFileName, L".") || !strcmpW(FindData.cFileName, L".."))
439 return S_OK;
440
441 // Does this directory need special handling?
443 {
444 WCHAR Tmp[MAX_PATH];
445 CLSID clsidFolder;
446
447 PathCombineW(Tmp, sParentDir, FindData.cFileName);
448
449 hr = SHELL32_GetCLSIDForDirectory(Tmp, L"CLSID", &clsidFolder);
450 if (SUCCEEDED(hr))
451 {
452 ERR("Got CLSID override for '%S'\n", Tmp);
453 }
454 }
455 }
456 else
457 {
458 CLSID clsidFile;
459 LPWSTR pExtension = PathFindExtensionW(FindData.cFileName);
460 if (pExtension)
461 {
462 // FIXME: Cache this?
463 hr = GetCLSIDForFileTypeFromExtension(pExtension, L"CLSID", &clsidFile);
464 if (hr == S_OK)
465 {
466 HKEY hkey;
467 hr = SHRegGetCLSIDKeyW(clsidFile, L"ShellFolder", FALSE, FALSE, &hkey);
468 if (SUCCEEDED(hr))
469 {
470 ::RegCloseKey(hkey);
471
472 // This should be presented as directory!
473 bDirectory = TRUE;
474 TRACE("Treating '%S' as directory!\n", FindData.cFileName);
475 }
476 }
477 }
478 }
479
480 LPITEMIDLIST pidl = NULL;
481 if (bDirectory)
482 {
483 if (dwFlags & SHCONTF_FOLDERS)
484 {
485 TRACE("(%p)-> (folder=%s)\n", this, debugstr_w(FindData.cFileName));
486 pidl = _ILCreateFromFindDataW(&FindData);
487 }
488 }
489 else
490 {
491 if (dwFlags & SHCONTF_NONFOLDERS)
492 {
493 TRACE("(%p)-> (file =%s)\n", this, debugstr_w(FindData.cFileName));
494 pidl = _ILCreateFromFindDataW(&FindData);
495 }
496 }
497
498 if (pidl && !AddToEnumList(pidl))
499 {
501 return E_FAIL;
502 }
503
504 return S_OK;
505 }
#define ERR(fmt,...)
Definition: precomp.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
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
LPWSTR WINAPI PathFindExtensionW(const WCHAR *path)
Definition: path.c:1274
static HRESULT SHELL32_GetCLSIDForDirectory(LPCWSTR pwszDir, LPCWSTR KeyName, CLSID *pclsidFolder)
Definition: CFSFolder.cpp:624
#define SUPER_HIDDEN
static HRESULT GetCLSIDForFileTypeFromExtension(LPCWSTR pExtension, LPCWSTR KeyName, CLSID *pclsid)
Definition: CFSFolder.cpp:109
HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID, LPCWSTR, BOOL, BOOL, PHKEY)
Definition: reg.c:2422
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:30
#define L(x)
Definition: resources.c:13
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
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#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 PathCombineW
Definition: pathcch.h:318
LPITEMIDLIST _ILCreateFromFindDataW(const WIN32_FIND_DATAW *wfd)
Definition: pidl.c:1940
HRESULT hr
Definition: shlfolder.c:183
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define TRACE(s)
Definition: solgame.cpp:4
_Field_z_ WCHAR cFileName[MAX_PATH]
Definition: minwinbase.h:291
DWORD dwFileAttributes
Definition: minwinbase.h:283
#define strcmpW(s1, s2)
Definition: unicode.h:44
__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 517 of file CFSFolder.cpp.

518 {
519 TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(sPathTarget), dwFlags);
520
521 if (!sPathTarget || !sPathTarget[0])
522 {
523 WARN("No path for CFileSysEnum, empty result!\n");
524 return S_FALSE;
525 }
526
527 WCHAR szFindPattern[MAX_PATH];
528 HRESULT hr = StringCchCopyW(szFindPattern, _countof(szFindPattern), sPathTarget);
530 return hr;
531
532 /* FIXME: UNSAFE CRAP */
533 PathAddBackslashW(szFindPattern);
534
535 hr = StringCchCatW(szFindPattern, _countof(szFindPattern), L"*.*");
537 return hr;
538
539
540 WIN32_FIND_DATAW FindData;
541 HANDLE hFind = FindFirstFileW(szFindPattern, &FindData);
542 if (hFind == INVALID_HANDLE_VALUE)
544
545 do
546 {
547 hr = _AddFindResult(sPathTarget, FindData, dwFlags);
548
550 break;
551
552 } while(FindNextFileW(hFind, &FindData));
553
554 if (SUCCEEDED(hr))
555 {
556 DWORD dwError = GetLastError();
557 if (dwError != ERROR_NO_MORE_FILES)
558 {
559 hr = HRESULT_FROM_WIN32(dwError);
561 }
562 }
563 TRACE("(%p)->(hr=0x%08x)\n", this, hr);
564 FindClose(hFind);
565 return hr;
566 }
#define WARN(fmt,...)
Definition: precomp.h:61
HRESULT _AddFindResult(LPWSTR sParentDir, const WIN32_FIND_DATAW &FindData, DWORD dwFlags)
Definition: CFSFolder.cpp:414
#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
#define PathAddBackslashW
Definition: pathcch.h:302
#define _countof(array)
Definition: sndvol32.h:70
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:1042
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_NO_MORE_FILES
Definition: winerror.h:243

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