text/qzip.cpp

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

Generated by Squish Coco Non-Commercial