From 96a165870de71f918f6480b7832ef53b90576093 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Wed, 11 Apr 2012 11:06:21 +0300 Subject: support UTF-8 encoded file names in QZip* Change-Id: Iba0457b55ef9fa3673f78b4d30d018a146e8fb1c Reviewed-by: Oswald Buddenhagen Reviewed-by: Harald Fernengel --- src/gui/text/qzip.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') 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(&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); -- cgit v1.2.3