MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / load

Method load

lib/Epub/Epub.cpp:365–505  ·  view source on GitHub ↗

load in the meta data for the epub file

Source from the content-addressed store, hash-verified

363
364// load in the meta data for the epub file
365bool Epub::load(const bool buildIfMissing, const bool skipLoadingCss) {
366 LOG_DBG("EBP", "Loading ePub: %s", filepath.c_str());
367
368 // Initialize spine/TOC cache
369 bookMetadataCache.reset(new BookMetadataCache(cachePath));
370 // Always create CssParser - needed for inline style parsing even without CSS files
371 cssParser.reset(new CssParser(cachePath));
372
373 // Try to load existing cache first
374 if (bookMetadataCache->load()) {
375 if (!skipLoadingCss) {
376 // Rebuild CSS cache when missing or when cache version changed (loadFromCache removes stale file)
377 if (!cssParser->hasCache() || !cssParser->loadFromCache()) {
378 LOG_DBG("EBP", "CSS rules cache missing or stale, attempting to parse CSS files");
379 cssParser->deleteCache();
380
381 BookMetadataCache::BookMetadata cachedMetadata = bookMetadataCache->coreMetadata;
382 if (!parseContentOpf(cachedMetadata, /*writeSpineEntries=*/false)) {
383 LOG_ERR("EBP", "Could not parse content.opf from cached bookMetadata for CSS files");
384 // continue anyway - book will work without CSS and we'll still load any inline style CSS
385 } else {
386 discoverCssFilesFromZip();
387 }
388 bookMetadataCache.reset();
389 parseCssFiles();
390 bookMetadataCache.reset(new BookMetadataCache(cachePath));
391 if (!bookMetadataCache->load()) {
392 LOG_ERR("EBP", "Failed to reload cache after CSS rebuild");
393 return false;
394 }
395 // Invalidate section caches so they are rebuilt with the new CSS
396 Storage.removeDir((cachePath + "/sections").c_str());
397 }
398 }
399 LOG_DBG("EBP", "Loaded ePub: %s", filepath.c_str());
400 return true;
401 }
402
403 // If we didn't load from cache above and we aren't allowed to build, fail now
404 if (!buildIfMissing) {
405 return false;
406 }
407
408 // Cache doesn't exist or is invalid, build it
409 LOG_DBG("EBP", "Cache not found, building spine/TOC cache");
410 setupCacheDir();
411
412 const uint32_t indexingStart = millis();
413
414 // Begin building cache - stream entries to disk immediately
415 if (!bookMetadataCache->beginWrite()) {
416 LOG_ERR("EBP", "Could not begin writing cache");
417 return false;
418 }
419
420 // OPF Pass
421 const uint32_t opfStart = millis();
422 BookMetadataCache::BookMetadata bookMetadata;

Callers

nothing calls this directly

Calls 14

hasCacheMethod · 0.80
loadFromCacheMethod · 0.80
deleteCacheMethod · 0.80
removeDirMethod · 0.80
beginWriteMethod · 0.80
beginContentOpfPassMethod · 0.80
endContentOpfPassMethod · 0.80
beginTocPassMethod · 0.80
endTocPassMethod · 0.80
endWriteMethod · 0.80
buildBookBinMethod · 0.80
cleanupTmpFilesMethod · 0.80

Tested by

no test coverage detected