summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-04-11 11:06:21 +0300
committerQt by Nokia <qt-info@nokia.com>2012-04-25 10:29:56 +0200
commit96a165870de71f918f6480b7832ef53b90576093 (patch)
tree6254c9052f6164736f3f6d79d649b92b9646fabc /src
parent2cbd5906df8f00e62c84423c12cb9d0c64f6e69d (diff)
support UTF-8 encoded file names in QZip*
Change-Id: Iba0457b55ef9fa3673f78b4d30d018a146e8fb1c Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com> Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qzip.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp
index 1491c1efbc..e9ff5e8b59 100644
--- a/src/gui/text/qzip.cpp
+++ b/src/gui/text/qzip.cpp
@@ -416,7 +416,9 @@ public:
void QZipPrivate::fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const
{
FileHeader header = fileHeaders.at(index);
- fileInfo.filePath = QString::fromLocal8Bit(header.file_name);
+ // if bit 11 is set, the filename and comment fields must be encoded using UTF-8
+ const bool inUtf8 = (readUShort(header.h.general_purpose_bits) & 0x0800) != 0;
+ fileInfo.filePath = inUtf8 ? QString::fromUtf8(header.file_name) : QString::fromLocal8Bit(header.file_name);
const quint32 mode = (qFromLittleEndian<quint32>(&header.h.external_file_attributes[0]) >> 16) & 0xFFFF;
fileInfo.isDir = S_ISDIR(mode);
fileInfo.isFile = S_ISREG(mode);
@@ -629,7 +631,12 @@ void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const
crc_32 = ::crc32(crc_32, (const uchar *)contents.constData(), contents.length());
writeUInt(header.h.crc_32, crc_32);
- header.file_name = fileName.toLocal8Bit();
+ // if bit 11 is set, the filename and comment fields must be encoded using UTF-8
+ ushort general_purpose_bits = 0x0800; // always use utf-8
+ writeUShort(header.h.general_purpose_bits, general_purpose_bits);
+
+ const bool inUtf8 = (general_purpose_bits & 0x0800) != 0;
+ header.file_name = inUtf8 ? fileName.toUtf8() : fileName.toLocal8Bit();
if (header.file_name.size() > 0xffff) {
qWarning("QZip: Filename too long, chopping it to 65535 characters");
header.file_name = header.file_name.left(0xffff);