00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00021 #if !defined(ZIPARCHIVE_ZIPCALLBACK_DOT_H)
00022 #define ZIPARCHIVE_ZIPCALLBACK_DOT_H
00023
00024 #if _MSC_VER > 1000
00025 #pragma once
00026 #if defined ZIP_HAS_DLL
00027 #pragma warning (push)
00028 #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
00029 #endif
00030 #endif
00031
00032 #include "ZipString.h"
00033 #include "ZipExport.h"
00034
00035
00036
00037
00038
00039 #define ZIP_SPLIT_LAST_VOLUME (ZIP_SIZE_TYPE)(-1)
00040
00058 struct ZIP_API CZipCallback
00059 {
00089 virtual bool Callback(ZIP_SIZE_TYPE uProgress) = 0;
00090
00091
00095 CZipString m_szExternalFile;
00096 virtual ~CZipCallback(){}
00097 };
00098
00119 struct ZIP_API CZipSegmCallback : public CZipCallback
00120 {
00124 enum SegmCodes
00125 {
00126 scVolumeNeededForRead,
00127 scVolumeNeededForWrite,
00128 scFileNameDuplicated,
00129 scCannotSetVolLabel,
00130 scFileCreationFailure,
00131 scFileNotFound,
00132 };
00133
00134 ZIP_VOLUME_TYPE m_uVolumeNeeded;
00135
00136 int m_iCode;
00137 };
00138
00152 struct ZIP_API CZipActionCallback : public CZipCallback
00153 {
00154 friend class CZipArchive;
00155 friend class CZipCentralDir;
00156
00167 enum CallbackType
00168 {
00173 cbNothing = 0x0000,
00174
00179 cbAdd = 0x0001,
00180
00187 cbAddTmp = 0x0002,
00188
00196 cbAddStore = 0x0004,
00197
00202 cbExtract = 0x0008,
00203
00210 cbDeleteCnt = 0x0010,
00211
00217 cbDelete = 0x0020,
00218
00223 cbTest = 0x0040,
00224
00231 cbSave = 0x0080,
00232
00237 cbGet = 0x0100,
00238
00244 cbModify = 0x0200,
00245
00251 cbMoveData = 0x0400,
00252
00259 cbCalculateForMulti= 0x0800,
00260
00268 cbMultiAdd = 0x1000 | cbAdd,
00269
00270
00277 cbEncryptPrepare= 0x2000,
00278
00285 cbEncryptMoveData= 0x4000,
00286
00293 cbEncrypt = 0x8000,
00294
00295
00304 cbMultiEncrypt = 0x10000 | cbEncryptMoveData | cbEncrypt,
00305
00311 cbNextValue = 0x20000,
00312
00318 cbSubActions = cbAddTmp | cbAddStore | cbDeleteCnt | cbMoveData | cbCalculateForMulti | cbEncryptPrepare | cbEncryptMoveData,
00319
00324 cbActions = cbAdd | cbExtract | cbDelete | cbTest | cbSave | cbGet | cbModify | cbEncrypt,
00325
00331 cbMultiActions = cbMultiAdd | cbMultiEncrypt,
00332
00337 cbAll = cbActions | cbSubActions | cbMultiActions
00338 };
00339
00340
00349 struct ZIP_API CMultiActionsInfo
00350 {
00351 friend struct CZipActionCallback;
00352
00353 ZIP_SIZE_TYPE m_uTotalBytesToProcess;
00354 ZIP_SIZE_TYPE m_uTotalFilesToProcess;
00355 ZIP_SIZE_TYPE m_uBytesProcessed;
00356 ZIP_SIZE_TYPE m_uFilesProcessed;
00357
00363 ZIP_SIZE_TYPE LeftFilesToProcess() const {return m_uTotalFilesToProcess - m_uFilesProcessed;}
00364
00370 ZIP_SIZE_TYPE LeftBytesToProcess() const {return m_uTotalBytesToProcess - m_uBytesProcessed;}
00371 private:
00372 void Init(ZIP_SIZE_TYPE uTotalItemsToProcess, ZIP_SIZE_TYPE uTotalBytesToProcess, int iReactType)
00373 {
00374 m_uTotalFilesToProcess = uTotalItemsToProcess;
00375 m_uTotalBytesToProcess = uTotalBytesToProcess;
00376 m_uBytesProcessed = m_uFilesProcessed = 0;
00377 m_iReactType = iReactType;
00378 m_bActive = false;
00379 }
00380 void OnCallbackInit(int iType)
00381 {
00382
00383
00384 m_bActive = iType == m_iReactType;
00385 }
00386
00387 void OnCallCallback(ZIP_SIZE_TYPE uProgress)
00388 {
00389 if (m_bActive)
00390 m_uBytesProcessed += uProgress;
00391 }
00392 bool OnNextFile()
00393 {
00394 if (m_bActive)
00395 {
00396 m_uFilesProcessed++;
00397 return true;
00398 }
00399 else
00400 return false;
00401 }
00402 bool m_bActive;
00403 int m_iReactType;
00404 };
00405
00406 CZipActionCallback()
00407 {
00408 m_uTotalToProcess = 0;
00409 m_uProcessed = 0;
00410 m_pMultiActionsInfo = NULL;
00411 }
00412
00434 virtual void MultiActionsInit(ZIP_SIZE_TYPE uTotalFilesToProcess, ZIP_SIZE_TYPE uTotalBytesToProcess, int iReactType)
00435 {
00436 InitMultiActionsInfo();
00437 m_pMultiActionsInfo->Init(uTotalFilesToProcess, uTotalBytesToProcess, iReactType);
00438 }
00439
00451 virtual void Init(LPCTSTR lpszFileInZip = NULL, LPCTSTR lpszExternalFile = NULL)
00452 {
00453 m_szFileInZip = lpszFileInZip;
00454 m_szExternalFile = lpszExternalFile;
00455 m_uTotalToProcess = 0;
00456 m_uProcessed = 0;
00457 CacheStepSize();
00458 ResetProgressStage();
00459 if (m_pMultiActionsInfo)
00460
00461 m_pMultiActionsInfo->OnCallbackInit(m_iType);
00462 }
00463
00470 virtual void SetTotal(ZIP_SIZE_TYPE uTotalToDo)
00471 {
00472 m_uTotalToProcess = uTotalToDo;
00473
00474 }
00475
00489 virtual bool MultiActionsNext()
00490 {
00491 if (m_pMultiActionsInfo && m_pMultiActionsInfo->OnNextFile())
00492 return Callback(0);
00493 else
00494 return true;
00495 }
00496
00502 virtual void CallbackEnd()
00503 {
00504
00505 };
00506
00517 virtual void MultiActionsEnd()
00518 {
00519 ReleaseMultiActionsInfo();
00520 }
00521
00528 ZIP_SIZE_TYPE LeftToProcess() const {return m_uTotalToProcess - m_uProcessed;}
00529
00542 ZIP_SIZE_TYPE m_uTotalToProcess;
00543 ZIP_SIZE_TYPE m_uProcessed;
00544 CZipString m_szFileInZip;
00545
00550 int m_iType;
00551
00562 CMultiActionsInfo* GetMultiActionsInfo()
00563 {
00564 return m_pMultiActionsInfo;
00565 }
00566
00573 void SetReactType(int iType)
00574 {
00575 m_pMultiActionsInfo->m_iReactType = iType;
00576 }
00577
00596 virtual int GetStepSize()
00597 {
00598 return m_iType == cbSave || m_iType == cbDeleteCnt || m_iType == cbCalculateForMulti || m_iType == cbEncryptPrepare ? 256 : 1;
00599 }
00600
00601 ~CZipActionCallback()
00602 {
00603 ReleaseMultiActionsInfo();
00604 }
00605
00616 bool RequestCallback(ZIP_SIZE_TYPE uProgress = 1)
00617 {
00618 if (!uProgress)
00619 return true;
00620 if (m_iCachedStepSize == 1)
00621 return CallCallback(uProgress);
00622 else
00623 {
00624 m_uAccumulatedProgress += uProgress;
00625 if (m_iCurrentStep >= m_iCachedStepSize)
00626 {
00627 bool ret = CallCallback(m_uAccumulatedProgress);
00628 ResetProgressStage();
00629 return ret;
00630 }
00631 else
00632 {
00633 m_iCurrentStep++;
00634 return true;
00635 }
00636 }
00637 }
00638
00652 bool RequestLastCallback(ZIP_SIZE_TYPE uProgress = 0)
00653 {
00654 bool ret;
00655 if (m_uAccumulatedProgress == 0 && uProgress == 0)
00656 ret = true;
00657 else
00658 ret = CallCallback(m_uAccumulatedProgress + uProgress);
00659 ResetProgressStage();
00660 return ret;
00661 }
00662
00663 protected:
00675 virtual bool CallCallback(ZIP_SIZE_TYPE uProgress)
00676 {
00677 m_uProcessed += uProgress;
00678 if (m_pMultiActionsInfo)
00679 m_pMultiActionsInfo->OnCallCallback(uProgress);
00680 return Callback(uProgress);
00681 }
00682
00686 void CacheStepSize()
00687 {
00688 m_iCachedStepSize = GetStepSize();
00689 if (m_iCachedStepSize == 0)
00690 m_iCachedStepSize = 1;
00691 }
00692
00700 void ResetProgressStage()
00701 {
00702 m_iCurrentStep = 1;
00703 m_uAccumulatedProgress = 0;
00704 }
00705 private:
00706 CMultiActionsInfo* m_pMultiActionsInfo;
00707 void InitMultiActionsInfo()
00708 {
00709 ReleaseMultiActionsInfo();
00710 m_pMultiActionsInfo = new CMultiActionsInfo();
00711 }
00712 void ReleaseMultiActionsInfo()
00713 {
00714 if (m_pMultiActionsInfo != NULL)
00715 {
00716 delete m_pMultiActionsInfo;
00717 m_pMultiActionsInfo = NULL;
00718 }
00719 }
00720
00721 int m_iCachedStepSize;
00722 int m_iCurrentStep;
00723 ZIP_SIZE_TYPE m_uAccumulatedProgress;
00724 };
00725
00726 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
00727 #pragma warning (pop)
00728 #endif
00729
00730
00731 #endif