MCPcopy Create free account
hub / github.com/buggins/coolreader / readIndex

Method readIndex

crengine/src/lvtinydom.cpp:8421–8462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8419 }
8420
8421 bool readIndex( )
8422 {
8423 lString16 filename = _cacheDir + L"cr3cache.inx";
8424 // read index
8425 lUInt32 totalSize = 0;
8426 LVStreamRef instream = LVOpenFileStream( filename.c_str(), LVOM_READ );
8427 if ( !instream.isNull() ) {
8428 LVStreamBufferRef sb = instream->GetReadBuffer(0, instream->GetSize() );
8429 if ( !sb )
8430 return false;
8431 SerialBuf buf( sb->getReadOnly(), sb->getSize() );
8432 if ( !buf.checkMagic( doccache_magic ) ) {
8433 CRLog::error("wrong cache index file format");
8434 return false;
8435 }
8436
8437 lUInt32 start = buf.pos();
8438 lUInt32 count;
8439 buf >> count;
8440 for ( unsigned i=0; i<count && !buf.error(); i++ ) {
8441 FileItem * item = new FileItem();
8442 _files.add( item );
8443 buf >> item->filename;
8444 buf >> item->size;
8445 CRLog::trace("cache %d: %s [%d]", i, UnicodeToUtf8(item->filename).c_str(), (int)item->size );
8446 totalSize += item->size;
8447 }
8448 if ( !buf.checkCRC( buf.pos() - start ) ) {
8449 CRLog::error("CRC32 doesn't match in cache index file");
8450 return false;
8451 }
8452
8453 if ( buf.error() )
8454 return false;
8455
8456 CRLog::info( "Document cache index file read ok, %d files in cache, %d bytes", _files.length(), totalSize );
8457 return true;
8458 } else {
8459 CRLog::error( "Document cache index file cannot be read" );
8460 return false;
8461 }
8462 }
8463
8464 /// remove all .cr3 files which are not listed in index
8465 bool removeExtraFiles( )

Callers

nothing calls this directly

Calls 14

LVOpenFileStreamFunction · 0.85
UnicodeToUtf8Function · 0.85
checkMagicMethod · 0.80
checkCRCMethod · 0.80
c_strMethod · 0.45
isNullMethod · 0.45
GetReadBufferMethod · 0.45
GetSizeMethod · 0.45
getReadOnlyMethod · 0.45
getSizeMethod · 0.45
posMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected