bool BooksDBUtil::getBooks(std::map<std::string, shared_ptr<Book> > &booksmap, bool checkFile) { BookList books; if (!BooksDB::Instance().loadBooks(books)) { return false; } for (BookList::iterator it = books.begin(); it != books.end(); ++it) { Book &book = **it; const std::string &filePath = book.filePath(); const std::string physicalFilePath = ZLFile(filePath).physicalFilePath(); ZLFile file(physicalFilePath); if (!checkFile || file.exists()) { if (!checkFile || checkInfo(file)) { if (isBookFull(book)) { booksmap.insert(std::make_pair(filePath, *it)); continue; } } else { if (physicalFilePath != filePath) { resetZipInfo(file); } saveInfo(file); } shared_ptr<Book> bookptr = Book::loadFromFile(filePath); if (!bookptr.isNull()) { BooksDB::Instance().saveBook(bookptr); booksmap.insert(std::make_pair(filePath, bookptr)); } } } return true; }
shared_ptr<Book> BooksDBUtil::getBook(const std::string &filePath, bool checkFile) { const std::string physicalFilePath = ZLFile(filePath).physicalFilePath(); ZLFile file(physicalFilePath); if (checkFile && !file.exists()) { return 0; } if (!checkFile || checkInfo(file)) { shared_ptr<Book> book = loadFromDB(filePath); if (!book.isNull() && isBookFull(*book)) { return book; } } else { if (physicalFilePath != filePath) { resetZipInfo(file); } saveInfo(file); } shared_ptr<Book> book = Book::loadFromFile(filePath); if (book.isNull()) { return 0; } BooksDB::Instance().saveBook(book); return book; }
void BooksDBUtil::listZipEntries(const ZLFile &zipFile, std::vector<std::string> &entries) { entries.clear(); BooksDB::Instance().loadFileEntries(zipFile.path(), entries); if (entries.empty()) { resetZipInfo(zipFile.path()); BooksDB::Instance().loadFileEntries(zipFile.path(), entries); } }
void BookDescriptionUtil::listZipEntries(const ZLFile &zipFile, std::vector<std::string> &entries) { int entriesNumber = ZLIntegerOption(FBCategoryKey::BOOKS, zipFile.path(), ENTRIES_NUMBER, -1).value(); if (entriesNumber == -1) { resetZipInfo(zipFile.path()); entriesNumber = ZLIntegerOption(FBCategoryKey::BOOKS, zipFile.path(), ENTRIES_NUMBER, -1).value(); } for (int i = 0; i < entriesNumber; ++i) { std::string optionName = ENTRY; ZLStringUtil::appendNumber(optionName, i); std::string entry = ZLStringOption(FBCategoryKey::BOOKS, zipFile.path(), optionName, "").value(); if (!entry.empty()) { entries.push_back(entry); } } }