bool DocPlugin::readMetaInfo(Book &book) const { if (!DocMetaInfoReader(book).readMetaInfo()) { return false; } shared_ptr<ZLInputStream> stream = new DocCharStream(book.file(), 50000); if (!detectEncodingAndLanguage(book, *stream)) { stream = new DocAnsiStream(book.file(), 50000); detectLanguage(book, *stream, ZLEncodingConverter::UTF8, true); } return true; }
bool RtfPlugin::readMetaInfo(Book &book) const { if (!RtfDescriptionReader(book).readDocument(book.file())) { return false; } if (book.encoding().empty()) { book.setEncoding("utf-8"); } else if (book.language().empty()) { shared_ptr<ZLInputStream> stream = new RtfReaderStream(book.file(), 50000); if (!stream.isNull()) { detectLanguage(book, *stream); } } return true; }
bool OEBPlugin::readLanguageAndEncoding(Book &book) const { if (book.language().empty()) { shared_ptr<ZLInputStream> oebStream = new OEBTextStream(opfFile(book.file())); detectLanguage(book, *oebStream, book.encoding()); } return true; }
bool BooksDB::removeBook(const Book &book) { if (!isInitialized() || book.bookId() == 0) { return false; } myDeleteBook->setFileName(book.file().path()); return executeAsTransaction(*myDeleteBook); }
bool TxtPlugin::readLanguageAndEncoding(Book &book) const { shared_ptr<ZLInputStream> stream = book.file().inputStream(); if (stream.isNull()) { return false; } detectEncodingAndLanguage(book, *stream); return !book.encoding().empty(); }
bool PluckerPlugin::readMetaInfo(Book &book) const { shared_ptr<ZLInputStream> stream = new PluckerTextStream(book.file()); detectEncodingAndLanguage(book, *stream); if (book.encoding().empty()) { return false; } return true; }
bool OEBPlugin::readMetaInfo(Book &book) const { const ZLFile &file = book.file(); shared_ptr<ZLInputStream> lock = file.inputStream(); const ZLFile opfFile = this->opfFile(file); bool code = OEBMetaInfoReader(book).readMetaInfo(opfFile); if (code && book.language().empty()) { shared_ptr<ZLInputStream> oebStream = new OEBTextStream(opfFile); detectLanguage(book, *oebStream); } return code; }
bool HtmlPlugin::readMetaInfo(Book &book) const { shared_ptr<ZLInputStream> stream = book.file().inputStream(); if (stream.isNull()) { return false; } shared_ptr<ZLInputStream> htmlStream = new HtmlReaderStream(stream, 50000); detectEncodingAndLanguage(book, *htmlStream); if (book.encoding().empty()) { return false; } HtmlDescriptionReader(book).readDocument(*stream); return true; }
bool EReaderPlugin::readMetaInfo(Book &book) const { shared_ptr<ZLInputStream> stream = book.file().inputStream(); if (stream.isNull() || ! stream->open()) { return false; } PdbHeader header; if (!header.read(stream)) { return false; } stream->seek(header.Offsets[0] + 46, true); unsigned short metaInfoOffset; PdbUtil::readUnsignedShort(*stream, metaInfoOffset); if (metaInfoOffset == 0 || metaInfoOffset >= header.Offsets.size()) { return false; } std::size_t currentOffset = header.Offsets[metaInfoOffset]; std::size_t nextOffset = (metaInfoOffset + 1 < (unsigned short)header.Offsets.size()) ? header.Offsets[metaInfoOffset + 1] : stream->sizeOfOpened(); if (nextOffset <= currentOffset) { return false; } std::size_t length = nextOffset - currentOffset; char* metaInfoBuffer = new char[length]; stream->seek(currentOffset, true); stream->read(metaInfoBuffer, length); std::string metaInfoStr(metaInfoBuffer, length); delete[] metaInfoBuffer; std::string metaInfoData[5]; // Title; Author; Rights; Publisher; isbn; for (std::size_t i = 0; i < 5; ++i) { const std::size_t index = metaInfoStr.find('\0'); metaInfoData[i] = metaInfoStr.substr(0,index); metaInfoStr = metaInfoStr.substr(index + 1); } if (!metaInfoData[0].empty()) { book.setTitle(metaInfoData[0]); } if (!metaInfoData[1].empty()) { book.addAuthor(metaInfoData[1]); } stream->close(); return SimplePdbPlugin::readMetaInfo(book); }
bool CHMPlugin::readMetaInfo(Book &book) const { const ZLFile &file = book.file(); shared_ptr<ZLInputStream> stream = file.inputStream(); if (stream.isNull() || !stream->open()) { return false; } CHMFileInfo chmFile(file); if (!chmFile.init(*stream)) { return false; } CHMFileInfo::FileNames names = chmFile.sectionNames(stream); if (names.empty()) { return false; } /* shared_ptr<ZLInputStream> entryStream = chmFile.entryStream(stream, names.Start); if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.Home); } if (entryStream.isNull()) { entryStream = chmFile.entryStream(stream, names.TOC); } / * if (entryStream.isNull()) { chmFile.entryStream(stream, names.Index); } * / if (entryStream.isNull()) { return false; } */ CHMTextStream textStream(chmFile, stream); detectEncodingAndLanguage(book, textStream); if (book.encoding().empty()) { return false; } return true; }
bool SimplePdbPlugin::readMetainfo(Book &book) const { const ZLFile &file = book.file(); shared_ptr<ZLInputStream> stream = createStream(file); detectEncodingAndLanguage(book, *stream); if (book.encoding().empty()) { return false; } int readType = HtmlMetainfoReader::NONE; if (book.title().empty()) { readType |= HtmlMetainfoReader::TITLE; } if (book.authors().empty()) { readType |= HtmlMetainfoReader::AUTHOR; } if (readType != HtmlMetainfoReader::NONE) { //if ((readType != HtmlMetainfoReader::NONE) && TextFormatDetector().isHtml(*stream)) { readType |= HtmlMetainfoReader::TAGS; HtmlMetainfoReader metainfoReader(book, (HtmlMetainfoReader::ReadType)readType); metainfoReader.readDocument(*stream); } return true; }
bool OEBPlugin::readUids(Book &book) const { const ZLFile &file = book.file(); return OEBUidReader(book).readUids(opfFile(file)); }
std::vector<shared_ptr<FileEncryptionInfo> > OEBPlugin::readEncryptionInfos(Book &book) const { const ZLFile &opf = opfFile(book.file()); return OEBEncryptionReader().readEncryptionInfos(epubFile(opf), opf); }
bool OEBPlugin::readMetainfo(Book &book) const { const ZLFile &file = book.file(); return OEBMetaInfoReader(book).readMetainfo(opfFile(file)); }