ReactOS  0.4.15-dev-1389-g828d5fa
CZipExtract Class Reference
Inheritance diagram for CZipExtract:
Collaboration diagram for CZipExtract:

Classes

class  CCompleteSettingsPage
 
class  CExtractSettingsPage
 

Public Member Functions

 CZipExtract (PCWSTR Filename)
 
 ~CZipExtract ()
 
void Close ()
 
STDMETHODIMP QueryInterface (REFIID riid, void **ppvObject)
 
 STDMETHODIMP_ (ULONG) AddRef(void)
 
 STDMETHODIMP_ (ULONG) Release(void)
 
 STDMETHODIMP_ (unzFile) getZip()
 
void runWizard ()
 
bool Extract (HWND hDlg, HWND hProgress, const bool *bCancel)
 
- Public Member Functions inherited from IUnknown
ULONG AddRef ()
 
ULONG Release ()
 

Private Attributes

CStringW m_Filename
 
CStringW m_Directory
 
CStringA m_Password
 
bool m_DirectoryChanged
 
unzFile uf
 

Additional Inherited Members

- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 

Detailed Description

Definition at line 10 of file CZipExtract.cpp.

Constructor & Destructor Documentation

◆ CZipExtract()

CZipExtract::CZipExtract ( PCWSTR  Filename)
inline

Definition at line 19 of file CZipExtract.cpp.

20  :m_DirectoryChanged(false)
21  ,uf(NULL)
22  {
25  PWSTR Dir = m_Directory.GetBuffer();
28  }
CStringW m_Filename
Definition: CZipExtract.cpp:13
uint16_t * PWSTR
Definition: typedefs.h:56
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:934
bool m_DirectoryChanged
Definition: CZipExtract.cpp:16
CStringW m_Directory
Definition: CZipExtract.cpp:14
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:818
unzFile uf
Definition: CZipExtract.cpp:17
#define NULL
Definition: types.h:112

◆ ~CZipExtract()

CZipExtract::~CZipExtract ( )
inline

Definition at line 30 of file CZipExtract.cpp.

31  {
32  if (uf)
33  {
34  DPRINT1("WARNING: uf not closed!\n");
35  Close();
36  }
37  }
void Close()
Definition: CZipExtract.cpp:39
unzFile uf
Definition: CZipExtract.cpp:17
#define DPRINT1
Definition: precomp.h:8

Member Function Documentation

◆ Close()

void CZipExtract::Close ( )
inline

Definition at line 39 of file CZipExtract.cpp.

40  {
41  if (uf)
42  unzClose(uf);
43  uf = NULL;
44  }
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:808
unzFile uf
Definition: CZipExtract.cpp:17
#define NULL
Definition: types.h:112

Referenced by Extract(), and ~CZipExtract().

◆ Extract()

bool CZipExtract::Extract ( HWND  hDlg,
HWND  hProgress,
const bool bCancel 
)
inline

Definition at line 347 of file CZipExtract.cpp.

348  {
351  int err = unzGetGlobalInfo64(uf, &gi);
352  if (err != UNZ_OK)
353  {
354  DPRINT1("ERROR, unzGetGlobalInfo64: 0x%x\n", err);
355  Close();
356  return false;
357  }
358 
359  CZipEnumerator zipEnum;
360  if (!zipEnum.initialize(this))
361  {
362  DPRINT1("ERROR, zipEnum.initialize\n");
363  Close();
364  return false;
365  }
366 
367  CWindow Progress(hProgress);
368  Progress.SendMessage(PBM_SETRANGE32, 0, gi.number_entry);
369  Progress.SendMessage(PBM_SETPOS, 0, 0);
370 
371  BYTE Buffer[2048];
372  CStringA BaseDirectory = m_Directory;
373  CStringA Name;
376  int CurrentFile = 0;
377  bool bOverwriteAll = false;
378  while (zipEnum.next(Name, Info))
379  {
380  if (*bCancel)
381  {
382  Close();
383  return false;
384  }
385 
386  bool is_dir = Name.GetLength() > 0 && Name[Name.GetLength()-1] == '/';
387 
388  char CombinedPath[MAX_PATH * 2] = { 0 };
389  PathCombineA(CombinedPath, BaseDirectory, Name);
390  CStringA FullPath = CombinedPath;
391  FullPath.Replace('/', '\\'); /* SHPathPrepareForWriteA does not handle '/' */
393  HRESULT hr = SHPathPrepareForWriteA(hDlg, NULL, FullPath, dwFlags);
394  if (FAILED_UNEXPECTEDLY(hr))
395  {
396  Close();
397  return false;
398  }
399  CurrentFile++;
400  if (is_dir)
401  continue;
402 
403  if (Info.flag & MINIZIP_PASSWORD_FLAG)
404  {
406  do
407  {
408  /* If there is a password set, try it */
409  if (!Password.IsEmpty())
410  {
412  if (err == UNZ_OK)
413  {
414  /* Try to read some bytes, because unzOpenCurrentFilePassword does not return failure */
415  char Buf[10];
416  err = unzReadCurrentFile(uf, Buf, sizeof(Buf));
418  if (err >= UNZ_OK)
419  {
420  /* 're'-open the file so that we can begin to extract */
422  break;
423  }
424  }
425  }
427  } while (Response == eAccept);
428 
429  if (Response == eSkip)
430  {
431  Progress.SendMessage(PBM_SETPOS, CurrentFile, 0);
432  continue;
433  }
434  else if (Response == eAbort)
435  {
436  Close();
437  return false;
438  }
439  }
440  else
441  {
443  }
444 
445  if (err != UNZ_OK)
446  {
447  DPRINT1("ERROR, unzOpenCurrentFilePassword: 0x%x\n", err);
448  Close();
449  return false;
450  }
451 
454  {
456  if (dwErr == ERROR_FILE_EXISTS)
457  {
458  bool bOverwrite = bOverwriteAll;
459  if (!bOverwriteAll)
460  {
461  eZipConfirmResponse Result = _CZipAskReplace(hDlg, FullPath);
462  switch (Result)
463  {
464  case eYesToAll:
465  bOverwriteAll = true;
466  case eYes:
467  bOverwrite = true;
468  break;
469  case eNo:
470  break;
471  case eCancel:
473  Close();
474  return false;
475  }
476  }
477 
478  if (bOverwrite)
479  {
482  {
483  dwErr = GetLastError();
484  }
485  }
486  else
487  {
489  continue;
490  }
491  }
493  {
495  DPRINT1("ERROR, CreateFileA: 0x%x (%s)\n", dwErr, bOverwriteAll ? "Y" : "N");
496  Close();
497  return false;
498  }
499  }
500 
501  do
502  {
503  if (*bCancel)
504  {
506  BOOL deleteResult = DeleteFileA(FullPath);
507  if (deleteResult == 0)
508  DPRINT1("ERROR, DeleteFileA: 0x%x\n", GetLastError());
509  Close();
510  return false;
511  }
512 
513  err = unzReadCurrentFile(uf, Buffer, sizeof(Buffer));
514 
515  if (err < 0)
516  {
517  DPRINT1("ERROR, unzReadCurrentFile: 0x%x\n", err);
518  break;
519  }
520  else if (err > 0)
521  {
522  DWORD dwWritten;
523  if (!WriteFile(hFile, Buffer, err, &dwWritten, NULL))
524  {
525  DPRINT1("ERROR, WriteFile: 0x%x\n", GetLastError());
526  break;
527  }
528  if (dwWritten != (DWORD)err)
529  {
530  DPRINT1("ERROR, WriteFile: dwWritten:%d err:%d\n", dwWritten, err);
531  break;
532  }
533  }
534 
535  } while (err > 0);
536 
537  /* Update Filetime */
538  FILETIME LocalFileTime;
539  DosDateTimeToFileTime((WORD)(Info.dosDate >> 16), (WORD)Info.dosDate, &LocalFileTime);
540  FILETIME FileTime;
541  LocalFileTimeToFileTime(&LocalFileTime, &FileTime);
542  SetFileTime(hFile, &FileTime, &FileTime, &FileTime);
543 
544  /* Done */
546 
547  if (err)
548  {
550  DPRINT1("ERROR, unzReadCurrentFile2: 0x%x\n", err);
551  Close();
552  return false;
553  }
554  else
555  {
557  if (err != UNZ_OK)
558  {
559  DPRINT1("ERROR(non-fatal), unzCloseCurrentFile: 0x%x\n", err);
560  }
561  }
562  Progress.SendMessage(PBM_SETPOS, CurrentFile, 0);
563  }
564 
565  Close();
566  return true;
567  }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define PBM_SETRANGE32
Definition: commctrl.h:2184
#define CloseHandle
Definition: compat.h:598
HRESULT hr
Definition: shlfolder.c:183
CStringW m_Filename
Definition: CZipExtract.cpp:13
eZipPasswordResponse _CZipAskPassword(HWND hDlg, const char *filename, CStringA &Password)
Definition: precomp.h:71
#define UNZ_OK
Definition: unzip.h:74
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
CStringA m_Password
Definition: CZipExtract.cpp:15
#define PBM_SETPOS
Definition: commctrl.h:2180
bool initialize(IZip *zip)
void Close()
Definition: CZipExtract.cpp:39
CStringW m_Directory
Definition: CZipExtract.cpp:14
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
BOOL WINAPI LocalFileTimeToFileTime(IN CONST FILETIME *lpLocalFileTime, OUT LPFILETIME lpFileTime)
Definition: time.c:253
int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition: unzip.c:1641
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:828
#define SHPPFW_DIRCREATE
Definition: shlobj.h:303
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
eZipConfirmResponse _CZipAskReplace(HWND hDlg, PCSTR FullPath)
struct NameRec_ * Name
Definition: cdprocs.h:459
Definition: precomp.h:63
eZipConfirmResponse
Definition: precomp.h:69
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Definition: unzip.c:1684
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
Definition: precomp.h:73
Definition: bufpool.h:45
DWORD dwErr
Definition: service.c:36
unzFile uf
Definition: CZipExtract.cpp:17
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:2004
BOOL WINAPI DosDateTimeToFileTime(IN WORD wFatDate, IN WORD wFatTime, OUT LPFILETIME lpFileTime)
Definition: time.c:75
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: unzip.c:778
#define MAX_PATH
Definition: compat.h:34
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:43
PCXSTR GetString() const
Definition: atlsimpstr.h:361
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
Definition: unzip.c:1646
Definition: ncftp.h:89
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MINIZIP_PASSWORD_FLAG
Definition: precomp.h:43
#define err(...)
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned char BYTE
Definition: xxhash.c:193
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteA(HWND hwnd, IUnknown *modless, LPCSTR path, DWORD flags)
Definition: shlfileop.cpp:2227
int Replace(PCXSTR pszOld, PCXSTR pszNew)
Definition: cstringt.h:774
#define CREATE_ALWAYS
Definition: disk.h:72
bool next(CStringA &name, unz_file_info64 &info)
#define NULL
Definition: types.h:112
eZipPasswordResponse
Definition: precomp.h:60
#define DPRINT1
Definition: precomp.h:8
Definition: precomp.h:62
#define SHPPFW_NONE
Definition: shlobj.h:302
#define SHPPFW_IGNOREFILENAME
Definition: shlobj.h:306
#define CREATE_NEW
Definition: disk.h:69
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:599
ZPOS64_T number_entry
Definition: unzip.h:98

Referenced by CZipExtract::CExtractSettingsPage::ExtractEntry().

◆ QueryInterface()

STDMETHODIMP CZipExtract::QueryInterface ( REFIID  riid,
void **  ppvObject 
)
inline

Implements IUnknown.

Definition at line 47 of file CZipExtract.cpp.

48  {
49  if (riid == IID_IUnknown)
50  {
51  *ppvObject = this;
52  AddRef();
53  return S_OK;
54  }
55  return E_NOINTERFACE;
56  }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
const GUID IID_IUnknown
ULONG AddRef()
REFIID LPVOID * ppvObject
Definition: precomp.h:44
#define S_OK
Definition: intsafe.h:51

◆ runWizard()

void CZipExtract::runWizard ( )
inline

Definition at line 325 of file CZipExtract.cpp.

326  {
327  PROPSHEETHEADERW psh = { sizeof(psh), 0 };
328  psh.dwFlags = PSH_WIZARD97 | PSH_HEADER;
329  psh.hInstance = _AtlBaseModule.GetResourceInstance();
330 
331  CExtractSettingsPage extractPage(this, &m_Password);
332  CCompleteSettingsPage completePage(this);
333  HPROPSHEETPAGE hpsp[] =
334  {
335  extractPage.Create(),
336  completePage.Create()
337  };
338 
339  psh.phpage = hpsp;
340  psh.nPages = _countof(hpsp);
341  psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
342  psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
343 
344  PropertySheetW(&psh);
345  }
#define MAKEINTRESOURCE
Definition: winuser.h:591
CStringA m_Password
Definition: CZipExtract.cpp:15
#define IDB_HEADER
Definition: resource.h:30
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
HINSTANCE hInstance
Definition: prsht.h:296
#define _countof(array)
Definition: sndvol32.h:68
DWORD dwFlags
Definition: prsht.h:294
HPROPSHEETPAGE * phpage
Definition: prsht.h:309
#define IDB_WATERMARK
Definition: resource.h:4

Referenced by _CZipExtract_runWizard().

◆ STDMETHODIMP_() [1/3]

CZipExtract::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 57 of file CZipExtract.cpp.

58  {
59  return 2;
60  }

◆ STDMETHODIMP_() [2/3]

CZipExtract::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 61 of file CZipExtract.cpp.

62  {
63  return 1;
64  }

◆ STDMETHODIMP_() [3/3]

CZipExtract::STDMETHODIMP_ ( unzFile  )
inlinevirtual

Reimplemented from IZip.

Definition at line 65 of file CZipExtract.cpp.

66  {
67  return uf;
68  }
unzFile uf
Definition: CZipExtract.cpp:17

Member Data Documentation

◆ m_Directory

◆ m_DirectoryChanged

◆ m_Filename

CStringW CZipExtract::m_Filename
private

Definition at line 13 of file CZipExtract.cpp.

Referenced by CZipExtract(), and Extract().

◆ m_Password

CStringA CZipExtract::m_Password
private

Definition at line 15 of file CZipExtract.cpp.

Referenced by Extract(), and runWizard().

◆ uf

unzFile CZipExtract::uf
private

Definition at line 17 of file CZipExtract.cpp.

Referenced by Close(), Extract(), STDMETHODIMP_(), and ~CZipExtract().


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