Пример #1
0
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;
}
Пример #2
0
bool BooksDB::loadBooks(BookList &books) {
	AppLog(" BooksDB::loadBooks(BookList &books)");
	shared_ptr<DBDataReader> reader = myLoadBooks->executeReader();

	books.clear();
	std::map<int,shared_ptr<Book> > bookMap;

	while (reader->next()) {
		if (reader->type(0) != DBValue::DBINT || /* book_id */
				reader->type(4) != DBValue::DBINT) { /* file_id */
			return false;
		}
		const int bookId = reader->intValue(0);
		const int fileId = reader->intValue(4);
		const std::string fileName = getFileName(fileId);

		shared_ptr<Book> book = Book::createBook(
			ZLFile(fileName),
			bookId,
			reader->textValue(1, Book::AutoEncoding),
			reader->textValue(2, ZLLanguageUtil::OtherLanguageCode),
			reader->textValue(3, std::string())
		);
		books.push_back(book);
		bookMap[bookId] = book;
	}

	loadSeries(bookMap);
	AppLog("loadSeries(bookMap);");
	loadAuthors(bookMap);
	AppLog("loadAuthors(bookMap);");
	loadTags(bookMap);
	AppLog("loadTags(bookMap);");
	return true;
}
Пример #3
0
void FileHandler::saveBookList(string fname, BookList& b_list)
{
	// open file
	ofstream fout;
	fout.open(fname, ios_base::out);
	if (!fout.is_open())
	{
		cerr << "\n" << "can't open file!!";
		exit(1);
	}

	// save data into file
	for (OperatorHandler curNode = b_list.getFirst(); curNode != b_list.getHead(); ++curNode)
	{
		fout << curNode->getBookNo() << " " << curNode->getName() << endl;
	}
	// close file
	fout.close();
}
Пример #4
0
bool BooksDBUtil::getRecentBooks(BookList &books) {
	std::vector<std::string> fileNames;
	if (!BooksDB::Instance().loadRecentBooks(fileNames)) {
		return false;
	}
	for (std::vector<std::string>::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
		shared_ptr<Book> book = getBook(*it /*, true OR false ? */); // TODO: check file ???
		if (!book.isNull()) {
			books.push_back(book);
		}
	}
	return true;
}
Пример #5
0
void FileHandler::loadBookList(string fname, BookList& b_list)
{
	//open file
	ifstream fin;
	fin.open(fname, ios_base::in);
	if (!fin)
	{
		cerr << "\n" << "can't open file!!";
		return;
	}

	// read data from file
	while (!fin.eof()) // read data
	{
		string book_no;
		string name;
		string book_text;

		getline(fin, book_text);

		if (book_text == "") break;

		if (fin.fail()) break;

		book_text = book_text.substr(book_text.find_first_not_of(' '), book_text.length());		// 공백부터 전체 문자열의 길이만큼 읽어들임

		book_no = book_text.substr(0, book_text.find_first_of(' '));	// 0부터 공백까지 읽어들임
		name = book_text.substr(book_text.find_first_of(' ') + 1, book_text.length());	// 먼저 찾은 공백부터 길이만큼 읽어들임

		name = name.substr(name.find_first_not_of(' '), book_text.length());	// 공백부터 해당 문자열의 길이만큼 읽어들임	
		name = name.substr(0, name.find_last_not_of(' ') + 1);	// 다시 0부터 공백까지 읽어들임

		Book* b = new Book(book_no, name);	// 새로운 노드

		b_list.insertBook(b);
	}

	// close file
	fin.close();
}
Пример #6
0
void BookCollection::rebuild() {
  myPath = PathOption.value();
  myScanSubdirs = ScanSubdirsOption.value();

  myAuthors.clear();
  myCollection.clear();
  myExternalBooks.clear();

  std::set<std::string> fileNamesSet;

  std::set<std::string> dirs;
  collectDirNames(dirs);

  for (std::set<std::string>::iterator it = dirs.begin(); it != dirs.end(); ++it) {
    std::vector<std::string> files;
    shared_ptr<ZLDir> dir = ZLFile(*it).directory();
    if (dir.isNull()) {
      continue;
    }
    dir->collectFiles(files, false);
    if (!files.empty()) {
      const std::string dirName = dir->name() + '/';
      for (std::vector<std::string>::const_iterator jt = files.begin(); jt != files.end(); ++jt) {
        const std::string fileName = dirName + *jt;
        ZLFile file(fileName);
        if (PluginCollection::instance().plugin(file, true) != 0) {
          fileNamesSet.insert(fileName);
        } else if (file.extension() == "zip") {
          if (!BookDescriptionUtil::checkInfo(file)) {
            BookDescriptionUtil::resetZipInfo(file);
            BookDescriptionUtil::saveInfo(file);
          }
          std::vector<std::string> zipEntries;
          BookDescriptionUtil::listZipEntries(file, zipEntries);
          for (std::vector<std::string>::const_iterator zit = zipEntries.begin(); zit != zipEntries.end(); ++zit) {
            fileNamesSet.insert(*zit);
          }
        }
      }
    }
  }

  for (std::set<std::string>::iterator it = fileNamesSet.begin(); it != fileNamesSet.end(); ++it) {
    addDescription(BookDescription::create(*it));
  }

  BookList bookList;
  const std::set<std::string> &bookListSet = bookList.fileNames();
  for (std::set<std::string>::const_iterator it = bookListSet.begin(); it != bookListSet.end(); ++it) {
    if (fileNamesSet.find(*it) == fileNamesSet.end()) {
      BookDescriptionPtr description = BookDescription::create(*it);
      addDescription(description);
      myExternalBooks.insert(description);
    }
  }

  std::sort(myAuthors.begin(), myAuthors.end(), AuthorComparator());
  DescriptionComparator descriptionComparator;
  for (std::map<AuthorPtr,Books>::iterator it = myCollection.begin(); it != myCollection.end(); ++it) {
    std::sort((*it).second.begin(), (*it).second.end(), descriptionComparator);
  }
}