ZipCallback.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive Library Open Source distribution
3 // and is Copyrighted 2000 - 2022 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: https://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_iCurrentStep = 0;
410  m_iType = 0;
411  m_uAccumulatedProgress = 0;
412  m_iCachedStepSize = 0;
413  m_uTotalToProcess = 0;
414  m_uProcessed = 0;
415  m_pMultiActionsInfo = NULL;
416  }
417 
439  virtual void MultiActionsInit(ZIP_SIZE_TYPE uTotalFilesToProcess, ZIP_SIZE_TYPE uTotalBytesToProcess, int iReactType)
440  {
441  InitMultiActionsInfo();
442  m_pMultiActionsInfo->Init(uTotalFilesToProcess, uTotalBytesToProcess, iReactType);
443  }
444 
456  virtual void Init(LPCTSTR lpszFileInZip = NULL, LPCTSTR lpszExternalFile = NULL)
457  {
458  m_szFileInZip = lpszFileInZip;
459  m_szExternalFile = lpszExternalFile;
460  m_uTotalToProcess = 0; // not yet known
461  m_uProcessed = 0; // nothing yet done
462  CacheStepSize();
464  if (m_pMultiActionsInfo)
465  // the type is known now
466  m_pMultiActionsInfo->OnCallbackInit(m_iType);
467  }
468 
475  virtual void SetTotal(ZIP_SIZE_TYPE uTotalToDo)
476  {
477  m_uTotalToProcess = uTotalToDo;
478 // m_uProcessed = 0; // already done in CZipCallbackProvider::Get
479  }
480 
497  virtual bool MultiActionsNext(LPCTSTR = NULL)
498  {
499  if (m_pMultiActionsInfo && m_pMultiActionsInfo->OnNextFile())
500  return Callback(0);
501  else
502  return true;
503  }
504 
510  virtual void CallbackEnd()
511  {
512  //ASSERT(m_uProcessed == m_uTotalToProcess);
513  };
514 
525  virtual void MultiActionsEnd()
526  {
527  ReleaseMultiActionsInfo();
528  }
529 
536  ZIP_SIZE_TYPE LeftToProcess() const {return m_uTotalToProcess - m_uProcessed;}
537 
550  ZIP_SIZE_TYPE m_uTotalToProcess;
551  ZIP_SIZE_TYPE m_uProcessed;
552  CZipString m_szFileInZip;
553 
558  int m_iType;
559 
571  {
572  return m_pMultiActionsInfo;
573  }
574 
581  void SetReactType(int iType)
582  {
583  m_pMultiActionsInfo->m_iReactType = iType;
584  }
585 
604  virtual int GetStepSize()
605  {
607  }
608 
610  {
611  ReleaseMultiActionsInfo();
612  }
613 
624  bool RequestCallback(ZIP_SIZE_TYPE uProgress = 1)
625  {
626  if (!uProgress)
627  return true;
628  if (m_iCachedStepSize == 1)
629  return CallCallback(uProgress);
630  else
631  {
632  m_uAccumulatedProgress += uProgress;
633  if (m_iCurrentStep >= m_iCachedStepSize)
634  {
635  bool ret = CallCallback(m_uAccumulatedProgress);
637  return ret;
638  }
639  else
640  {
641  m_iCurrentStep++;
642  return true;
643  }
644  }
645  }
646 
660  bool RequestLastCallback(ZIP_SIZE_TYPE uProgress = 0)
661  {
662  bool ret;
663  if (m_uAccumulatedProgress == 0 && uProgress == 0)
664  ret = true;
665  else
666  ret = CallCallback(m_uAccumulatedProgress + uProgress);
668  return ret;
669  }
670 
671 protected:
683  virtual bool CallCallback(ZIP_SIZE_TYPE uProgress)
684  {
685  m_uProcessed += uProgress;
686  if (m_pMultiActionsInfo)
687  m_pMultiActionsInfo->OnCallCallback(uProgress);
688  return Callback(uProgress);
689  }
690 
695  {
696  m_iCachedStepSize = GetStepSize();
697  if (m_iCachedStepSize == 0)
698  m_iCachedStepSize = 1;
699  }
700 
709  {
710  m_iCurrentStep = 1;
711  m_uAccumulatedProgress = 0;
712  }
713 private:
714  CMultiActionsInfo* m_pMultiActionsInfo;
715  void InitMultiActionsInfo()
716  {
717  ReleaseMultiActionsInfo();
718  m_pMultiActionsInfo = new CMultiActionsInfo();
719  }
720  void ReleaseMultiActionsInfo()
721  {
722  if (m_pMultiActionsInfo != NULL)
723  {
724  delete m_pMultiActionsInfo;
725  m_pMultiActionsInfo = NULL;
726  }
727  }
728 
729  int m_iCachedStepSize;
730  int m_iCurrentStep;
731  ZIP_SIZE_TYPE m_uAccumulatedProgress;
732 };
733 
734 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
735  #pragma warning (pop)
736 #endif
737 
738 
739 #endif

The ZipArchive Library Copyright © 2000 - 2022 Artpol Software - Tadeusz Dracz. Generated at Sat Dec 17 2022 19:57:03.