ZIPS: Change handling of UTF-8 encoded file names

This commit is contained in:
Abs62 2014-10-09 23:30:11 +04:00
parent eac157af29
commit 6238f33d1f
4 changed files with 29 additions and 24 deletions

View file

@ -187,32 +187,35 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords &zipFileNames )
// Failed to decode // Failed to decode
} }
// CP866 if( !entry.fileNameInUTF8 )
try
{ {
wstring decoded = Iconv::toWstring( "CP866", entry.fileName.constData(), // CP866
entry.fileName.size() ); try
{
wstring decoded = Iconv::toWstring( "CP866", entry.fileName.constData(),
entry.fileName.size() );
zipFileNames.addSingleWord( decoded, zipFileNames.addSingleWord( decoded,
entry.localHeaderOffset ); entry.localHeaderOffset );
} }
catch( Iconv::Ex ) 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 // 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
} }
} }
} }

View file

@ -151,6 +151,7 @@ bool readNextEntry( QFile & zip, CentralDirEntry & entry )
entry.compressedSize = qFromLittleEndian( record.compressedSize ); entry.compressedSize = qFromLittleEndian( record.compressedSize );
entry.uncompressedSize = qFromLittleEndian( record.uncompressedSize ); entry.uncompressedSize = qFromLittleEndian( record.uncompressedSize );
entry.compressionMethod = getCompressionMethod( record.compressionMethod ); entry.compressionMethod = getCompressionMethod( record.compressionMethod );
entry.fileNameInUTF8 = ( qFromLittleEndian( record.gpBits ) & 0x800 ) != 0;
return true; return true;
} }

View file

@ -24,6 +24,7 @@ struct CentralDirEntry
quint32 localHeaderOffset, compressedSize, uncompressedSize; quint32 localHeaderOffset, compressedSize, uncompressedSize;
CompressionMethod compressionMethod; CompressionMethod compressionMethod;
bool fileNameInUTF8;
}; };
/// Represents contents of the local file header -- that what CentralDirEntry:: /// Represents contents of the local file header -- that what CentralDirEntry::

View file

@ -44,7 +44,7 @@ DEF_EX( exInvalidData, "Invalid data encountered", Dictionary::Ex )
enum enum
{ {
Signature = 0x5350495a, // ZIPS on little-endian, SPIZ on big-endian Signature = 0x5350495a, // ZIPS on little-endian, SPIZ on big-endian
CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion
}; };
struct IdxHeader struct IdxHeader