void Library::rebuildBookSet() const { myBooks.clear(); myExternalBooks.clear(); std::map<std::string, shared_ptr<Book> > booksMap; BooksDBUtil::getBooks(booksMap); std::set<std::string> fileNamesSet; collectBookFileNames(fileNamesSet); // collect books from book path for (std::set<std::string>::iterator it = fileNamesSet.begin(); it != fileNamesSet.end(); ++it) { std::map<std::string, shared_ptr<Book> >::iterator jt = booksMap.find(*it); if (jt == booksMap.end()) { insertIntoBookSet(BooksDBUtil::getBook(*it)); } else { insertIntoBookSet(jt->second); booksMap.erase(jt); } } // other books from our database for (std::map<std::string, shared_ptr<Book> >::iterator jt = booksMap.begin(); jt != booksMap.end(); ++jt) { shared_ptr<Book> book = jt->second; if (!book.isNull()) { if (BooksDB::Instance().checkBookList(*book)) { insertIntoBookSet(book); myExternalBooks.insert(book); } } } }
void Library::rebuildBookSet() const { AppLog("Library::rebuildBookSet()"); // FunctionTimer timer(__PRETTY_FUNCTION__); myBooks.clear(); myExternalBooks.clear(); std::map<std::string, shared_ptr<Book> > booksMap; AppLog("BooksDBUtil::getBooks(booksMap)"); BooksDBUtil::getBooks(booksMap); std::set<std::string> fileNamesSet; std::vector<shared_ptr<ZLInputStream> > inputStreamCache; AppLog("collectBookFileNames(fileNamesSet, inputStreamCache);"); collectBookFileNames(fileNamesSet, inputStreamCache); // collect books from book path for (std::set<std::string>::iterator it = fileNamesSet.begin(); it != fileNamesSet.end(); ++it) { std::map<std::string, shared_ptr<Book> >::iterator jt = booksMap.find(*it); if (jt == booksMap.end()) { // std::cerr << "Check file \"" << (*it) << "\" ... "; // std::cerr.flush(); // clock_t start = clock(); insertIntoBookSet(BooksDBUtil::getBook(*it)); // std::cerr << (double(clock() - start) * 1000. / CLOCKS_PER_SEC) << " ms" << std::endl; // std::cerr.flush(); } else { insertIntoBookSet(jt->second); booksMap.erase(jt); } } // other books from our database for (std::map<std::string, shared_ptr<Book> >::iterator jt = booksMap.begin(); jt != booksMap.end(); ++jt) { shared_ptr<Book> book = jt->second; if (!book.isNull()) { if (BooksDB::Instance().checkBookList(*book)) { insertIntoBookSet(book); myExternalBooks.insert(book); } } } // help file shared_ptr<Book> help = FBReader::Instance().helpFile(); if (!help.isNull()) { insertIntoBookSet(help); myExternalBooks.insert(help); } }
void Library::addBook(shared_ptr<Book> book) { if (!book.isNull()) { BooksDB::Instance().saveBook(book); insertIntoBookSet(book); myBuildMode = (BuildMode)(myBuildMode | BUILD_UPDATE_BOOKS_INFO); } }