2017-12-29 22:45:02 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Zip Shell Extension
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: CEnumZipContents
|
|
|
|
* COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
|
2023-07-17 11:12:45 +00:00
|
|
|
* Copyright 2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
2017-12-29 22:45:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
class CEnumZipContents :
|
|
|
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
|
|
|
public IEnumIDList
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CZipEnumerator mEnumerator;
|
|
|
|
DWORD dwFlags;
|
2023-07-17 11:12:45 +00:00
|
|
|
CStringW m_Prefix;
|
2017-12-29 22:45:02 +00:00
|
|
|
public:
|
|
|
|
CEnumZipContents()
|
|
|
|
:dwFlags(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-17 11:12:45 +00:00
|
|
|
STDMETHODIMP Initialize(IZip* zip, DWORD flags, PCWSTR prefix)
|
2017-12-29 22:45:02 +00:00
|
|
|
{
|
|
|
|
dwFlags = flags;
|
|
|
|
m_Prefix = prefix;
|
|
|
|
if (mEnumerator.initialize(zip))
|
|
|
|
return S_OK;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *** IEnumIDList methods ***
|
|
|
|
STDMETHODIMP Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched)
|
|
|
|
{
|
2023-11-13 15:31:37 +00:00
|
|
|
if (!rgelt || (!pceltFetched && celt != 1))
|
2017-12-29 22:45:02 +00:00
|
|
|
return E_POINTER;
|
|
|
|
|
2023-11-26 12:41:02 +00:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ULONG fetched = 0;
|
2023-11-13 15:31:37 +00:00
|
|
|
LPITEMIDLIST item;
|
2023-07-17 11:12:45 +00:00
|
|
|
CStringW name;
|
2017-12-29 22:45:02 +00:00
|
|
|
bool dir;
|
|
|
|
unz_file_info64 info;
|
2023-11-26 12:41:02 +00:00
|
|
|
|
|
|
|
while (fetched < celt)
|
2017-12-29 22:45:02 +00:00
|
|
|
{
|
2023-11-26 12:41:02 +00:00
|
|
|
if (mEnumerator.next_unique(m_Prefix, name, dir, info))
|
|
|
|
{
|
|
|
|
item = _ILCreate(dir ? ZIP_PIDL_DIRECTORY : ZIP_PIDL_FILE, name, info);
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
hr = fetched ? S_FALSE : E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rgelt[fetched++] = item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2017-12-29 22:45:02 +00:00
|
|
|
}
|
2023-11-26 12:41:02 +00:00
|
|
|
|
|
|
|
if (pceltFetched)
|
|
|
|
*pceltFetched = fetched;
|
|
|
|
return hr;
|
2017-12-29 22:45:02 +00:00
|
|
|
}
|
|
|
|
STDMETHODIMP Skip(ULONG celt)
|
|
|
|
{
|
2023-07-17 11:12:45 +00:00
|
|
|
CStringW name;
|
2017-12-29 22:45:02 +00:00
|
|
|
bool dir;
|
|
|
|
unz_file_info64 info;
|
|
|
|
while (celt--)
|
|
|
|
{
|
|
|
|
if (!mEnumerator.next_unique(m_Prefix, name, dir, info))
|
|
|
|
return E_FAIL;
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
STDMETHODIMP Reset()
|
|
|
|
{
|
|
|
|
if (mEnumerator.reset())
|
|
|
|
return S_OK;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
STDMETHODIMP Clone(IEnumIDList **ppenum)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
DECLARE_NOT_AGGREGATABLE(CEnumZipContents)
|
|
|
|
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-12-29 22:45:02 +00:00
|
|
|
BEGIN_COM_MAP(CEnumZipContents)
|
|
|
|
COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList)
|
|
|
|
END_COM_MAP()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-07-17 11:12:45 +00:00
|
|
|
HRESULT _CEnumZipContents_CreateInstance(IZip* zip, DWORD flags, PCWSTR prefix, REFIID riid, LPVOID * ppvOut)
|
2017-12-29 22:45:02 +00:00
|
|
|
{
|
|
|
|
return ShellObjectCreatorInit<CEnumZipContents>(zip, flags, prefix, riid, ppvOut);
|
|
|
|
}
|
|
|
|
|