AbZip  1.0.0
LocalFileHeader.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Andy Bray
4 **
5 ** This file is part of AbZip.
6 **
7 ** AbZip is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** AbZip is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with AbZip. If not, see <http://www.gnu.org/licenses/>.
19 **
20 ****************************************************************************/
21 
22 #ifndef LOCALFILEHEADER_H
23 #define LOCALFILEHEADER_H
24 
25 #include "zipglobal.h"
26 #include "ExtraFields.h"
27 #include <ZipFileInfo.h>
28 
29 #include <QObject>
30 #include <QIODevice>
31 #include <QDateTime>
32 #include <QFileInfo>
33 
34 #define VERSION_MADE_BY MAKESHORT(20, getOsMadeBy() ) // Version 2.0 and sys compat 0 for now
35 #define VERSION_NEEDED 20 // version 2.0 (default)
36 #define VERSION_NEEDED_ZIP64 45
37 
38 
39 #define LOCAL_FILE_HEADER_SIZE 30
40 #define LOCAL_FILE_HEADER_SIGNATURE 0x04034b50
41 
42 #define DATA_DESCRIPTOR_SIZE 16
43 #define DATA_DESCRIPTOR_SIGNATURE 0x08074b50
44 
45 #define ZIP_IS_ENCRYPTED 0x01 // bit 0
46 #define ZIP_IS_STRONG_ENCRYPTION 0x40 // bit 6
47 #define ZIP_WRITE_DATA_DESCRIPTOR 0x08 // bit 3
48 #define ZIP_IS_UTF8 0x0800 // Bit 11
49 
51 
52 class LocalFileHeader : public QObject
53 {
54  Q_OBJECT
55 public:
56  explicit LocalFileHeader(QObject *parent = 0);
57  virtual ~LocalFileHeader();
58 
59 
60  void init( CentralDirFileHeader* );
61 
62  virtual void initFromFile( const QFileInfo& file );
63  virtual bool validate( LocalFileHeader* header);
64 
65  virtual bool read(QIODevice* ioDevice);
66  void readExtraData(QIODevice* ioDevice);
67  virtual qint64 write(QIODevice* ioDevice );
68  void checkForExtraData( );
69 
70  virtual quint32 size() { return LOCAL_FILE_HEADER_SIZE + fileName.size() + extraField.size(); }
71  virtual void setSizes( qint64 uncompSize, qint64 compSize, qint64 offset);
72 
73  virtual quint64 getCompressedSize();
74  virtual quint64 getUncompressedSize();
75 
76  virtual ZipFileInfo getFileInfo();
77 
78  void setWinZipAES( );
79  bool getWinZipAES( quint16& method, quint8& strength );
80 
81  qint32 writeDataDescriptor( QIODevice* ioDevice );
82 
83  bool isEncrypted()const { return generalFlag & ZIP_IS_ENCRYPTED; } // Bit 1
84  bool isStrongEncryption()const { return isEncrypted() && (generalFlag & ZIP_IS_STRONG_ENCRYPTION); } // Bit 6
85  bool hasDataDescriptor() const { return generalFlag & ZIP_WRITE_DATA_DESCRIPTOR; } // Bit 3
86  bool isUTF8()const { return generalFlag & ZIP_IS_UTF8; } // Bit 11
87  virtual bool isDirectory( );
88 
89  QDateTime lastModDate();
90 
91  virtual bool isValid()
92  {
93  return true;
94  }
95 
96  bool isNewer( LocalFileHeader* header );
97 
98  quint32 signature;
99  quint16 versionNeeded;
100  quint16 generalFlag;
101  quint16 compressionMethod;
102  quint16 lastModFileTime;
103  quint16 lastModFileDate;
104  quint32 crc_32;
105  quint32 compressedSize;
106  quint32 uncompressedSize;
107  quint16 filenameLength;
108  quint16 extraFieldLength;
109  QByteArray fileName;
110  QByteArray extraField;
111 
112  ExtraFields* extraFields;
113  };
114 
115 
116 #endif // LOCALFILEHEADER_H
Definition: LocalFileHeader.h:52
Definition: ExtraFields.h:36
Definition: CentralDirFileHeader.h:39
Definition: ZipFileInfo.h:35