summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/quazip/quazip.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-06-08 20:25:36 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-08-07 22:18:41 +0200
commitb0f22620a2dbfb991b10a8e1e8b0c8db5e3ee117 (patch)
tree2695997733229be38ec71c36753b19ba2e98aa61 /rbutil/rbutilqt/quazip/quazip.cpp
parentb3a0187416e48d80275af6be0178cef155aa03dc (diff)
downloadrockbox-b0f22620a2.tar.gz
rockbox-b0f22620a2.tar.bz2
rockbox-b0f22620a2.zip
rbutil: Update quazip to release 0.9.1.
Update to latest quazip release. Change-Id: I03189ceeadbe3110a9420153d84bd5d33d5b663f
Diffstat (limited to 'rbutil/rbutilqt/quazip/quazip.cpp')
-rw-r--r--rbutil/rbutilqt/quazip/quazip.cpp96
1 files changed, 77 insertions, 19 deletions
diff --git a/rbutil/rbutilqt/quazip/quazip.cpp b/rbutil/rbutilqt/quazip/quazip.cpp
index e3623c76e3..61c2ea87eb 100644
--- a/rbutil/rbutilqt/quazip/quazip.cpp
+++ b/rbutil/rbutilqt/quazip/quazip.cpp
@@ -22,12 +22,14 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license.
**/
-#include <QFile>
-#include <QFlags>
-#include <QHash>
+#include <QtCore/QFile>
+#include <QtCore/QFlags>
+#include <QtCore/QHash>
#include "quazip.h"
+#define QUAZIP_OS_UNIX 3u
+
/// All the internal stuff for the QuaZip class.
/**
\internal
@@ -39,11 +41,12 @@ quazip/(un)zip.h files for details, basically it's zlib license.
class QuaZipPrivate {
friend class QuaZip;
private:
+ Q_DISABLE_COPY(QuaZipPrivate)
/// The pointer to the corresponding QuaZip instance.
QuaZip *q;
- /// The codec for file names.
+ /// The codec for file names (used when UTF-8 is not enabled).
QTextCodec *fileNameCodec;
- /// The codec for comments.
+ /// The codec for comments (used when UTF-8 is not enabled).
QTextCodec *commentCodec;
/// The archive file name.
QString zipName;
@@ -69,6 +72,10 @@ class QuaZipPrivate {
bool zip64;
/// The auto-close flag.
bool autoClose;
+ /// The UTF-8 flag.
+ bool utf8;
+ /// The OS code.
+ uint osCode;
inline QTextCodec *getDefaultFileNameCodec()
{
if (defaultFileNameCodec == NULL) {
@@ -88,8 +95,12 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
@@ -105,14 +116,18 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
/// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
- q(q),
+ q(q),
fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()),
ioDevice(ioDevice),
@@ -121,8 +136,12 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
@@ -138,9 +157,11 @@ class QuaZipPrivate {
QHash<QString, unz64_file_pos> directoryCaseInsensitive;
unz64_file_pos lastMappedDirectoryEntry;
static QTextCodec *defaultFileNameCodec;
+ static uint defaultOsCode;
};
QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL;
+uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX;
void QuaZipPrivate::clearDirectoryMap()
{
@@ -273,6 +294,8 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
flags |= ZIP_AUTO_CLOSE;
if (p->dataDescriptorWritingEnabled)
flags |= ZIP_WRITE_DATA_DESCRIPTOR;
+ if (p->utf8)
+ flags |= ZIP_ENCODING_UTF8;
p->zipFile_f=zipOpen3(ioDevice,
mode==mdCreate?APPEND_STATUS_CREATE:
mode==mdAppend?APPEND_STATUS_CREATEAFTER:
@@ -334,9 +357,9 @@ void QuaZip::close()
case mdCreate:
case mdAppend:
case mdAdd:
- p->zipError=zipClose(p->zipFile_f,
- p->comment.isNull() ? NULL
- : p->commentCodec->fromUnicode(p->comment).constData());
+ p->zipError=zipClose(p->zipFile_f, p->comment.isNull() ? NULL : isUtf8Enabled()
+ ? p->comment.toUtf8().constData()
+ : p->commentCodec->fromUnicode(p->comment).constData());
break;
default:
qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
@@ -402,7 +425,9 @@ QString QuaZip::getComment()const
if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0)
return QString();
fakeThis->p->zipError = UNZ_OK;
- return p->commentCodec->toUnicode(comment);
+ unsigned flags = 0;
+ return (unzGetFileFlags(p->unzFile_f, &flags) == UNZ_OK) && (flags & UNZ_ENCODING_UTF8)
+ ? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
}
bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
@@ -537,8 +562,8 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
info->diskNumberStart=info_z.disk_num_start;
info->internalAttr=info_z.internal_fa;
info->externalAttr=info_z.external_fa;
- info->name=p->fileNameCodec->toUnicode(fileName);
- info->comment=p->commentCodec->toUnicode(comment);
+ info->name=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
+ info->comment=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
info->extra=extra;
info->dateTime=QDateTime(
QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday),
@@ -558,10 +583,13 @@ QString QuaZip::getCurrentFileName()const
}
if(!isOpen()||!hasCurrentFile()) return QString();
QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
- if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL, fileName.data(), fileName.size(),
+ unz_file_info64 file_info;
+ if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &file_info, fileName.data(), fileName.size(),
NULL, 0, NULL, 0))!=UNZ_OK)
return QString();
- QString result = p->fileNameCodec->toUnicode(fileName.constData());
+ fileName.resize(file_info.size_filename);
+ QString result = (file_info.flag & UNZ_ENCODING_UTF8)
+ ? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
if (result.isEmpty())
return result;
// Add to directory map
@@ -576,7 +604,17 @@ void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
void QuaZip::setFileNameCodec(const char *fileNameCodecName)
{
- p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
+ p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
+}
+
+void QuaZip::setOsCode(uint osCode)
+{
+ p->osCode = osCode;
+}
+
+uint QuaZip::getOsCode() const
+{
+ return p->osCode;
}
QTextCodec *QuaZip::getFileNameCodec()const
@@ -747,7 +785,7 @@ QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
{
if (cs == csDefault) {
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
return Qt::CaseInsensitive;
#else
return Qt::CaseSensitive;
@@ -767,6 +805,16 @@ void QuaZip::setDefaultFileNameCodec(const char *codecName)
setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
}
+void QuaZip::setDefaultOsCode(uint osCode)
+{
+ QuaZipPrivate::defaultOsCode = osCode;
+}
+
+uint QuaZip::getDefaultOsCode()
+{
+ return QuaZipPrivate::defaultOsCode;
+}
+
void QuaZip::setZip64Enabled(bool zip64)
{
p->zip64 = zip64;
@@ -777,6 +825,16 @@ bool QuaZip::isZip64Enabled() const
return p->zip64;
}
+void QuaZip::setUtf8Enabled(bool utf8)
+{
+ p->utf8 = utf8;
+}
+
+bool QuaZip::isUtf8Enabled() const
+{
+ return p->utf8;
+}
+
bool QuaZip::isAutoClose() const
{
return p->autoClose;