00001
00002
00003
00004
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00023 #if !defined(AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_)
00024 #define AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_
00025
00026 #if _MSC_VER > 1000
00027 #pragma once
00028 #endif // _MSC_VER > 1000
00029
00030 #include "ZipFile.h"
00031 #include "ZipAutoBuffer.h"
00032 #include "ZipString.h"
00033 #include "ZipMemFile.h"
00034 #include "ZipExport.h"
00035
00036
00037
00044 struct ZIP_API CZipCallback
00045 {
00062 virtual bool Callback(int iProgress) = 0;
00063
00064
00065 CZipString m_szExternalFile;
00066 };
00067
00084 struct ZIP_API CZipSpanCallback : public CZipCallback
00085 {
00086 DWORD m_uDiskNeeded;
00087 };
00088
00089
00090
00101 struct ZIP_API CZipActionCallback : public CZipCallback
00102 {
00103
00104 CZipActionCallback()
00105 {
00106 m_uTotalToDo = 0;
00107 m_uTotalSoFar = 0;
00108 }
00109
00114 int m_iType;
00115
00120 virtual void Init(LPCTSTR lpszFileInZip = NULL, LPCTSTR lpszExternalFile = NULL)
00121 {
00122 m_szFileInZip = lpszFileInZip;
00123 m_szExternalFile = lpszExternalFile;
00124 m_uTotalToDo = 0;
00125 m_uTotalSoFar = 0;
00126 }
00127
00133 virtual void SetTotal(DWORD uTotalToDo)
00134 {
00135 m_uTotalToDo = uTotalToDo;
00136
00137 }
00138
00139
00140
00151 DWORD m_uTotalToDo;
00152 DWORD m_uTotalSoFar;
00153 CZipString m_szFileInZip;
00154
00155
00159 DWORD LeftToDo() {return m_uTotalToDo - m_uTotalSoFar;}
00160
00161
00166 virtual void CallbackEnd()
00167 {
00168 ASSERT(m_uTotalSoFar == m_uTotalToDo);
00169 };
00170
00174 virtual bool operator()(int iProgress)
00175 {
00176 m_uTotalSoFar += iProgress;
00177 return Callback(iProgress);
00178 }
00179
00188 static int m_iStep;
00189
00190
00194 int GetStep(){return m_iStep ? m_iStep : 1;}
00195
00196 };
00197
00198
00202 class ZIP_API CZipStorage
00203 {
00204 friend class CZipCentralDir;
00205 public:
00206
00211 enum ZipSpanMode {
00212 noSpan,
00213 pkzipSpan,
00214 tdSpan,
00215
00220 suggestedAuto,
00225 suggestedTd
00226 };
00227
00228 CZipStorage();
00229 virtual ~CZipStorage();
00230
00241 void Open(CZipAbstractFile& af, int iMode);
00242
00253 void Open(LPCTSTR szPathName, int iMode, int iVolumeSize);
00254
00255
00259 void FinalizeSpan();
00260
00261
00269 void UpdateSpanMode(WORD uLastDisk);
00270
00271
00272
00280 DWORD AssureFree(DWORD iNeeded);
00281
00293 void Write(const void *pBuf, DWORD iSize, bool bAtOnce);
00294
00298 DWORD GetOccupiedSpace() const
00299 {
00300 return (DWORD)m_pFile->GetLength() + m_uBytesInWriteBuffer;
00301 }
00302
00306 bool IsClosed(bool bArchive) const
00307 {
00308 return bArchive ?(GetCurrentDisk() == -1) : (!m_pFile || m_pFile->IsClosed());
00309 }
00321 DWORD Read(void* pBuf, DWORD iSize, bool bAtOnce);
00322
00327 DWORD GetPosition() const {return (DWORD)(m_pFile->GetPosition()) + m_uBytesInWriteBuffer;}
00328
00329
00334 void Flush();
00335
00336
00340 void FlushFile()
00341 {
00342 if (!m_bInMemory && !IsReadOnly())
00343 m_pFile->Flush();
00344 }
00345
00354 void NextDisk(int iNeeded, LPCTSTR lpszFileName = NULL);
00355
00356
00360 int GetCurrentDisk() const {return m_iCurrentDisk;}
00361
00362
00369 void ChangeDisk(int iNumber);
00370
00379 int IsSpanMode() const
00380 {
00381 return m_iSpanMode == noSpan ? 0 : (m_bNewSpan ? 1 : -1);
00382 }
00383
00387 bool IsReadOnly()
00388 {
00389 return m_bReadOnly || IsSpanMode() < 0;
00390 }
00391
00396 void SetTreatAsSingleDisk(bool bSingleDisk = true){m_bTreatAsSingleDisk = bSingleDisk;}
00397
00408 CZipString Close(bool bAfterException);
00409
00410
00418 int m_iWriteBufferSize;
00419
00420
00426 CZipFile m_internalfile;
00427
00437 CZipAbstractFile* m_pFile;
00438
00442 int m_iSpanMode;
00443
00449 CZipSpanCallback* m_pChangeDiskFunc;
00450
00454 static char m_gszExtHeaderSignat[];
00455 protected:
00456
00460 void EmptyWriteBuffer()
00461 {
00462 m_uBytesInWriteBuffer = 0;
00463 }
00464
00475 bool OpenFile(LPCTSTR lpszName, UINT uFlags, bool bThrow = true);
00481 void ThrowError(int err);
00482
00486 DWORD VolumeLeft() const;
00487
00491 CZipString RenameLastFileInTDSpan();
00500 void WriteInternalBuffer(const char *pBuf, DWORD uSize);
00501
00505 DWORD GetFreeVolumeSpace() const;
00506
00519 void CallCallback(int iCode, CZipString szTemp);
00520
00521
00531 CZipString GetTdVolumeName(bool bLast, LPCTSTR lpszZipName = NULL) const;
00532
00536 CZipString ChangeTdRead();
00537
00541 CZipString ChangePkzipRead();
00542
00543
00554 int m_iTdSpanData;
00555
00559 CZipString m_szSpanExtension;
00560
00564 DWORD GetFreeInBuffer() const {return m_pWriteBuffer.GetSize() - m_uBytesInWriteBuffer;}
00565
00569 DWORD m_uBytesInWriteBuffer;
00570
00577 DWORD m_uCurrentVolSize;
00578
00579
00583 DWORD m_uVolumeFreeInBuffer;
00584
00588 CZipAutoBuffer m_pWriteBuffer;
00589
00590
00595 DWORD m_iBytesWritten;
00596
00600 bool m_bNewSpan;
00601
00606 int m_iCurrentDisk;
00607
00611 bool m_bInMemory;
00612
00616 bool m_bReadOnly;
00617
00621 bool m_bTreatAsSingleDisk;
00622
00623 };
00624
00625 #endif // !defined(AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_)