ReactOS 0.4.16-dev-338-g34e76ad
CZipEnumerator.hpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Zip Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: CZipEnumerator
5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
6 * Copyright 2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7 */
8
10{
11private:
12 CComPtr<IZip> m_Zip;
13 bool m_First;
14 CAtlList<CStringW> m_Returned;
16public:
18 : m_First(true)
20 {
21 }
22
23 bool initialize(IZip* zip)
24 {
25 m_Zip = zip;
26 return reset();
27 }
28
29 bool reset()
30 {
31 unzFile uf = m_Zip->getZip();
32 m_First = true;
33 if (unzGoToFirstFile(uf) != UNZ_OK)
34 return false;
36 return true;
37 }
38
39 bool next_unique(PCWSTR prefix, CStringW& name, bool& folder, unz_file_info64& info)
40 {
41 size_t len = wcslen(prefix);
42 CStringW tmp;
43 while (next(tmp, info))
44 {
45 if (!_wcsnicmp(tmp, prefix, len))
46 {
47 int pos = tmp.Find(L'/', len);
48 if (pos < 0)
49 {
50 name = tmp.Mid(len);
51 folder = false;
52 }
53 else
54 {
55 name = tmp.Mid(len, pos - len);
56 folder = true;
57 }
58 tmp = name;
59 tmp.MakeLower();
60
61 POSITION it = m_Returned.Find(tmp);
62 if (!name.IsEmpty() && !it)
63 {
65 return true;
66 }
67 }
68 }
69 return false;
70 }
71
72 bool next(CStringW& name, unz_file_info64& info)
73 {
74 int err;
75
76 unzFile uf = m_Zip->getZip();
77 if (!m_First)
78 {
79 err = unzGoToNextFile(uf);
81 {
82 return false;
83 }
84 }
85 m_First = false;
86
87 err = unzGetCurrentFileInfo64(uf, &info, NULL, 0, NULL, 0, NULL, 0);
88 if (err == UNZ_OK)
89 {
90 CStringA nameA;
91 PSTR buf = nameA.GetBuffer(info.size_filename);
92 err = unzGetCurrentFileInfo64(uf, NULL, buf, nameA.GetAllocLength(), NULL, 0, NULL, 0);
93 nameA.ReleaseBuffer(info.size_filename);
94 nameA.Replace('\\', '/');
95
96 if (info.flag & MINIZIP_UTF8_FLAG)
97 name = CA2WEX<MAX_PATH>(nameA, CP_UTF8);
98 else
99 name = CA2WEX<MAX_PATH>(nameA, m_nCodePage);
100 }
101 return err == UNZ_OK;
102 }
103};
104
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:629
void RemoveAll()
Definition: atlcoll.h:748
POSITION Find(INARGTYPE element, _In_opt_ POSITION posStartAfter=NULL) const
Definition: atlcoll.h:794
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
UINT GetZipCodePage(BOOL bUnZip)
Definition: zipfldr.cpp:90
#define MINIZIP_UTF8_FLAG
Definition: precomp.h:43
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
static unsigned __int64 next
Definition: rand_nt.c:6
#define err(...)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define CP_UTF8
Definition: nls.h:20
#define true
Definition: stdbool.h:36
CComPtr< IZip > m_Zip
bool next_unique(PCWSTR prefix, CStringW &name, bool &folder, unz_file_info64 &info)
bool next(CStringW &name, unz_file_info64 &info)
bool initialize(IZip *zip)
CAtlList< CStringW > m_Returned
Definition: IZip.hpp:9
Definition: fci.c:116
Definition: name.c:39
char * PSTR
Definition: typedefs.h:51
const uint16_t * PCWSTR
Definition: typedefs.h:57
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1129
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1183
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1204
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:75
voidp unzFile
Definition: unzip.h:70
#define UNZ_OK
Definition: unzip.h:74