void createArchive()
{
quint32 tdstamp = dt.toTime_t ();
for (std::vector<std::string>::iterator it = _files.begin(); it != _files.end(); ++it)
{
quint32 signature, crc, compSize, unCompSize;
quint16 extractVersion, bitFlag, compMethod, modTime, modDate;
quint16 nameLen, extraLen;
signature = 0x04034b50;
extractVersion = 20;
bitFlag = 2;
compMethod = 8;
extraLen = 0;
modTime = 23818;
modDate = 15248;
return;
curfile.close();
unCompSize = curba.length();
crc = qChecksum(curba, unCompSize);
QtIOCompressor qtcmp(&buffer);
qtcmp.setStreamFormat(QtIOCompressor::RawZipFormat);
// compress file into the buffer
qtcmp.write(curba);
compSize = compressedFile.length();
nameLen = fname.length();
// uncompressed logic taken from the example in the solution
// st >> extractVersion >> bitFlag >> compMethod;
// s >> modTime >> modDate >> crc >> compSize >> unCompSize;
// s >> nameLen >> extraLen;
st << signature << extractVersion << bitFlag << compMethod << modTime << modDate;
st << /*tdstamp <<*/ crc << compSize << unCompSize << nameLen << extraLen;
st.writeRawData(fname.toAscii(), nameLen);
st.writeRawData(compressedFile, compSize);
}
archive.flush();
archive.close();
}
void createArchive()
{
QFile archive(_path);
archive.open(QIODevice::WriteOnly);
QDataStream st (&archive);
st.setByteOrder(QDataStream::LittleEndian);
QDateTime dt = QDateTime::currentDateTime();
quint32 tdstamp = dt.toTime_t ();
for (std::vector<std::string>::iterator it = _files.begin(); it != _files.end(); ++it)
{
quint32 signature, crc, compSize, unCompSize;
quint16 extractVersion, bitFlag, compMethod, modTime, modDate;
quint16 nameLen, extraLen;
signature = 0x04034b50;
extractVersion = 20;
bitFlag = 2;
compMethod = 8;
extraLen = 0;
modTime = 23818;
modDate = 15248;
QString itfpath (it->c_str());
QFileInfo finfo(it->c_str());
QString fname = finfo.fileName();
QFile curfile(itfpath);
if (! curfile.open(QIODevice::ReadOnly))
return;
QByteArray curba = curfile.readAll();
curfile.close();
unCompSize = curba.length();
crc = qChecksum(curba, unCompSize);
QByteArray compressedFile;
QBuffer buffer(&compressedFile);
QtIOCompressor qtcmp(&buffer);
qtcmp.setStreamFormat(QtIOCompressor::RawZipFormat);
qtcmp.open(QIODevice::WriteOnly);
// compress file into the buffer
qtcmp.write(curba);
compSize = compressedFile.length();
nameLen = fname.length();
// uncompressed logic taken from the example in the solution
// st >> extractVersion >> bitFlag >> compMethod;
// s >> modTime >> modDate >> crc >> compSize >> unCompSize;
// s >> nameLen >> extraLen;
st << signature << extractVersion << bitFlag << compMethod << modTime << modDate;
st << /*tdstamp <<*/ crc << compSize << unCompSize << nameLen << extraLen;
st.writeRawData(fname.toAscii(), nameLen);
st.writeRawData(compressedFile, compSize);
}
archive.flush();
archive.close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks