From ba302bed333bac125427d87814622876d17553c6 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 8 Dec 2020 18:53:02 +0100 Subject: [PATCH 1/3] Use new libzim method `getFaviconEntry` to get the favicon. --- src/reader.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index c9fb91be..5dfaaf15 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -179,17 +179,13 @@ Entry Reader::getMainPage() const bool Reader::getFavicon(string& content, string& mimeType) const { - static const char* const paths[] = {"-/favicon", "-/favicon.png", "I/favicon.png", "I/favicon"}; - - for (auto &path: paths) { - try { - auto entry = zimArchive->getEntryByPath(path); - auto item = entry.getItem(true); - content = item.getData(); - mimeType = item.getMimetype(); - return true; - } catch(zim::EntryNotFound& e) {}; - } + try { + auto entry = zimArchive->getFaviconEntry(); + auto item = entry.getItem(true); + content = item.getData(); + mimeType = item.getMimetype(); + return true; + } catch(zim::EntryNotFound& e) {}; return false; } From d51000c4a9680bc108d89ca6f41e5b53257336bc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 8 Dec 2020 18:53:38 +0100 Subject: [PATCH 2/3] Use new libzim method `hasFulltextIndex` to check for fulltext index. --- src/reader.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 5dfaaf15..862f61bd 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -390,18 +390,7 @@ bool Reader::hasFulltextIndex() const return false; } - for(auto path: {"Z//fulltextIndex/xapian", "X/fulltext/xapian"}) { - try { - auto entry = zimArchive->getEntryByPath(path); - auto item = entry.getItem(true); - auto accessInfo = item.getDirectAccessInformation(); - if (accessInfo.second) { - return true; - } - } catch(...) {} - } - - return false; + return zimArchive->hasFulltextIndex(); } /* Search titles by prefix */ From 1002c15e0d5c3b7f1715245ea1f7e967b2df0f9f Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 8 Dec 2020 18:54:36 +0100 Subject: [PATCH 3/3] Remove unnecessary checks. `Reader` cannot be created with a null `zimArchive`. We don't have to check for zimArchive being not null. --- src/reader.cpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 862f61bd..db756f7b 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -339,10 +339,6 @@ string Reader::getOrigId() const Entry Reader::getEntryFromPath(const std::string& path) const { - if (!this->zimArchive) { - throw NoEntry(); - } - if (path.empty() || path == "/") { return getMainPage(); } @@ -361,10 +357,6 @@ Entry Reader::getEntryFromEncodedPath(const std::string& path) const Entry Reader::getEntryFromTitle(const std::string& title) const { - if (!this->zimArchive) { - throw NoEntry(); - } - try { return zimArchive->getEntryByTitle(title); } catch(zim::EntryNotFound& e) { @@ -374,22 +366,12 @@ Entry Reader::getEntryFromTitle(const std::string& title) const bool Reader::pathExists(const string& path) const { - if (!zimArchive) - { - return false; - } - return zimArchive->hasEntryByPath(path); } /* Does the ZIM file has a fulltext index */ bool Reader::hasFulltextIndex() const { - if (!zimArchive) - { - return false; - } - return zimArchive->hasFulltextIndex(); } @@ -593,9 +575,6 @@ bool Reader::isCorrupted() const /* Return the file size, works also for splitted files */ unsigned int Reader::getFileSize() const { - if (!zimArchive) { - return 0; - } return zimArchive->getFilesize() / 1024; }