Simplified Library::getReaderById()

Reused `Library::getArchiveById()` in `Library::getReaderById()`.
This commit is contained in:
Veloman Yunkan 2021-10-20 22:20:04 +04:00
parent c7b88398bd
commit 0e48baf9f9
1 changed files with 3 additions and 11 deletions

View File

@ -148,19 +148,11 @@ std::shared_ptr<Reader> Library::getReaderById(const std::string& id)
return m_readers.at(id); return m_readers.at(id);
} catch (std::out_of_range& e) {} } catch (std::out_of_range& e) {}
try { const auto archive = getArchiveById(id);
auto reader = make_shared<Reader>(m_archives.at(id)); if ( !archive )
m_readers[id] = reader;
return reader;
} catch (std::out_of_range& e) {}
auto book = getBookById(id);
if (!book.isPathValid())
return nullptr; return nullptr;
auto archive = make_shared<zim::Archive>(book.getPath()); const auto reader = make_shared<Reader>(archive);
m_archives[id] = archive;
auto reader = make_shared<Reader>(archive);
m_readers[id] = reader; m_readers[id] = reader;
return reader; return reader;
} }