mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-07-10 13:29:52 -04:00
rbutil: Update vendored quazip from v1.3 to v1.5
Change-Id: Ife2678a7ef1f48020a3cc3b75dc87f725dd14068
This commit is contained in:
parent
1e3301388c
commit
f42d95b4a6
12 changed files with 287 additions and 260 deletions
|
|
@ -3,7 +3,7 @@ These files are distributed under the LGPL v2.1 or later. Only source files
|
|||
actually used in Rockbox Utility are included, further sources have been left
|
||||
out. Check the quazip source distribution for those.
|
||||
|
||||
The source files have been last synced with the project's release 1.3 at
|
||||
https://github.com/stachenov/quazip/ from April 16, 2022.
|
||||
The source files have been last synced with the project's release 1.6 at
|
||||
https://github.com/stachenov/quazip/ from March 5, 2025.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,51 +32,67 @@
|
|||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)
|
||||
voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc, voidpf file, int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopen64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,file,mode);
|
||||
else
|
||||
{
|
||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,file,mode);
|
||||
}
|
||||
auto func = pfilefunc->zfile_func64.zopen64_file != nullptr
|
||||
? pfilefunc->zfile_func64.zopen64_file
|
||||
: pfilefunc->zopen32_file;
|
||||
return (*func)(pfilefunc->zfile_func64.opaque, file, mode);
|
||||
}
|
||||
|
||||
int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
||||
namespace {
|
||||
|
||||
int zseek64(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
||||
else
|
||||
{
|
||||
uLong offsetTruncated = (uLong)offset;
|
||||
if (offsetTruncated != offset)
|
||||
return -1;
|
||||
else
|
||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
||||
}
|
||||
return (*pfilefunc->zfile_func64.zseek64_file)(pfilefunc->zfile_func64.opaque, filestream, offset, origin);
|
||||
}
|
||||
|
||||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
||||
|
||||
int zseek32(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
||||
else
|
||||
{
|
||||
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
||||
if ((tell_uLong) == ((uLong)-1))
|
||||
return (ZPOS64_T)-1;
|
||||
else
|
||||
return tell_uLong;
|
||||
}
|
||||
uLong offsetTruncated = static_cast<uLong>(offset);
|
||||
if (offsetTruncated != offset)
|
||||
return -1;
|
||||
return (*pfilefunc->zseek32_file)(pfilefunc->zfile_func64.opaque, filestream, offsetTruncated, origin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int call_zseek64(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
auto func = pfilefunc->zfile_func64.zseek64_file != nullptr ? zseek64 : zseek32;
|
||||
return (*func)(pfilefunc, filestream, offset, origin);
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
ZPOS64_T ztell64(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream)
|
||||
{
|
||||
return (*pfilefunc->zfile_func64.ztell64_file) (pfilefunc->zfile_func64.opaque, filestream);
|
||||
}
|
||||
|
||||
ZPOS64_T ztell32(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream)
|
||||
{
|
||||
uLong tell_uLong = (*pfilefunc->ztell32_file)(pfilefunc->zfile_func64.opaque, filestream);
|
||||
if (tell_uLong == static_cast<uLong>(-1))
|
||||
return static_cast<ZPOS64_T>(-1);
|
||||
return tell_uLong;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc, voidpf filestream)
|
||||
{
|
||||
auto *func = pfilefunc->zfile_func64.zseek64_file != nullptr ? ztell64 : ztell32;
|
||||
return (*func)(pfilefunc, filestream);
|
||||
|
||||
}
|
||||
|
||||
/// @cond internal
|
||||
struct QIODevice_descriptor {
|
||||
// Position only used for writing to sequential devices.
|
||||
qint64 pos;
|
||||
inline QIODevice_descriptor():
|
||||
pos(0)
|
||||
{}
|
||||
qint64 pos{0};
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
|
|
@ -94,28 +110,27 @@ voidpf ZCALLBACK qiodevice_open_file_func (
|
|||
desiredMode = QIODevice::ReadWrite;
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
desiredMode = QIODevice::WriteOnly;
|
||||
else
|
||||
return nullptr;
|
||||
if (iodevice->isOpen()) {
|
||||
if ((iodevice->openMode() & desiredMode) == desiredMode) {
|
||||
if (desiredMode != QIODevice::WriteOnly
|
||||
&& iodevice->isSequential()) {
|
||||
// We can use sequential devices only for writing.
|
||||
delete d;
|
||||
return nullptr;
|
||||
} else {
|
||||
if ((desiredMode & QIODevice::WriteOnly) != 0) {
|
||||
// open for writing, need to seek existing device
|
||||
if (!iodevice->isSequential()) {
|
||||
iodevice->seek(0);
|
||||
} else {
|
||||
d->pos = iodevice->pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
return iodevice;
|
||||
} else {
|
||||
if ((iodevice->openMode() & desiredMode) != desiredMode) {
|
||||
delete d;
|
||||
return nullptr;
|
||||
}
|
||||
if (desiredMode != QIODevice::WriteOnly && iodevice->isSequential()) {
|
||||
// We can use sequential devices only for writing.
|
||||
delete d;
|
||||
return nullptr;
|
||||
}
|
||||
if ((desiredMode & QIODevice::WriteOnly) != 0) {
|
||||
// open for writing, need to seek existing device
|
||||
if (!iodevice->isSequential()) {
|
||||
iodevice->seek(0);
|
||||
} else {
|
||||
d->pos = iodevice->pos();
|
||||
}
|
||||
}
|
||||
return iodevice;
|
||||
}
|
||||
iodevice->open(desiredMode);
|
||||
if (iodevice->isOpen()) {
|
||||
|
|
@ -124,13 +139,11 @@ voidpf ZCALLBACK qiodevice_open_file_func (
|
|||
iodevice->close();
|
||||
delete d;
|
||||
return nullptr;
|
||||
} else {
|
||||
return iodevice;
|
||||
}
|
||||
} else {
|
||||
delete d;
|
||||
return nullptr;
|
||||
return iodevice;
|
||||
}
|
||||
delete d;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -142,9 +155,9 @@ uLong ZCALLBACK qiodevice_read_file_func (
|
|||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
qint64 ret64 = iodevice->read((char*)buf,size);
|
||||
qint64 ret64 = iodevice->read(static_cast<char*>(buf),size);
|
||||
uLong ret;
|
||||
ret = (uLong) ret64;
|
||||
ret = static_cast<uLong>(ret64);
|
||||
if (ret64 != -1) {
|
||||
d->pos += ret64;
|
||||
}
|
||||
|
|
@ -165,7 +178,7 @@ uLong ZCALLBACK qiodevice_write_file_func (
|
|||
if (ret64 != -1) {
|
||||
d->pos += ret64;
|
||||
}
|
||||
ret = (uLong) ret64;
|
||||
ret = static_cast<uLong>(ret64);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -209,24 +222,22 @@ int ZCALLBACK qiodevice_seek_file_func (
|
|||
{
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
if (iodevice->isSequential()) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END
|
||||
&& offset == 0) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END && offset == 0) {
|
||||
// sequential devices are always at end (needed in mdAppend)
|
||||
return 0;
|
||||
} else {
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
uLong qiodevice_seek_result=0;
|
||||
int ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
|
||||
qiodevice_seek_result = (static_cast<QIODevice*>(stream))->pos() + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
|
||||
qiodevice_seek_result = (static_cast<QIODevice*>(stream))->size() - offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
qiodevice_seek_result = offset;
|
||||
|
|
@ -246,24 +257,22 @@ int ZCALLBACK qiodevice64_seek_file_func (
|
|||
{
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
if (iodevice->isSequential()) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END
|
||||
&& offset == 0) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END && offset == 0) {
|
||||
// sequential devices are always at end (needed in mdAppend)
|
||||
return 0;
|
||||
} else {
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
qint64 qiodevice_seek_result=0;
|
||||
int ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
|
||||
qiodevice_seek_result = (static_cast<QIODevice*>(stream))->pos() + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
|
||||
qiodevice_seek_result = (static_cast<QIODevice*>(stream))->size() - offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
qiodevice_seek_result = offset;
|
||||
|
|
|
|||
|
|
@ -79,10 +79,9 @@ class QuaZipPrivate {
|
|||
inline QTextCodec *getDefaultFileNameCodec()
|
||||
{
|
||||
if (defaultFileNameCodec == nullptr) {
|
||||
return QTextCodec::codecForLocale();
|
||||
} else {
|
||||
return defaultFileNameCodec;
|
||||
return QTextCodec::codecForLocale();
|
||||
}
|
||||
return defaultFileNameCodec;
|
||||
}
|
||||
/// The constructor for the corresponding QuaZip constructor.
|
||||
inline QuaZipPrivate(QuaZip *q):
|
||||
|
|
@ -245,9 +244,8 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
|
|||
if (p->zipName.isEmpty()) {
|
||||
qWarning("QuaZip::open(): set either ZIP file name or IO device first");
|
||||
return false;
|
||||
} else {
|
||||
ioDevice = new QFile(p->zipName);
|
||||
}
|
||||
ioDevice = new QFile(p->zipName);
|
||||
}
|
||||
unsigned flags = 0;
|
||||
switch(mode) {
|
||||
|
|
@ -267,25 +265,23 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
|
|||
}
|
||||
}
|
||||
}
|
||||
if(p->unzFile_f!=nullptr) {
|
||||
if (ioDevice->isSequential()) {
|
||||
unzClose(p->unzFile_f);
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
qWarning("QuaZip::open(): "
|
||||
"only mdCreate can be used with "
|
||||
"sequential devices");
|
||||
return false;
|
||||
}
|
||||
p->mode=mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
} else {
|
||||
p->zipError=UNZ_OPENERROR;
|
||||
if (p->unzFile_f == nullptr) {
|
||||
p->zipError = UNZ_OPENERROR;
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
if (ioDevice->isSequential()) {
|
||||
unzClose(p->unzFile_f);
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
qWarning("QuaZip::open(): only mdCreate can be used with sequential devices");
|
||||
return false;
|
||||
}
|
||||
p->mode = mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
|
||||
case mdCreate:
|
||||
case mdAppend:
|
||||
case mdAdd:
|
||||
|
|
@ -313,30 +309,28 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
|
|||
zipSetFlags(p->zipFile_f, flags);
|
||||
}
|
||||
}
|
||||
if(p->zipFile_f!=nullptr) {
|
||||
if (ioDevice->isSequential()) {
|
||||
if (mode != mdCreate) {
|
||||
zipClose(p->zipFile_f, nullptr);
|
||||
qWarning("QuaZip::open(): "
|
||||
"only mdCreate can be used with "
|
||||
"sequential devices");
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
|
||||
}
|
||||
p->mode=mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
} else {
|
||||
p->zipError=UNZ_OPENERROR;
|
||||
if(p->zipFile_f == nullptr) {
|
||||
p->zipError = UNZ_OPENERROR;
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
if (ioDevice->isSequential()) {
|
||||
if (mode != mdCreate) {
|
||||
zipClose(p->zipFile_f, nullptr);
|
||||
qWarning("QuaZip::open(): only mdCreate can be used with sequential devices");
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
|
||||
}
|
||||
p->mode=mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
|
||||
default:
|
||||
qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
|
||||
qWarning("QuaZip::open(): unknown mode: %d", static_cast<int>(mode));
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
|
|
@ -361,7 +355,7 @@ void QuaZip::close()
|
|||
: p->commentCodec->fromUnicode(p->comment).constData());
|
||||
break;
|
||||
default:
|
||||
qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
|
||||
qWarning("QuaZip::close(): unknown mode: %d", static_cast<int>(p->mode));
|
||||
return;
|
||||
}
|
||||
// opened by name, need to delete the internal IO device
|
||||
|
|
@ -395,7 +389,7 @@ void QuaZip::setIoDevice(QIODevice *ioDevice)
|
|||
|
||||
int QuaZip::getEntriesCount()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
QuaZip *fakeThis=const_cast<QuaZip*>(this); // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
|
||||
|
|
@ -404,12 +398,12 @@ int QuaZip::getEntriesCount()const
|
|||
unz_global_info64 globalInfo;
|
||||
if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
|
||||
return p->zipError;
|
||||
return (int)globalInfo.number_entry;
|
||||
return static_cast<int>(globalInfo.number_entry);
|
||||
}
|
||||
|
||||
QString QuaZip::getComment()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
QuaZip *fakeThis=const_cast<QuaZip*>(this); // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
|
||||
|
|
@ -518,17 +512,16 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
|
|||
if (info == nullptr) { // Very unlikely because of the overloads
|
||||
return false;
|
||||
}
|
||||
if (getCurrentFileInfo(&info64)) {
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
} else {
|
||||
if (!getCurrentFileInfo(&info64)) {
|
||||
return false;
|
||||
}
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
QuaZip *fakeThis=const_cast<QuaZip*>(this); // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode");
|
||||
|
|
@ -573,7 +566,7 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
|
|||
|
||||
QString QuaZip::getCurrentFileName()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
QuaZip *fakeThis=const_cast<QuaZip*>(this); // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode");
|
||||
|
|
@ -756,28 +749,25 @@ bool QuaZipPrivate::getFileInfoList(QList<TFileInfo> *result) const
|
|||
QStringList QuaZip::getFileNameList() const
|
||||
{
|
||||
QStringList list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
if (!p->getFileInfoList(&list))
|
||||
return QStringList();
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo> QuaZip::getFileInfoList() const
|
||||
{
|
||||
QList<QuaZipFileInfo> list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
if (!p->getFileInfoList(&list))
|
||||
return QList<QuaZipFileInfo>();
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
|
||||
{
|
||||
QList<QuaZipFileInfo64> list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
if (!p->getFileInfoList(&list))
|
||||
return QList<QuaZipFileInfo64>();
|
||||
return list;
|
||||
}
|
||||
|
||||
Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
|
||||
|
|
|
|||
|
|
@ -127,10 +127,6 @@ class QUAZIP_EXPORT QuaZip {
|
|||
CaseSensitivity cs);
|
||||
private:
|
||||
QuaZipPrivate *p;
|
||||
// not (and will not be) implemented
|
||||
QuaZip(const QuaZip& that);
|
||||
// not (and will not be) implemented
|
||||
QuaZip& operator=(const QuaZip& that);
|
||||
public:
|
||||
/// Constructs QuaZip object.
|
||||
/** Call setName() before opening constructed object. */
|
||||
|
|
@ -140,6 +136,10 @@ class QUAZIP_EXPORT QuaZip {
|
|||
/// Constructs QuaZip object associated with ZIP file represented by \a ioDevice.
|
||||
/** The IO device must be seekable, otherwise an error will occur when opening. */
|
||||
QuaZip(QIODevice *ioDevice);
|
||||
// not (and will not be) implemented
|
||||
QuaZip(const QuaZip& that) = delete;
|
||||
// not (and will not be) implemented
|
||||
QuaZip& operator=(const QuaZip& that) = delete;
|
||||
/// Destroys QuaZip object.
|
||||
/** Calls close() if necessary. */
|
||||
~QuaZip();
|
||||
|
|
@ -303,9 +303,9 @@ class QUAZIP_EXPORT QuaZip {
|
|||
QString getComment() const;
|
||||
/// Sets the global comment in the ZIP file.
|
||||
/** The comment will be written to the archive on close operation.
|
||||
* QuaZip makes a distinction between a null QByteArray() comment
|
||||
* and an empty "" comment in the QuaZip::mdAdd mode.
|
||||
* A null comment is the default and it means "don't change
|
||||
* QuaZip makes a distinction between a null QByteArray() comment
|
||||
* and an empty "" comment in the QuaZip::mdAdd mode.
|
||||
* A null comment is the default and it means "don't change
|
||||
* the comment". An empty comment removes the original comment.
|
||||
*
|
||||
* \sa open()
|
||||
|
|
|
|||
|
|
@ -30,10 +30,9 @@ inline bool quazip_close(QIODevice *device) {
|
|||
if (file != nullptr) {
|
||||
// We have to call the ugly commit() instead:
|
||||
return file->commit();
|
||||
} else {
|
||||
device->close();
|
||||
return true;
|
||||
}
|
||||
device->close();
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
inline bool quazip_close(QIODevice *device) {
|
||||
|
|
@ -104,16 +103,36 @@ inline QString quazip_symlink_target(const QFileInfo &fi) {
|
|||
}
|
||||
#endif
|
||||
|
||||
// deprecation
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||
#include <QtCore/QTimeZone>
|
||||
inline QDateTime quazip_since_epoch() {
|
||||
return QDateTime(QDate(1970, 1, 1), QTime(0, 0), QTimeZone::utc());
|
||||
}
|
||||
|
||||
inline QDateTime quazip_since_epoch_ntfs() {
|
||||
return QDateTime(QDate(1601, 1, 1), QTime(0, 0), QTimeZone::utc());
|
||||
}
|
||||
#else
|
||||
inline QDateTime quazip_since_epoch() {
|
||||
return QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
}
|
||||
|
||||
inline QDateTime quazip_since_epoch_ntfs() {
|
||||
return QDateTime(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
}
|
||||
#endif
|
||||
|
||||
// this is not a deprecation but an improvement, for a change
|
||||
#include <QtCore/QDateTime>
|
||||
#if (QT_VERSION >= 0x040700)
|
||||
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
QDateTime base = quazip_since_epoch_ntfs();
|
||||
return base.msecsTo(time) * 10000 + fineTicks;
|
||||
}
|
||||
#else
|
||||
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
QDateTime base = quazip_since_epoch_ntfs();
|
||||
QDateTime utc = time.toUTC();
|
||||
return (static_cast<qint64>(base.date().daysTo(utc.date()))
|
||||
* Q_INT64_C(86400000)
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const ch
|
|||
}
|
||||
if(p->zip->getMode()!=QuaZip::mdUnzip) {
|
||||
qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
|
||||
(int)mode, (int)p->zip->getMode());
|
||||
(int)mode, static_cast<int>(p->zip->getMode()));
|
||||
return false;
|
||||
}
|
||||
if(!p->zip->hasCurrentFile()) {
|
||||
|
|
@ -293,13 +293,13 @@ bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const ch
|
|||
return false;
|
||||
}
|
||||
}
|
||||
p->setZipError(unzOpenCurrentFile3(p->zip->getUnzFile(), method, level, (int)raw, password));
|
||||
if(p->zipError==UNZ_OK) {
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
return true;
|
||||
} else
|
||||
p->setZipError(unzOpenCurrentFile3(p->zip->getUnzFile(), method, level, static_cast<int>(raw), password));
|
||||
if(p->zipError != UNZ_OK) {
|
||||
return false;
|
||||
}
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
return true;
|
||||
}
|
||||
qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
|
||||
return false;
|
||||
|
|
@ -327,7 +327,7 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
|
|||
}
|
||||
if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) {
|
||||
qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
|
||||
(int)mode, (int)p->zip->getMode());
|
||||
(int)mode, static_cast<int>(p->zip->getMode()));
|
||||
return false;
|
||||
}
|
||||
info_z.tmz_date.tm_year=info.dateTime.date().year();
|
||||
|
|
@ -337,8 +337,8 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
|
|||
info_z.tmz_date.tm_min=info.dateTime.time().minute();
|
||||
info_z.tmz_date.tm_sec=info.dateTime.time().second();
|
||||
info_z.dosDate = 0;
|
||||
info_z.internal_fa=(uLong)info.internalAttr;
|
||||
info_z.external_fa=(uLong)info.externalAttr;
|
||||
info_z.internal_fa=static_cast<uLong>(info.internalAttr);
|
||||
info_z.external_fa=static_cast<uLong>(info.externalAttr);
|
||||
if (p->zip->isDataDescriptorWritingEnabled())
|
||||
zipSetFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
|
||||
else
|
||||
|
|
@ -353,23 +353,23 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
|
|||
p->zip->isUtf8Enabled()
|
||||
? info.comment.toUtf8().constData()
|
||||
: p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
|
||||
method, level, (int)raw,
|
||||
method, level, static_cast<int>(raw),
|
||||
windowBits, memLevel, strategy,
|
||||
password, (uLong)crc,
|
||||
password, static_cast<uLong>(crc),
|
||||
(p->zip->getOsCode() << 8) | QUAZIP_VERSION_MADE_BY,
|
||||
0,
|
||||
p->zip->isZip64Enabled()));
|
||||
if(p->zipError==UNZ_OK) {
|
||||
p->writePos=0;
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
if(raw) {
|
||||
p->crc=crc;
|
||||
p->uncompressedSize=info.uncompressedSize;
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
if (p->zipError != UNZ_OK) {
|
||||
return false;
|
||||
}
|
||||
p->writePos=0;
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
if(raw) {
|
||||
p->crc=crc;
|
||||
p->uncompressedSize=info.uncompressedSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
|
||||
return false;
|
||||
|
|
@ -395,8 +395,7 @@ qint64 QuaZipFile::pos()const
|
|||
// but thankfully bytesAvailable() returns the number of
|
||||
// bytes buffered, so we know how far ahead we are.
|
||||
return unztell64(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
|
||||
else
|
||||
return p->writePos;
|
||||
return p->writePos;
|
||||
}
|
||||
|
||||
bool QuaZipFile::atEnd()const
|
||||
|
|
@ -413,8 +412,7 @@ bool QuaZipFile::atEnd()const
|
|||
// the same problem as with pos()
|
||||
return QIODevice::bytesAvailable() == 0
|
||||
&& unzeof(p->zip->getUnzFile())==1;
|
||||
else
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::size()const
|
||||
|
|
@ -425,8 +423,7 @@ qint64 QuaZipFile::size()const
|
|||
}
|
||||
if(openMode()&ReadOnly)
|
||||
return p->raw?csize():usize();
|
||||
else
|
||||
return p->writePos;
|
||||
return p->writePos;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::csize()const
|
||||
|
|
@ -454,12 +451,11 @@ qint64 QuaZipFile::usize()const
|
|||
bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
|
||||
{
|
||||
QuaZipFileInfo64 info64;
|
||||
if (getFileInfo(&info64)) {
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
} else {
|
||||
if (!getFileInfo(&info64)) {
|
||||
return false;
|
||||
}
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info)
|
||||
|
|
@ -498,9 +494,9 @@ void QuaZipFile::close()
|
|||
qint64 QuaZipFile::readData(char *data, qint64 maxSize)
|
||||
{
|
||||
p->setZipError(UNZ_OK);
|
||||
qint64 bytesRead=unzReadCurrentFile(p->zip->getUnzFile(), data, (unsigned)maxSize);
|
||||
qint64 bytesRead=unzReadCurrentFile(p->zip->getUnzFile(), data, static_cast<unsigned>(maxSize));
|
||||
if (bytesRead < 0) {
|
||||
p->setZipError((int) bytesRead);
|
||||
p->setZipError(static_cast<int>(bytesRead));
|
||||
return -1;
|
||||
}
|
||||
return bytesRead;
|
||||
|
|
@ -509,12 +505,12 @@ qint64 QuaZipFile::readData(char *data, qint64 maxSize)
|
|||
qint64 QuaZipFile::writeData(const char* data, qint64 maxSize)
|
||||
{
|
||||
p->setZipError(ZIP_OK);
|
||||
p->setZipError(zipWriteInFileInZip(p->zip->getZipFile(), data, (uint)maxSize));
|
||||
if(p->zipError!=ZIP_OK) return -1;
|
||||
else {
|
||||
p->writePos+=maxSize;
|
||||
return maxSize;
|
||||
p->setZipError(zipWriteInFileInZip(p->zip->getZipFile(), data, static_cast<uint>(maxSize)));
|
||||
if (p->zipError != ZIP_OK) {
|
||||
return -1;
|
||||
}
|
||||
p->writePos += maxSize;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
QString QuaZipFile::getFileName() const
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
QuaZipFile& operator=(const QuaZipFile& that);
|
||||
protected:
|
||||
/// Implementation of the QIODevice::readData().
|
||||
qint64 readData(char *data, qint64 maxSize);
|
||||
qint64 readData(char *data, qint64 maxSize) override;
|
||||
/// Implementation of the QIODevice::writeData().
|
||||
qint64 writeData(const char *data, qint64 maxSize);
|
||||
qint64 writeData(const char *data, qint64 maxSize) override;
|
||||
public:
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** You should use setZipName() and setFileName() or setZip() before
|
||||
|
|
@ -174,7 +174,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
/** Closes file if open, destructs internal QuaZip object (if it
|
||||
* exists and \em is internal, of course).
|
||||
**/
|
||||
virtual ~QuaZipFile();
|
||||
~QuaZipFile() override;
|
||||
/// Returns the ZIP archive file name.
|
||||
/** If this object was created by passing QuaZip pointer to the
|
||||
* constructor, this function will return that QuaZip's file name
|
||||
|
|
@ -201,7 +201,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* Returns null string if there is no file name set yet. This is the
|
||||
* case when this QuaZipFile operates on the existing QuaZip object
|
||||
* (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used).
|
||||
*
|
||||
*
|
||||
* \sa getActualFileName
|
||||
**/
|
||||
QString getFileName() const;
|
||||
|
|
@ -289,7 +289,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* QuaZipFile does not support unbuffered reading. So do not pass
|
||||
* QIODevice::Unbuffered flag in \a mode, or open will fail.
|
||||
**/
|
||||
virtual bool open(OpenMode mode);
|
||||
bool open(OpenMode mode) override;
|
||||
/// Opens a file for reading.
|
||||
/** \overload
|
||||
* Argument \a password specifies a password to decrypt the file. If
|
||||
|
|
@ -323,7 +323,8 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* use the raw mode (see below).
|
||||
*
|
||||
* Arguments \a method and \a level specify compression method and
|
||||
* level. The only method supported is Z_DEFLATED, but you may also
|
||||
* level. The only compression methods supported are
|
||||
* Z_DEFLATED and Z_BZIP2ED. But you may also
|
||||
* specify 0 for no compression. If all of the files in the archive
|
||||
* use both method 0 and either level 0 is explicitly specified or
|
||||
* data descriptor writing is disabled with
|
||||
|
|
@ -332,6 +333,10 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* format version, should you need that. Except for this, \a level
|
||||
* has no other effects with method 0.
|
||||
*
|
||||
* If the method is \a Z_BZIP2ED, then the level must be specified
|
||||
* explicitly (1 to 9), as the bzip2 backend doesn't support
|
||||
* \a Z_DEFAULT_COMPRESSION.
|
||||
*
|
||||
* If \a raw is \c true, no compression is performed. In this case,
|
||||
* \a crc and uncompressedSize field of the \a info are required.
|
||||
*
|
||||
|
|
@ -343,7 +348,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false,
|
||||
int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY);
|
||||
/// Returns \c true, but \ref quazipfile-sequential "beware"!
|
||||
virtual bool isSequential()const;
|
||||
bool isSequential()const override;
|
||||
/// Returns current position in the file.
|
||||
/** Implementation of the QIODevice::pos(). When reading, this
|
||||
* function is a wrapper to the ZIP/UNZIP unztell(), therefore it is
|
||||
|
|
@ -366,7 +371,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* Error code returned by getZipError() is not affected by this
|
||||
* function call.
|
||||
**/
|
||||
virtual qint64 pos()const;
|
||||
qint64 pos()const override;
|
||||
/// Returns \c true if the end of file was reached.
|
||||
/** This function returns \c false in the case of error. This means
|
||||
* that you called this function on either not open file, or a file
|
||||
|
|
@ -384,7 +389,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* Error code returned by getZipError() is not affected by this
|
||||
* function call.
|
||||
**/
|
||||
virtual bool atEnd()const;
|
||||
bool atEnd()const override;
|
||||
/// Returns file size.
|
||||
/** This function returns csize() if the file is open for reading in
|
||||
* raw mode, usize() if it is open for reading in normal mode and
|
||||
|
|
@ -398,7 +403,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
* name would be very misguiding otherwise, so just keep in mind
|
||||
* this inconsistence.
|
||||
**/
|
||||
virtual qint64 size()const;
|
||||
qint64 size()const override;
|
||||
/// Returns compressed file size.
|
||||
/** Equivalent to calling getFileInfo() and then getting
|
||||
* compressedSize field, but more convenient and faster.
|
||||
|
|
@ -446,11 +451,11 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
|||
/// Closes the file.
|
||||
/** Call getZipError() to determine if the close was successful.
|
||||
**/
|
||||
virtual void close();
|
||||
void close() override;
|
||||
/// Returns the error code returned by the last ZIP/UNZIP API call.
|
||||
int getZipError() const;
|
||||
/// Returns the number of bytes available for reading.
|
||||
virtual qint64 bytesAvailable() const;
|
||||
qint64 bytesAvailable() const override;
|
||||
/// Returns the local extra field
|
||||
/**
|
||||
There are two (optional) local extra fields associated with a file.
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
|||
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
#include "quazip_qt_compat.h"
|
||||
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
|
||||
|
|
@ -117,7 +119,7 @@ static QDateTime getNTFSTime(const QByteArray &extra, int position,
|
|||
timeReader >> time;
|
||||
if (time == 0)
|
||||
return dateTime;
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
QDateTime base = quazip_since_epoch_ntfs();
|
||||
dateTime = base.addMSecs(time / 10000);
|
||||
if (fineTicks != nullptr) {
|
||||
*fineTicks = static_cast<int>(time % 10000);
|
||||
|
|
@ -161,7 +163,7 @@ QDateTime QuaZipFileInfo64::getExtTime(const QByteArray &extra, int flag)
|
|||
qint32 time;
|
||||
input >> time;
|
||||
if (nextFlag == flag) {
|
||||
QDateTime base(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
QDateTime base = quazip_since_epoch();
|
||||
dateTime = base.addSecs(time);
|
||||
return dateTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,15 @@ QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
|
|||
}
|
||||
}
|
||||
|
||||
QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file, const QDateTime& dateTime):
|
||||
name(name), dateTime(dateTime), internalAttr(0), externalAttr(0), uncompressedSize(0)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
if (info.exists()) {
|
||||
QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir(), quazip_is_symlink(info));
|
||||
}
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileDateTime(const QString& file)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
|
|
@ -177,14 +186,12 @@ static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
|
|||
timesPos = i - 4; // the beginning of the NTFS times tag
|
||||
ntfsTimesLength = tagsize;
|
||||
break;
|
||||
} else {
|
||||
i += tagsize;
|
||||
}
|
||||
i += tagsize;
|
||||
}
|
||||
break; // I ain't going to search for yet another NTFS record!
|
||||
} else {
|
||||
i += length;
|
||||
}
|
||||
i += length;
|
||||
}
|
||||
if (ntfsPos == -1) {
|
||||
// No NTFS record, need to create one.
|
||||
|
|
|
|||
|
|
@ -94,10 +94,18 @@ struct QUAZIP_EXPORT QuaZipNewInfo {
|
|||
* is inaccessible (e. g. you do not have read permission for the
|
||||
* directory file in), uses current time and zero permissions. Other attributes are
|
||||
* initialized with zeros, comment and extra field with null values.
|
||||
*
|
||||
* \sa setFileDateTime()
|
||||
**/
|
||||
QuaZipNewInfo(const QString& name, const QString& file);
|
||||
/// Constructs QuaZipNewInfo instance.
|
||||
/** Initializes name with \a name and provided timestamp. Permissions are taken
|
||||
* from the specified file. If the \a file does not exists or
|
||||
* is inaccessible (e. g. you do not have read permission for the
|
||||
* directory file in), uses zero permissions. Other attributes are
|
||||
* initialized with zeros, comment and extra field with null values.
|
||||
* \sa setFileDateTime()
|
||||
**/
|
||||
QuaZipNewInfo(const QString& name, const QString& file, const QDateTime& dateTime);
|
||||
/// Initializes the new instance from existing file info.
|
||||
/** Mainly used when copying files between archives.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -223,13 +223,8 @@ local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, v
|
|||
*pi = (int)c;
|
||||
return UNZ_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return UNZ_ERRNO;
|
||||
else
|
||||
return UNZ_EOF;
|
||||
}
|
||||
|
||||
return ZERROR64(*pzlib_filefunc_def, filestream) ? UNZ_ERRNO : UNZ_EOF;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -780,8 +775,7 @@ extern unzFile ZEXPORT unzOpen2 (voidpf file,
|
|||
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
|
||||
return unzOpenInternal(file, &zlib_filefunc64_32_def_fill, 0, UNZ_DEFAULT_FLAGS);
|
||||
}
|
||||
else
|
||||
return unzOpenInternal(file, NULL, 0, UNZ_DEFAULT_FLAGS);
|
||||
return unzOpenInternal(file, NULL, 0, UNZ_DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2_64 (voidpf file,
|
||||
|
|
@ -795,8 +789,7 @@ extern unzFile ZEXPORT unzOpen2_64 (voidpf file,
|
|||
zlib_filefunc64_32_def_fill.zseek32_file = NULL;
|
||||
return unzOpenInternal(file, &zlib_filefunc64_32_def_fill, 1, UNZ_DEFAULT_FLAGS);
|
||||
}
|
||||
else
|
||||
return unzOpenInternal(file, NULL, 1, UNZ_DEFAULT_FLAGS);
|
||||
return unzOpenInternal(file, NULL, 1, UNZ_DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen (voidpf file)
|
||||
|
|
@ -874,8 +867,8 @@ extern int ZEXPORT unzGetFileFlags (unzFile file, unsigned* pflags)
|
|||
*/
|
||||
local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
|
||||
{
|
||||
ZPOS64_T uDate;
|
||||
uDate = (ZPOS64_T)(ulDosDate>>16);
|
||||
ZPOS64_T uDate = ulDosDate >> 16;
|
||||
|
||||
ptm->tm_mday = (uInt)(uDate&0x1f) ;
|
||||
ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
|
||||
ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
|
||||
|
|
@ -1782,7 +1775,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
|
|||
|
||||
pfile_in_zip_read_info->stream.next_in =
|
||||
(Bytef*)pfile_in_zip_read_info->read_buffer;
|
||||
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
|
||||
pfile_in_zip_read_info->stream.avail_in = uReadThis;
|
||||
}
|
||||
|
||||
if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
|
||||
|
|
@ -1949,10 +1942,7 @@ extern int ZEXPORT unzeof (unzFile file)
|
|||
if (pfile_in_zip_read_info==NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
return pfile_in_zip_read_info->rest_read_uncompressed == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -2069,7 +2059,7 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uS
|
|||
unz64_s* s;
|
||||
uLong uReadThis ;
|
||||
if (file==NULL)
|
||||
return (int)UNZ_PARAMERROR;
|
||||
return UNZ_PARAMERROR;
|
||||
s=(unz64_s*)file;
|
||||
|
||||
uReadThis = uSizeBuf;
|
||||
|
|
|
|||
|
|
@ -316,8 +316,7 @@ local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def,
|
|||
|
||||
if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
|
||||
return ZIP_ERRNO;
|
||||
else
|
||||
return ZIP_OK;
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
|
||||
|
|
@ -368,13 +367,8 @@ local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,vo
|
|||
*pi = (int)c;
|
||||
return ZIP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return ZIP_ERRNO;
|
||||
else
|
||||
return ZIP_EOF;
|
||||
}
|
||||
|
||||
return ZERROR64(*pzlib_filefunc_def, filestream) ? ZIP_ERRNO : ZIP_EOF;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -830,7 +824,7 @@ int LoadCentralDirectoryRecord(zip64_internal* pziinit)
|
|||
{
|
||||
ZPOS64_T size_central_dir_to_read = size_central_dir;
|
||||
size_t buf_size = SIZEDATA_INDATABLOCK;
|
||||
void* buf_read = (void*)ALLOC(buf_size);
|
||||
void* buf_read = ALLOC(buf_size);
|
||||
if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
|
||||
err=ZIP_ERRNO;
|
||||
|
||||
|
|
@ -934,11 +928,9 @@ extern zipFile ZEXPORT zipOpen3 (voidpf file, int append, zipcharpc* globalcomme
|
|||
TRYFREE(zi);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
*zi = ziinit;
|
||||
return (zipFile)zi;
|
||||
}
|
||||
|
||||
*zi = ziinit;
|
||||
return (zipFile)zi;
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 (voidpf file, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
|
||||
|
|
@ -949,8 +941,7 @@ extern zipFile ZEXPORT zipOpen2 (voidpf file, int append, zipcharpc* globalcomme
|
|||
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
|
||||
return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
|
||||
}
|
||||
else
|
||||
return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
|
||||
return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2_64 (voidpf file, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
|
|
@ -963,8 +954,7 @@ extern zipFile ZEXPORT zipOpen2_64 (voidpf file, int append, zipcharpc* globalco
|
|||
zlib_filefunc64_32_def_fill.zseek32_file = NULL;
|
||||
return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
|
||||
}
|
||||
else
|
||||
return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
|
||||
return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -998,17 +988,17 @@ int Write_LocalFileHeader(zip64_internal* zi, const char* filename,
|
|||
else if(zi->ci.zip64)
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
|
||||
else
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)version_to_extract,2);
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,version_to_extract,2);
|
||||
}
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,zi->ci.flag,2);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,zi->ci.dosDate,4);
|
||||
|
||||
/* CRC / Compressed size / Uncompressed size will be filled in later and rewritten later */
|
||||
if (err==ZIP_OK)
|
||||
|
|
@ -1063,11 +1053,11 @@ int Write_LocalFileHeader(zip64_internal* zi, const char* filename,
|
|||
/* Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) */
|
||||
zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
|
||||
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, HeaderID,2);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, DataSize,2);
|
||||
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, UncompressedSize,8);
|
||||
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, CompressedSize,8);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
@ -1112,6 +1102,17 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
|
|||
return ZIP_PARAMERROR;
|
||||
#endif
|
||||
|
||||
// The filename and comment length must fit in 16 bits.
|
||||
if ((filename!=NULL) && (strlen(filename)>0xffff))
|
||||
return ZIP_PARAMERROR;
|
||||
if ((comment!=NULL) && (strlen(comment)>0xffff))
|
||||
return ZIP_PARAMERROR;
|
||||
// The extra field length must fit in 16 bits. If the member also requires
|
||||
// a Zip64 extra block, that will also need to fit within that 16-bit
|
||||
// length, but that will be checked for later.
|
||||
if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
|
||||
return ZIP_PARAMERROR;
|
||||
|
||||
zi = (zip64_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 1)
|
||||
|
|
@ -1187,11 +1188,11 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
|
|||
zi->ci.size_centralExtra = size_extrafield_global;
|
||||
zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
|
||||
/* version info */
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)version_to_extract,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+4,versionMadeBy,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+6,version_to_extract,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+8,zi->ci.flag,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+12,zi->ci.dosDate,4);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
|
||||
|
|
@ -1203,12 +1204,12 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
|
|||
if (zipfi==NULL)
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
|
||||
else
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+36,zipfi->internal_fa,2);
|
||||
|
||||
if (zipfi==NULL)
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
|
||||
else
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+38,zipfi->external_fa,4);
|
||||
|
||||
if(zi->ci.pos_local_header >= 0xffffffff)
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
|
||||
|
|
@ -1299,7 +1300,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
|
|||
zi->ci.pcrc_32_tab = get_crc_table();
|
||||
/*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
|
||||
if (crcForCrypting == 0) {
|
||||
crcForCrypting = (uLong)zi->ci.dosDate << 16; /* ATTANTION! Without this row, you don't unpack your password protected archive in other app. */
|
||||
crcForCrypting = zi->ci.dosDate << 16; /* ATTANTION! Without this row, you don't unpack your password protected archive in other app. */
|
||||
}
|
||||
sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
|
||||
zi->ci.crypt_header_size = sizeHead;
|
||||
|
|
@ -1645,7 +1646,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
|
|||
|
||||
if (!zi->ci.raw)
|
||||
{
|
||||
crc32 = (uLong)zi->ci.crc32;
|
||||
crc32 = zi->ci.crc32;
|
||||
uncompressed_size = zi->ci.totalUncompressedData;
|
||||
}
|
||||
compressed_size = zi->ci.totalCompressedData;
|
||||
|
|
@ -1736,11 +1737,11 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
|
|||
|
||||
/* Update the extra info size field */
|
||||
zi->ci.size_centralExtra += datasize + 4;
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
|
||||
zip64local_putValue_inmemory(zi->ci.central_header+30,zi->ci.size_centralExtra,2);
|
||||
}
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
|
||||
err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, zi->ci.size_centralheader);
|
||||
|
||||
TRYFREE(zi->ci.central_header);
|
||||
|
||||
|
|
@ -1874,7 +1875,7 @@ int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centra
|
|||
if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
|
||||
{
|
||||
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
|
@ -1910,7 +1911,7 @@ int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir,
|
|||
}
|
||||
|
||||
if (err==ZIP_OK) /* size of the central directory */
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
|
||||
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,size_centraldir,4);
|
||||
|
||||
if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue