FFSM++  1.1.0
French Forest Sector Model ++
ZipPrivate Class Reference

#include <zip_p.h>

Public Member Functions

 ZipPrivate ()
 
virtual ~ZipPrivate ()
 
Zip::ErrorCode createArchive (QIODevice *device)
 
Zip::ErrorCode closeArchive ()
 
void reset ()
 
bool zLibInit ()
 
Zip::ErrorCode createEntry (const QFileInfo &file, const QString &root, Zip::CompressionLevel level)
 
Zip::CompressionLevel detectCompressionByMime (const QString &ext)
 
void encryptBytes (quint32 *keys, char *buffer, qint64 read)
 
void setULong (quint32 v, char *buffer, unsigned int offset)
 
void updateKeys (quint32 *keys, int c) const
 
void initKeys (quint32 *keys) const
 
int decryptByte (quint32 key2) const
 
QString extractRoot (const QString &p)
 

Public Attributes

QMap< QString, ZipEntryP * > * headers
 
QIODevice * device
 
char buffer1 [ZIP_READ_BUFFER]
 
char buffer2 [ZIP_READ_BUFFER]
 
unsigned char * uBuffer
 
const quint32 * crcTable
 
QString comment
 
QString password
 

Detailed Description

Definition at line 54 of file zip_p.h.

Constructor & Destructor Documentation

Definition at line 500 of file zip.cpp.

501 {
502  headers = 0;
503  device = 0;
504 
505  // keep an unsigned pointer so we avoid to over bloat the code with casts
506  uBuffer = (unsigned char*) buffer1;
507  crcTable = (quint32*) get_crc_table();
508 }
unsigned char * uBuffer
Definition: zip_p.h:67
QIODevice * device
Definition: zip_p.h:62
const quint32 * crcTable
Definition: zip_p.h:69
char buffer1[ZIP_READ_BUFFER]
Definition: zip_p.h:64
QMap< QString, ZipEntryP * > * headers
Definition: zip_p.h:60
~ZipPrivate ( )
virtual

Definition at line 511 of file zip.cpp.

512 {
513  closeArchive();
514 }
Zip::ErrorCode closeArchive()
Definition: zip.cpp:1014

Here is the call graph for this function:

Member Function Documentation

Zip::ErrorCode closeArchive ( )

Closes the current archive and writes out pending data.

Todo:
See if we can detect QFile objects using the Qt Meta Object System
Todo:
SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System
Todo:
SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System
Todo:
SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System

Definition at line 1014 of file zip.cpp.

Referenced by Zip::closeArchive().

1015 {
1016  // Close current archive by writing out central directory
1017  // and free up resources
1018 
1019  if (device == 0)
1020  return Zip::Ok;
1021 
1022  if (headers == 0)
1023  return Zip::Ok;
1024 
1025  const ZipEntryP* h;
1026 
1027  unsigned int sz;
1028  quint32 szCentralDir = 0;
1029  quint32 offCentralDir = device->pos();
1030 
1031  for (QMap<QString,ZipEntryP*>::ConstIterator itr = headers->constBegin(); itr != headers->constEnd(); ++itr)
1032  {
1033  h = itr.value();
1034 
1035  // signature
1036  buffer1[0] = 'P';
1037  buffer1[1] = 'K';
1038  buffer1[2] = 0x01;
1039  buffer1[3] = 0x02;
1040 
1041  // version made by (currently only MS-DOS/FAT - no symlinks or other stuff supported)
1043 
1044  // version needed to extract
1046  buffer1[ZIP_CD_OFF_VERSION + 1] = 0;
1047 
1048  // general purpose flag
1049  buffer1[ZIP_CD_OFF_GPFLAG] = h->gpFlag[0];
1050  buffer1[ZIP_CD_OFF_GPFLAG + 1] = h->gpFlag[1];
1051 
1052  // compression method
1053  buffer1[ZIP_CD_OFF_CMET] = h->compMethod & 0xFF;
1054  buffer1[ZIP_CD_OFF_CMET + 1] = (h->compMethod >> 8) & 0xFF;
1055 
1056  // last mod file time
1057  buffer1[ZIP_CD_OFF_MODT] = h->modTime[0];
1058  buffer1[ZIP_CD_OFF_MODT + 1] = h->modTime[1];
1059 
1060  // last mod file date
1061  buffer1[ZIP_CD_OFF_MODD] = h->modDate[0];
1062  buffer1[ZIP_CD_OFF_MODD + 1] = h->modDate[1];
1063 
1064  // crc (4bytes) [16,17,18,19]
1066 
1067  // compressed size (4bytes: [20,21,22,23])
1069 
1070  // uncompressed size [24,25,26,27]
1072 
1073  // filename
1074  //QByteArray fileNameBytes = itr.key().toAscii();
1075  QByteArray fileNameBytes = itr.key().toLatin1();
1076  sz = fileNameBytes.size();
1077  buffer1[ZIP_CD_OFF_NAMELEN] = sz & 0xFF;
1078  buffer1[ZIP_CD_OFF_NAMELEN + 1] = (sz >> 8) & 0xFF;
1079 
1080  // extra field length
1082 
1083  // file comment length
1085 
1086  // disk number start
1088 
1089  // internal file attributes
1091 
1092  // external file attributes
1094  buffer1[ZIP_CD_OFF_EATTR + 1] =
1095  buffer1[ZIP_CD_OFF_EATTR + 2] =
1096  buffer1[ZIP_CD_OFF_EATTR + 3] = 0;
1097 
1098  // relative offset of local header [42->45]
1100 
1101  if (device->write(buffer1, ZIP_CD_SIZE) != ZIP_CD_SIZE)
1102  {
1103  //! \todo See if we can detect QFile objects using the Qt Meta Object System
1104  /*
1105  if (!device->remove())
1106  qDebug() << tr("Unable to delete corrupted archive: %1").arg(device->fileName());
1107  */
1108  return Zip::WriteFailed;
1109  }
1110 
1111  // Write out filename
1112  if ((unsigned int)device->write(fileNameBytes) != sz)
1113  {
1114  //! \todo SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System
1115  /*
1116  if (!device->remove())
1117  qDebug() << tr("Unable to delete corrupted archive: %1").arg(device->fileName());
1118  */
1119  return Zip::WriteFailed;
1120  }
1121 
1122  szCentralDir += (ZIP_CD_SIZE + sz);
1123 
1124  } // central dir headers loop
1125 
1126 
1127  // Write end of central directory
1128 
1129  // signature
1130  buffer1[0] = 'P';
1131  buffer1[1] = 'K';
1132  buffer1[2] = 0x05;
1133  buffer1[3] = 0x06;
1134 
1135  // number of this disk
1137 
1138  // number of disk with central directory
1140 
1141  // number of entries in this disk
1142  sz = headers->count();
1143  buffer1[ZIP_EOCD_OFF_ENTRIES] = sz & 0xFF;
1144  buffer1[ZIP_EOCD_OFF_ENTRIES + 1] = (sz >> 8) & 0xFF;
1145 
1146  // total number of entries
1149 
1150  // size of central directory [12->15]
1151  setULong(szCentralDir, buffer1, ZIP_EOCD_OFF_CDSIZE);
1152 
1153  // central dir offset [16->19]
1154  setULong(offCentralDir, buffer1, ZIP_EOCD_OFF_CDOFF);
1155 
1156  // ZIP file comment length
1157  //QByteArray commentBytes = comment.toAscii();
1158  QByteArray commentBytes = comment.toLatin1();
1159  quint16 commentLength = commentBytes.size();
1160 
1161  if (commentLength == 0)
1162  {
1164  }
1165  else
1166  {
1167  buffer1[ZIP_EOCD_OFF_COMMLEN] = commentLength & 0xFF;
1168  buffer1[ZIP_EOCD_OFF_COMMLEN + 1] = (commentLength >> 8) & 0xFF;
1169  }
1170 
1171  if (device->write(buffer1, ZIP_EOCD_SIZE) != ZIP_EOCD_SIZE)
1172  {
1173  //! \todo SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System
1174  /*
1175  if (!device->remove())
1176  qDebug() << tr("Unable to delete corrupted archive: %1").arg(device->fileName());
1177  */
1178  return Zip::WriteFailed;
1179  }
1180 
1181  if (commentLength != 0)
1182  {
1183  if ((unsigned int)device->write(commentBytes) != commentLength)
1184  {
1185  //! \todo SAME AS ABOVE: See if we can detect QFile objects using the Qt Meta Object System
1186  /*
1187  if (!device->remove())
1188  qDebug() << tr("Unable to delete corrupted archive: %1").arg(device->fileName());
1189  */
1190  return Zip::WriteFailed;
1191  }
1192  }
1193 
1194  return Zip::Ok;
1195 }
#define ZIP_CD_OFF_USIZE
Definition: zip.cpp:83
#define ZIP_CD_OFF_LHOFF
Definition: zip.cpp:90
Definition: zip.h:50
quint16 compMethod
Definition: zipentry_p.h:64
#define ZIP_EOCD_OFF_CDDISKNUM
Definition: zip.cpp:94
unsigned char modTime[2]
Definition: zipentry_p.h:65
quint32 lhOffset
Definition: zipentry_p.h:61
#define ZIP_CD_OFF_IATTR
Definition: zip.cpp:88
#define ZIP_EOCD_OFF_DISKNUM
Definition: zip.cpp:93
#define ZIP_EOCD_OFF_CDENTRIES
Definition: zip.cpp:96
#define ZIP_CD_OFF_MADEBY
Definition: zip.cpp:75
#define ZIP_EOCD_OFF_CDSIZE
Definition: zip.cpp:97
#define ZIP_EOCD_OFF_ENTRIES
Definition: zip.cpp:95
#define ZIP_EOCD_OFF_CDOFF
Definition: zip.cpp:98
QString comment
Definition: zip_p.h:71
#define ZIP_CD_OFF_CRC
Definition: zip.cpp:81
#define ZIP_CD_OFF_MODT
Definition: zip.cpp:79
#define ZIP_CD_OFF_CMET
Definition: zip.cpp:78
#define ZIP_EOCD_SIZE
End of Central Directory record size (signature included)
Definition: zip.cpp:55
#define ZIP_CD_OFF_XLEN
Definition: zip.cpp:85
#define ZIP_VERSION
PKZip version for archives created by this API.
Definition: zip.cpp:102
QIODevice * device
Definition: zip_p.h:62
#define ZIP_CD_OFF_EATTR
Definition: zip.cpp:89
#define ZIP_CD_SIZE
Central Directory record size (signature included)
Definition: zip.cpp:53
#define ZIP_EOCD_OFF_COMMLEN
Definition: zip.cpp:99
#define ZIP_CD_OFF_DISKSTART
Definition: zip.cpp:87
#define ZIP_CD_OFF_MODD
Definition: zip.cpp:80
#define ZIP_CD_OFF_VERSION
Definition: zip.cpp:76
#define ZIP_CD_OFF_GPFLAG
Definition: zip.cpp:77
char buffer1[ZIP_READ_BUFFER]
Definition: zip_p.h:64
unsigned char gpFlag[2]
Definition: zipentry_p.h:63
QMap< QString, ZipEntryP * > * headers
Definition: zip_p.h:60
quint32 szUncomp
Definition: zipentry_p.h:69
unsigned char modDate[2]
Definition: zipentry_p.h:66
void setULong(quint32 v, char *buffer, unsigned int offset)
Definition: zip.cpp:930
#define ZIP_CD_OFF_NAMELEN
Definition: zip.cpp:84
#define ZIP_CD_OFF_COMMLEN
Definition: zip.cpp:86
#define ZIP_CD_OFF_CSIZE
Definition: zip.cpp:82
quint32 szComp
Definition: zipentry_p.h:68
quint32 crc
Definition: zipentry_p.h:67

Here is the caller graph for this function:

Zip::ErrorCode createArchive ( QIODevice *  device)

Definition at line 517 of file zip.cpp.

Referenced by Zip::createArchive().

518 {
519  Q_ASSERT(dev != 0);
520 
521  if (device != 0)
522  closeArchive();
523 
524  device = dev;
525 
526  if (!device->isOpen())
527  {
528  if (!device->open(QIODevice::ReadOnly)) {
529  delete device;
530  device = 0;
531  qDebug() << "Unable to open device for writing.";
532  return Zip::OpenFailed;
533  }
534  }
535 
536  headers = new QMap<QString,ZipEntryP*>;
537  return Zip::Ok;
538 }
Definition: zip.h:50
QIODevice * device
Definition: zip_p.h:62
QMap< QString, ZipEntryP * > * headers
Definition: zip_p.h:60
Zip::ErrorCode closeArchive()
Definition: zip.cpp:1014

Here is the call graph for this function:

Here is the caller graph for this function:

Zip::ErrorCode createEntry ( const QFileInfo &  file,
const QString &  root,
Zip::CompressionLevel  level 
)
Todo:
Automatic level detection (cpu, extension & file size)

Definition at line 541 of file zip.cpp.

Referenced by Zip::addDirectory().

542 {
543  //! \todo Automatic level detection (cpu, extension & file size)
544 
545  // Directories and very small files are always stored
546  // (small files would get bigger due to the compression headers overhead)
547 
548  // Need this for zlib
549  bool isPNGFile = false;
550  bool dirOnly = file.isDir();
551 
552  QString entryName = root;
553 
554  // Directory entry
555  if (dirOnly)
556  level = Zip::Store;
557  else
558  {
559  entryName.append(file.fileName());
560 
561  QString ext = file.completeSuffix().toLower();
562  isPNGFile = ext == "png";
563 
564  if (file.size() < ZIP_COMPRESSION_THRESHOLD)
565  level = Zip::Store;
566  else
567  switch (level)
568  {
569  case Zip::AutoCPU:
570  level = Zip::Deflate5;
571  break;
572  case Zip::AutoMIME:
573  level = detectCompressionByMime(ext);
574  break;
575  case Zip::AutoFull:
576  level = detectCompressionByMime(ext);
577  break;
578  default:
579  ;
580  }
581  }
582 
583  // entryName contains the path as it should be written
584  // in the zip file records
585  // qDebug() << QString("addDir(file=%1, root=%2, entry=%3)").arg(file.absoluteFilePath(), root, entryName);
586 
587  // create header and store it to write a central directory later
588  ZipEntryP* h = new ZipEntryP;
589 
590  h->compMethod = (level == Zip::Store) ? 0 : 0x0008;
591 
592  // Set encryption bit and set the data descriptor bit
593  // so we can use mod time instead of crc for password check
594  bool encrypt = !dirOnly && !password.isEmpty();
595  if (encrypt)
596  h->gpFlag[0] |= 9;
597 
598  QDateTime dt = file.lastModified();
599  QDate d = dt.date();
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;
603  h->modDate[0] |= d.day();
604 
605  QTime t = dt.time();
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;
610 
611  h->szUncomp = dirOnly ? 0 : file.size();
612 
613  // **** Write local file header ****
614 
615  // signature
616  buffer1[0] = 'P'; buffer1[1] = 'K';
617  buffer1[2] = 0x3; buffer1[3] = 0x4;
618 
619  // version needed to extract
621  buffer1[ZIP_LH_OFF_VERS + 1] = 0;
622 
623  // general purpose flag
625  buffer1[ZIP_LH_OFF_GPFLAG + 1] = h->gpFlag[1];
626 
627  // compression method
628  buffer1[ZIP_LH_OFF_CMET] = h->compMethod & 0xFF;
629  buffer1[ZIP_LH_OFF_CMET + 1] = (h->compMethod>>8) & 0xFF;
630 
631  // last mod file time
633  buffer1[ZIP_LH_OFF_MODT + 1] = h->modTime[1];
634 
635  // last mod file date
637  buffer1[ZIP_LH_OFF_MODD + 1] = h->modDate[1];
638 
639  // skip crc (4bytes) [14,15,16,17]
640 
641  // skip compressed size but include evtl. encryption header (4bytes: [18,19,20,21])
645  buffer1[ZIP_LH_OFF_CSIZE + 3] = 0;
646 
647  h->szComp = encrypt ? ZIP_LOCAL_ENC_HEADER_SIZE : 0;
648 
649  // uncompressed size [22,23,24,25]
651 
652  // filename length
653  //QByteArray entryNameBytes = entryName.toAscii();
654  QByteArray entryNameBytes = entryName.toLatin1(); // Qt5
655  int sz = entryNameBytes.size();
656 
657  buffer1[ZIP_LH_OFF_NAMELEN] = sz & 0xFF;
658  buffer1[ZIP_LH_OFF_NAMELEN + 1] = (sz >> 8) & 0xFF;
659 
660  // extra field length
662 
663  // Store offset to write crc and compressed size
664  h->lhOffset = device->pos();
665  quint32 crcOffset = h->lhOffset + ZIP_LH_OFF_CRC;
666 
668  {
669  delete h;
670  return Zip::WriteFailed;
671  }
672 
673  // Write out filename
674  if (device->write(entryNameBytes) != sz)
675  {
676  delete h;
677  return Zip::WriteFailed;
678  }
679 
680  // Encryption keys
681  quint32 keys[3] = { 0, 0, 0 };
682 
683  if (encrypt)
684  {
685  // **** encryption header ****
686 
687  // XOR with PI to ensure better random numbers
688  // with poorly implemented rand() as suggested by Info-Zip
689  srand(time(NULL) ^ 3141592654UL);
690  int randByte;
691 
692  initKeys(keys);
693  for (int i=0; i<10; ++i)
694  {
695  randByte = (rand() >> 7) & 0xff;
696  buffer1[i] = decryptByte(keys[2]) ^ randByte;
697  updateKeys(keys, randByte);
698  }
699 
700  // Encrypt encryption header
701  initKeys(keys);
702  for (int i=0; i<10; ++i)
703  {
704  randByte = decryptByte(keys[2]);
705  updateKeys(keys, buffer1[i]);
706  buffer1[i] ^= randByte;
707  }
708 
709  // We don't know the CRC at this time, so we use the modification time
710  // as the last two bytes
711  randByte = decryptByte(keys[2]);
712  updateKeys(keys, h->modTime[0]);
713  buffer1[10] ^= randByte;
714 
715  randByte = decryptByte(keys[2]);
716  updateKeys(keys, h->modTime[1]);
717  buffer1[11] ^= randByte;
718 
719  // Write out encryption header
721  {
722  delete h;
723  return Zip::WriteFailed;
724  }
725  }
726 
727  qint64 written = 0;
728  quint32 crc = crc32(0L, Z_NULL, 0);
729 
730  if (!dirOnly)
731  {
732  QFile actualFile(file.absoluteFilePath());
733  if (!actualFile.open(QIODevice::ReadOnly))
734  {
735  qDebug() << QString("An error occurred while opening %1").arg(file.absoluteFilePath());
736  return Zip::OpenFailed;
737  }
738 
739  // Write file data
740  qint64 read = 0;
741  qint64 totRead = 0;
742  qint64 toRead = actualFile.size();
743 
744  if (level == Zip::Store)
745  {
746  while ( (read = actualFile.read(buffer1, ZIP_READ_BUFFER)) > 0 )
747  {
748  crc = crc32(crc, uBuffer, read);
749 
750  if (password != 0)
751  encryptBytes(keys, buffer1, read);
752 
753  if ( (written = device->write(buffer1, read)) != read )
754  {
755  actualFile.close();
756  delete h;
757  return Zip::WriteFailed;
758  }
759  }
760  }
761  else
762  {
763  z_stream zstr;
764 
765  // Initialize zalloc, zfree and opaque before calling the init function
766  zstr.zalloc = Z_NULL;
767  zstr.zfree = Z_NULL;
768  zstr.opaque = Z_NULL;
769 
770  int zret;
771 
772  // Use deflateInit2 with negative windowBits to get raw compression
773  if ((zret = deflateInit2_(
774  &zstr,
775  (int)level,
776  Z_DEFLATED,
777  -MAX_WBITS,
778  8,
779  isPNGFile ? Z_RLE : Z_DEFAULT_STRATEGY,
780  ZLIB_VERSION,
781  sizeof(z_stream)
782  )) != Z_OK )
783  {
784  actualFile.close();
785  qDebug() << "Could not initialize zlib for compression";
786  delete h;
787  return Zip::ZlibError;
788  }
789 
790  qint64 compressed;
791 
792  int flush = Z_NO_FLUSH;
793 
794  do
795  {
796  read = actualFile.read(buffer1, ZIP_READ_BUFFER);
797  totRead += read;
798 
799  if (read == 0)
800  break;
801  if (read < 0)
802  {
803  actualFile.close();
804  deflateEnd(&zstr);
805  qDebug() << QString("Error while reading %1").arg(file.absoluteFilePath());
806  delete h;
807  return Zip::ReadFailed;
808  }
809 
810  crc = crc32(crc, uBuffer, read);
811 
812  zstr.next_in = (Bytef*) buffer1;
813  zstr.avail_in = (uInt)read;
814 
815  // Tell zlib if this is the last chunk we want to encode
816  // by setting the flush parameter to Z_FINISH
817  flush = (totRead == toRead) ? Z_FINISH : Z_NO_FLUSH;
818 
819  // Run deflate() on input until output buffer not full
820  // finish compression if all of source has been read in
821  do
822  {
823  zstr.next_out = (Bytef*) buffer2;
824  zstr.avail_out = ZIP_READ_BUFFER;
825 
826  zret = deflate(&zstr, flush);
827  // State not clobbered
828  Q_ASSERT(zret != Z_STREAM_ERROR);
829 
830  // Write compressed data to file and empty buffer
831  compressed = ZIP_READ_BUFFER - zstr.avail_out;
832 
833  if (password != 0)
834  encryptBytes(keys, buffer2, compressed);
835 
836  if (device->write(buffer2, compressed) != compressed)
837  {
838  deflateEnd(&zstr);
839  actualFile.close();
840  qDebug() << QString("Error while writing %1").arg(file.absoluteFilePath());
841  delete h;
842  return Zip::WriteFailed;
843  }
844 
845  written += compressed;
846 
847  } while (zstr.avail_out == 0);
848 
849  // All input will be used
850  Q_ASSERT(zstr.avail_in == 0);
851 
852  } while (flush != Z_FINISH);
853 
854  // Stream will be complete
855  Q_ASSERT(zret == Z_STREAM_END);
856 
857  deflateEnd(&zstr);
858 
859  } // if (level != STORE)
860 
861  actualFile.close();
862  }
863 
864  // Store end of entry offset
865  quint32 current = device->pos();
866 
867  // Update crc and compressed size in local header
868  if (!device->seek(crcOffset))
869  {
870  delete h;
871  return Zip::SeekFailed;
872  }
873 
874  h->crc = dirOnly ? 0 : crc;
875  h->szComp += written;
876 
877  setULong(h->crc, buffer1, 0);
878  setULong(h->szComp, buffer1, 4);
879  if ( device->write(buffer1, 8) != 8)
880  {
881  delete h;
882  return Zip::WriteFailed;
883  }
884 
885  // Seek to end of entry
886  if (!device->seek(current))
887  {
888  delete h;
889  return Zip::SeekFailed;
890  }
891 
892  if ((h->gpFlag[0] & 8) == 8)
893  {
894  // Write data descriptor
895 
896  // Signature: PK\7\8
897  buffer1[0] = 'P';
898  buffer1[1] = 'K';
899  buffer1[2] = 0x07;
900  buffer1[3] = 0x08;
901 
902  // CRC
904 
905  // Compressed size
907 
908  // Uncompressed size
910 
912  {
913  delete h;
914  return Zip::WriteFailed;
915  }
916  }
917 
918  headers->insert(entryName, h);
919  return Zip::Ok;
920 }
unsigned char * uBuffer
Definition: zip_p.h:67
#define ZIP_READ_BUFFER
Definition: zip_p.h:52
#define ZIP_LH_OFF_CSIZE
Definition: zip.cpp:64
#define ZIP_LH_OFF_MODT
Definition: zip.cpp:61
Definition: zip.h:50
quint16 compMethod
Definition: zipentry_p.h:64
void initKeys(quint32 *keys) const
Definition: zip.cpp:939
#define ZIP_LH_OFF_MODD
Definition: zip.cpp:62
unsigned char modTime[2]
Definition: zipentry_p.h:65
quint32 lhOffset
Definition: zipentry_p.h:61
void updateKeys(quint32 *keys, int c) const
Definition: zip.cpp:957
#define ZIP_COMPRESSION_THRESHOLD
Do not store very small files as the compression headers overhead would be to big.
Definition: zip.cpp:105
#define ZIP_LH_OFF_CRC
Definition: zip.cpp:63
#define ZIP_LH_OFF_CMET
Definition: zip.cpp:60
char buffer2[ZIP_READ_BUFFER]
Definition: zip_p.h:65
#define ZIP_LH_OFF_GPFLAG
Definition: zip.cpp:59
#define ZIP_LH_OFF_USIZE
Definition: zip.cpp:65
#define ZIP_DD_OFF_USIZE
Definition: zip.cpp:72
#define ZIP_LOCAL_ENC_HEADER_SIZE
Encryption header size.
Definition: zip.cpp:49
#define ZIP_VERSION
PKZip version for archives created by this API.
Definition: zip.cpp:102
QIODevice * device
Definition: zip_p.h:62
QString password
Definition: zip_p.h:72
Definition: zip.h:64
Zip::CompressionLevel detectCompressionByMime(const QString &ext)
Definition: zip.cpp:979
#define ZIP_DD_OFF_CRC32
Definition: zip.cpp:70
void encryptBytes(quint32 *keys, char *buffer, qint64 read)
Definition: zip.cpp:966
#define ZIP_LH_OFF_VERS
Definition: zip.cpp:58
int decryptByte(quint32 key2) const
Definition: zip.cpp:923
char buffer1[ZIP_READ_BUFFER]
Definition: zip_p.h:64
unsigned char gpFlag[2]
Definition: zipentry_p.h:63
QMap< QString, ZipEntryP * > * headers
Definition: zip_p.h:60
#define ZIP_LH_OFF_XLEN
Definition: zip.cpp:67
quint32 szUncomp
Definition: zipentry_p.h:69
#define ZIP_LOCAL_HEADER_SIZE
Local header size (including signature, excluding variable length fields)
Definition: zip.cpp:47
#define ZIP_DD_OFF_CSIZE
Definition: zip.cpp:71
unsigned char modDate[2]
Definition: zipentry_p.h:66
void setULong(quint32 v, char *buffer, unsigned int offset)
Definition: zip.cpp:930
#define ZIP_LH_OFF_NAMELEN
Definition: zip.cpp:66
#define ZIP_DD_SIZE_WS
Data descriptor size (signature included)
Definition: zip.cpp:51
quint32 szComp
Definition: zipentry_p.h:68
quint32 crc
Definition: zipentry_p.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

int decryptByte ( quint32  key2) const
inline

Definition at line 923 of file zip.cpp.

924 {
925  quint16 temp = ((quint16)(key2) & 0xffff) | 2;
926  return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
927 }
Zip::CompressionLevel detectCompressionByMime ( const QString &  ext)

Definition at line 979 of file zip.cpp.

980 {
981  // files really hard to compress
982  if ((ext == "png") ||
983  (ext == "jpg") ||
984  (ext == "jpeg") ||
985  (ext == "mp3") ||
986  (ext == "ogg") ||
987  (ext == "ogm") ||
988  (ext == "avi") ||
989  (ext == "mov") ||
990  (ext == "rm") ||
991  (ext == "ra") ||
992  (ext == "zip") ||
993  (ext == "rar") ||
994  (ext == "bz2") ||
995  (ext == "gz") ||
996  (ext == "7z") ||
997  (ext == "z") ||
998  (ext == "jar")
999  ) return Zip::Store;
1000 
1001  // files slow and hard to compress
1002  if ((ext == "exe") ||
1003  (ext == "bin") ||
1004  (ext == "rpm") ||
1005  (ext == "deb")
1006  ) return Zip::Deflate2;
1007 
1008  return Zip::Deflate9;
1009 }
Definition: zip.h:64
void encryptBytes ( quint32 *  keys,
char *  buffer,
qint64  read 
)
inline

Definition at line 966 of file zip.cpp.

967 {
968  char t;
969 
970  for (int i=0; i<(int)read; ++i)
971  {
972  t = buffer[i];
973  buffer[i] ^= decryptByte(keys[2]);
974  updateKeys(keys, t);
975  }
976 }
void updateKeys(quint32 *keys, int c) const
Definition: zip.cpp:957
int decryptByte(quint32 key2) const
Definition: zip.cpp:923
QString extractRoot ( const QString &  p)
inline

Definition at line 1213 of file zip.cpp.

Referenced by Zip::addDirectory().

1214 {
1215  QDir d(QDir::cleanPath(p));
1216  if (!d.exists())
1217  return QString();
1218 
1219  if (!d.cdUp())
1220  return QString();
1221 
1222  return d.absolutePath();
1223 }

Here is the caller graph for this function:

void initKeys ( quint32 *  keys) const
inline

Definition at line 939 of file zip.cpp.

940 {
941  // Encryption keys initialization constants are taken from the
942  // PKZip file format specification docs
943  keys[0] = 305419896L;
944  keys[1] = 591751049L;
945  keys[2] = 878082192L;
946 
947  //QByteArray pwdBytes = password.toAscii();
948  QByteArray pwdBytes = password.toLatin1();
949  int sz = pwdBytes.size();
950  const char* ascii = pwdBytes.data();
951 
952  for (int i=0; i<sz; ++i)
953  updateKeys(keys, (int)ascii[i]);
954 }
void updateKeys(quint32 *keys, int c) const
Definition: zip.cpp:957
QString password
Definition: zip_p.h:72

Here is the call graph for this function:

void reset ( )

Definition at line 1198 of file zip.cpp.

Referenced by Zip::closeArchive().

1199 {
1200  comment.clear();
1201 
1202  if (headers != 0)
1203  {
1204  qDeleteAll(*headers);
1205  delete headers;
1206  headers = 0;
1207  }
1208 
1209  delete device; device = 0;
1210 }
QString comment
Definition: zip_p.h:71
QIODevice * device
Definition: zip_p.h:62
QMap< QString, ZipEntryP * > * headers
Definition: zip_p.h:60

Here is the caller graph for this function:

void setULong ( quint32  v,
char *  buffer,
unsigned int  offset 
)
inline

Definition at line 930 of file zip.cpp.

931 {
932  buffer[offset+3] = ((v >> 24) & 0xFF);
933  buffer[offset+2] = ((v >> 16) & 0xFF);
934  buffer[offset+1] = ((v >> 8) & 0xFF);
935  buffer[offset] = (v & 0xFF);
936 }
void updateKeys ( quint32 *  keys,
int  c 
) const
inline

Definition at line 957 of file zip.cpp.

958 {
959  keys[0] = CRC32(keys[0], c);
960  keys[1] += keys[0] & 0xff;
961  keys[1] = keys[1] * 134775813L + 1;
962  keys[2] = CRC32(keys[2], ((int)keys[1]) >> 24);
963 }
#define CRC32(c, b)
This macro updates a one-char-only CRC; it&#39;s the Info-Zip macro re-adapted.
Definition: zip.cpp:108
bool zLibInit ( )

Member Data Documentation

char buffer1[ZIP_READ_BUFFER]

Definition at line 64 of file zip_p.h.

char buffer2[ZIP_READ_BUFFER]

Definition at line 65 of file zip_p.h.

QString comment

Definition at line 71 of file zip_p.h.

Referenced by Zip::archiveComment(), and Zip::setArchiveComment().

const quint32* crcTable

Definition at line 69 of file zip_p.h.

QIODevice* device

Definition at line 62 of file zip_p.h.

Referenced by Zip::addDirectory(), Zip::isOpen(), and Zip::setArchiveComment().

QMap<QString,ZipEntryP*>* headers

Definition at line 60 of file zip_p.h.

QString password

Definition at line 72 of file zip_p.h.

Referenced by Zip::clearPassword(), Zip::password(), and Zip::setPassword().

unsigned char* uBuffer

Definition at line 67 of file zip_p.h.


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