From 6238f33d1f639c7644796e5ad619cb4120c1090b Mon Sep 17 00:00:00 2001 From: Abs62 Date: Thu, 9 Oct 2014 23:30:11 +0400 Subject: [PATCH] ZIPS: Change handling of UTF-8 encoded file names --- indexedzip.cc | 49 ++++++++++++++++++++++++++----------------------- zipfile.cc | 1 + zipfile.hh | 1 + zipsounds.cc | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/indexedzip.cc b/indexedzip.cc index 153473ec..f12e0b96 100644 --- a/indexedzip.cc +++ b/indexedzip.cc @@ -187,32 +187,35 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords &zipFileNames ) // Failed to decode } - // CP866 - try + if( !entry.fileNameInUTF8 ) { - wstring decoded = Iconv::toWstring( "CP866", entry.fileName.constData(), - entry.fileName.size() ); + // CP866 + try + { + wstring decoded = Iconv::toWstring( "CP866", entry.fileName.constData(), + entry.fileName.size() ); - zipFileNames.addSingleWord( decoded, - entry.localHeaderOffset ); - } - catch( Iconv::Ex ) - { + zipFileNames.addSingleWord( decoded, + entry.localHeaderOffset ); + } + catch( Iconv::Ex ) + { + // Failed to decode + } + + // CP1251 + try + { + wstring decoded = Iconv::toWstring( "CP1251", entry.fileName.constData(), + entry.fileName.size() ); + + zipFileNames.addSingleWord( decoded, + entry.localHeaderOffset ); + } + catch( Iconv::Ex ) + { // Failed to decode - } - - // CP1251 - try - { - wstring decoded = Iconv::toWstring( "CP1251", entry.fileName.constData(), - entry.fileName.size() ); - - zipFileNames.addSingleWord( decoded, - entry.localHeaderOffset ); - } - catch( Iconv::Ex ) - { - // Failed to decode + } } } } diff --git a/zipfile.cc b/zipfile.cc index 7c4f1562..3b3ede5f 100644 --- a/zipfile.cc +++ b/zipfile.cc @@ -151,6 +151,7 @@ bool readNextEntry( QFile & zip, CentralDirEntry & entry ) entry.compressedSize = qFromLittleEndian( record.compressedSize ); entry.uncompressedSize = qFromLittleEndian( record.uncompressedSize ); entry.compressionMethod = getCompressionMethod( record.compressionMethod ); + entry.fileNameInUTF8 = ( qFromLittleEndian( record.gpBits ) & 0x800 ) != 0; return true; } diff --git a/zipfile.hh b/zipfile.hh index 9fe8474d..627bb819 100644 --- a/zipfile.hh +++ b/zipfile.hh @@ -24,6 +24,7 @@ struct CentralDirEntry quint32 localHeaderOffset, compressedSize, uncompressedSize; CompressionMethod compressionMethod; + bool fileNameInUTF8; }; /// Represents contents of the local file header -- that what CentralDirEntry:: diff --git a/zipsounds.cc b/zipsounds.cc index 0c2f743e..826456aa 100644 --- a/zipsounds.cc +++ b/zipsounds.cc @@ -44,7 +44,7 @@ DEF_EX( exInvalidData, "Invalid data encountered", Dictionary::Ex ) enum { Signature = 0x5350495a, // ZIPS on little-endian, SPIZ on big-endian - CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion }; struct IdxHeader