Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qzip.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | static inline uint readUInt(const uchar *data) | - | ||||||||||||
8 | { | - | ||||||||||||
9 | return (data[0]) + (data[1]<<8) + (data[2]<<16) + (data[3]<<24); | - | ||||||||||||
10 | } | - | ||||||||||||
11 | - | |||||||||||||
12 | static inline ushort readUShort(const uchar *data) | - | ||||||||||||
13 | { | - | ||||||||||||
14 | return (data[0]) + (data[1]<<8); | - | ||||||||||||
15 | } | - | ||||||||||||
16 | - | |||||||||||||
17 | static inline void writeUInt(uchar *data, uint i) | - | ||||||||||||
18 | { | - | ||||||||||||
19 | data[0] = i & 0xff; | - | ||||||||||||
20 | data[1] = (i>>8) & 0xff; | - | ||||||||||||
21 | data[2] = (i>>16) & 0xff; | - | ||||||||||||
22 | data[3] = (i>>24) & 0xff; | - | ||||||||||||
23 | } | - | ||||||||||||
24 | - | |||||||||||||
25 | static inline void writeUShort(uchar *data, ushort i) | - | ||||||||||||
26 | { | - | ||||||||||||
27 | data[0] = i & 0xff; | - | ||||||||||||
28 | data[1] = (i>>8) & 0xff; | - | ||||||||||||
29 | } | - | ||||||||||||
30 | - | |||||||||||||
31 | static inline void copyUInt(uchar *dest, const uchar *src) | - | ||||||||||||
32 | { | - | ||||||||||||
33 | dest[0] = src[0]; | - | ||||||||||||
34 | dest[1] = src[1]; | - | ||||||||||||
35 | dest[2] = src[2]; | - | ||||||||||||
36 | dest[3] = src[3]; | - | ||||||||||||
37 | } | - | ||||||||||||
38 | - | |||||||||||||
39 | static inline void copyUShort(uchar *dest, const uchar *src) | - | ||||||||||||
40 | { | - | ||||||||||||
41 | dest[0] = src[0]; | - | ||||||||||||
42 | dest[1] = src[1]; | - | ||||||||||||
43 | } | - | ||||||||||||
44 | - | |||||||||||||
45 | static void writeMSDosDate(uchar *dest, const QDateTime& dt) | - | ||||||||||||
46 | { | - | ||||||||||||
47 | if (dt.isValid()) { | - | ||||||||||||
48 | quint16 time = | - | ||||||||||||
49 | (dt.time().hour() << 11) | - | ||||||||||||
50 | | (dt.time().minute() << 5) | - | ||||||||||||
51 | | (dt.time().second() >> 1); | - | ||||||||||||
52 | - | |||||||||||||
53 | dest[0] = time & 0xff; | - | ||||||||||||
54 | dest[1] = time >> 8; | - | ||||||||||||
55 | - | |||||||||||||
56 | quint16 date = | - | ||||||||||||
57 | ((dt.date().year() - 1980) << 9) | - | ||||||||||||
58 | | (dt.date().month() << 5) | - | ||||||||||||
59 | | (dt.date().day()); | - | ||||||||||||
60 | - | |||||||||||||
61 | dest[2] = char(date); | - | ||||||||||||
62 | dest[3] = char(date >> 8); | - | ||||||||||||
63 | } else { | - | ||||||||||||
64 | dest[0] = 0; | - | ||||||||||||
65 | dest[1] = 0; | - | ||||||||||||
66 | dest[2] = 0; | - | ||||||||||||
67 | dest[3] = 0; | - | ||||||||||||
68 | } | - | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | z_stream stream; | - | ||||||||||||
74 | int err; | - | ||||||||||||
75 | - | |||||||||||||
76 | stream.next_in = const_cast<Bytef*>(source); | - | ||||||||||||
77 | stream.avail_in = (uInt)sourceLen; | - | ||||||||||||
78 | if ((uLong)stream.avail_in != sourceLen) | - | ||||||||||||
79 | return (-5); | - | ||||||||||||
80 | - | |||||||||||||
81 | stream.next_out = dest; | - | ||||||||||||
82 | stream.avail_out = (uInt)*destLen; | - | ||||||||||||
83 | if ((uLong)stream.avail_out != *destLen) | - | ||||||||||||
84 | return (-5); | - | ||||||||||||
85 | - | |||||||||||||
86 | stream.zalloc = (alloc_func)0; | - | ||||||||||||
87 | stream.zfree = (free_func)0; | - | ||||||||||||
88 | - | |||||||||||||
89 | err = inflateInit2_((&stream), (-15), "1.2.8", (int)sizeof(z_stream)); | - | ||||||||||||
90 | if (err != 0) | - | ||||||||||||
91 | return err; | - | ||||||||||||
92 | - | |||||||||||||
93 | err = inflate(&stream, 4); | - | ||||||||||||
94 | if (err != 1) { | - | ||||||||||||
95 | inflateEnd(&stream); | - | ||||||||||||
96 | if (err == 2 || (err == (-5) && stream.avail_in == 0)) | - | ||||||||||||
97 | return (-3); | - | ||||||||||||
98 | return err; | - | ||||||||||||
99 | } | - | ||||||||||||
100 | *destLen = stream.total_out; | - | ||||||||||||
101 | - | |||||||||||||
102 | err = inflateEnd(&stream); | - | ||||||||||||
103 | return err; | - | ||||||||||||
104 | } | - | ||||||||||||
105 | - | |||||||||||||
106 | static int deflate (Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen) | - | ||||||||||||
107 | { | - | ||||||||||||
108 | z_stream stream; | - | ||||||||||||
109 | int err; | - | ||||||||||||
110 | - | |||||||||||||
111 | stream.next_in = const_cast<Bytef*>(source); | - | ||||||||||||
112 | stream.avail_in = (uInt)sourceLen; | - | ||||||||||||
113 | stream.next_out = dest; | - | ||||||||||||
114 | stream.avail_out = (uInt)*destLen; | - | ||||||||||||
115 | if ((uLong)stream.avail_out != *destLen) return (-5); | - | ||||||||||||
116 | - | |||||||||||||
117 | stream.zalloc = (alloc_func)0; | - | ||||||||||||
118 | stream.zfree = (free_func)0; | - | ||||||||||||
119 | stream.opaque = (voidpf)0; | - | ||||||||||||
120 | - | |||||||||||||
121 | err = deflateInit2_((&stream),((-1)),(8),(-15),(8), (0), "1.2.8", (int)sizeof(z_stream)); | - | ||||||||||||
122 | if (err != 0) return err; | - | ||||||||||||
123 | - | |||||||||||||
124 | err = deflate(&stream, 4); | - | ||||||||||||
125 | if (err != 1) { | - | ||||||||||||
126 | deflateEnd(&stream); | - | ||||||||||||
127 | return err == 0 ? (-5) : err; | - | ||||||||||||
128 | } | - | ||||||||||||
129 | *destLen = stream.total_out; | - | ||||||||||||
130 | - | |||||||||||||
131 | err = deflateEnd(&stream); | - | ||||||||||||
132 | return err; | - | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | namespace WindowsFileAttributes { | - | ||||||||||||
137 | enum { | - | ||||||||||||
138 | Dir = 0x10, | - | ||||||||||||
139 | File = 0x80, | - | ||||||||||||
140 | TypeMask = 0x90, | - | ||||||||||||
141 | - | |||||||||||||
142 | ReadOnly = 0x01, | - | ||||||||||||
143 | PermMask = 0x01 | - | ||||||||||||
144 | }; | - | ||||||||||||
145 | } | - | ||||||||||||
146 | - | |||||||||||||
147 | namespace UnixFileAttributes { | - | ||||||||||||
148 | enum { | - | ||||||||||||
149 | Dir = 0040000, | - | ||||||||||||
150 | File = 0100000, | - | ||||||||||||
151 | SymLink = 0120000, | - | ||||||||||||
152 | TypeMask = 0170000, | - | ||||||||||||
153 | - | |||||||||||||
154 | ReadUser = 0400, | - | ||||||||||||
155 | WriteUser = 0200, | - | ||||||||||||
156 | ExeUser = 0100, | - | ||||||||||||
157 | ReadGroup = 0040, | - | ||||||||||||
158 | WriteGroup = 0020, | - | ||||||||||||
159 | ExeGroup = 0010, | - | ||||||||||||
160 | ReadOther = 0004, | - | ||||||||||||
161 | WriteOther = 0002, | - | ||||||||||||
162 | ExeOther = 0001, | - | ||||||||||||
163 | PermMask = 0777 | - | ||||||||||||
164 | }; | - | ||||||||||||
165 | } | - | ||||||||||||
166 | - | |||||||||||||
167 | static QFile::Permissions modeToPermissions(quint32 mode) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | QFile::Permissions ret; | - | ||||||||||||
170 | if (mode & UnixFileAttributes::ReadUser) | - | ||||||||||||
171 | ret |= QFile::ReadOwner | QFile::ReadUser; | - | ||||||||||||
172 | if (mode & UnixFileAttributes::WriteUser) | - | ||||||||||||
173 | ret |= QFile::WriteOwner | QFile::WriteUser; | - | ||||||||||||
174 | if (mode & UnixFileAttributes::ExeUser) | - | ||||||||||||
175 | ret |= QFile::ExeOwner | QFile::ExeUser; | - | ||||||||||||
176 | if (mode & UnixFileAttributes::ReadGroup) | - | ||||||||||||
177 | ret |= QFile::ReadGroup; | - | ||||||||||||
178 | if (mode & UnixFileAttributes::WriteGroup) | - | ||||||||||||
179 | ret |= QFile::WriteGroup; | - | ||||||||||||
180 | if (mode & UnixFileAttributes::ExeGroup) | - | ||||||||||||
181 | ret |= QFile::ExeGroup; | - | ||||||||||||
182 | if (mode & UnixFileAttributes::ReadOther) | - | ||||||||||||
183 | ret |= QFile::ReadOther; | - | ||||||||||||
184 | if (mode & UnixFileAttributes::WriteOther) | - | ||||||||||||
185 | ret |= QFile::WriteOther; | - | ||||||||||||
186 | if (mode & UnixFileAttributes::ExeOther) | - | ||||||||||||
187 | ret |= QFile::ExeOther; | - | ||||||||||||
188 | return ret; | - | ||||||||||||
189 | } | - | ||||||||||||
190 | - | |||||||||||||
191 | static quint32 permissionsToMode(QFile::Permissions perms) | - | ||||||||||||
192 | { | - | ||||||||||||
193 | quint32 mode = 0; | - | ||||||||||||
194 | if (perms & (QFile::ReadOwner | QFile::ReadUser)) | - | ||||||||||||
195 | mode |= UnixFileAttributes::ReadUser; | - | ||||||||||||
196 | if (perms & (QFile::WriteOwner | QFile::WriteUser)) | - | ||||||||||||
197 | mode |= UnixFileAttributes::WriteUser; | - | ||||||||||||
198 | if (perms & (QFile::ExeOwner | QFile::ExeUser)) | - | ||||||||||||
199 | mode |= UnixFileAttributes::WriteUser; | - | ||||||||||||
200 | if (perms & QFile::ReadGroup) | - | ||||||||||||
201 | mode |= UnixFileAttributes::ReadGroup; | - | ||||||||||||
202 | if (perms & QFile::WriteGroup) | - | ||||||||||||
203 | mode |= UnixFileAttributes::WriteGroup; | - | ||||||||||||
204 | if (perms & QFile::ExeGroup) | - | ||||||||||||
205 | mode |= UnixFileAttributes::ExeGroup; | - | ||||||||||||
206 | if (perms & QFile::ReadOther) | - | ||||||||||||
207 | mode |= UnixFileAttributes::ReadOther; | - | ||||||||||||
208 | if (perms & QFile::WriteOther) | - | ||||||||||||
209 | mode |= UnixFileAttributes::WriteOther; | - | ||||||||||||
210 | if (perms & QFile::ExeOther) | - | ||||||||||||
211 | mode |= UnixFileAttributes::ExeOther; | - | ||||||||||||
212 | return mode; | - | ||||||||||||
213 | } | - | ||||||||||||
214 | - | |||||||||||||
215 | static QDateTime readMSDosDate(const uchar *src) | - | ||||||||||||
216 | { | - | ||||||||||||
217 | uint dosDate = readUInt(src); | - | ||||||||||||
218 | quint64 uDate; | - | ||||||||||||
219 | uDate = (quint64)(dosDate >> 16); | - | ||||||||||||
220 | uint tm_mday = (uDate & 0x1f); | - | ||||||||||||
221 | uint tm_mon = ((uDate & 0x1E0) >> 5); | - | ||||||||||||
222 | uint tm_year = (((uDate & 0x0FE00) >> 9) + 1980); | - | ||||||||||||
223 | uint tm_hour = ((dosDate & 0xF800) >> 11); | - | ||||||||||||
224 | uint tm_min = ((dosDate & 0x7E0) >> 5); | - | ||||||||||||
225 | uint tm_sec = ((dosDate & 0x1f) << 1); | - | ||||||||||||
226 | - | |||||||||||||
227 | return QDateTime(QDate(tm_year, tm_mon, tm_mday), QTime(tm_hour, tm_min, tm_sec)); | - | ||||||||||||
228 | } | - | ||||||||||||
229 | - | |||||||||||||
230 | - | |||||||||||||
231 | - | |||||||||||||
232 | enum HostOS { | - | ||||||||||||
233 | HostFAT = 0, | - | ||||||||||||
234 | HostAMIGA = 1, | - | ||||||||||||
235 | HostVMS = 2, | - | ||||||||||||
236 | HostUnix = 3, | - | ||||||||||||
237 | HostVM_CMS = 4, | - | ||||||||||||
238 | HostAtari = 5, | - | ||||||||||||
239 | HostHPFS = 6, | - | ||||||||||||
240 | HostMac = 7, | - | ||||||||||||
241 | HostZ_System = 8, | - | ||||||||||||
242 | HostCPM = 9, | - | ||||||||||||
243 | HostTOPS20 = 10, | - | ||||||||||||
244 | HostNTFS = 11, | - | ||||||||||||
245 | HostQDOS = 12, | - | ||||||||||||
246 | HostAcorn = 13, | - | ||||||||||||
247 | HostVFAT = 14, | - | ||||||||||||
248 | HostMVS = 15, | - | ||||||||||||
249 | HostBeOS = 16, | - | ||||||||||||
250 | HostTandem = 17, | - | ||||||||||||
251 | HostOS400 = 18, | - | ||||||||||||
252 | HostOSX = 19 | - | ||||||||||||
253 | }; | - | ||||||||||||
254 | template<> class QTypeInfo<HostOS > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(HostOS)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< HostOS >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(HostOS) }; static inline const char *name() { return "HostOS"; } }; | - | ||||||||||||
255 | - | |||||||||||||
256 | enum GeneralPurposeFlag { | - | ||||||||||||
257 | Encrypted = 0x01, | - | ||||||||||||
258 | AlgTune1 = 0x02, | - | ||||||||||||
259 | AlgTune2 = 0x04, | - | ||||||||||||
260 | HasDataDescriptor = 0x08, | - | ||||||||||||
261 | PatchedData = 0x20, | - | ||||||||||||
262 | StrongEncrypted = 0x40, | - | ||||||||||||
263 | Utf8Names = 0x0800, | - | ||||||||||||
264 | CentralDirectoryEncrypted = 0x2000 | - | ||||||||||||
265 | }; | - | ||||||||||||
266 | template<> class QTypeInfo<GeneralPurposeFlag > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(GeneralPurposeFlag)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< GeneralPurposeFlag >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(GeneralPurposeFlag) }; static inline const char *name() { return "GeneralPurposeFlag"; } }; | - | ||||||||||||
267 | - | |||||||||||||
268 | enum CompressionMethod { | - | ||||||||||||
269 | CompressionMethodStored = 0, | - | ||||||||||||
270 | CompressionMethodShrunk = 1, | - | ||||||||||||
271 | CompressionMethodReduced1 = 2, | - | ||||||||||||
272 | CompressionMethodReduced2 = 3, | - | ||||||||||||
273 | CompressionMethodReduced3 = 4, | - | ||||||||||||
274 | CompressionMethodReduced4 = 5, | - | ||||||||||||
275 | CompressionMethodImploded = 6, | - | ||||||||||||
276 | CompressionMethodReservedTokenizing = 7, | - | ||||||||||||
277 | CompressionMethodDeflated = 8, | - | ||||||||||||
278 | CompressionMethodDeflated64 = 9, | - | ||||||||||||
279 | CompressionMethodPKImploding = 10, | - | ||||||||||||
280 | - | |||||||||||||
281 | CompressionMethodBZip2 = 12, | - | ||||||||||||
282 | - | |||||||||||||
283 | CompressionMethodLZMA = 14, | - | ||||||||||||
284 | - | |||||||||||||
285 | CompressionMethodTerse = 18, | - | ||||||||||||
286 | CompressionMethodLz77 = 19, | - | ||||||||||||
287 | - | |||||||||||||
288 | CompressionMethodJpeg = 96, | - | ||||||||||||
289 | CompressionMethodWavPack = 97, | - | ||||||||||||
290 | CompressionMethodPPMd = 98, | - | ||||||||||||
291 | CompressionMethodWzAES = 99 | - | ||||||||||||
292 | }; | - | ||||||||||||
293 | template<> class QTypeInfo<CompressionMethod > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(CompressionMethod)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< CompressionMethod >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(CompressionMethod) }; static inline const char *name() { return "CompressionMethod"; } }; | - | ||||||||||||
294 | - | |||||||||||||
295 | struct LocalFileHeader | - | ||||||||||||
296 | { | - | ||||||||||||
297 | uchar signature[4]; | - | ||||||||||||
298 | uchar version_needed[2]; | - | ||||||||||||
299 | uchar general_purpose_bits[2]; | - | ||||||||||||
300 | uchar compression_method[2]; | - | ||||||||||||
301 | uchar last_mod_file[4]; | - | ||||||||||||
302 | uchar crc_32[4]; | - | ||||||||||||
303 | uchar compressed_size[4]; | - | ||||||||||||
304 | uchar uncompressed_size[4]; | - | ||||||||||||
305 | uchar file_name_length[2]; | - | ||||||||||||
306 | uchar extra_field_length[2]; | - | ||||||||||||
307 | }; | - | ||||||||||||
308 | template<> class QTypeInfo<LocalFileHeader > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(LocalFileHeader)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< LocalFileHeader >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(LocalFileHeader) }; static inline const char *name() { return "LocalFileHeader"; } }; | - | ||||||||||||
309 | - | |||||||||||||
310 | struct DataDescriptor | - | ||||||||||||
311 | { | - | ||||||||||||
312 | uchar crc_32[4]; | - | ||||||||||||
313 | uchar compressed_size[4]; | - | ||||||||||||
314 | uchar uncompressed_size[4]; | - | ||||||||||||
315 | }; | - | ||||||||||||
316 | template<> class QTypeInfo<DataDescriptor > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(DataDescriptor)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< DataDescriptor >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(DataDescriptor) }; static inline const char *name() { return "DataDescriptor"; } }; | - | ||||||||||||
317 | - | |||||||||||||
318 | struct CentralFileHeader | - | ||||||||||||
319 | { | - | ||||||||||||
320 | uchar signature[4]; | - | ||||||||||||
321 | uchar version_made[2]; | - | ||||||||||||
322 | uchar version_needed[2]; | - | ||||||||||||
323 | uchar general_purpose_bits[2]; | - | ||||||||||||
324 | uchar compression_method[2]; | - | ||||||||||||
325 | uchar last_mod_file[4]; | - | ||||||||||||
326 | uchar crc_32[4]; | - | ||||||||||||
327 | uchar compressed_size[4]; | - | ||||||||||||
328 | uchar uncompressed_size[4]; | - | ||||||||||||
329 | uchar file_name_length[2]; | - | ||||||||||||
330 | uchar extra_field_length[2]; | - | ||||||||||||
331 | uchar file_comment_length[2]; | - | ||||||||||||
332 | uchar disk_start[2]; | - | ||||||||||||
333 | uchar internal_file_attributes[2]; | - | ||||||||||||
334 | uchar external_file_attributes[4]; | - | ||||||||||||
335 | uchar offset_local_header[4]; | - | ||||||||||||
336 | LocalFileHeader toLocalHeader() const; | - | ||||||||||||
337 | }; | - | ||||||||||||
338 | template<> class QTypeInfo<CentralFileHeader > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(CentralFileHeader)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< CentralFileHeader >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(CentralFileHeader) }; static inline const char *name() { return "CentralFileHeader"; } }; | - | ||||||||||||
339 | - | |||||||||||||
340 | struct EndOfDirectory | - | ||||||||||||
341 | { | - | ||||||||||||
342 | uchar signature[4]; | - | ||||||||||||
343 | uchar this_disk[2]; | - | ||||||||||||
344 | uchar start_of_directory_disk[2]; | - | ||||||||||||
345 | uchar num_dir_entries_this_disk[2]; | - | ||||||||||||
346 | uchar num_dir_entries[2]; | - | ||||||||||||
347 | uchar directory_size[4]; | - | ||||||||||||
348 | uchar dir_start_offset[4]; | - | ||||||||||||
349 | uchar comment_length[2]; | - | ||||||||||||
350 | }; | - | ||||||||||||
351 | template<> class QTypeInfo<EndOfDirectory > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(EndOfDirectory)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< EndOfDirectory >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(EndOfDirectory) }; static inline const char *name() { return "EndOfDirectory"; } }; | - | ||||||||||||
352 | - | |||||||||||||
353 | struct FileHeader | - | ||||||||||||
354 | { | - | ||||||||||||
355 | CentralFileHeader h; | - | ||||||||||||
356 | QByteArray file_name; | - | ||||||||||||
357 | QByteArray extra_field; | - | ||||||||||||
358 | QByteArray file_comment; | - | ||||||||||||
359 | }; | - | ||||||||||||
360 | template<> class QTypeInfo<FileHeader > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(FileHeader)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< FileHeader >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(FileHeader) }; static inline const char *name() { return "FileHeader"; } }; | - | ||||||||||||
361 | - | |||||||||||||
362 | class QZipPrivate | - | ||||||||||||
363 | { | - | ||||||||||||
364 | public: | - | ||||||||||||
365 | QZipPrivate(QIODevice *device, bool ownDev) | - | ||||||||||||
366 | : device(device), ownDevice(ownDev), dirtyFileTree(true), start_of_directory(0) | - | ||||||||||||
367 | { | - | ||||||||||||
368 | } | - | ||||||||||||
369 | - | |||||||||||||
370 | ~QZipPrivate() | - | ||||||||||||
371 | { | - | ||||||||||||
372 | if (ownDevice) | - | ||||||||||||
373 | delete device; | - | ||||||||||||
374 | } | - | ||||||||||||
375 | - | |||||||||||||
376 | QZipReader::FileInfo fillFileInfo(int index) const; | - | ||||||||||||
377 | - | |||||||||||||
378 | QIODevice *device; | - | ||||||||||||
379 | bool ownDevice; | - | ||||||||||||
380 | bool dirtyFileTree; | - | ||||||||||||
381 | QVector<FileHeader> fileHeaders; | - | ||||||||||||
382 | QByteArray comment; | - | ||||||||||||
383 | uint start_of_directory; | - | ||||||||||||
384 | }; | - | ||||||||||||
385 | - | |||||||||||||
386 | QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const | - | ||||||||||||
387 | { | - | ||||||||||||
388 | QZipReader::FileInfo fileInfo; | - | ||||||||||||
389 | FileHeader header = fileHeaders.at(index); | - | ||||||||||||
390 | quint32 mode = readUInt(header.h.external_file_attributes); | - | ||||||||||||
391 | const HostOS hostOS = HostOS(readUShort(header.h.version_made) >> 8); | - | ||||||||||||
392 | switch (hostOS) { | - | ||||||||||||
393 | case HostUnix: | - | ||||||||||||
394 | mode = (mode >> 16) & 0xffff; | - | ||||||||||||
395 | switch (mode & UnixFileAttributes::TypeMask) { | - | ||||||||||||
396 | case UnixFileAttributes::SymLink: | - | ||||||||||||
397 | fileInfo.isSymLink = true; | - | ||||||||||||
398 | break; | - | ||||||||||||
399 | case UnixFileAttributes::Dir: | - | ||||||||||||
400 | fileInfo.isDir = true; | - | ||||||||||||
401 | break; | - | ||||||||||||
402 | case UnixFileAttributes::File: | - | ||||||||||||
403 | default: | - | ||||||||||||
404 | fileInfo.isFile = true; | - | ||||||||||||
405 | break; | - | ||||||||||||
406 | } | - | ||||||||||||
407 | fileInfo.permissions = modeToPermissions(mode); | - | ||||||||||||
408 | break; | - | ||||||||||||
409 | case HostFAT: | - | ||||||||||||
410 | case HostNTFS: | - | ||||||||||||
411 | case HostHPFS: | - | ||||||||||||
412 | case HostVFAT: | - | ||||||||||||
413 | switch (mode & WindowsFileAttributes::TypeMask) { | - | ||||||||||||
414 | case WindowsFileAttributes::Dir: | - | ||||||||||||
415 | fileInfo.isDir = true; | - | ||||||||||||
416 | break; | - | ||||||||||||
417 | case WindowsFileAttributes::File: | - | ||||||||||||
418 | default: | - | ||||||||||||
419 | fileInfo.isFile = true; | - | ||||||||||||
420 | break; | - | ||||||||||||
421 | } | - | ||||||||||||
422 | fileInfo.permissions |= QFile::ReadOwner | QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther; | - | ||||||||||||
423 | if ((mode & WindowsFileAttributes::ReadOnly) == 0) | - | ||||||||||||
424 | fileInfo.permissions |= QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther; | - | ||||||||||||
425 | if (fileInfo.isDir) | - | ||||||||||||
426 | fileInfo.permissions |= QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther; | - | ||||||||||||
427 | break; | - | ||||||||||||
428 | default: | - | ||||||||||||
429 | QMessageLogger(__FILE__, 481487, __PRETTY_FUNCTION__).warning("QZip: Zip entry format at %d is not supported.", index); | - | ||||||||||||
430 | return fileInfo; | - | ||||||||||||
431 | } | - | ||||||||||||
432 | - | |||||||||||||
433 | ushort general_purpose_bits = readUShort(header.h.general_purpose_bits); | - | ||||||||||||
434 | - | |||||||||||||
435 | const bool inUtf8 = (general_purpose_bits & Utf8Names) != 0; | - | ||||||||||||
436 | fileInfo.filePath = inUtf8 ? QString::fromUtf8(header.file_name) : QString::fromLocal8Bit(header.file_name); | - | ||||||||||||
437 | fileInfo.crc = readUInt(header.h.crc_32); | - | ||||||||||||
438 | fileInfo.size = readUInt(header.h.uncompressed_size); | - | ||||||||||||
439 | fileInfo.lastModified = readMSDosDate(header.h.last_mod_file); | - | ||||||||||||
440 | - | |||||||||||||
441 | - | |||||||||||||
442 | fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath); | - | ||||||||||||
443 | while (!fileInfo.filePath.isEmpty() && (fileInfo.filePath.at(0) == QLatin1Char('.') || fileInfo.filePath.at(0) == QLatin1Char('/'))) | - | ||||||||||||
444 | fileInfo.filePath = fileInfo.filePath.mid(1); | - | ||||||||||||
445 | while (!fileInfo.filePath.isEmpty() && fileInfo.filePath.at(fileInfo.filePath.size() - 1) == QLatin1Char('/')) | - | ||||||||||||
446 | fileInfo.filePath.chop(1); | - | ||||||||||||
447 | - | |||||||||||||
448 | return fileInfo; | - | ||||||||||||
449 | } | - | ||||||||||||
450 | - | |||||||||||||
451 | class QZipReaderPrivate : public QZipPrivate | - | ||||||||||||
452 | { | - | ||||||||||||
453 | public: | - | ||||||||||||
454 | QZipReaderPrivate(QIODevice *device, bool ownDev) | - | ||||||||||||
455 | : QZipPrivate(device, ownDev), status(QZipReader::NoError) | - | ||||||||||||
456 | { | - | ||||||||||||
457 | } | - | ||||||||||||
458 | - | |||||||||||||
459 | void scanFiles(); | - | ||||||||||||
460 | - | |||||||||||||
461 | QZipReader::Status status; | - | ||||||||||||
462 | }; | - | ||||||||||||
463 | - | |||||||||||||
464 | class QZipWriterPrivate : public QZipPrivate | - | ||||||||||||
465 | { | - | ||||||||||||
466 | public: | - | ||||||||||||
467 | QZipWriterPrivate(QIODevice *device, bool ownDev) | - | ||||||||||||
468 | : QZipPrivate(device, ownDev), | - | ||||||||||||
469 | status(QZipWriter::NoError), | - | ||||||||||||
470 | permissions(QFile::ReadOwner | QFile::WriteOwner), | - | ||||||||||||
471 | compressionPolicy(QZipWriter::AlwaysCompress) | - | ||||||||||||
472 | { | - | ||||||||||||
473 | } | - | ||||||||||||
474 | - | |||||||||||||
475 | QZipWriter::Status status; | - | ||||||||||||
476 | QFile::Permissions permissions; | - | ||||||||||||
477 | QZipWriter::CompressionPolicy compressionPolicy; | - | ||||||||||||
478 | - | |||||||||||||
479 | enum EntryType { Directory, File, Symlink }; | - | ||||||||||||
480 | - | |||||||||||||
481 | void addEntry(EntryType type, const QString &fileName, const QByteArray &contents); | - | ||||||||||||
482 | }; | - | ||||||||||||
483 | - | |||||||||||||
484 | LocalFileHeader CentralFileHeader::toLocalHeader() const | - | ||||||||||||
485 | { | - | ||||||||||||
486 | LocalFileHeader h; | - | ||||||||||||
487 | writeUInt(h.signature, 0x04034b50); | - | ||||||||||||
488 | copyUShort(h.version_needed, version_needed); | - | ||||||||||||
489 | copyUShort(h.general_purpose_bits, general_purpose_bits); | - | ||||||||||||
490 | copyUShort(h.compression_method, compression_method); | - | ||||||||||||
491 | copyUInt(h.last_mod_file, last_mod_file); | - | ||||||||||||
492 | copyUInt(h.crc_32, crc_32); | - | ||||||||||||
493 | copyUInt(h.compressed_size, compressed_size); | - | ||||||||||||
494 | copyUInt(h.uncompressed_size, uncompressed_size); | - | ||||||||||||
495 | copyUShort(h.file_name_length, file_name_length); | - | ||||||||||||
496 | copyUShort(h.extra_field_length, extra_field_length); | - | ||||||||||||
497 | return h; | - | ||||||||||||
498 | } | - | ||||||||||||
499 | - | |||||||||||||
500 | void QZipReaderPrivate::scanFiles() | - | ||||||||||||
501 | { | - | ||||||||||||
502 | if (!dirtyFileTree
| 0 | ||||||||||||
503 | return; never executed: return; | 0 | ||||||||||||
504 | - | |||||||||||||
505 | if (! (device->isOpen()
| 0 | ||||||||||||
506 | status = QZipReader::FileOpenError; | - | ||||||||||||
507 | return; never executed: return; | 0 | ||||||||||||
508 | } | - | ||||||||||||
509 | - | |||||||||||||
510 | if ((
| 0 | ||||||||||||
511 | status = QZipReader::FileReadError; | - | ||||||||||||
512 | return; never executed: return; | 0 | ||||||||||||
513 | } | - | ||||||||||||
514 | - | |||||||||||||
515 | dirtyFileTree = false; | - | ||||||||||||
516 | uchar tmp[4]; | - | ||||||||||||
517 | device->read((char *)tmp, 4); | - | ||||||||||||
518 | if (readUInt(tmp) != 0x04034b50
| 0 | ||||||||||||
519 | QMessageLogger(__FILE__, 571577, __PRETTY_FUNCTION__).warning() << ("QZip: not a zip file!";); | - | ||||||||||||
520 | return; never executed: return; | 0 | ||||||||||||
521 | } | - | ||||||||||||
522 | - | |||||||||||||
523 | - | |||||||||||||
524 | int i = 0; | - | ||||||||||||
525 | int start_of_directory = -1; | - | ||||||||||||
526 | int num_dir_entries = 0; | - | ||||||||||||
527 | EndOfDirectory eod; | - | ||||||||||||
528 | while (start_of_directory == -1
| 0 | ||||||||||||
529 | const int pos = device->size() - int(sizeof(EndOfDirectory)) - i; | - | ||||||||||||
530 | if (pos < 0
| 0 | ||||||||||||
531 | QMessageLogger(__FILE__, 583589, __PRETTY_FUNCTION__).warning() << ("QZip: EndOfDirectory not found";); | - | ||||||||||||
532 | return; never executed: return; | 0 | ||||||||||||
533 | } | - | ||||||||||||
534 | - | |||||||||||||
535 | device->seek(pos); | - | ||||||||||||
536 | device->read((char *)&eod, sizeof(EndOfDirectory)); | - | ||||||||||||
537 | if (readUInt(eod.signature) == 0x06054b50
| 0 | ||||||||||||
538 | break; never executed: break; | 0 | ||||||||||||
539 | ++i; | - | ||||||||||||
540 | } never executed: end of block | 0 | ||||||||||||
541 | - | |||||||||||||
542 | - | |||||||||||||
543 | start_of_directory = readUInt(eod.dir_start_offset); | - | ||||||||||||
544 | num_dir_entries = readUShort(eod.num_dir_entries); | - | ||||||||||||
545 | if (0) QMessageLogger(__FILE__, 597603, __PRETTY_FUNCTION__).debug("start_of_directory at %d, num_dir_entries=%d", start_of_directory, num_dir_entries); dead code: QMessageLogger(__FILE__, 603, __PRETTY_FUNCTION__).debug("start_of_directory at %d, num_dir_entries=%d", start_of_directory, num_dir_entries); | - | ||||||||||||
546 | int comment_length = readUShort(eod.comment_length); | - | ||||||||||||
547 | if (comment_length != i
| 0 | ||||||||||||
548 | QMessageLogger(__FILE__, 600606, __PRETTY_FUNCTION__).warning() << ("QZip: failed to parse zip file.";); never executed: QMessageLogger(__FILE__, 606, __PRETTY_FUNCTION__).warning("QZip: failed to parse zip file."); | 0 | ||||||||||||
549 | comment = device->read(qMin(comment_length, i)); | - | ||||||||||||
550 | - | |||||||||||||
551 | - | |||||||||||||
552 | device->seek(start_of_directory); | - | ||||||||||||
553 | for (i = 0; i < num_dir_entries
| 0 | ||||||||||||
554 | FileHeader header; | - | ||||||||||||
555 | int read = device->read((char *) &header.h, sizeof(CentralFileHeader)); | - | ||||||||||||
556 | if (read < (int)sizeof(CentralFileHeader)
| 0 | ||||||||||||
557 | QMessageLogger(__FILE__, 609615, __PRETTY_FUNCTION__).warning() << ("QZip: Failed to read complete header, index may be incomplete";); | - | ||||||||||||
558 | break; never executed: break; | 0 | ||||||||||||
559 | } | - | ||||||||||||
560 | if (readUInt(header.h.signature) != 0x02014b50
| 0 | ||||||||||||
561 | QMessageLogger(__FILE__, 613619, __PRETTY_FUNCTION__).warning() << ("QZip: invalid header signature, index may be incomplete";); | - | ||||||||||||
562 | break; never executed: break; | 0 | ||||||||||||
563 | } | - | ||||||||||||
564 | - | |||||||||||||
565 | int l = readUShort(header.h.file_name_length); | - | ||||||||||||
566 | header.file_name = device->read(l); | - | ||||||||||||
567 | if (header.file_name.length() != l
| 0 | ||||||||||||
568 | QMessageLogger(__FILE__, 620626, __PRETTY_FUNCTION__).warning() << ("QZip: Failed to read filename from zip index, index may be incomplete";); | - | ||||||||||||
569 | break; never executed: break; | 0 | ||||||||||||
570 | } | - | ||||||||||||
571 | l = readUShort(header.h.extra_field_length); | - | ||||||||||||
572 | header.extra_field = device->read(l); | - | ||||||||||||
573 | if (header.extra_field.length() != l
| 0 | ||||||||||||
574 | QMessageLogger(__FILE__, 626632, __PRETTY_FUNCTION__).warning() << ("QZip: Failed to read extra field in zip file, skipping file, index may be incomplete";); | - | ||||||||||||
575 | break; never executed: break; | 0 | ||||||||||||
576 | } | - | ||||||||||||
577 | l = readUShort(header.h.file_comment_length); | - | ||||||||||||
578 | header.file_comment = device->read(l); | - | ||||||||||||
579 | if (header.file_comment.length() != l
| 0 | ||||||||||||
580 | QMessageLogger(__FILE__, 632638, __PRETTY_FUNCTION__).warning() << ("QZip: Failed to read read file comment, index may be incomplete";); | - | ||||||||||||
581 | break; never executed: break; | 0 | ||||||||||||
582 | } | - | ||||||||||||
583 | - | |||||||||||||
584 | if (0) QMessageLogger(__FILE__, 636642, __PRETTY_FUNCTION__).debug("found file '%s'", header.file_name.data()); dead code: QMessageLogger(__FILE__, 642, __PRETTY_FUNCTION__).debug("found file '%s'", header.file_name.data()); | - | ||||||||||||
585 | fileHeaders.append(header); | - | ||||||||||||
586 | } never executed: end of block | 0 | ||||||||||||
587 | } never executed: end of block | 0 | ||||||||||||
588 | - | |||||||||||||
589 | void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const QByteArray &contents ) | - | ||||||||||||
590 | { | - | ||||||||||||
591 | - | |||||||||||||
592 | static const char *const entryTypes[] = { | - | ||||||||||||
593 | "directory", | - | ||||||||||||
594 | "file ", | - | ||||||||||||
595 | "symlink " }; | - | ||||||||||||
596 | if (0) QMessageLogger(__FILE__, 648654, __PRETTY_FUNCTION__).debug() << "adding" << entryTypes[type] <<":" << fileName.toUtf8().data() << (type == 2 ? QByteArray(" -> " + contents).constData() : ""); dead code: QMessageLogger(__FILE__, 654, __PRETTY_FUNCTION__).debug() << "adding" << entryTypes[type] <<":" << fileName.toUtf8().data() << (type == 2 ? QByteArray(" -> " + contents).constData() : ""); | - | ||||||||||||
597 | - | |||||||||||||
598 | - | |||||||||||||
599 | if (! (device->isOpen() || device->open(QIODevice::WriteOnly))) { | - | ||||||||||||
600 | status = QZipWriter::FileOpenError; | - | ||||||||||||
601 | return; | - | ||||||||||||
602 | } | - | ||||||||||||
603 | device->seek(start_of_directory); | - | ||||||||||||
604 | - | |||||||||||||
605 | - | |||||||||||||
606 | QZipWriter::CompressionPolicy compression = compressionPolicy; | - | ||||||||||||
607 | if (compressionPolicy == QZipWriter::AutoCompress) { | - | ||||||||||||
608 | if (contents.length() < 64) | - | ||||||||||||
609 | compression = QZipWriter::NeverCompress; | - | ||||||||||||
610 | else | - | ||||||||||||
611 | compression = QZipWriter::AlwaysCompress; | - | ||||||||||||
612 | } | - | ||||||||||||
613 | - | |||||||||||||
614 | FileHeader header; | - | ||||||||||||
615 | memset(&header.h, 0, sizeof(CentralFileHeader)); | - | ||||||||||||
616 | writeUInt(header.h.signature, 0x02014b50); | - | ||||||||||||
617 | - | |||||||||||||
618 | writeUShort(header.h.version_needed, 20); | - | ||||||||||||
619 | writeUInt(header.h.uncompressed_size, contents.length()); | - | ||||||||||||
620 | writeMSDosDate(header.h.last_mod_file, QDateTime::currentDateTime()); | - | ||||||||||||
621 | QByteArray data = contents; | - | ||||||||||||
622 | if (compression == QZipWriter::AlwaysCompress) { | - | ||||||||||||
623 | writeUShort(header.h.compression_method, CompressionMethodDeflated); | - | ||||||||||||
624 | - | |||||||||||||
625 | ulong len = contents.length(); | - | ||||||||||||
626 | - | |||||||||||||
627 | len += (len >> 12) + (len >> 14) + 11; | - | ||||||||||||
628 | int res; | - | ||||||||||||
629 | do { | - | ||||||||||||
630 | data.resize(len); | - | ||||||||||||
631 | res = deflate((uchar*)data.data(), &len, (const uchar*)contents.constData(), contents.length()); | - | ||||||||||||
632 | - | |||||||||||||
633 | switch (res) { | - | ||||||||||||
634 | case 0: | - | ||||||||||||
635 | data.resize(len); | - | ||||||||||||
636 | break; | - | ||||||||||||
637 | case (-4): | - | ||||||||||||
638 | QMessageLogger(__FILE__, 690696, __PRETTY_FUNCTION__).warning("QZip: Z_MEM_ERROR: Not enough memory to compress file, skipping"); | - | ||||||||||||
639 | data.resize(0); | - | ||||||||||||
640 | break; | - | ||||||||||||
641 | case (-5): | - | ||||||||||||
642 | len *= 2; | - | ||||||||||||
643 | break; | - | ||||||||||||
644 | } | - | ||||||||||||
645 | } while (res == (-5)); | - | ||||||||||||
646 | } | - | ||||||||||||
647 | - | |||||||||||||
648 | writeUInt(header.h.compressed_size, data.length()); | - | ||||||||||||
649 | uint crc_32 = ::crc32(0, 0, 0); | - | ||||||||||||
650 | crc_32 = ::crc32(crc_32, (const uchar *)contents.constData(), contents.length()); | - | ||||||||||||
651 | writeUInt(header.h.crc_32, crc_32); | - | ||||||||||||
652 | - | |||||||||||||
653 | - | |||||||||||||
654 | ushort general_purpose_bits = Utf8Names; | - | ||||||||||||
655 | writeUShort(header.h.general_purpose_bits, general_purpose_bits); | - | ||||||||||||
656 | - | |||||||||||||
657 | const bool inUtf8 = (general_purpose_bits & Utf8Names) != 0; | - | ||||||||||||
658 | header.file_name = inUtf8 ? fileName.toUtf8() : fileName.toLocal8Bit(); | - | ||||||||||||
659 | if (header.file_name.size() > 0xffff) { | - | ||||||||||||
660 | QMessageLogger(__FILE__, 712718, __PRETTY_FUNCTION__).warning("QZip: Filename is too long, chopping it to 65535 bytes"); | - | ||||||||||||
661 | header.file_name = header.file_name.left(0xffff); | - | ||||||||||||
662 | } | - | ||||||||||||
663 | if (header.file_comment.size() + header.file_name.size() > 0xffff) { | - | ||||||||||||
664 | QMessageLogger(__FILE__, 716722, __PRETTY_FUNCTION__).warning("QZip: File comment is too long, chopping it to 65535 bytes"); | - | ||||||||||||
665 | header.file_comment.truncate(0xffff - header.file_name.size()); | - | ||||||||||||
666 | } | - | ||||||||||||
667 | writeUShort(header.h.file_name_length, header.file_name.length()); | - | ||||||||||||
668 | - | |||||||||||||
669 | - | |||||||||||||
670 | writeUShort(header.h.version_made, HostUnix << 8); | - | ||||||||||||
671 | - | |||||||||||||
672 | - | |||||||||||||
673 | quint32 mode = permissionsToMode(permissions); | - | ||||||||||||
674 | switch (type) { | - | ||||||||||||
675 | case Symlink: | - | ||||||||||||
676 | mode |= UnixFileAttributes::SymLink; | - | ||||||||||||
677 | break; | - | ||||||||||||
678 | case Directory: | - | ||||||||||||
679 | mode |= UnixFileAttributes::Dir; | - | ||||||||||||
680 | break; | - | ||||||||||||
681 | case File: | - | ||||||||||||
682 | mode |= UnixFileAttributes::File; | - | ||||||||||||
683 | break; | - | ||||||||||||
684 | default: | - | ||||||||||||
685 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,737743) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||
686 | break; | - | ||||||||||||
687 | } | - | ||||||||||||
688 | writeUInt(header.h.external_file_attributes, mode << 16); | - | ||||||||||||
689 | writeUInt(header.h.offset_local_header, start_of_directory); | - | ||||||||||||
690 | - | |||||||||||||
691 | - | |||||||||||||
692 | fileHeaders.append(header); | - | ||||||||||||
693 | - | |||||||||||||
694 | LocalFileHeader h = header.h.toLocalHeader(); | - | ||||||||||||
695 | device->write((const char *)&h, sizeof(LocalFileHeader)); | - | ||||||||||||
696 | device->write(header.file_name); | - | ||||||||||||
697 | device->write(data); | - | ||||||||||||
698 | start_of_directory = device->pos(); | - | ||||||||||||
699 | dirtyFileTree = true; | - | ||||||||||||
700 | } | - | ||||||||||||
701 | QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode) | - | ||||||||||||
702 | { | - | ||||||||||||
703 | QScopedPointer<QFile> f(new QFile(archive)); | - | ||||||||||||
704 | const bool result = f->open(mode); | - | ||||||||||||
705 | QZipReader::Status status; | - | ||||||||||||
706 | if (const QFileDevice::FileError error = f->openerror(); | - | ||||||||||||
707 | if (mode)result
| 0 | ||||||||||||
708 | status = NoError; | - | ||||||||||||
709 | } never executed: else {end of block | 0 | ||||||||||||
710 | if (f->error ()== QFile::ReadError
| 0 | ||||||||||||
711 | status = FileReadError; never executed: status = FileReadError; | 0 | ||||||||||||
712 | else if (f->error ()== QFile::OpenError
| 0 | ||||||||||||
713 | status = FileOpenError; never executed: status = FileOpenError; | 0 | ||||||||||||
714 | else if (f->error ()== QFile::PermissionsError
| 0 | ||||||||||||
715 | status = FilePermissionsError; never executed: status = FilePermissionsError; | 0 | ||||||||||||
716 | else | - | ||||||||||||
717 | status = FileError; never executed: status = FileError; | 0 | ||||||||||||
718 | } | - | ||||||||||||
719 | - | |||||||||||||
720 | d = new QZipReaderPrivate(f.data(), true); | - | ||||||||||||
721 | f.take(); | - | ||||||||||||
722 | d->status = status; | - | ||||||||||||
723 | } never executed: end of block | 0 | ||||||||||||
724 | - | |||||||||||||
725 | - | |||||||||||||
726 | - | |||||||||||||
727 | - | |||||||||||||
728 | - | |||||||||||||
729 | - | |||||||||||||
730 | QZipReader::QZipReader(QIODevice *device) | - | ||||||||||||
731 | : d(new QZipReaderPrivate(device, false)) | - | ||||||||||||
732 | { | - | ||||||||||||
733 | ((!(device)) ? qt_assert("device",__FILE__,846854) : qt_noop()); | - | ||||||||||||
734 | } | - | ||||||||||||
735 | - | |||||||||||||
736 | - | |||||||||||||
737 | - | |||||||||||||
738 | - | |||||||||||||
739 | QZipReader::~QZipReader() | - | ||||||||||||
740 | { | - | ||||||||||||
741 | close(); | - | ||||||||||||
742 | delete d; | - | ||||||||||||
743 | } | - | ||||||||||||
744 | - | |||||||||||||
745 | - | |||||||||||||
746 | - | |||||||||||||
747 | - | |||||||||||||
748 | QIODevice* QZipReader::device() const | - | ||||||||||||
749 | { | - | ||||||||||||
750 | return d->device; | - | ||||||||||||
751 | } | - | ||||||||||||
752 | - | |||||||||||||
753 | - | |||||||||||||
754 | - | |||||||||||||
755 | - | |||||||||||||
756 | bool QZipReader::isReadable() const | - | ||||||||||||
757 | { | - | ||||||||||||
758 | return d->device->isReadable(); | - | ||||||||||||
759 | } | - | ||||||||||||
760 | - | |||||||||||||
761 | - | |||||||||||||
762 | - | |||||||||||||
763 | - | |||||||||||||
764 | bool QZipReader::exists() const | - | ||||||||||||
765 | { | - | ||||||||||||
766 | QFile *f = qobject_cast<QFile*> (d->device); | - | ||||||||||||
767 | if (f == 0) | - | ||||||||||||
768 | return true; | - | ||||||||||||
769 | return f->exists(); | - | ||||||||||||
770 | } | - | ||||||||||||
771 | - | |||||||||||||
772 | - | |||||||||||||
773 | - | |||||||||||||
774 | - | |||||||||||||
775 | QVector<QZipReader::FileInfo> QZipReader::fileInfoList() const | - | ||||||||||||
776 | { | - | ||||||||||||
777 | d->scanFiles(); | - | ||||||||||||
778 | QVector<FileInfo> files; | - | ||||||||||||
779 | const int numFileHeaders = d->fileHeaders.size(); | - | ||||||||||||
780 | files.reserve(numFileHeaders); | - | ||||||||||||
781 | for (int i = 0; i < numFileHeaders; ++i) | - | ||||||||||||
782 | files.append(d->fillFileInfo(i)); | - | ||||||||||||
783 | return files; | - | ||||||||||||
784 | - | |||||||||||||
785 | } | - | ||||||||||||
786 | - | |||||||||||||
787 | - | |||||||||||||
788 | - | |||||||||||||
789 | - | |||||||||||||
790 | int QZipReader::count() const | - | ||||||||||||
791 | { | - | ||||||||||||
792 | d->scanFiles(); | - | ||||||||||||
793 | return d->fileHeaders.count(); | - | ||||||||||||
794 | } | - | ||||||||||||
795 | QZipReader::FileInfo QZipReader::entryInfoAt(int index) const | - | ||||||||||||
796 | { | - | ||||||||||||
797 | d->scanFiles(); | - | ||||||||||||
798 | if (index >= 0 && index < d->fileHeaders.count()) | - | ||||||||||||
799 | return d->fillFileInfo(index); | - | ||||||||||||
800 | return QZipReader::FileInfo(); | - | ||||||||||||
801 | } | - | ||||||||||||
802 | - | |||||||||||||
803 | - | |||||||||||||
804 | - | |||||||||||||
805 | - | |||||||||||||
806 | QByteArray QZipReader::fileData(const QString &fileName) const | - | ||||||||||||
807 | { | - | ||||||||||||
808 | d->scanFiles(); | - | ||||||||||||
809 | int i; | - | ||||||||||||
810 | for (i = 0; i < d->fileHeaders.size(); ++i) { | - | ||||||||||||
811 | if (QString::fromLocal8Bit(d->fileHeaders.at(i).file_name) == fileName) | - | ||||||||||||
812 | break; | - | ||||||||||||
813 | } | - | ||||||||||||
814 | if (i == d->fileHeaders.size()) | - | ||||||||||||
815 | return QByteArray(); | - | ||||||||||||
816 | - | |||||||||||||
817 | FileHeader header = d->fileHeaders.at(i); | - | ||||||||||||
818 | - | |||||||||||||
819 | ushort version_needed = readUShort(header.h.version_needed); | - | ||||||||||||
820 | if (version_needed > 20) { | - | ||||||||||||
821 | QMessageLogger(__FILE__, 942950, __PRETTY_FUNCTION__).warning("QZip: .ZIP specification version %d implementationis needed to extract the data.", version_needed); | - | ||||||||||||
822 | return QByteArray(); | - | ||||||||||||
823 | } | - | ||||||||||||
824 | - | |||||||||||||
825 | ushort general_purpose_bits = readUShort(header.h.general_purpose_bits); | - | ||||||||||||
826 | int compressed_size = readUInt(header.h.compressed_size); | - | ||||||||||||
827 | int uncompressed_size = readUInt(header.h.uncompressed_size); | - | ||||||||||||
828 | int start = readUInt(header.h.offset_local_header); | - | ||||||||||||
829 | - | |||||||||||||
830 | - | |||||||||||||
831 | d->device->seek(start); | - | ||||||||||||
832 | LocalFileHeader lh; | - | ||||||||||||
833 | d->device->read((char *)&lh, sizeof(LocalFileHeader)); | - | ||||||||||||
834 | uint skip = readUShort(lh.file_name_length) + readUShort(lh.extra_field_length); | - | ||||||||||||
835 | d->device->seek(d->device->pos() + skip); | - | ||||||||||||
836 | - | |||||||||||||
837 | int compression_method = readUShort(lh.compression_method); | - | ||||||||||||
838 | - | |||||||||||||
839 | - | |||||||||||||
840 | if ((general_purpose_bits & Encrypted) != 0) { | - | ||||||||||||
841 | QMessageLogger(__FILE__, 962970, __PRETTY_FUNCTION__).warning("QZip: Unsupported encryption method is needed to extract the data."); | - | ||||||||||||
842 | return QByteArray(); | - | ||||||||||||
843 | } | - | ||||||||||||
844 | - | |||||||||||||
845 | - | |||||||||||||
846 | QByteArray compressed = d->device->read(compressed_size); | - | ||||||||||||
847 | if (compression_method == CompressionMethodStored) { | - | ||||||||||||
848 | - | |||||||||||||
849 | compressed.truncate(uncompressed_size); | - | ||||||||||||
850 | return compressed; | - | ||||||||||||
851 | } else if (compression_method == CompressionMethodDeflated) { | - | ||||||||||||
852 | - | |||||||||||||
853 | - | |||||||||||||
854 | compressed.truncate(compressed_size); | - | ||||||||||||
855 | QByteArray baunzip; | - | ||||||||||||
856 | ulong len = qMax(uncompressed_size, 1); | - | ||||||||||||
857 | int res; | - | ||||||||||||
858 | do { | - | ||||||||||||
859 | baunzip.resize(len); | - | ||||||||||||
860 | res = inflate((uchar*)baunzip.data(), &len, | - | ||||||||||||
861 | (const uchar*)compressed.constData(), compressed_size); | - | ||||||||||||
862 | - | |||||||||||||
863 | switch (res) { | - | ||||||||||||
864 | case 0: | - | ||||||||||||
865 | if ((int)len != baunzip.size()) | - | ||||||||||||
866 | baunzip.resize(len); | - | ||||||||||||
867 | break; | - | ||||||||||||
868 | case (-4): | - | ||||||||||||
869 | QMessageLogger(__FILE__, 990998, __PRETTY_FUNCTION__).warning("QZip: Z_MEM_ERROR: Not enough memory"); | - | ||||||||||||
870 | break; | - | ||||||||||||
871 | case (-5): | - | ||||||||||||
872 | len *= 2; | - | ||||||||||||
873 | break; | - | ||||||||||||
874 | case (-3): | - | ||||||||||||
875 | QMessageLogger(__FILE__, 9961004, __PRETTY_FUNCTION__).warning("QZip: Z_DATA_ERROR: Input data is corrupted"); | - | ||||||||||||
876 | break; | - | ||||||||||||
877 | } | - | ||||||||||||
878 | } while (res == (-5)); | - | ||||||||||||
879 | return baunzip; | - | ||||||||||||
880 | } | - | ||||||||||||
881 | - | |||||||||||||
882 | QMessageLogger(__FILE__, 10031011, __PRETTY_FUNCTION__).warning("QZip: Unsupported compression method %d is needed to extract the data.", compression_method); | - | ||||||||||||
883 | return QByteArray(); | - | ||||||||||||
884 | } | - | ||||||||||||
885 | - | |||||||||||||
886 | - | |||||||||||||
887 | - | |||||||||||||
888 | - | |||||||||||||
889 | - | |||||||||||||
890 | - | |||||||||||||
891 | bool QZipReader::extractAll(const QString &destinationDir) const | - | ||||||||||||
892 | { | - | ||||||||||||
893 | QDir baseDir(destinationDir); | - | ||||||||||||
894 | - | |||||||||||||
895 | - | |||||||||||||
896 | const QVector<FileInfo> allFiles = fileInfoList(); | - | ||||||||||||
897 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(allFiles)>::type> _container_((allFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const FileInfo &fi = *_container_.i; _container_.control; _container_.control = 0: allFiles) { | - | ||||||||||||
898 | const QString absPath = destinationDir + QDir::separator() + fi.filePath; | - | ||||||||||||
899 | if (fi.isDir
| 0 | ||||||||||||
900 | if (!baseDir.mkpath(fi.filePath)
| 0 | ||||||||||||
901 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
902 | if (!QFile::setPermissions(absPath, fi.permissions)
| 0 | ||||||||||||
903 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
904 | } never executed: end of block | 0 | ||||||||||||
905 | } never executed: end of block | 0 | ||||||||||||
906 | - | |||||||||||||
907 | - | |||||||||||||
908 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(allFiles)>::type> _container_((allFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const FileInfo &fi = *_container_.i; _container_.control; _container_.control = 0: allFiles) { | - | ||||||||||||
909 | const QString absPath = destinationDir + QDir::separator() + fi.filePath; | - | ||||||||||||
910 | if (fi.isSymLink
| 0 | ||||||||||||
911 | QString destination = QFile::decodeName(fileData(fi.filePath)); | - | ||||||||||||
912 | if (destination.isEmpty()
| 0 | ||||||||||||
913 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
914 | QFileInfo linkFi(absPath); | - | ||||||||||||
915 | if (!QFile::exists(linkFi.absolutePath())
| 0 | ||||||||||||
916 | QDir::root().mkpath(linkFi.absolutePath()); never executed: QDir::root().mkpath(linkFi.absolutePath()); | 0 | ||||||||||||
917 | if (!QFile::link(destination, absPath)
| 0 | ||||||||||||
918 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
919 | - | |||||||||||||
920 | - | |||||||||||||
921 | - | |||||||||||||
922 | - | |||||||||||||
923 | } never executed: end of block | 0 | ||||||||||||
924 | } never executed: end of block | 0 | ||||||||||||
925 | - | |||||||||||||
926 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(allFiles)>::type> _container_((allFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const FileInfo &fi = *_container_.i; _container_.control; _container_.control = 0: allFiles) { | - | ||||||||||||
927 | const QString absPath = destinationDir + QDir::separator() + fi.filePath; | - | ||||||||||||
928 | if (fi.isFile
| 0 | ||||||||||||
929 | QFile f(absPath); | - | ||||||||||||
930 | if (!f.open(QIODevice::WriteOnly)
| 0 | ||||||||||||
931 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
932 | f.write(fileData(fi.filePath)); | - | ||||||||||||
933 | f.setPermissions(fi.permissions); | - | ||||||||||||
934 | f.close(); | - | ||||||||||||
935 | } never executed: end of block | 0 | ||||||||||||
936 | } never executed: end of block | 0 | ||||||||||||
937 | - | |||||||||||||
938 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
939 | } | - | ||||||||||||
940 | QZipReader::Status QZipReader::status() const | - | ||||||||||||
941 | { | - | ||||||||||||
942 | return d->status; | - | ||||||||||||
943 | } | - | ||||||||||||
944 | - | |||||||||||||
945 | - | |||||||||||||
946 | - | |||||||||||||
947 | - | |||||||||||||
948 | void QZipReader::close() | - | ||||||||||||
949 | { | - | ||||||||||||
950 | d->device->close(); | - | ||||||||||||
951 | } | - | ||||||||||||
952 | QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode) | - | ||||||||||||
953 | { | - | ||||||||||||
954 | QScopedPointer<QFile> f(new QFile(fileName)); | - | ||||||||||||
955 | QZipWriter::Status status; | - | ||||||||||||
956 | if (f->open(mode) && f->error() == QFile::NoError) | - | ||||||||||||
957 | status = QZipWriter::NoError; | - | ||||||||||||
958 | else { | - | ||||||||||||
959 | if (f->error() == QFile::WriteError) | - | ||||||||||||
960 | status = QZipWriter::FileWriteError; | - | ||||||||||||
961 | else if (f->error() == QFile::OpenError) | - | ||||||||||||
962 | status = QZipWriter::FileOpenError; | - | ||||||||||||
963 | else if (f->error() == QFile::PermissionsError) | - | ||||||||||||
964 | status = QZipWriter::FilePermissionsError; | - | ||||||||||||
965 | else | - | ||||||||||||
966 | status = QZipWriter::FileError; | - | ||||||||||||
967 | } | - | ||||||||||||
968 | - | |||||||||||||
969 | d = new QZipWriterPrivate(f.data(), true); | - | ||||||||||||
970 | f.take(); | - | ||||||||||||
971 | d->status = status; | - | ||||||||||||
972 | } | - | ||||||||||||
973 | - | |||||||||||||
974 | - | |||||||||||||
975 | - | |||||||||||||
976 | - | |||||||||||||
977 | - | |||||||||||||
978 | - | |||||||||||||
979 | QZipWriter::QZipWriter(QIODevice *device) | - | ||||||||||||
980 | : d(new QZipWriterPrivate(device, false)) | - | ||||||||||||
981 | { | - | ||||||||||||
982 | ((!(device)) ? qt_assert("device",__FILE__,11411149) : qt_noop()); | - | ||||||||||||
983 | } | - | ||||||||||||
984 | - | |||||||||||||
985 | QZipWriter::~QZipWriter() | - | ||||||||||||
986 | { | - | ||||||||||||
987 | close(); | - | ||||||||||||
988 | delete d; | - | ||||||||||||
989 | } | - | ||||||||||||
990 | - | |||||||||||||
991 | - | |||||||||||||
992 | - | |||||||||||||
993 | - | |||||||||||||
994 | QIODevice* QZipWriter::device() const | - | ||||||||||||
995 | { | - | ||||||||||||
996 | return d->device; | - | ||||||||||||
997 | } | - | ||||||||||||
998 | - | |||||||||||||
999 | - | |||||||||||||
1000 | - | |||||||||||||
1001 | - | |||||||||||||
1002 | bool QZipWriter::isWritable() const | - | ||||||||||||
1003 | { | - | ||||||||||||
1004 | return d->device->isWritable(); | - | ||||||||||||
1005 | } | - | ||||||||||||
1006 | - | |||||||||||||
1007 | - | |||||||||||||
1008 | - | |||||||||||||
1009 | - | |||||||||||||
1010 | bool QZipWriter::exists() const | - | ||||||||||||
1011 | { | - | ||||||||||||
1012 | QFile *f = qobject_cast<QFile*> (d->device); | - | ||||||||||||
1013 | if (f == 0) | - | ||||||||||||
1014 | return true; | - | ||||||||||||
1015 | return f->exists(); | - | ||||||||||||
1016 | } | - | ||||||||||||
1017 | QZipWriter::Status QZipWriter::status() const | - | ||||||||||||
1018 | { | - | ||||||||||||
1019 | return d->status; | - | ||||||||||||
1020 | } | - | ||||||||||||
1021 | void QZipWriter::setCompressionPolicy(CompressionPolicy policy) | - | ||||||||||||
1022 | { | - | ||||||||||||
1023 | d->compressionPolicy = policy; | - | ||||||||||||
1024 | } | - | ||||||||||||
1025 | - | |||||||||||||
1026 | - | |||||||||||||
1027 | - | |||||||||||||
1028 | - | |||||||||||||
1029 | - | |||||||||||||
1030 | - | |||||||||||||
1031 | QZipWriter::CompressionPolicy QZipWriter::compressionPolicy() const | - | ||||||||||||
1032 | { | - | ||||||||||||
1033 | return d->compressionPolicy; | - | ||||||||||||
1034 | } | - | ||||||||||||
1035 | void QZipWriter::setCreationPermissions(QFile::Permissions permissions) | - | ||||||||||||
1036 | { | - | ||||||||||||
1037 | d->permissions = permissions; | - | ||||||||||||
1038 | } | - | ||||||||||||
1039 | - | |||||||||||||
1040 | - | |||||||||||||
1041 | - | |||||||||||||
1042 | - | |||||||||||||
1043 | - | |||||||||||||
1044 | - | |||||||||||||
1045 | - | |||||||||||||
1046 | QFile::Permissions QZipWriter::creationPermissions() const | - | ||||||||||||
1047 | { | - | ||||||||||||
1048 | return d->permissions; | - | ||||||||||||
1049 | } | - | ||||||||||||
1050 | void QZipWriter::addFile(const QString &fileName, const QByteArray &data) | - | ||||||||||||
1051 | { | - | ||||||||||||
1052 | d->addEntry(QZipWriterPrivate::File, QDir::fromNativeSeparators(fileName), data); | - | ||||||||||||
1053 | } | - | ||||||||||||
1054 | void QZipWriter::addFile(const QString &fileName, QIODevice *device) | - | ||||||||||||
1055 | { | - | ||||||||||||
1056 | ((!(device)) ? qt_assert("device",__FILE__,12791287) : qt_noop()); | - | ||||||||||||
1057 | QIODevice::OpenMode mode = device->openMode(); | - | ||||||||||||
1058 | bool opened = false; | - | ||||||||||||
1059 | if ((mode & QIODevice::ReadOnly) == 0) { | - | ||||||||||||
1060 | opened = true; | - | ||||||||||||
1061 | if (! device->open(QIODevice::ReadOnly)) { | - | ||||||||||||
1062 | d->status = FileOpenError; | - | ||||||||||||
1063 | return; | - | ||||||||||||
1064 | } | - | ||||||||||||
1065 | } | - | ||||||||||||
1066 | d->addEntry(QZipWriterPrivate::File, QDir::fromNativeSeparators(fileName), device->readAll()); | - | ||||||||||||
1067 | if (opened) | - | ||||||||||||
1068 | device->close(); | - | ||||||||||||
1069 | } | - | ||||||||||||
1070 | - | |||||||||||||
1071 | - | |||||||||||||
1072 | - | |||||||||||||
1073 | - | |||||||||||||
1074 | - | |||||||||||||
1075 | void QZipWriter::addDirectory(const QString &dirName) | - | ||||||||||||
1076 | { | - | ||||||||||||
1077 | QString name(QDir::fromNativeSeparators(dirName)); | - | ||||||||||||
1078 | - | |||||||||||||
1079 | if (!name.endsWith(QLatin1Char('/'))) | - | ||||||||||||
1080 | name.append(QLatin1Char('/')); | - | ||||||||||||
1081 | d->addEntry(QZipWriterPrivate::Directory, name, QByteArray()); | - | ||||||||||||
1082 | } | - | ||||||||||||
1083 | - | |||||||||||||
1084 | - | |||||||||||||
1085 | - | |||||||||||||
1086 | - | |||||||||||||
1087 | - | |||||||||||||
1088 | - | |||||||||||||
1089 | void QZipWriter::addSymLink(const QString &fileName, const QString &destination) | - | ||||||||||||
1090 | { | - | ||||||||||||
1091 | d->addEntry(QZipWriterPrivate::Symlink, QDir::fromNativeSeparators(fileName), QFile::encodeName(destination)); | - | ||||||||||||
1092 | } | - | ||||||||||||
1093 | - | |||||||||||||
1094 | - | |||||||||||||
1095 | - | |||||||||||||
1096 | - | |||||||||||||
1097 | void QZipWriter::close() | - | ||||||||||||
1098 | { | - | ||||||||||||
1099 | if (!(d->device->openMode() & QIODevice::WriteOnly)) { | - | ||||||||||||
1100 | d->device->close(); | - | ||||||||||||
1101 | return; | - | ||||||||||||
1102 | } | - | ||||||||||||
1103 | - | |||||||||||||
1104 | - | |||||||||||||
1105 | d->device->seek(d->start_of_directory); | - | ||||||||||||
1106 | - | |||||||||||||
1107 | for (int i = 0; i < d->fileHeaders.size(); ++i) { | - | ||||||||||||
1108 | const FileHeader &header = d->fileHeaders.at(i); | - | ||||||||||||
1109 | d->device->write((const char *)&header.h, sizeof(CentralFileHeader)); | - | ||||||||||||
1110 | d->device->write(header.file_name); | - | ||||||||||||
1111 | d->device->write(header.extra_field); | - | ||||||||||||
1112 | d->device->write(header.file_comment); | - | ||||||||||||
1113 | } | - | ||||||||||||
1114 | int dir_size = d->device->pos() - d->start_of_directory; | - | ||||||||||||
1115 | - | |||||||||||||
1116 | EndOfDirectory eod; | - | ||||||||||||
1117 | memset(&eod, 0, sizeof(EndOfDirectory)); | - | ||||||||||||
1118 | writeUInt(eod.signature, 0x06054b50); | - | ||||||||||||
1119 | - | |||||||||||||
1120 | - | |||||||||||||
1121 | writeUShort(eod.num_dir_entries_this_disk, d->fileHeaders.size()); | - | ||||||||||||
1122 | writeUShort(eod.num_dir_entries, d->fileHeaders.size()); | - | ||||||||||||
1123 | writeUInt(eod.directory_size, dir_size); | - | ||||||||||||
1124 | writeUInt(eod.dir_start_offset, d->start_of_directory); | - | ||||||||||||
1125 | writeUShort(eod.comment_length, d->comment.length()); | - | ||||||||||||
1126 | - | |||||||||||||
1127 | d->device->write((const char *)&eod, sizeof(EndOfDirectory)); | - | ||||||||||||
1128 | d->device->write(d->comment); | - | ||||||||||||
1129 | d->device->close(); | - | ||||||||||||
1130 | } | - | ||||||||||||
1131 | - | |||||||||||||
1132 | - | |||||||||||||
Switch to Source code | Preprocessed file |