AbZip  1.0.0
EndOfCentralDir.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 ENDOFCENTRALDIR_H
23 #define ENDOFCENTRALDIR_H
24 
25 #include <QObject>
26 #include <QIODevice>
27 
28 #define CENTRAL_DIR_END_SIZE 22
29 #define CENTRAL_DIR_END64_LOCATOR_SIZE 20
30 #define CENTRAL_DIR_END64_SIZE 56
31 
32 #define CENTRAL_DIR_END_SIGNATURE 0x06054b50
33 #define CENTRAL_DIR_END64_SIGNATURE 0x06064b50
34 #define CENTRAL_DIR_END64_LOCATOR_SIGNATURE 0x07064b50
35 
37 {
38 
39 public:
41 
42  void reset( );
43 
44  bool read(QIODevice* ioDevice);
45  qint32 write(QIODevice* ioDevice);
46 
47  bool needsZip64() const
48  {
49  return numberOfThisDisk >= 0xffff || numberOfDiskCdStarts >= 0xffff ||
50  numberOfCdEntriesOnDisk >= 0xffff || numberOfEntries >= 0xffff ||
51  sizeOfCD >= 0xffffffff || offsetToStartOfCD >= 0xffffffff;
52  }
53 
54  QString getComment( );
55  void setComment( const QString& cmt );
56 
57  bool isValid()
58  {
59  return (signature == CENTRAL_DIR_END_SIGNATURE &&
60  ((sizeOfCD || !numberOfEntries) && (numberOfEntries || !sizeOfCD) ));
61  }
62 
63  qint32 size(){ return CENTRAL_DIR_END_SIZE + comment.size(); }
64 
65  quint32 signature; // 0x06054b50
66  quint16 numberOfThisDisk; // assume no splits so = 0
67  quint16 numberOfDiskCdStarts; // = 0
68  quint16 numberOfCdEntriesOnDisk;
69  quint16 numberOfEntries;
70  quint32 sizeOfCD; // size of the central directory
71  quint32 offsetToStartOfCD; // relative to start of file
72  quint16 commentLength;
73  QByteArray comment;
74 };
75 
76 
78 {
79 
80 public:
82 
83  bool read(QIODevice* ioDevice);
84 
85  qint32 write(QIODevice* ioDevice);
86 
87  bool isValid()
88  {
89  return ( signature == CENTRAL_DIR_END64_SIGNATURE &&
90  (numberOfEntries != numberOfCdEntriesOnDisk ||
91  numberOfDiskCdStarts != 0 || numberOfThisDisk != 0 ||
92  ((sizeOfCD || !numberOfEntries) && (numberOfEntries || !sizeOfCD))) );
93  }
94 
95  qint32 size(){ return CENTRAL_DIR_END64_SIZE; }
96 
97  quint32 signature; // 0x06064b50
98  quint64 sizeOfzip64EndOfCDRecord;
99  quint16 versionMadeBy;
100  quint16 versionNeeded;
101  quint32 numberOfThisDisk; // assume no splits so = 0
102  quint32 numberOfDiskCdStarts; // = 0
103  quint64 numberOfCdEntriesOnDisk;
104  quint64 numberOfEntries;
105  quint64 sizeOfCD; // size of the central directory
106  quint64 offsetToStartOfCD; // relative to start of file
107  QByteArray extensibleData;
108 };
109 
110 
111 #endif // ENDOFCENTRALDIR_H
Definition: EndOfCentralDir.h:36
Definition: EndOfCentralDir.h:77