ZipCallback.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive library source distribution and
3 // is Copyrighted 2000 - 2013 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: http://www.artpol-software.com
14 
21 #if !defined(ZIPARCHIVE_ZIPCALLBACK_DOT_H)
22 #define ZIPARCHIVE_ZIPCALLBACK_DOT_H
23 
24 #if _MSC_VER > 1000
25  #pragma once
26  #if defined ZIP_HAS_DLL
27  #pragma warning (push)
28  #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
29  #endif
30 #endif
31 
32 #include "ZipString.h"
33 #include "ZipExport.h"
34 
35 /*
36  When processing split archives, this value is passes as the argument to the CZipCallback::Callback method
37  to notify that the current volume is the last one.
38 */
39 #define ZIP_SPLIT_LAST_VOLUME (ZIP_SIZE_TYPE)(-1)
40 
58 struct ZIP_API CZipCallback
59 {
89  virtual bool Callback(ZIP_SIZE_TYPE uProgress) = 0;
90 
91 
96  CZipString m_szExternalFile;
97  virtual ~CZipCallback(){}
98 };
99 
120 struct ZIP_API CZipSegmCallback : public CZipCallback
121 {
126  {
133  };
134 
135  ZIP_VOLUME_TYPE m_uVolumeNeeded;
136 
137  int m_iCode;
138 };
139 
153 struct ZIP_API CZipActionCallback : public CZipCallback
154 {
155  friend class CZipArchive;
156  friend class CZipCentralDir;
157 
169  {
174  cbNothing = 0x0000,
175 
180  cbAdd = 0x0001,
181 
188  cbAddTmp = 0x0002,
189 
197  cbAddStore = 0x0004,
198 
203  cbExtract = 0x0008,
204 
211  cbDeleteCnt = 0x0010,
212 
218  cbDelete = 0x0020,
219 
224  cbTest = 0x0040,
225 
232  cbSave = 0x0080,
233 
238  cbGet = 0x0100,
239 
245  cbModify = 0x0200,
246 
252  cbMoveData = 0x0400,
253 
260  cbCalculateForMulti= 0x0800,
261 
269  cbMultiAdd = 0x1000 | cbAdd,
270 
271 
278  cbEncryptPrepare= 0x2000,
279 
286  cbEncryptMoveData= 0x4000,
287 
294  cbEncrypt = 0x8000,
295 
296 
305  cbMultiEncrypt = 0x10000 | cbEncryptMoveData | cbEncrypt,
306 
312  cbNextValue = 0x20000,
313 
319  cbSubActions = cbAddTmp | cbAddStore | cbDeleteCnt | cbMoveData | cbCalculateForMulti | cbEncryptPrepare | cbEncryptMoveData,
320 
325  cbActions = cbAdd | cbExtract | cbDelete | cbTest | cbSave | cbGet | cbModify | cbEncrypt,
326 
332  cbMultiActions = cbMultiAdd | cbMultiEncrypt,
333 
338  cbAll = cbActions | cbSubActions | cbMultiActions
339  };
340 
341 
350  struct ZIP_API CMultiActionsInfo
351  {
352  friend struct CZipActionCallback;
353 
354  ZIP_SIZE_TYPE m_uTotalBytesToProcess;
355  ZIP_SIZE_TYPE m_uTotalFilesToProcess;
356  ZIP_SIZE_TYPE m_uBytesProcessed;
357  ZIP_SIZE_TYPE m_uFilesProcessed;
358 
364  ZIP_SIZE_TYPE LeftFilesToProcess() const {return m_uTotalFilesToProcess - m_uFilesProcessed;}
365 
371  ZIP_SIZE_TYPE LeftBytesToProcess() const {return m_uTotalBytesToProcess - m_uBytesProcessed;}
372  private:
373  void Init(ZIP_SIZE_TYPE uTotalItemsToProcess, ZIP_SIZE_TYPE uTotalBytesToProcess, int iReactType)
374  {
375  m_uTotalFilesToProcess = uTotalItemsToProcess;
376  m_uTotalBytesToProcess = uTotalBytesToProcess;
377  m_uBytesProcessed = m_uFilesProcessed = 0;
378  m_iReactType = iReactType;
379  m_bActive = false;
380  }
381  void OnCallbackInit(int iType)
382  {
383  // this assumes, that the callback type will stay unchanged
384  // between Init() and CallbackEnd()
385  m_bActive = iType == m_iReactType;
386  }
387 
388  void OnCallCallback(ZIP_SIZE_TYPE uProgress)
389  {
390  if (m_bActive)
391  m_uBytesProcessed += uProgress;
392  }
393  bool OnNextFile()
394  {
395  if (m_bActive)
396  {
397  m_uFilesProcessed++;
398  return true;
399  }
400  else
401  return false;
402  }
403  bool m_bActive;
404  int m_iReactType;
405  };
406 
408  {
409  m_uTotalToProcess = 0;
410  m_uProcessed = 0;
411  m_pMultiActionsInfo = NULL;
412  }
413 
435  virtual void MultiActionsInit(ZIP_SIZE_TYPE uTotalFilesToProcess, ZIP_SIZE_TYPE uTotalBytesToProcess, int iReactType)
436  {
437  InitMultiActionsInfo();
438  m_pMultiActionsInfo->Init(uTotalFilesToProcess, uTotalBytesToProcess, iReactType);
439  }
440 
452  virtual void Init(LPCTSTR lpszFileInZip = NULL, LPCTSTR lpszExternalFile = NULL)
453  {
454  m_szFileInZip = lpszFileInZip;
455  m_szExternalFile = lpszExternalFile;
456  m_uTotalToProcess = 0; // not yet known
457  m_uProcessed = 0; // nothing yet done
458  CacheStepSize();
460  if (m_pMultiActionsInfo)
461  // the type is known now
462  m_pMultiActionsInfo->OnCallbackInit(m_iType);
463  }
464 
471  virtual void SetTotal(ZIP_SIZE_TYPE uTotalToDo)
472  {
473  m_uTotalToProcess = uTotalToDo;
474 // m_uProcessed = 0; // already done in CZipCallbackProvider::Get
475  }
476 
490  virtual bool MultiActionsNext()
491  {
492  if (m_pMultiActionsInfo && m_pMultiActionsInfo->OnNextFile())
493  return Callback(0);
494  else
495  return true;
496  }
497 
503  virtual void CallbackEnd()
504  {
505  //ASSERT(m_uProcessed == m_uTotalToProcess);
506  };
507 
518  virtual void MultiActionsEnd()
519  {
520  ReleaseMultiActionsInfo();
521  }
522 
529  ZIP_SIZE_TYPE LeftToProcess() const {return m_uTotalToProcess - m_uProcessed;}
530 
543  ZIP_SIZE_TYPE m_uTotalToProcess;
544  ZIP_SIZE_TYPE m_uProcessed;
545  CZipString m_szFileInZip;
546 
551  int m_iType;
552 
564  {
565  return m_pMultiActionsInfo;
566  }
567 
574  void SetReactType(int iType)
575  {
576  m_pMultiActionsInfo->m_iReactType = iType;
577  }
578 
597  virtual int GetStepSize()
598  {
600  }
601 
603  {
604  ReleaseMultiActionsInfo();
605  }
606 
617  bool RequestCallback(ZIP_SIZE_TYPE uProgress = 1)
618  {
619  if (!uProgress)
620  return true;
621  if (m_iCachedStepSize == 1)
622  return CallCallback(uProgress);
623  else
624  {
625  m_uAccumulatedProgress += uProgress;
626  if (m_iCurrentStep >= m_iCachedStepSize)
627  {
628  bool ret = CallCallback(m_uAccumulatedProgress);
630  return ret;
631  }
632  else
633  {
634  m_iCurrentStep++;
635  return true;
636  }
637  }
638  }
639 
653  bool RequestLastCallback(ZIP_SIZE_TYPE uProgress = 0)
654  {
655  bool ret;
656  if (m_uAccumulatedProgress == 0 && uProgress == 0)
657  ret = true;
658  else
659  ret = CallCallback(m_uAccumulatedProgress + uProgress);
661  return ret;
662  }
663 
664 protected:
676  virtual bool CallCallback(ZIP_SIZE_TYPE uProgress)
677  {
678  m_uProcessed += uProgress;
679  if (m_pMultiActionsInfo)
680  m_pMultiActionsInfo->OnCallCallback(uProgress);
681  return Callback(uProgress);
682  }
683 
688  {
689  m_iCachedStepSize = GetStepSize();
690  if (m_iCachedStepSize == 0)
691  m_iCachedStepSize = 1;
692  }
693 
702  {
703  m_iCurrentStep = 1;
704  m_uAccumulatedProgress = 0;
705  }
706 private:
707  CMultiActionsInfo* m_pMultiActionsInfo;
708  void InitMultiActionsInfo()
709  {
710  ReleaseMultiActionsInfo();
711  m_pMultiActionsInfo = new CMultiActionsInfo();
712  }
713  void ReleaseMultiActionsInfo()
714  {
715  if (m_pMultiActionsInfo != NULL)
716  {
717  delete m_pMultiActionsInfo;
718  m_pMultiActionsInfo = NULL;
719  }
720  }
721 
722  int m_iCachedStepSize;
723  int m_iCurrentStep;
724  ZIP_SIZE_TYPE m_uAccumulatedProgress;
725 };
726 
727 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
728  #pragma warning (pop)
729 #endif
730 
731 
732 #endif

The ZipArchive Library Copyright © 2000 - 2013 Artpol Software - Tadeusz Dracz. Generated at Mon Feb 25 2013 16:29:20.