ZipExtraField.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_ZIPEXTRAFIELD_DOT_H)
22 #define ZIPARCHIVE_ZIPEXTRAFIELD_DOT_H
23 
24 #if _MSC_VER > 1000
25 #pragma once
26 #endif
27 
28 #include "ZipExport.h"
29 #include "ZipExtraData.h"
30 #include "ZipCollections.h"
31 #include "ZipStorage.h"
32 
33 #define ZIP_EXTRA_PKZIP 0x0001
34 
35 #define ZIP_EXTRA_NTFS 0x000A
36 
37 #define ZIP_EXTRA_ZARCH_NAME 0x5A4C // ZL - ZipArchive Library
38 
39 #define ZIP_EXTRA_ZARCH_SEEK 0x5A4D
40 
41 #define ZIP_EXTRA_WINZIP_AES 0x9901
42 
43 #define ZIP_EXTRA_UNICODE_PATH 0x7075
44 #define ZIP_EXTRA_UNICODE_COMMENT 0x6375
45 
46 
47 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
48  #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
49 #endif
50 
60 class ZIP_API CZipExtraField
61 {
62  friend class CZipFileHeader;
63 public:
65  {
66  }
67  CZipExtraField(const CZipExtraField& arr)
68  {
69  *this = arr;
70  }
71  CZipExtraField& operator=(const CZipExtraField& field)
72  {
73  Clear();
74  for (int i = 0; i < field.GetCount(); i++)
75  Add(new CZipExtraData(*field.GetAt(i)));
76  return *this;
77  }
78 
85  int GetTotalSize() const;
86 
93  bool Validate() const
94  {
95  return GetTotalSize() <= (int)USHRT_MAX;
96  }
97 
104  int GetCount() const
105  {
106  return (int)m_aData.GetSize();
107  }
108 
118  CZipExtraData* GetAt(int index) const
119  {
120  return m_aData.GetAt(index);
121  }
122 
129  void RemoveAt(int index)
130  {
131  delete (GetAt(index));
132  m_aData.RemoveAt(index);
133  }
134 
144  int Add(CZipExtraData* pExtra)
145  {
146  return (int)m_aData.Add(pExtra);
147  }
148 
162  CZipExtraData* CreateNew(WORD headerID)
163  {
164  int temp;
165  return CreateNew(headerID, temp);
166  }
167 
185  CZipExtraData* CreateNew(WORD headerID, int& idx)
186  {
187  CZipExtraData* pData = new CZipExtraData(headerID);
188  pData->m_bHasSize = HasSize(headerID);
189  idx = (int)m_aData.Add(pData);
190  return pData;
191  }
192 
197  void RemoveInternalHeaders();
198 
203  void RemoveInternalLocalHeaders();
204 
211  void Remove(WORD headerID);
212 
222  CZipExtraData* Lookup(WORD headerID) const
223  {
224  int temp;
225  return Lookup(headerID, temp);
226  }
227 
237  bool HasHeader(WORD headerID)
238  {
239  return Lookup(headerID) != NULL;
240  }
241 
255  CZipExtraData* Lookup(WORD headerID, int& index) const;
256  ~CZipExtraField()
257  {
258  Clear();
259  }
260 
267  static CZipArray<WORD> m_aNoSizeExtraHeadersID;
268 
281  static bool HasSize(WORD headerID)
282  {
283  ZIP_ARRAY_SIZE_TYPE size = m_aNoSizeExtraHeadersID.GetSize();
284  for (ZIP_ARRAY_SIZE_TYPE i = 0; i < size; i++)
285  {
286  if (m_aNoSizeExtraHeadersID.GetAt(i) == headerID)
287  return false;
288  }
289  return true;
290  }
291 
292 protected:
293 
297  void Clear()
298  {
299  for (int i = 0; i < GetCount(); i++)
300  delete (GetAt(i));
301  m_aData.RemoveAll();
302  }
303 
316  bool Read(CZipStorage* pStorage, WORD uSize);
317 
324  void Write(char* buffer) const;
325 
326 private:
327 
328  CZipArray<CZipExtraData*> m_aData;
329 };
330 
331 
332 #endif // !defined(ZIPARCHIVE_ZIPEXTRAFIELD_DOT_H)

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