ZipExtraField.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_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 
165  CZipExtraData* CreateNew(WORD headerID, bool bAppend = true)
166  {
167  int temp;
168  return CreateNew(headerID, temp, bAppend);
169  }
170 
191  CZipExtraData* CreateNew(WORD headerID, int& idx, bool bAppend = true)
192  {
193  CZipExtraData* pData = new CZipExtraData(headerID);
194  pData->m_bHasSize = HasSize(headerID);
195  if (bAppend)
196  idx = (int)m_aData.Add(pData);
197  else
198  {
199  idx = 0;
200  m_aData.InsertAt(0, pData);
201  }
202  return pData;
203  }
204 
209  void RemoveInternalHeaders();
210 
215  void RemoveInternalLocalHeaders();
216 
223  void Remove(WORD headerID);
224 
234  CZipExtraData* Lookup(WORD headerID) const
235  {
236  int temp;
237  return Lookup(headerID, temp);
238  }
239 
249  bool HasHeader(WORD headerID)
250  {
251  return Lookup(headerID) != NULL;
252  }
253 
267  CZipExtraData* Lookup(WORD headerID, int& index) const;
268  ~CZipExtraField()
269  {
270  Clear();
271  }
272 
279  static CZipArray<WORD> m_aNoSizeExtraHeadersID;
280 
293  static bool HasSize(WORD headerID)
294  {
295  ZIP_ARRAY_SIZE_TYPE size = m_aNoSizeExtraHeadersID.GetSize();
296  for (ZIP_ARRAY_SIZE_TYPE i = 0; i < size; i++)
297  {
298  if (m_aNoSizeExtraHeadersID.GetAt(i) == headerID)
299  return false;
300  }
301  return true;
302  }
303 
304 protected:
305 
309  void Clear()
310  {
311  for (int i = 0; i < GetCount(); i++)
312  delete (GetAt(i));
313  m_aData.RemoveAll();
314  }
315 
328  bool Read(CZipStorage* pStorage, WORD uSize);
329 
336  void Write(char* buffer) const;
337 
338 private:
339 
340  CZipArray<CZipExtraData*> m_aData;
341 };
342 
343 
344 #endif // !defined(ZIPARCHIVE_ZIPEXTRAFIELD_DOT_H)

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