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

Method loadCacheFileContent

crengine/src/lvtinydom.cpp:7752–7877  ·  view source on GitHub ↗

load document cache file content, @see saveChanges()

Source from the content-addressed store, hash-verified

7750
7751/// load document cache file content, @see saveChanges()
7752bool ldomDocument::loadCacheFileContent(CacheLoadingCallback * formatCallback)
7753{
7754
7755 CRLog::trace("ldomDocument::loadCacheFileContent()");
7756 {
7757 SerialBuf propsbuf(0, true);
7758 if ( !_cacheFile->read( CBT_PROP_DATA, propsbuf ) ) {
7759 CRLog::error("Error while reading props data");
7760 return false;
7761 }
7762 getProps()->deserialize( propsbuf );
7763 if ( propsbuf.error() ) {
7764 CRLog::error("Cannot decode property table for document");
7765 return false;
7766 }
7767
7768 if ( formatCallback ) {
7769 int fmt = getProps()->getIntDef(DOC_PROP_FILE_FORMAT_ID,
7770 doc_format_fb2);
7771 if (fmt < doc_format_fb2 || fmt > doc_format_max)
7772 fmt = doc_format_fb2;
7773 // notify about format detection, to allow setting format-specific CSS
7774 formatCallback->OnCacheFileFormatDetected((doc_format_t)fmt);
7775 }
7776
7777 SerialBuf idbuf(0, true);
7778 if ( !_cacheFile->read( CBT_MAPS_DATA, idbuf ) ) {
7779 CRLog::error("Error while reading Id data");
7780 return false;
7781 }
7782 deserializeMaps( idbuf );
7783 if ( idbuf.error() ) {
7784 CRLog::error("Cannot decode ID table for document");
7785 return false;
7786 }
7787
7788 CRLog::trace("ldomDocument::loadCacheFileContent() - page data");
7789 SerialBuf pagebuf(0, true);
7790 if ( !_cacheFile->read( CBT_PAGE_DATA, pagebuf ) ) {
7791 CRLog::error("Error while reading pages data");
7792 return false;
7793 }
7794 pagebuf.swap( _pagesData );
7795 _pagesData.setPos( 0 );
7796 LVRendPageList pages;
7797 pages.deserialize(_pagesData);
7798 if ( _pagesData.error() ) {
7799 CRLog::error("Page data deserialization is failed");
7800 return false;
7801 }
7802 CRLog::info("%d pages read from cache file", pages.length());
7803 //_pagesData.setPos( 0 );
7804
7805 DocFileHeader h;
7806 memset(&h, 0, sizeof(h));
7807 SerialBuf hdrbuf(0,true);
7808 if ( !_cacheFile->read( CBT_REND_PARAMS, hdrbuf ) ) {
7809 CRLog::error("Error while reading header data");

Callers

nothing calls this directly

Calls 10

getPropsFunction · 0.85
readMethod · 0.45
deserializeMethod · 0.45
errorMethod · 0.45
getIntDefMethod · 0.45
swapMethod · 0.45
setPosMethod · 0.45
lengthMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected