Qt 4.8
Public Functions | Public Variables | List of all members
QZipReaderPrivate Class Reference
Inheritance diagram for QZipReaderPrivate:
QZipPrivate

Public Functions

 QZipReaderPrivate (QIODevice *device, bool ownDev)
 
void scanFiles ()
 
- Public Functions inherited from QZipPrivate
void fillFileInfo (int index, QZipReader::FileInfo &fileInfo) const
 
 QZipPrivate (QIODevice *device, bool ownDev)
 
 ~QZipPrivate ()
 

Public Variables

QZipReader::Status status
 
- Public Variables inherited from QZipPrivate
QByteArray comment
 
QIODevicedevice
 
bool dirtyFileTree
 
QList< FileHeaderfileHeaders
 
bool ownDevice
 
uint start_of_directory
 

Detailed Description

Definition at line 430 of file qzip.cpp.

Constructors and Destructors

◆ QZipReaderPrivate()

QZipReaderPrivate::QZipReaderPrivate ( QIODevice device,
bool  ownDev 
)
inline

Definition at line 433 of file qzip.cpp.

434  : QZipPrivate(device, ownDev), status(QZipReader::NoError)
435  {
436  }
QZipReader::Status status
Definition: qzip.cpp:440
QZipPrivate(QIODevice *device, bool ownDev)
Definition: qzip.cpp:395

Functions

◆ scanFiles()

void QZipReaderPrivate::scanFiles ( )

Definition at line 479 of file qzip.cpp.

Referenced by QZipReader::count(), QZipReader::entryInfoAt(), QZipReader::fileData(), and QZipReader::fileInfoList().

480 {
481  if (!dirtyFileTree)
482  return;
483 
484  if (! (device->isOpen() || device->open(QIODevice::ReadOnly))) {
486  return;
487  }
488 
489  if ((device->openMode() & QIODevice::ReadOnly) == 0) { // only read the index from readable files.
491  return;
492  }
493 
494  dirtyFileTree = false;
495  uchar tmp[4];
496  device->read((char *)tmp, 4);
497  if (readUInt(tmp) != 0x04034b50) {
498  qWarning() << "QZip: not a zip file!";
499  return;
500  }
501 
502  // find EndOfDirectory header
503  int i = 0;
504  int start_of_directory = -1;
505  int num_dir_entries = 0;
506  EndOfDirectory eod;
507  while (start_of_directory == -1) {
508  int pos = device->size() - sizeof(EndOfDirectory) - i;
509  if (pos < 0 || i > 65535) {
510  qWarning() << "QZip: EndOfDirectory not found";
511  return;
512  }
513 
514  device->seek(pos);
515  device->read((char *)&eod, sizeof(EndOfDirectory));
516  if (readUInt(eod.signature) == 0x06054b50)
517  break;
518  ++i;
519  }
520 
521  // have the eod
522  start_of_directory = readUInt(eod.dir_start_offset);
523  num_dir_entries = readUShort(eod.num_dir_entries);
524  ZDEBUG("start_of_directory at %d, num_dir_entries=%d", start_of_directory, num_dir_entries);
525  int comment_length = readUShort(eod.comment_length);
526  if (comment_length != i)
527  qWarning() << "QZip: failed to parse zip file.";
528  comment = device->read(qMin(comment_length, i));
529 
530 
531  device->seek(start_of_directory);
532  for (i = 0; i < num_dir_entries; ++i) {
533  FileHeader header;
534  int read = device->read((char *) &header.h, sizeof(CentralFileHeader));
535  if (read < (int)sizeof(CentralFileHeader)) {
536  qWarning() << "QZip: Failed to read complete header, index may be incomplete";
537  break;
538  }
539  if (readUInt(header.h.signature) != 0x02014b50) {
540  qWarning() << "QZip: invalid header signature, index may be incomplete";
541  break;
542  }
543 
544  int l = readUShort(header.h.file_name_length);
545  header.file_name = device->read(l);
546  if (header.file_name.length() != l) {
547  qWarning() << "QZip: Failed to read filename from zip index, index may be incomplete";
548  break;
549  }
550  l = readUShort(header.h.extra_field_length);
551  header.extra_field = device->read(l);
552  if (header.extra_field.length() != l) {
553  qWarning() << "QZip: Failed to read extra field in zip file, skipping file, index may be incomplete";
554  break;
555  }
556  l = readUShort(header.h.file_comment_length);
557  header.file_comment = device->read(l);
558  if (header.file_comment.length() != l) {
559  qWarning() << "QZip: Failed to read read file comment, index may be incomplete";
560  break;
561  }
562 
563  ZDEBUG("found file '%s'", header.file_name.data());
564  fileHeaders.append(header);
565  }
566 }
uchar extra_field_length[2]
Definition: qzip.cpp:331
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QByteArray extra_field
Definition: qzip.cpp:356
uchar file_name_length[2]
Definition: qzip.cpp:330
#define ZDEBUG
Definition: qzip.cpp:90
static uint readUInt(const uchar *data)
Definition: qzip.cpp:95
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
unsigned char uchar
Definition: qglobal.h:994
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
QZipReader::Status status
Definition: qzip.cpp:440
static ushort readUShort(const uchar *data)
Definition: qzip.cpp:100
CentralFileHeader h
Definition: qzip.cpp:354
uchar signature[4]
Definition: qzip.cpp:321
Q_CORE_EXPORT void qWarning(const char *,...)
QList< FileHeader > fileHeaders
Definition: qzip.cpp:411
int length() const
Same as size().
Definition: qbytearray.h:356
QByteArray file_name
Definition: qzip.cpp:355
OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
Definition: qiodevice.cpp:465
QFactoryLoader * l
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QByteArray file_comment
Definition: qzip.cpp:357
QIODevice * device
Definition: qzip.cpp:408
bool dirtyFileTree
Definition: qzip.cpp:410
uchar file_comment_length[2]
Definition: qzip.cpp:332
QByteArray comment
Definition: qzip.cpp:412
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659
uint start_of_directory
Definition: qzip.cpp:413

Properties

◆ status

QZipReader::Status QZipReaderPrivate::status

Definition at line 440 of file qzip.cpp.

Referenced by QZipWriter::QZipWriter(), and QZipReader::status().


The documentation for this class was generated from the following file: