ReactOS  0.4.15-dev-2487-g7b27e7c
CZipCreatorImpl Struct Reference
Collaboration diagram for CZipCreatorImpl:

Public Member Functions

unsigned JustDoIt ()
 

Public Attributes

CSimpleArray< CStringWm_items
 

Detailed Description

Definition at line 164 of file CZipCreator.cpp.

Member Function Documentation

◆ JustDoIt()

unsigned CZipCreatorImpl::JustDoIt ( )

Definition at line 228 of file CZipCreator.cpp.

229 {
230  // TODO: Show progress.
231 
232  if (m_items.GetSize() <= 0)
233  {
234  DPRINT1("GetSize() <= 0\n");
235  return CZCERR_ZEROITEMS;
236  }
237 
239  for (INT iItem = 0; iItem < m_items.GetSize(); ++iItem)
240  {
241  DoAddFilesFromItem(files, m_items[iItem]);
242  }
243 
244  if (files.GetSize() <= 0)
245  {
246  DPRINT1("files.GetSize() <= 0\n");
247 
249  CStringW strText;
250  strText.Format(IDS_NOFILES, static_cast<LPCWSTR>(m_items[0]));
251  MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
252 
253  return CZCERR_NOFILES;
254  }
255 
256  zlib_filefunc64_def ffunc;
257  fill_win32_filefunc64W(&ffunc);
258 
259  CStringW strZipName = DoGetZipName(m_items[0]);
260  zipFile zf = zipOpen2_64(strZipName, APPEND_STATUS_CREATE, NULL, &ffunc);
261  if (zf == 0)
262  {
263  DPRINT1("zf == 0\n");
264 
265  int err = CZCERR_CREATE;
266 
268  CStringW strText;
269  strText.Format(IDS_CANTCREATEZIP, static_cast<LPCWSTR>(strZipName), err);
270  MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
271 
272  return err;
273  }
274 
275  // TODO: password
276  const char *password = NULL;
277  int zip64 = 1; // always zip64
278  zip_fileinfo zi;
279 
280  int err = 0;
281  CStringW strTarget, strBaseName = DoGetBaseName(m_items[0]);
282  for (INT iFile = 0; iFile < files.GetSize(); ++iFile)
283  {
284  const CStringW& strFile = files[iFile];
285 
286  CSimpleArray<BYTE> contents;
287  if (!DoReadAllOfFile(strFile, contents, &zi))
288  {
289  DPRINT1("DoReadAllOfFile failed\n");
290  err = CZCERR_READ;
291  strTarget = strFile;
292  break;
293  }
294 
295  unsigned long crc = 0;
296  if (password)
297  {
298  // TODO: crc = ...;
299  }
300 
301  CStringA strNameInZip = DoGetNameInZip(strBaseName, strFile);
303  strNameInZip,
304  &zi,
305  NULL,
306  0,
307  NULL,
308  0,
309  NULL,
310  Z_DEFLATED,
312  0,
313  -MAX_WBITS,
316  password,
317  crc,
318  zip64);
319  if (err)
320  {
321  DPRINT1("zipOpenNewFileInZip3_64\n");
322  break;
323  }
324 
325  err = zipWriteInFileInZip(zf, contents.GetData(), contents.GetSize());
326  if (err)
327  {
328  DPRINT1("zipWriteInFileInZip\n");
329  break;
330  }
331 
332  err = zipCloseFileInZip(zf);
333  if (err)
334  {
335  DPRINT1("zipCloseFileInZip\n");
336  break;
337  }
338  }
339 
340  zipClose(zf, NULL);
341 
342  if (err)
343  {
344  DeleteFileW(strZipName);
345 
347 
348  CStringW strText;
349  if (err < 0)
350  strText.Format(IDS_CANTCREATEZIP, static_cast<LPCWSTR>(strZipName), err);
351  else
352  strText.Format(IDS_CANTREADFILE, static_cast<LPCWSTR>(strTarget));
353 
354  MessageBoxW(NULL, strText, strTitle, MB_ICONERROR);
355  }
356  else
357  {
358  WCHAR szFullPath[MAX_PATH];
359  GetFullPathNameW(strZipName, _countof(szFullPath), szFullPath, NULL);
361  }
362 
363  return err;
364 }
static CStringW DoGetBaseName(LPCWSTR filename)
Definition: CZipCreator.cpp:44
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:452
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:716
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:130
#define MAX_WBITS
Definition: zlib.h:151
#define IDS_ERRORTITLE
Definition: resource.h:44
int GetSize() const
Definition: atlsimpcoll.h:104
int32_t INT
Definition: typedefs.h:58
#define IDS_NOFILES
Definition: resource.h:46
#define IDS_CANTREADFILE
Definition: resource.h:48
static CStringW DoGetZipName(LPCWSTR filename)
Definition: CZipCreator.cpp:15
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
Definition: zip.c:1409
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
static BOOL DoReadAllOfFile(LPCWSTR filename, CSimpleArray< BYTE > &contents, zip_fileinfo *pzi)
Definition: CZipCreator.cpp:72
voidp zipFile
Definition: zip.h:69
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
T1_FIELD_DICT_PRIVATE password
Definition: t1tokens.h:64
#define MB_ICONERROR
Definition: winuser.h:781
#define IDS_CANTCREATEZIP
Definition: resource.h:47
#define err(...)
int ZEXPORT zipOpenNewFileInZip3_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, int zip64)
Definition: zip.c:1303
#define SHCNF_PATHW
Definition: shlobj.h:1764
#define Z_DEFLATED
Definition: zlib.h:146
#define NULL
Definition: types.h:112
zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: zip.c:939
#define DPRINT1
Definition: precomp.h:8
int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1757
_In_ ULONG_PTR iFile
Definition: winddi.h:3835
CSimpleArray< CStringW > m_items
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define SHCNE_CREATE
Definition: shlobj.h:1730
#define DEF_MEM_LEVEL
Definition: zutil.h:53
#define APPEND_STATUS_CREATE
Definition: zip.h:112
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:137
static CStringA DoGetNameInZip(const CStringW &basename, const CStringW &filename)
Definition: CZipCreator.cpp:54
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1889
static void DoAddFilesFromItem(CSimpleArray< CStringW > &files, LPCWSTR item)

Member Data Documentation

◆ m_items

CSimpleArray<CStringW> CZipCreatorImpl::m_items

Definition at line 166 of file CZipCreator.cpp.

Referenced by JustDoIt().


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