44 #ifndef QT_NO_TEXTODFWRITER 49 #include <qplatformdefs.h> 58 # define S_IFREG 0100000 60 # define S_IFDIR 0040000 63 # define S_ISDIR(x) ((x) & S_IFDIR) > 0 66 # define S_ISREG(x) ((x) & 0170000) == S_IFREG 68 # define S_IFLNK 020000 69 # define S_ISLNK(x) ((x) & S_IFLNK) > 0 90 #define ZDEBUG if (0) qDebug 97 return (data[0]) + (data[1]<<8) + (data[2]<<16) + (data[3]<<24);
102 return (data[0]) + (data[1]<<8);
108 data[1] = (i>>8) & 0xff;
109 data[2] = (i>>16) & 0xff;
110 data[3] = (i>>24) & 0xff;
116 data[1] = (i>>8) & 0xff;
141 dest[0] = time & 0xff;
149 dest[2] = char(date);
150 dest[3] = char(date >> 8);
194 stream.next_in = (Bytef*)source;
195 stream.avail_in = (uInt)sourceLen;
196 if ((uLong)stream.avail_in != sourceLen)
199 stream.next_out = dest;
200 stream.avail_out = (uInt)*destLen;
201 if ((uLong)stream.avail_out != *destLen)
204 stream.zalloc = (alloc_func)0;
205 stream.zfree = (free_func)0;
207 err = inflateInit2(&stream, -MAX_WBITS);
211 err =
inflate(&stream, Z_FINISH);
212 if (err != Z_STREAM_END) {
214 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
218 *destLen = stream.total_out;
220 err = inflateEnd(&stream);
229 stream.next_in = (Bytef*)source;
230 stream.avail_in = (uInt)sourceLen;
231 stream.next_out = dest;
232 stream.avail_out = (uInt)*destLen;
233 if ((uLong)stream.avail_out != *destLen)
return Z_BUF_ERROR;
235 stream.zalloc = (alloc_func)0;
236 stream.zfree = (free_func)0;
237 stream.opaque = (voidpf)0;
239 err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
240 if (err != Z_OK)
return err;
242 err =
deflate(&stream, Z_FINISH);
243 if (err != Z_STREAM_END) {
245 return err == Z_OK ? Z_BUF_ERROR : err;
247 *destLen = stream.total_out;
249 err = deflateEnd(&stream);
255 QFile::Permissions ret;
287 uDate = (
quint64)(dosDate >> 16);
288 uint tm_mday = (uDate & 0x1f);
289 uint tm_mon = ((uDate & 0x1E0) >> 5);
290 uint tm_year = (((uDate & 0x0FE00) >> 9) + 1980);
291 uint tm_hour = ((dosDate & 0xF800) >> 11);
292 uint tm_min = ((dosDate & 0x7E0) >> 5);
293 uint tm_sec = ((dosDate & 0x1f) << 1);
361 : isDir(false), isFile(false), isSymLink(false), crc32(0), size(0)
396 : device(device), ownDevice(ownDev), dirtyFileTree(true), start_of_directory(0)
494 dirtyFileTree =
false;
498 qWarning() <<
"QZip: not a zip file!";
504 int start_of_directory = -1;
505 int num_dir_entries = 0;
507 while (start_of_directory == -1) {
509 if (pos < 0 || i > 65535) {
510 qWarning() <<
"QZip: EndOfDirectory not found";
516 if (
readUInt(eod.signature) == 0x06054b50)
524 ZDEBUG(
"start_of_directory at %d, num_dir_entries=%d", start_of_directory, num_dir_entries);
526 if (comment_length != i)
527 qWarning() <<
"QZip: failed to parse zip file.";
532 for (i = 0; i < num_dir_entries; ++i) {
536 qWarning() <<
"QZip: Failed to read complete header, index may be incomplete";
540 qWarning() <<
"QZip: invalid header signature, index may be incomplete";
547 qWarning() <<
"QZip: Failed to read filename from zip index, index may be incomplete";
553 qWarning() <<
"QZip: Failed to read extra field in zip file, skipping file, index may be incomplete";
559 qWarning() <<
"QZip: Failed to read read file comment, index may be incomplete";
564 fileHeaders.append(header);
571 static const char *entryTypes[] = {
587 if (contents.
length() < 64)
606 len += (len >> 12) + (len >> 14) + 11;
617 qWarning(
"QZip: Z_MEM_ERROR: Not enough memory to compress file, skipping");
624 }
while (res == Z_BUF_ERROR);
634 qWarning(
"QZip: Filename too long, chopping it to 65535 characters");
645 case File: mode |=
S_IFREG;
break;
646 case Directory: mode |=
S_IFDIR;
break;
647 case Symlink: mode |=
S_IFLNK;
break;
653 fileHeaders.append(header);
660 dirtyFileTree =
true;
864 if (index >= 0 && index < d->fileHeaders.count())
896 int compression_method =
readUShort(lh.compression_method);
901 if (compression_method == 0) {
903 compressed.
truncate(uncompressed_size);
905 }
else if (compression_method == 8) {
908 compressed.
truncate(compressed_size);
919 if ((
int)len != baunzip.
size())
923 qWarning(
"QZip: Z_MEM_ERROR: Not enough memory");
929 qWarning(
"QZip: Z_DATA_ERROR: Input data is corrupted");
932 }
while (res == Z_BUF_ERROR);
935 qWarning() <<
"QZip: Unknown compression method";
946 QDir baseDir(destinationDir);
1222 QIODevice::OpenMode mode = device->
openMode();
1223 bool opened =
false;
1226 if (! device->
open(QIODevice::ReadOnly)) {
1299 #endif // QT_NO_TEXTODFWRITER QZipReaderPrivate(QIODevice *device, bool ownDev)
The QDir class provides access to directory structures and their contents.
T qobject_cast(QObject *object)
Status status() const
Returns a status code indicating the first error that was met by QZipReader, or QZipReader::NoError i...
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
uchar dir_start_offset[4]
Status status() const
Returns a status code indicating the first error that was met by QZipWriter, or QZipWriter::NoError i...
QIODevice * device() const
Returns device used for reading zip archive.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
bool isWritable() const
Returns true if the user can write to the archive; otherwise returns false.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
void truncate(int pos)
Truncates the byte array at index position pos.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
void fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const
char * data()
Returns a pointer to the data stored in the byte array.
static int deflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
bool exists() const
Returns true if the file exists; otherwise returns false.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
T * data() const
Returns the value of the pointer referenced by this object.
void addEntry(EntryType type, const QString &fileName, const QByteArray &contents)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
The QByteArray class provides an array of bytes.
Status
The following status values are possible:
T * take()
Returns the value of the pointer referenced by this object.
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
CompressionPolicy compressionPolicy() const
Returns the currently set compression policy.
int day() const
Returns the day of the month (1 to 31) of this date.
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
The QDate class provides date functions.
int count(const T &t) const
Returns the number of occurrences of value in the list.
uint isFile
A boolean type, if it is one this entry is a file.
QString filePath
The full filepath inside the archive.
The QString class provides a Unicode character string.
void addDirectory(const QString &dirName)
Create a new directory in the archive with the specified dirName and the permissions;.
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
QByteArray fileData(const QString &fileName) const
Fetch the file contents from the zip archive and return the uncompressed bytes.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
static uint readUInt(const uchar *data)
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
void addFile(const QString &fileName, const QByteArray &data)
Add a file to the archive with data as the file contents.
void append(const T &t)
Inserts value at the end of the list.
Represents one entry in the zip table of contents.
QFile::Permissions creationPermissions() const
Returns the currently set creation permissions.
the QZipReader class provides a way to inspect the contents of a zip archive and extract individual f...
The QTime class provides clock time functions.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setCompressionPolicy(CompressionPolicy policy)
Sets the policy for compressing newly added files to the new policy.
static void copyUShort(uchar *dest, const uchar *src)
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QZipReader::Status status
QFile::Permissions permissions
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static ushort readUShort(const uchar *data)
QZipWriter::Status status
QZipReader(const QString &fileName, QIODevice::OpenMode mode=QIODevice::ReadOnly)
Create a new zip archive that operates on the fileName.
bool exists() const
Returns true if the file exists; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the list.
QZipWriterPrivate(QIODevice *device, bool ownDev)
QFile::Permissions permissions
Q_CORE_EXPORT void qWarning(const char *,...)
quint32 qFromLittleEndian< quint32 >(const uchar *src)
qint64 size
The total size of the unpacked content.
int second() const
Returns the second part (0 to 59) of the time.
QList< FileInfo > fileInfoList() const
Returns the list of files the archive contains.
static const char * data(const QByteArray &arr)
uint isSymLink
A boolean type, if it is one this entry is symbolic link.
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
int minute() const
Returns the minute part (0 to 59) of the time.
static QFile::Permissions modeToPermissions(quint32 mode)
QIODevice * device() const
Returns device used for writing zip archive.
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
QList< FileHeader > fileHeaders
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
QDate date() const
Returns the date part of the datetime.
uint crc32
The calculated checksum as a crc32 type.
static void writeMSDosDate(uchar *dest, const QDateTime &dt)
QString & append(QChar c)
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
Status
The following status values are possible:
The QDateTime class provides date and time functions.
The QFile class provides an interface for reading from and writing to files.
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 ...
bool extractAll(const QString &destinationDir) const
Extracts the full contents of the zip file into destinationDir on the local filesystem.
QZipPrivate(QIODevice *device, bool ownDev)
OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
QZipWriter::CompressionPolicy compressionPolicy
static void writeUShort(uchar *data, ushort i)
void close()
Close the zip file.
void resize(int size)
Sets the size of the byte array to size bytes.
void setCreationPermissions(QFile::Permissions permissions)
Sets the permissions that will be used for newly added files.
int size() const
Returns the number of items in the list.
~QZipReader()
Desctructor.
bool setPermissions(Permissions permissionSpec)
Sets the permissions for the file to the permissions specified.
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
int size() const
Returns the number of bytes in this byte array.
static QDateTime readMSDosDate(const uchar *src)
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
void close()
Closes the zip file.
QZipWriter(const QString &fileName, QIODevice::OpenMode mode=(QIODevice::WriteOnly|QIODevice::Truncate))
Create a new zip archive that operates on the archive filename.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
int year() const
Returns the year of this date.
QTime time() const
Returns the time part of the datetime.
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using '/' as file separator.
int count() const
Return the number of items in the zip archive.
FileError error() const
Returns the file error status.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
uint isDir
A boolean type indicating if the entry is a directory.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
The QFileInfo class provides system-independent file information.
static quint32 permissionsToMode(QFile::Permissions perms)
the QZipWriter class provides a way to create a new zip archive.
The QIODevice class is the base interface class of all I/O devices in Qt.
virtual void close()
Calls QFile::flush() and closes the file.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
static QString fileName(const QString &fileUrl)
FileInfo & operator=(const FileInfo &other)
QString absolutePath() const
Returns a file's path absolute path.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
FileInfo entryInfoAt(int index) const
Returns a FileInfo of an entry in the zipfile.
static QDir root()
Returns the root directory.
uchar num_dir_entries_this_disk[2]
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
int hour() const
Returns the hour part (0 to 23) of the time.
static void copyUInt(uchar *dest, const uchar *src)
static void writeUInt(uchar *data, uint i)