ReactOS 0.4.16-dev-2208-g6350669
CZipCreatorImpl Struct Reference
Collaboration diagram for CZipCreatorImpl:

Public Member Functions

unsigned JustDoIt ()
 

Public Attributes

CSimpleArray< CStringWm_items
 
CStringW m_ExistingZip
 
CStringW m_TargetDir
 

Detailed Description

Definition at line 162 of file CZipCreator.cpp.

Member Function Documentation

◆ JustDoIt()

unsigned CZipCreatorImpl::JustDoIt ( )

Definition at line 243 of file CZipCreator.cpp.

244{
245 // TODO: Show progress.
246
247 CStringW strZipName;
248 INT appendMode;
250 {
251 strZipName = DoGetZipName(m_items[0]);
252 appendMode = APPEND_STATUS_CREATE;
253 }
254 else
255 {
256 strZipName = m_ExistingZip;
257 appendMode = APPEND_STATUS_ADDINZIP;
258 }
259
260 if (m_items.GetSize() <= 0)
261 {
262 DPRINT1("GetSize() <= 0\n");
263 return CZCERR_ZEROITEMS;
264 }
265
267 for (INT iItem = 0; iItem < m_items.GetSize(); ++iItem)
268 {
269 DoAddFilesFromItem(files, m_items[iItem]);
270 }
271
272 if (files.GetSize() <= 0)
273 {
274 DPRINT1("files.GetSize() <= 0\n");
275
277 CStringW strText;
278 strText.Format(IDS_NOFILES, static_cast<PCWSTR>(m_items[0]));
279 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
280
281 return CZCERR_NOFILES;
282 }
283
285 ZeroMemory(&ffunc, sizeof(ffunc));
287
288 zipFile zf = zipOpen2_64(strZipName, appendMode, NULL, &ffunc);
289 if (zf == 0)
290 {
291 DPRINT1("zf == 0\n");
292
293 int err = CZCERR_CREATE;
294
296 CStringW strText;
297 strText.Format(IDS_CANTCREATEZIP, static_cast<PCWSTR>(strZipName), err);
298 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
299
300 return err;
301 }
302
303 // TODO: password
304 const char *password = NULL;
305 int zip64 = 1; // always zip64
306 zip_fileinfo zi;
307
308 int err = 0;
309 CStringW strTarget, strBaseName = DoGetBaseName(m_items[0]);
310 UINT nCodePage = GetZipCodePage(FALSE);
311 for (INT iFile = 0; iFile < files.GetSize(); ++iFile)
312 {
313 const CStringW& strFile = files[iFile];
314
316 if (!DoReadAllOfFile(strFile, contents, &zi))
317 {
318 DPRINT1("DoReadAllOfFile failed\n");
320 strTarget = strFile;
321 break;
322 }
323
324 unsigned long crc = 0;
325 if (password)
326 {
327 // TODO: crc = ...;
328 }
329
330 CStringA strNameInZip = DoGetNameInZip(strBaseName, strFile, nCodePage);
331 CStringA strNameInZipUTF8 = DoGetNameInZip(strBaseName, strFile, CP_UTF8);
332 if (!m_TargetDir.IsEmpty())
333 {
334 CStringA strTargetDir = CStringA(CW2AEX<MAX_PATH>(m_TargetDir, nCodePage));
335 strNameInZip = strTargetDir + strNameInZip;
336
338 strNameInZipUTF8 = strTargetDirUTF8 + strNameInZipUTF8;
339 }
340
341 CSimpleArray<BYTE> extraField;
342 if (nCodePage != CP_UTF8 && strNameInZip != strNameInZipUTF8)
343 {
344 // Header
345 WORD headerID = EF_UNIPATH, dataSize = 1 + 4 + strNameInZipUTF8.GetLength();
346 extraField.Add(headerID & 0xFF);
347 extraField.Add((headerID >> 8) & 0xFF);
348 extraField.Add(dataSize & 0xFF);
349 extraField.Add((dataSize >> 8) & 0xFF);
350 extraField.Add(1); // Version
351
352 // CRC32
353 DWORD nameCRC = CalculateNameCRC32(strNameInZip);
354 extraField.Add(nameCRC & 0xFF);
355 extraField.Add((nameCRC >> 8) & 0xFF);
356 extraField.Add((nameCRC >> 16) & 0xFF);
357 extraField.Add((nameCRC >> 24) & 0xFF);
358
359 // UTF-8 name
360 for (INT ich = 0; ich < strNameInZipUTF8.GetLength(); ++ich)
361 extraField.Add(strNameInZipUTF8[ich]);
362 }
363
365 strNameInZip,
366 &zi,
367 (extraField.GetSize() > 0 ? extraField.GetData() : NULL),
368 extraField.GetSize(),
369 NULL,
370 0,
371 NULL,
374 0,
375 -MAX_WBITS,
378 password,
379 crc,
381 (nCodePage == CP_UTF8 ? MINIZIP_UTF8_FLAG : 0),
382 zip64);
383 if (err)
384 {
385 DPRINT1("zipOpenNewFileInZip3_64\n");
386 break;
387 }
388
389 err = zipWriteInFileInZip(zf, contents.GetData(), contents.GetSize());
390 if (err)
391 {
392 DPRINT1("zipWriteInFileInZip\n");
393 break;
394 }
395
397 if (err)
398 {
399 DPRINT1("zipCloseFileInZip\n");
400 break;
401 }
402 }
403
404 zipClose(zf, NULL);
405
406 if (err)
407 {
408 if (err && m_ExistingZip.IsEmpty())
409 DeleteFileW(strZipName);
410
412
413 CStringW strText;
414 if (err < 0)
415 strText.Format(IDS_CANTCREATEZIP, static_cast<PCWSTR>(strZipName), err);
416 else
417 strText.Format(IDS_CANTREADFILE, static_cast<PCWSTR>(strTarget));
418
419 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
420 }
421 else
422 {
423 WCHAR szFullPath[MAX_PATH];
424 GetFullPathNameW(strZipName, _countof(szFullPath), szFullPath, NULL);
425
428 else
430 }
431
432 return err;
433}
static CStringW DoGetZipName(PCWSTR filename)
Definition: CZipCreator.cpp:20
@ CZCERR_NOFILES
@ CZCERR_ZEROITEMS
@ CZCERR_READ
@ CZCERR_CREATE
static CStringA DoGetNameInZip(const CStringW &basename, const CStringW &filename, UINT nCodePage)
Definition: CZipCreator.cpp:52
static void DoAddFilesFromItem(CSimpleArray< CStringW > &files, PCWSTR item)
static CStringW DoGetBaseName(PCWSTR filename)
Definition: CZipCreator.cpp:42
static DWORD CalculateNameCRC32(PCSTR name)
Definition: CZipCreator.cpp:15
static BOOL DoReadAllOfFile(PCWSTR filename, CSimpleArray< BYTE > &contents, zip_fileinfo *pzi)
Definition: CZipCreator.cpp:70
#define DPRINT1
Definition: precomp.h:8
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
int GetLength() const noexcept
Definition: atlsimpstr.h:362
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define MINIZIP_COMPATIBLE_VERSION
Definition: precomp.h:41
UINT GetZipCodePage(BOOL bUnZip)
Definition: zipfldr.cpp:90
#define EF_UNIPATH
Definition: precomp.h:44
#define MINIZIP_UTF8_FLAG
Definition: precomp.h:43
#define IDS_CANTCREATEZIP
Definition: resource.h:50
#define IDS_ERRORTITLE
Definition: resource.h:47
#define IDS_CANTREADFILE
Definition: resource.h:51
#define IDS_NOFILES
Definition: resource.h:49
#define MAX_PATH
Definition: compat.h:34
#define Z_DEFLATED
Definition: zlib.h:146
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:137
#define MAX_WBITS
Definition: zlib.h:151
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:130
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DEF_MEM_LEVEL
Definition: zutil.h:53
GLenum GLsizei dataSize
Definition: glext.h:11123
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:457
#define ZeroMemory
Definition: minwinbase.h:31
static const char * contents
Definition: parser.c:511
static WCHAR password[]
Definition: url.c:33
CAtlStringA CStringA
Definition: atlstr.h:131
unsigned int UINT
Definition: ndis.h:50
#define err(...)
#define CP_UTF8
Definition: nls.h:20
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1908
#define SHCNE_CREATE
Definition: shlobj.h:1896
#define SHCNF_PATHW
Definition: shlobj.h:1931
#define _countof(array)
Definition: sndvol32.h:70
CStringW m_ExistingZip
CStringW m_TargetDir
CSimpleArray< CStringW > m_items
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
_In_ ULONG_PTR iFile
Definition: winddi.h:3835
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:798
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1883
int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)
Definition: zip.c:1061
zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: zip.c:938
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
Definition: zip.c:1408
int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1751
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:114
#define APPEND_STATUS_CREATE
Definition: zip.h:112
voidp zipFile
Definition: zip.h:69

Member Data Documentation

◆ m_ExistingZip

CStringW CZipCreatorImpl::m_ExistingZip

Definition at line 165 of file CZipCreator.cpp.

Referenced by JustDoIt().

◆ m_items

CSimpleArray<CStringW> CZipCreatorImpl::m_items

Definition at line 164 of file CZipCreator.cpp.

Referenced by JustDoIt().

◆ m_TargetDir

CStringW CZipCreatorImpl::m_TargetDir

Definition at line 166 of file CZipCreator.cpp.

Referenced by JustDoIt().


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