ReactOS 0.4.16-dev-2491-g3dc6630
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 128 of file CZipCreator.cpp.

Member Function Documentation

◆ JustDoIt()

unsigned CZipCreatorImpl::JustDoIt ( )

Definition at line 209 of file CZipCreator.cpp.

210{
211 // TODO: Show progress.
212
213 CStringW strZipName;
214 INT appendMode;
216 {
217 strZipName = DoGetZipName(m_items[0]);
218 appendMode = APPEND_STATUS_CREATE;
219 }
220 else
221 {
222 strZipName = m_ExistingZip;
223 appendMode = APPEND_STATUS_ADDINZIP;
224 }
225
226 if (m_items.GetSize() <= 0)
227 {
228 DPRINT1("GetSize() <= 0\n");
229 return CZCERR_ZEROITEMS;
230 }
231
233 for (INT iItem = 0; iItem < m_items.GetSize(); ++iItem)
234 {
235 DoAddFilesFromItem(files, m_items[iItem]);
236 }
237
238 if (files.GetSize() <= 0)
239 {
240 DPRINT1("files.GetSize() <= 0\n");
241
243 CStringW strText;
244 strText.Format(IDS_NOFILES, static_cast<PCWSTR>(m_items[0]));
245 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
246
247 return CZCERR_NOFILES;
248 }
249
251 ZeroMemory(&ffunc, sizeof(ffunc));
253
254 zipFile zf = zipOpen2_64(strZipName, appendMode, NULL, &ffunc);
255 if (zf == 0)
256 {
257 DPRINT1("zf == 0\n");
258
259 int err = CZCERR_CREATE;
260
262 CStringW strText;
263 strText.Format(IDS_CANTCREATEZIP, static_cast<PCWSTR>(strZipName), err);
264 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
265
266 return err;
267 }
268
269 // TODO: password
270 const char *password = NULL;
271
272 // Use dwAllocationGranularity for file mapping
275 const ULONGLONG dwChunkSize = si.dwAllocationGranularity * 256;
276
277 // The loop for creating a ZIP file
278 CStringW strTarget, strBaseName = DoGetBaseName(m_items[0]);
279 UINT nCodePage = GetZipCodePage(FALSE);
280 INT err = ZIP_OK;
281 for (INT iFile = 0; iFile < files.GetSize() && err == ZIP_OK; ++iFile)
282 {
283 const CStringW& strFile = files[iFile];
284 zip_fileinfo zi;
285
286 // Open the file for storing it into a ZIP file
290 {
291 DPRINT1("Cannot open file '%S'\n", (PCWSTR)strFile);
293 break;
294 }
295
296 // Load the file time info
298
299 // Get the file size
300 LARGE_INTEGER fileSize;
301 if (!GetFileSizeEx(hFile, &fileSize))
302 {
303 DPRINT1("Cannot get file size '%S'\n", (PCWSTR)strFile);
306 break;
307 }
308
309 unsigned long crc = 0;
310 if (password)
311 {
312 // TODO: crc = ...;
313 }
314
315 // Get filename info
316 CStringA strNameInZip = DoGetNameInZip(strBaseName, strFile, nCodePage);
317 CStringA strNameInZipUTF8 = DoGetNameInZip(strBaseName, strFile, CP_UTF8);
318 if (!m_TargetDir.IsEmpty())
319 {
320 CStringA strTargetDir = CStringA(CW2AEX<MAX_PATH>(m_TargetDir, nCodePage));
321 strNameInZip = strTargetDir + strNameInZip;
322
324 strNameInZipUTF8 = strTargetDirUTF8 + strNameInZipUTF8;
325 }
326
327 // Prepare additional field (UTF-8 name)
328 CSimpleArray<BYTE> extraField;
329 if (nCodePage != CP_UTF8 && strNameInZip != strNameInZipUTF8)
330 {
331 // Header
332 WORD headerID = EF_UNIPATH, dataSize = 1 + 4 + strNameInZipUTF8.GetLength();
333 extraField.Add(headerID & 0xFF);
334 extraField.Add((headerID >> 8) & 0xFF);
335 extraField.Add(dataSize & 0xFF);
336 extraField.Add((dataSize >> 8) & 0xFF);
337 extraField.Add(1); // Version
338
339 // CRC32
340 DWORD nameCRC = CalculateNameCRC32(strNameInZip);
341 extraField.Add(nameCRC & 0xFF);
342 extraField.Add((nameCRC >> 8) & 0xFF);
343 extraField.Add((nameCRC >> 16) & 0xFF);
344 extraField.Add((nameCRC >> 24) & 0xFF);
345
346 // UTF-8 name
347 for (INT ich = 0; ich < strNameInZipUTF8.GetLength(); ++ich)
348 extraField.Add(strNameInZipUTF8[ich]);
349 }
350
351 // Add a new file entry into a ZIP file
352 err = zipOpenNewFileInZip4_64(zf, strNameInZip, &zi,
353 (extraField.GetSize() ? extraField.GetData() : NULL),
354 extraField.GetSize(), NULL, 0, NULL, Z_DEFLATED,
358 (nCodePage == CP_UTF8 ? MINIZIP_UTF8_FLAG : 0), 1);
359 if (err)
360 {
361 DPRINT1("zipOpenNewFileInZip3_64\n");
362 break;
363 }
364
365 if (fileSize.QuadPart > 0) // Not an empty file?
366 {
367 // Use a file mapping for quick file access and large file support
369 if (!hMapping)
370 {
371 DPRINT1("Cannot create file mapping\n");
374 break;
375 }
376
377 // The loop for reading and storing file contents
378 DWORD dwMapSize;
379 for (ULONGLONG offset = 0; offset < (ULONGLONG)fileSize.QuadPart && err == ZIP_OK;
380 offset += dwMapSize)
381 {
382 ULONGLONG dwDelta = fileSize.QuadPart - offset;
383 dwMapSize = (DWORD)min(dwChunkSize, dwDelta);
384 DWORD offsetLow = (DWORD)offset, offsetHigh = (DWORD)(offset >> 32);
385 PVOID pData = MapViewOfFile(hMapping, FILE_MAP_READ, offsetHigh, offsetLow,
386 dwMapSize);
387 if (!pData)
388 {
389 DPRINT1("Cannot map the view\n");
391 break;
392 }
393
394 err = zipWriteInFileInZip(zf, pData, dwMapSize);
396 }
397
398 CloseHandle(hMapping);
399 }
400
402
404 }
405
406 zipClose(zf, NULL);
407
408 if (err)
409 {
410 if (err && m_ExistingZip.IsEmpty())
411 DeleteFileW(strZipName);
412
414
415 CStringW strText;
416 if (err < 0)
417 strText.Format(IDS_CANTCREATEZIP, static_cast<PCWSTR>(strZipName), err);
418 else
419 strText.Format(IDS_CANTREADFILE, static_cast<PCWSTR>(strTarget));
420
421 MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
422 }
423 else
424 {
425 WCHAR szFullPath[MAX_PATH];
426 GetFullPathNameW(strZipName, _countof(szFullPath), szFullPath, NULL);
427
430 else
432 }
433
434 return err;
435}
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)
Definition: CZipCreator.cpp:91
static CStringW DoGetBaseName(PCWSTR filename)
Definition: CZipCreator.cpp:42
static DWORD CalculateNameCRC32(PCSTR name)
Definition: CZipCreator.cpp:15
static BOOL DoGetFileTimeInfo(HANDLE hFile, zip_fileinfo *pzi)
Definition: CZipCreator.cpp:70
#define EF_UNIPATH
#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:91
#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 CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define GetFileSizeEx
Definition: compat.h:757
#define MapViewOfFile
Definition: compat.h:745
#define FILE_SHARE_READ
Definition: compat.h:136
#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
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DEF_MEM_LEVEL
Definition: zutil.h:53
GLintptr offset
Definition: glext.h:5920
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
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
static SYSTEM_INFO si
Definition: virtual.c:39
static WCHAR password[]
Definition: url.c:33
#define min(a, b)
Definition: monoChain.cc:55
_In_ HANDLE hFile
Definition: mswsock.h:90
CAtlStringA CStringA
Definition: atlstr.h:131
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define err(...)
#define CP_UTF8
Definition: nls.h:20
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1910
#define SHCNE_CREATE
Definition: shlobj.h:1898
#define SHCNF_PATHW
Definition: shlobj.h:1933
#define _countof(array)
Definition: sndvol32.h:70
CStringW m_ExistingZip
CStringW m_TargetDir
CSimpleArray< CStringW > m_items
DWORD dwAllocationGranularity
Definition: winbase.h:904
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
_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 ZIP_OK
Definition: zip.h:72
#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 131 of file CZipCreator.cpp.

Referenced by JustDoIt().

◆ m_items

CSimpleArray<CStringW> CZipCreatorImpl::m_items

Definition at line 130 of file CZipCreator.cpp.

Referenced by JustDoIt().

◆ m_TargetDir

CStringW CZipCreatorImpl::m_TargetDir

Definition at line 132 of file CZipCreator.cpp.

Referenced by JustDoIt().


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