23#define ZDEBUG if (0) qDebug
41 data[1] = (
i>>8) & 0xff;
42 data[2] = (
i>>16) & 0xff;
43 data[3] = (
i>>24) & 0xff;
49 data[1] = (
i>>8) & 0xff;
70 (dt.time().hour() << 11)
71 | (dt.time().minute() << 5)
72 | (dt.time().second() >> 1);
74 dest[0] =
time & 0xff;
78 ((dt.date().year() - 1980) << 9)
79 | (dt.date().month() << 5)
83 dest[3] = char(
date >> 8);
98 stream.avail_in = (uInt)sourceLen;
99 if ((uLong)
stream.avail_in != sourceLen)
103 stream.avail_out = (uInt)*destLen;
104 if ((uLong)
stream.avail_out != *destLen)
107 stream.zalloc = (alloc_func)
nullptr;
108 stream.zfree = (free_func)
nullptr;
110 err = inflateInit2(&
stream, -MAX_WBITS);
115 if (err != Z_STREAM_END) {
117 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR &&
stream.avail_in == 0))
121 *destLen =
stream.total_out;
123 err = inflateEnd(&
stream);
133 stream.avail_in = (uInt)sourceLen;
135 stream.avail_out = (uInt)*destLen;
136 if ((uLong)
stream.avail_out != *destLen)
return Z_BUF_ERROR;
138 stream.zalloc = (alloc_func)
nullptr;
139 stream.zfree = (free_func)
nullptr;
140 stream.opaque = (voidpf)
nullptr;
142 err = deflateInit2(&
stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
143 if (err != Z_OK)
return err;
146 if (err != Z_STREAM_END) {
148 return err == Z_OK ? Z_BUF_ERROR : err;
150 *destLen =
stream.total_out;
152 err = deflateEnd(&
stream);
190 QFile::Permissions
ret;
240 uDate = (
quint64)(dosDate >> 16);
241 uint tm_mday = (uDate & 0x1f);
242 uint tm_mon = ((uDate & 0x1E0) >> 5);
243 uint tm_year = (((uDate & 0x0FE00) >> 9) + 1980);
244 uint tm_hour = ((dosDate & 0xF800) >> 11);
245 uint tm_min = ((dosDate & 0x7E0) >> 5);
246 uint tm_sec = ((dosDate & 0x1f) << 1);
420 fileInfo.
isDir =
true;
435 fileInfo.
isDir =
true;
449 qWarning(
"QZip: Zip entry format at %d is not supported.",
index);
455 const bool inUtf8 = (general_purpose_bits &
Utf8Names) != 0;
464 while (filePathRef.startsWith(u
'.') || filePathRef.startsWith(u
'/'))
465 filePathRef = filePathRef.mid(1);
466 while (filePathRef.endsWith(u
'/'))
469 fileInfo.
filePath = filePathRef.toString();
516 copyUInt(
h.uncompressed_size,
ch.uncompressed_size);
548 int num_dir_entries = 0;
552 if (pos < 0 || i > 65535) {
553 qWarning(
"QZip: EndOfDirectory not found");
559 if (
readUInt(eod.signature) == 0x06054b50)
566 num_dir_entries =
readUShort(eod.num_dir_entries);
568 int comment_length =
readUShort(eod.comment_length);
569 if (comment_length !=
i)
570 qWarning(
"QZip: failed to parse zip file.");
575 for (
i = 0;
i < num_dir_entries; ++
i) {
579 qWarning(
"QZip: Failed to read complete header, index may be incomplete");
583 qWarning(
"QZip: invalid header signature, index may be incomplete");
589 if (
header.file_name.size() != l) {
590 qWarning(
"QZip: Failed to read filename from zip index, index may be incomplete");
595 if (
header.extra_field.size() != l) {
596 qWarning(
"QZip: Failed to read extra field in zip file, skipping file, index may be incomplete");
601 if (
header.file_comment.size() != l) {
602 qWarning(
"QZip: Failed to read read file comment, index may be incomplete");
614 static const char *
const entryTypes[] = {
660 qWarning(
"QZip: Z_MEM_ERROR: Not enough memory to compress file, skipping");
667 }
while (
res == Z_BUF_ERROR);
671 uint crc_32 = ::crc32(0,
nullptr, 0);
679 const bool inUtf8 = (general_purpose_bits &
Utf8Names) != 0;
681 if (
header.file_name.size() > 0xffff) {
682 qWarning(
"QZip: Filename is too long, chopping it to 65535 bytes");
685 if (
header.file_comment.size() +
header.file_name.size() > 0xffff) {
686 qWarning(
"QZip: File comment is too long, chopping it to 65535 bytes");
687 header.file_comment.truncate(0xffff -
header.file_name.size());
788 auto f = std::make_unique<QFile>(archive);
863 QList<FileInfo>
files;
865 files.reserve(numFileHeaders);
866 for (
int i = 0;
i < numFileHeaders; ++
i)
891 if (
index >= 0 && index < d->fileHeaders.size())
914 qWarning(
"QZip: .ZIP specification version %d implementationis needed to extract the data.", version_needed);
930 int compression_method =
readUShort(lh.compression_method);
933 if ((general_purpose_bits &
Encrypted) != 0) {
934 qWarning(
"QZip: Unsupported encryption method is needed to extract the data.");
958 if ((
int)
len != baunzip.size())
962 qWarning(
"QZip: Z_MEM_ERROR: Not enough memory");
968 qWarning(
"QZip: Z_DATA_ERROR: Input data is corrupted");
971 }
while (
res == Z_BUF_ERROR);
975 qWarning(
"QZip: Unsupported compression method %d is needed to extract the data.", compression_method);
986 QDir baseDir(destinationDir);
990 bool foundDirs =
false;
991 bool hasDirs =
false;
992 for (
const FileInfo &fi : allFiles) {
996 if (!baseDir.mkpath(fi.filePath))
1000 }
else if (!hasDirs && fi.filePath.contains(u
"/")) {
1010 if (hasDirs && !foundDirs) {
1011 for (
const FileInfo &fi : allFiles) {
1012 const auto dirPath = fi.filePath.left(fi.filePath.lastIndexOf(u
"/"));
1013 if (!baseDir.mkpath(dirPath))
1021 for (
const FileInfo &fi : allFiles) {
1039 for (
const FileInfo &fi : allFiles) {
1046 f.setPermissions(fi.permissions);
1105 auto f = std::make_unique<QFile>(
fileName);
1273 bool opened =
false;
1294 if (!
name.endsWith(u
'/'))
1338 writeUInt(eod.directory_size, dir_size);
IOBluetoothDevice * device
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
void truncate(qsizetype pos)
Truncates the byte array at index position pos.
\inmodule QtCore\reentrant
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
static QString fromNativeSeparators(const QString &pathName)
static QDir root()
Returns the root directory.
static QChar separator()
Returns the native directory separator: "/" under Unix and "\\" under Windows.
FileError
This enum describes the errors that may be returned by the error() function.
bool setPermissions(Permissions permissionSpec) override
Sets the permissions for the file to the permissions specified.
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QIODeviceBase::OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
QZipReader::FileInfo fillFileInfo(int index) const
QZipPrivate(QIODevice *device, bool ownDev)
QList< FileHeader > fileHeaders
QZipReader::Status status
QZipReaderPrivate(QIODevice *device, bool ownDev)
\variable QZipReader::FileInfo::filePath The full filepath inside the archive.
FileInfo entryInfoAt(int index) const
Returns a FileInfo of an entry in the zipfile.
QList< FileInfo > fileInfoList() const
Returns the list of files the archive contains.
void close()
Close the zip file.
QIODevice * device() const
Returns device used for reading zip archive.
bool exists() const
Returns true if the file exists; otherwise returns false.
QZipReader(const QString &fileName, QIODevice::OpenMode mode=QIODevice::ReadOnly)
Create a new zip archive that operates on the fileName.
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
Status status() const
Returns a status code indicating the first error that was met by QZipReader, or QZipReader::NoError i...
Status
The following status values are possible:
QByteArray fileData(const QString &fileName) const
Fetch the file contents from the zip archive and return the uncompressed bytes.
bool extractAll(const QString &destinationDir) const
Extracts the full contents of the zip file into destinationDir on the local filesystem.
int count() const
Return the number of items in the zip archive.
void addEntry(EntryType type, const QString &fileName, const QByteArray &contents)
QFile::Permissions permissions
QZipWriterPrivate(QIODevice *device, bool ownDev)
QZipWriter::Status status
QZipWriter::CompressionPolicy compressionPolicy
the QZipWriter class provides a way to create a new zip archive.
void addDirectory(const QString &dirName)
Create a new directory in the archive with the specified dirName and the permissions;.
QIODevice * device() const
Returns device used for writing zip archive.
void setCreationPermissions(QFile::Permissions permissions)
Sets the permissions that will be used for newly added files.
void addFile(const QString &fileName, const QByteArray &data)
Add a file to the archive with data as the file contents.
bool isWritable() const
Returns true if the user can write to the archive; otherwise returns false.
QZipWriter(const QString &fileName, QIODevice::OpenMode mode=(QIODevice::WriteOnly|QIODevice::Truncate))
Create a new zip archive that operates on the archive filename.
void close()
Closes the zip file.
QFile::Permissions creationPermissions() const
Returns the currently set creation permissions.
void setCompressionPolicy(CompressionPolicy policy)
Sets the policy for compressing newly added files to the new policy.
Status status() const
Returns a status code indicating the first error that was met by QZipWriter, or QZipWriter::NoError i...
Status
The following status values are possible:
CompressionPolicy
\value AlwaysCompress A file that is added is compressed.
bool exists() const
Returns true if the file exists; otherwise returns false.
CompressionPolicy compressionPolicy() const
Returns the currently set compression policy.
void addSymLink(const QString &fileName, const QString &destination)
Create a new symbolic link in the archive with the specified dirName and the permissions; A symbolic ...
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
DBusConnection const char DBusError * error
static QString header(const QString &name)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
unsigned long long quint64
ReturnedValue read(const char *data)
static QFile::Permissions modeToPermissions(quint32 mode)
static void copyUShort(uchar *dest, const uchar *src)
static QT_BEGIN_NAMESPACE uint readUInt(const uchar *data)
static void copyUInt(uchar *dest, const uchar *src)
@ CompressionMethodReduced1
@ CompressionMethodReduced4
@ CompressionMethodReduced3
@ CompressionMethodDeflated
@ CompressionMethodPKImploding
@ CompressionMethodShrunk
@ CompressionMethodReduced2
@ CompressionMethodStored
@ CompressionMethodReservedTokenizing
@ CompressionMethodDeflated64
@ CompressionMethodWavPack
@ CompressionMethodImploded
static void writeUInt(uchar *data, uint i)
static QDateTime readMSDosDate(const uchar *src)
static void writeMSDosDate(uchar *dest, const QDateTime &dt)
static LocalFileHeader toLocalHeader(const CentralFileHeader &ch)
static quint32 permissionsToMode(QFile::Permissions perms)
static void writeUShort(uchar *data, ushort i)
@ CentralDirectoryEncrypted
static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
static int deflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
static ushort readUShort(const uchar *data)
uchar uncompressed_size[4]
uchar start_of_directory_disk[2]
uchar dir_start_offset[4]
uchar num_dir_entries_this_disk[2]
QFile::Permissions permissions