549 bool isPNGFile =
false;
550 bool dirOnly = file.isDir();
552 QString entryName = root;
559 entryName.append(file.fileName());
561 QString ext = file.completeSuffix().toLower();
562 isPNGFile = ext ==
"png";
594 bool encrypt = !dirOnly && !
password.isEmpty();
598 QDateTime dt = file.lastModified();
600 h->
modDate[1] = ((d.year() - 1980) << 1) & 254;
601 h->
modDate[1] |= ((d.month() >> 3) & 1);
602 h->
modDate[0] = ((d.month() & 7) << 5) & 224;
606 h->
modTime[1] = (t.hour() << 3) & 248;
607 h->
modTime[1] |= ((t.minute() >> 3) & 7);
608 h->
modTime[0] = ((t.minute() & 7) << 5) & 224;
609 h->
modTime[0] |= t.second() / 2;
611 h->
szUncomp = dirOnly ? 0 : file.size();
654 QByteArray entryNameBytes = entryName.toLatin1();
655 int sz = entryNameBytes.size();
674 if (
device->write(entryNameBytes) != sz)
681 quint32 keys[3] = { 0, 0, 0 };
689 srand(time(NULL) ^ 3141592654UL);
693 for (
int i=0; i<10; ++i)
695 randByte = (rand() >> 7) & 0xff;
702 for (
int i=0; i<10; ++i)
728 quint32 crc = crc32(0L, Z_NULL, 0);
732 QFile actualFile(file.absoluteFilePath());
733 if (!actualFile.open(QIODevice::ReadOnly))
735 qDebug() << QString(
"An error occurred while opening %1").arg(file.absoluteFilePath());
742 qint64 toRead = actualFile.size();
748 crc = crc32(crc,
uBuffer, read);
766 zstr.zalloc = Z_NULL;
768 zstr.opaque = Z_NULL;
773 if ((zret = deflateInit2_(
779 isPNGFile ? Z_RLE : Z_DEFAULT_STRATEGY,
785 qDebug() <<
"Could not initialize zlib for compression";
792 int flush = Z_NO_FLUSH;
805 qDebug() << QString(
"Error while reading %1").arg(file.absoluteFilePath());
810 crc = crc32(crc,
uBuffer, read);
812 zstr.next_in = (Bytef*)
buffer1;
813 zstr.avail_in = (uInt)read;
817 flush = (totRead == toRead) ? Z_FINISH : Z_NO_FLUSH;
823 zstr.next_out = (Bytef*)
buffer2;
826 zret = deflate(&zstr, flush);
828 Q_ASSERT(zret != Z_STREAM_ERROR);
840 qDebug() << QString(
"Error while writing %1").arg(file.absoluteFilePath());
845 written += compressed;
847 }
while (zstr.avail_out == 0);
850 Q_ASSERT(zstr.avail_in == 0);
852 }
while (flush != Z_FINISH);
855 Q_ASSERT(zret == Z_STREAM_END);
865 quint32 current =
device->pos();
868 if (!
device->seek(crcOffset))
874 h->
crc = dirOnly ? 0 : crc;
886 if (!
device->seek(current))
892 if ((h->
gpFlag[0] & 8) == 8)
void initKeys(quint32 *keys) const
void updateKeys(quint32 *keys, int c) const
#define ZIP_COMPRESSION_THRESHOLD
Do not store very small files as the compression headers overhead would be to big.
char buffer2[ZIP_READ_BUFFER]
#define ZIP_LH_OFF_GPFLAG
#define ZIP_LOCAL_ENC_HEADER_SIZE
Encryption header size.
#define ZIP_VERSION
PKZip version for archives created by this API.
Zip::CompressionLevel detectCompressionByMime(const QString &ext)
void encryptBytes(quint32 *keys, char *buffer, qint64 read)
int decryptByte(quint32 key2) const
char buffer1[ZIP_READ_BUFFER]
QMap< QString, ZipEntryP * > * headers
#define ZIP_LOCAL_HEADER_SIZE
Local header size (including signature, excluding variable length fields)
void setULong(quint32 v, char *buffer, unsigned int offset)
#define ZIP_LH_OFF_NAMELEN
#define ZIP_DD_SIZE_WS
Data descriptor size (signature included)