ReactOS  0.4.14-dev-323-g6fe6a88
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)
 
- 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:54
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:925
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
smooth NULL
Definition: ftsmooth.c:416
unzFile uf
Definition: CZipExtract.cpp:17

◆ ~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
smooth NULL
Definition: ftsmooth.c:416
unzFile uf
Definition: CZipExtract.cpp:17

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

◆ Extract()

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

Definition at line 271 of file CZipExtract.cpp.

272  {
275  int err = unzGetGlobalInfo64(uf, &gi);
276  if (err != UNZ_OK)
277  {
278  DPRINT1("ERROR, unzGetGlobalInfo64: 0x%x\n", err);
279  Close();
280  return false;
281  }
282 
283  CZipEnumerator zipEnum;
284  if (!zipEnum.initialize(this))
285  {
286  DPRINT1("ERROR, zipEnum.initialize\n");
287  Close();
288  return false;
289  }
290 
291  CWindow Progress(hProgress);
292  Progress.SendMessage(PBM_SETRANGE32, 0, gi.number_entry);
293  Progress.SendMessage(PBM_SETPOS, 0, 0);
294 
295  BYTE Buffer[2048];
296  CStringA BaseDirectory = m_Directory;
297  CStringA Name;
300  int CurrentFile = 0;
301  bool bOverwriteAll = false;
302  while (zipEnum.next(Name, Info))
303  {
304  bool is_dir = Name.GetLength() > 0 && Name[Name.GetLength()-1] == '/';
305 
306  char CombinedPath[MAX_PATH * 2] = { 0 };
307  PathCombineA(CombinedPath, BaseDirectory, Name);
308  CStringA FullPath = CombinedPath;
309  FullPath.Replace('/', '\\'); /* SHPathPrepareForWriteA does not handle '/' */
311  HRESULT hr = SHPathPrepareForWriteA(hDlg, NULL, FullPath, dwFlags);
312  if (FAILED_UNEXPECTEDLY(hr))
313  {
314  Close();
315  return false;
316  }
317  CurrentFile++;
318  if (is_dir)
319  continue;
320 
321  if (Info.flag & MINIZIP_PASSWORD_FLAG)
322  {
324  do
325  {
326  /* If there is a password set, try it */
327  if (!Password.IsEmpty())
328  {
330  if (err == UNZ_OK)
331  {
332  /* Try to read some bytes, because unzOpenCurrentFilePassword does not return failure */
333  char Buf[10];
334  err = unzReadCurrentFile(uf, Buf, sizeof(Buf));
336  if (err >= UNZ_OK)
337  {
338  /* 're'-open the file so that we can begin to extract */
340  break;
341  }
342  }
343  }
345  } while (Response == eAccept);
346 
347  if (Response == eSkip)
348  {
349  Progress.SendMessage(PBM_SETPOS, CurrentFile, 0);
350  continue;
351  }
352  else if (Response == eAbort)
353  {
354  Close();
355  return false;
356  }
357  }
358  else
359  {
361  }
362 
363  if (err != UNZ_OK)
364  {
365  DPRINT1("ERROR, unzOpenCurrentFilePassword: 0x%x\n", err);
366  Close();
367  return false;
368  }
369 
372  {
374  if (dwErr == ERROR_FILE_EXISTS)
375  {
376  bool bOverwrite = bOverwriteAll;
377  if (!bOverwriteAll)
378  {
379  eZipConfirmResponse Result = _CZipAskReplace(hDlg, FullPath);
380  switch (Result)
381  {
382  case eYesToAll:
383  bOverwriteAll = true;
384  case eYes:
385  bOverwrite = true;
386  break;
387  case eNo:
388  break;
389  case eCancel:
391  Close();
392  return false;
393  }
394  }
395 
396  if (bOverwrite)
397  {
400  {
401  dwErr = GetLastError();
402  }
403  }
404  else
405  {
407  continue;
408  }
409  }
411  {
413  DPRINT1("ERROR, CreateFileA: 0x%x (%s)\n", dwErr, bOverwriteAll ? "Y" : "N");
414  Close();
415  return false;
416  }
417  }
418 
419  do
420  {
421  err = unzReadCurrentFile(uf, Buffer, sizeof(Buffer));
422 
423  if (err < 0)
424  {
425  DPRINT1("ERROR, unzReadCurrentFile: 0x%x\n", err);
426  break;
427  }
428  else if (err > 0)
429  {
430  DWORD dwWritten;
431  if (!WriteFile(hFile, Buffer, err, &dwWritten, NULL))
432  {
433  DPRINT1("ERROR, WriteFile: 0x%x\n", GetLastError());
434  break;
435  }
436  if (dwWritten != (DWORD)err)
437  {
438  DPRINT1("ERROR, WriteFile: dwWritten:%d err:%d\n", dwWritten, err);
439  break;
440  }
441  }
442 
443  } while (err > 0);
444 
445  /* Update Filetime */
446  FILETIME LastAccessTime;
447  GetFileTime(hFile, NULL, &LastAccessTime, NULL);
448  FILETIME LocalFileTime;
449  DosDateTimeToFileTime((WORD)(Info.dosDate >> 16), (WORD)Info.dosDate, &LocalFileTime);
450  FILETIME FileTime;
451  LocalFileTimeToFileTime(&LocalFileTime, &FileTime);
452  SetFileTime(hFile, &FileTime, &LastAccessTime, &FileTime);
453 
454  /* Done.. */
456 
457  if (err)
458  {
460  DPRINT1("ERROR, unzReadCurrentFile2: 0x%x\n", err);
461  Close();
462  return false;
463  }
464  else
465  {
467  if (err != UNZ_OK)
468  {
469  DPRINT1("ERROR(non-fatal), unzCloseCurrentFile: 0x%x\n", err);
470  }
471  }
472  Progress.SendMessage(PBM_SETPOS, CurrentFile, 0);
473  }
474 
475  Close();
476  return true;
477  }
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:398
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:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
CStringA m_Password
Definition: CZipExtract.cpp:15
#define PBM_SETPOS
Definition: commctrl.h:2180
bool initialize(IZip *zip)
void Close()
Definition: CZipExtract.cpp:39
struct TraceInfo Info
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:1098
BOOL WINAPI LocalFileTimeToFileTime(IN CONST FILETIME *lpLocalFileTime, OUT LPFILETIME lpFileTime)
Definition: time.c:243
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
#define GENERIC_WRITE
Definition: nt_native.h:90
eZipConfirmResponse _CZipAskReplace(HWND hDlg, PCSTR FullPath)
struct NameRec_ * Name
Definition: cdprocs.h:464
Definition: precomp.h:63
eZipConfirmResponse
Definition: precomp.h:69
smooth NULL
Definition: ftsmooth.c:416
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
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:77
#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:26
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:42
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:126
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
#define MINIZIP_PASSWORD_FLAG
Definition: precomp.h:43
#define err(...)
_In_ HANDLE hFile
Definition: mswsock.h:90
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteA(HWND hwnd, IUnknown *modless, LPCSTR path, DWORD flags)
Definition: shlfileop.cpp:2086
int Replace(PCXSTR pszOld, PCXSTR pszNew)
Definition: cstringt.h:696
#define CREATE_ALWAYS
Definition: disk.h:72
bool next(CStringA &name, unz_file_info64 &info)
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:399
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
ZPOS64_T number_entry
Definition: unzip.h:98

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

◆ 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:59

◆ runWizard()

void CZipExtract::runWizard ( )
inline

Definition at line 251 of file CZipExtract.cpp.

252  {
253  PROPSHEETHEADERW psh = { sizeof(psh), 0 };
254  psh.dwFlags = PSH_WIZARD97 | PSH_HEADER;
255  psh.hInstance = _AtlBaseModule.GetResourceInstance();
256 
257  CExtractSettingsPage extractPage(this, &m_Password);
258  CCompleteSettingsPage completePage(this);
259  HPROPSHEETPAGE hpsp[] =
260  {
261  extractPage.Create(),
262  completePage.Create()
263  };
264 
265  psh.phpage = hpsp;
266  psh.nPages = _countof(hpsp);
267 
268  PropertySheetW(&psh);
269  }
#define _countof(array)
Definition: fontsub.cpp:30
CStringA m_Password
Definition: CZipExtract.cpp:15
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
HINSTANCE hInstance
Definition: prsht.h:278
DWORD dwFlags
Definition: prsht.h:276
HPROPSHEETPAGE * phpage
Definition: prsht.h:291

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: