fix startdict index file reading caused by wrong order of reading
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run

partially revert  https://github.com/xiaoyifang/goldendict-ng/pull/1972
This commit is contained in:
shenleban tongying 2024-11-21 23:53:10 -05:00 committed by GitHub
parent 5b70a7e081
commit 3c5b76f77a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -122,7 +122,7 @@ class StardictDictionary: public BtreeIndexing::BtreeDictionary
File::Index idx;
IdxHeader idxHeader;
string sameTypeSequence;
ChunkedStorage::Reader chunks;
std::unique_ptr< ChunkedStorage::Reader > chunks;
QMutex dzMutex;
dictData * dz;
QMutex resourceZipMutex;
@ -215,12 +215,14 @@ StardictDictionary::StardictDictionary( string const & id,
string const & indexFile,
vector< string > const & dictionaryFiles ):
BtreeDictionary( id, dictionaryFiles ),
idx( indexFile, QIODevice::ReadOnly ),
idxHeader( idx.read< IdxHeader >() ),
sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ),
chunks( idx, idxHeader.chunksOffset )
idx( indexFile, QIODevice::ReadOnly )
{
dictionaryName = loadString( idxHeader.bookNameSize );
// reading headers, note that reading order matters
idxHeader = idx.read< IdxHeader >();
dictionaryName = loadString( idxHeader.bookNameSize );
sameTypeSequence = loadString( idxHeader.sameTypeSequenceSize );
chunks = std::make_unique< ChunkedStorage::Reader >( idx, idxHeader.chunksOffset );
// Open the .dict file
DZ_ERRORS error;
@ -301,7 +303,7 @@ void StardictDictionary::getArticleProps( uint32_t articleAddress,
QMutexLocker _( &idxMutex );
char * articleData = chunks.getBlock( articleAddress, chunk );
char * articleData = chunks->getBlock( articleAddress, chunk );
memcpy( &offset, articleData, sizeof( uint32_t ) );
articleData += sizeof( uint32_t );