00001
00002
00003
00004
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00023 #if !defined(AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_)
00024 #define AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_
00025
00026 #if _MSC_VER > 1000
00027 #pragma once
00028 #endif // _MSC_VER > 1000
00029
00030 #include "ZipExport.h"
00031 #include "ZipStorage.h"
00032 #include "ZipAutoBuffer.h"
00033 #include "sys/types.h"
00034 #include "ZipCompatibility.h"
00035 #define ZIPARCHIVE_ENCR_HEADER_LEN 12
00036
00045 class ZIP_API CZipFileHeader
00046 {
00047 friend class CZipCentralDir;
00048 friend class CZipArchive;
00049 friend void ZipCompatibility::FileNameUpdate(CZipFileHeader&, bool, bool);
00050 public:
00051 CZipFileHeader();
00052 virtual ~CZipFileHeader();
00053
00054
00055
00065 WORD GetFileNameSize()const {return (WORD)m_pszFileName.GetSize();}
00066
00070 WORD GetCommentSize() const {return (WORD)m_pszComment.GetSize();}
00071
00075 WORD GetExtraFieldSize()const{return (WORD)m_pExtraField.GetSize();}
00076
00080 CZipString GetFileName()const;
00081
00090 bool SetFileName(LPCTSTR lpszFileName);
00091
00095 CZipString GetComment() const;
00096
00106 bool SetComment(LPCTSTR lpszComment);
00107
00111 bool IsDataDescr()const { return (m_uFlag & (WORD) 8) != 0;}
00112
00113
00118 DWORD GetEffComprSize()
00119 {
00120 return m_uComprSize - (IsEncrypted() ? ZIPARCHIVE_ENCR_HEADER_LEN : 0);
00121 }
00126 bool CompressionEfficient()
00127 {
00128 DWORD uBefore = m_uUncomprSize;
00129
00130 DWORD uAfter = GetEffComprSize();
00131 return uAfter <= uBefore;
00132 }
00133
00137 float GetCompressionRatio()
00138 {
00139 return m_uUncomprSize ? ((float)m_uComprSize) * 100 / m_uUncomprSize : 0;
00140 }
00141
00146 bool IsEncrypted()const { return (m_uFlag & (WORD) 1) != 0;}
00147
00148 char m_szSignature[4];
00149 WORD m_uVersionMadeBy;
00150 WORD m_uVersionNeeded;
00151 WORD m_uFlag;
00152 WORD m_uMethod;
00153 WORD m_uModTime;
00154 WORD m_uModDate;
00155 DWORD m_uCrc32;
00156 DWORD m_uComprSize;
00157 DWORD m_uUncomprSize;
00158
00159
00160 WORD m_uDiskStart;
00161 WORD m_uInternalAttr;
00162 protected:
00163 DWORD m_uExternalAttr;
00164 WORD m_uLocalFileNameSize;
00165 WORD m_uLocalExtraFieldSize;
00166 public:
00167 DWORD m_uOffset;
00168 CZipAutoBuffer m_pExtraField;
00169 static char m_gszSignature[];
00170 static char m_gszLocalSignature[];
00171
00172
00179 void SetTime(const time_t& ttime);
00180
00185 time_t GetTime()const;
00186
00190 DWORD GetSize()const;
00191
00196 DWORD GetLocalSize() const
00197 {
00198 return GetLocalSize(false);
00199 }
00200
00212 int GetSystemCompatibility()const
00213 {
00214 return (m_uVersionMadeBy & 0xFF00) >> 8;
00215 }
00216
00225 DWORD GetSystemAttr()const;
00226
00231 DWORD GetOriginalAttributes() const {return m_uExternalAttr;}
00232
00238 bool IsDirectory()const;
00239
00240
00241 protected:
00242
00250 DWORD GetLocalSize(bool bReal)const;
00251
00258 void SetSystemCompatibility(int iSystemID)
00259 {
00260 m_uVersionMadeBy &= 0x00FF;
00261 m_uVersionMadeBy |= (WORD)(iSystemID << 8);
00262 }
00263
00275 void SetSystemAttr(DWORD uAttr);
00276
00281 void SetVersion(WORD uVersion)
00282 {
00283 if ((m_uVersionMadeBy & 0x00FF) != (uVersion & 0x00FF))
00284 {
00285 m_uVersionMadeBy &= 0xFF00;
00286 m_uVersionMadeBy |= (WORD)(uVersion & 0x00FF);
00287 }
00288 }
00289
00293 CZipAutoBuffer m_pszFileName;
00294
00298 CZipAutoBuffer m_pszComment;
00299
00306 void GetCrcAndSizes(char* pBuffer)const;
00307
00316 bool CheckCrcAndSizes(char* pBuf) const;
00317
00318
00331 bool PrepareData(int iLevel, bool bSpan, bool bEncrypted);
00337 void WriteLocal(CZipStorage& storage);
00338
00346 bool Read(CZipStorage *pStorage);
00353 bool ReadLocal(CZipStorage *pStorage);
00360 DWORD Write(CZipStorage *pStorage);
00361
00362 };
00363
00364 #endif // !defined(AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_)