1 /* 2 * PROJECT: ReactOS Zip Shell Extension 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: CEnumZipContents 5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8 #include "precomp.h" 9 10 class CEnumZipContents : 11 public CComObjectRootEx<CComMultiThreadModelNoCS>, 12 public IEnumIDList 13 { 14 private: 15 CZipEnumerator mEnumerator; 16 DWORD dwFlags; 17 CStringA m_Prefix; 18 public: 19 CEnumZipContents() 20 :dwFlags(0) 21 { 22 } 23 24 STDMETHODIMP Initialize(IZip* zip, DWORD flags, const char* prefix) 25 { 26 dwFlags = flags; 27 m_Prefix = prefix; 28 if (mEnumerator.initialize(zip)) 29 return S_OK; 30 return E_FAIL; 31 } 32 33 // *** IEnumIDList methods *** 34 STDMETHODIMP Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) 35 { 36 if (!pceltFetched || !rgelt) 37 return E_POINTER; 38 39 *pceltFetched = 0; 40 41 if (celt != 1) 42 return E_FAIL; 43 44 CStringA name; 45 bool dir; 46 unz_file_info64 info; 47 if (mEnumerator.next_unique(m_Prefix, name, dir, info)) 48 { 49 *pceltFetched = 1; 50 *rgelt = _ILCreate(dir ? ZIP_PIDL_DIRECTORY : ZIP_PIDL_FILE, name, info); 51 return S_OK; 52 } 53 54 return S_FALSE; 55 } 56 STDMETHODIMP Skip(ULONG celt) 57 { 58 CStringA name; 59 bool dir; 60 unz_file_info64 info; 61 while (celt--) 62 { 63 if (!mEnumerator.next_unique(m_Prefix, name, dir, info)) 64 return E_FAIL; 65 ; 66 } 67 return S_OK; 68 } 69 STDMETHODIMP Reset() 70 { 71 if (mEnumerator.reset()) 72 return S_OK; 73 return E_FAIL; 74 } 75 STDMETHODIMP Clone(IEnumIDList **ppenum) 76 { 77 return E_NOTIMPL; 78 } 79 80 81 public: 82 DECLARE_NOT_AGGREGATABLE(CEnumZipContents) 83 DECLARE_PROTECT_FINAL_CONSTRUCT() 84 85 BEGIN_COM_MAP(CEnumZipContents) 86 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) 87 END_COM_MAP() 88 }; 89 90 91 HRESULT _CEnumZipContents_CreateInstance(IZip* zip, DWORD flags, const char* prefix, REFIID riid, LPVOID * ppvOut) 92 { 93 return ShellObjectCreatorInit<CEnumZipContents>(zip, flags, prefix, riid, ppvOut); 94 } 95 96