bool NetworkLinkCollection::downloadBook(const BookReference &reference, std::string &fileName, const ZLNetworkSSLCertificate &sslCertificate, shared_ptr<ZLExecutionData::Listener> listener) {
	std::string nURL = ::normalize(reference.URL);
	rewriteUrl(nURL);
	const std::string nNetworkBookId = ::normalize(reference.cleanURL());
	const ZLResource &errorResource = ZLResource::resource("dialog")["networkError"];
	myErrorMessage.clear();

	if (nURL.empty() || nNetworkBookId.empty()) {
		myErrorMessage = errorResource["unknownErrorMessage"].value();
		return false;
	}
	std::string storedFileName = BooksDB::Instance().getNetFile(nNetworkBookId);
	if (!storedFileName.empty() && ZLFile(storedFileName).exists()) {
		fileName = storedFileName;
		return true;
	}
	fileName = makeBookFileName(nNetworkBookId, reference.BookFormat, reference.ReferenceType, true);
	if (fileName.empty()) {
		if (myErrorMessage.empty()) {
			myErrorMessage = errorResource["unknownErrorMessage"].value();
		}
		return false;
	}
	if (ZLFile(fileName).exists()) {
		ZLFile(fileName).remove();
	}
	myErrorMessage = ZLNetworkManager::Instance().downloadFile(nURL, sslCertificate, fileName, listener);
	if (!myErrorMessage.empty()) {
		return false;
	}
	BooksDB::Instance().setNetFile(nNetworkBookId, fileName);
	return true;
}
Exemplo n.º 2
0
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(ZLFile(filePath));
	if (book.isNull()) {
		return 0;
	}
	BooksDB::Instance().saveBook(book);
	return book;
}
Exemplo n.º 3
0
void XMLConfig::load() {
	XMLConfigReader(*this, "").readDocument(ZLFile(
		ZLibrary::DefaultFilesPathPrefix() + "config.xml"
	));
	XMLConfigReader(*this, "").readDocument(ZLFile(
		ZLibrary::ZLibraryDirectory() + ZLibrary::FileNameDelimiter + "default" + ZLibrary::FileNameDelimiter + "config.xml"
	));
	myDefaultGroups = myGroups;
	for (std::map<std::string,XMLConfigGroup*>::iterator it = myDefaultGroups.begin(); it != myDefaultGroups.end(); ++it) {
		it->second = new XMLConfigGroup(*it->second);
	}
	shared_ptr<ZLDir> configDir = ZLFile(ZLibrary::ApplicationWritableDirectory()).directory(false);
	if (!configDir.isNull()) {
		std::vector<std::string> fileNames;
		configDir->collectFiles(fileNames, true);
		for (std::vector<std::string>::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
			ZLFile configFile(configDir->itemPath(*it));
			if (configFile.extension() == "xml") {
				XMLConfigReader(*this, configFile.name(true)).readDocument(configFile.inputStream());
			}
		}
	}
	if (myDelta == 0) {
		myDelta = new XMLConfigDelta();
	}
	if (!configDir.isNull()) {
		XMLConfigReader(*this, UNKNOWN_CATEGORY).readDocument(
			ZLFile(configDir->itemPath(CHANGES_FILE))
		);
	}
}
Exemplo n.º 4
0
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
	// Ignore transparent images
	if (!reader.myParseStack.back().opacity) {
		return;
	}

	const char *fileName = reader.attributeValue(xmlattributes, *myPredicate);
	if (fileName == 0) {
		return;
	}

	const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName);
	if (!ZLFile(fullfileName).exists()) {
		return;
	}

	if ((strlen(fileName) > 2) && strncmp(fileName, "./", 2) == 0) {
		fileName +=2;
	}

	reader.myParseStack.back().kind = IMAGE;
	reader.haveContent();
	reader.myModelReader.addImageReference(fullfileName);
	reader.myModelReader.addImage(fullfileName, new ZLFileImage(ZLFile(fullfileName), 0));
}
Exemplo n.º 5
0
void ZLCommunicationManager::init() {
	ZLMessageDescriptionReader(*this).readDocument(ZLFile(
		ZLibrary::ZLibraryDirectory() + ZLibrary::FileNameDelimiter + "messages.xml"
	));
	ZLMessageDescriptionReader(*this).readDocument(ZLFile(
		ZLibrary::DefaultFilesPathPrefix() + "messages.xml"
	));
	myInitialized = true;
}
Exemplo n.º 6
0
void ZLTreeResource::loadData(const std::string &language) {
	std::string filePath = ZLibrary::FileNameDelimiter + "resources" + ZLibrary::FileNameDelimiter + language + ".xml";
	ZLResourceTreeReader(ourRoot).readDocument(ZLFile(
		ZLibrary::ZLibraryDirectory() + filePath
	));
	ZLResourceTreeReader(ourRoot).readDocument(ZLFile(
		ZLibrary::ApplicationDirectory() + filePath
	));
}
Exemplo n.º 7
0
bool ORBookReader::readBook() {
	const ZLFile &file = myModelReader.model().book()->file();
	myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path());

	myResources.clear();
	myCoverReference.erase();
	myHtmlFileIDs.clear();
	myImageIDs.clear();
	myHtmlFilesOrder.clear();
	myTOC.clear();
	myState = READ_NONE;

	if (!readDocument(file)) {
		return false;
	}

	myModelReader.setMainTextModel();
	myModelReader.pushKind(REGULAR);

	if (!myCoverReference.empty()) {
		myModelReader.addImageReference(myCoverReference);
	}

	for (std::vector<std::string>::const_iterator it = myHtmlFilesOrder.begin(); it != myHtmlFilesOrder.end(); ++it) {
		myHtmlFileIDs.erase(*it);
		XHTMLReader(myModelReader).readFile(ZLFile(myFilePrefix + myResources[*it]), *it);
	}

	int level = 1;
	for (std::vector<TOCItem>::const_iterator it = myTOC.begin(); it != myTOC.end(); ++it) {
		int index = myModelReader.model().label(it->Reference).ParagraphNumber;
		if (index != -1) {
			for (; level > it->Level; --level) {
				myModelReader.endContentsParagraph();
			}
			++level;
			myModelReader.beginContentsParagraph(index);
			myModelReader.addContentsData(it->Text);
		}
	}
	for (; level > 1; --level) {
		myModelReader.endContentsParagraph();
	}

	for (std::set<std::string>::const_iterator it = myHtmlFileIDs.begin(); it != myHtmlFileIDs.end(); ++it) {
		myModelReader.setFootnoteTextModel(*it);
		myModelReader.pushKind(REGULAR);
		XHTMLReader(myModelReader).readFile(ZLFile(myFilePrefix + myResources[*it]), *it);
	}

	for (std::map<std::string,std::string>::const_iterator it = myImageIDs.begin(); it != myImageIDs.end(); ++it) {
		myModelReader.addImage(it->first, new ZLFileImage(ZLFile(myFilePrefix + myResources[it->first], it->second), 0));
	}

	return true;
}
Exemplo n.º 8
0
FBFileHandler::FBFileHandler() :
    DirectoryOption(ZLCategoryKey::LOOK_AND_FEEL, "OpenFileDialog", "Directory", "~"), myIsUpToDate(false), mySelectedIndex(0) {
    myDir = ZLFile(DirectoryOption.value()).directory();
    if (myDir.isNull()) {
        myDir = ZLFile("~").directory();
    }
    if (myDir.isNull()) {
        myDir = ZLDir::root();
    }
}
Exemplo n.º 9
0
void XMLConfig::saveDelta() {
	if ((myDelta == 0) || (myDelta->myIsUpToDate)) {
		return;
	}
	shared_ptr<ZLDir> configDir = ZLFile(ZLibrary::ApplicationWritableDirectory()).directory(true);
	shared_ptr<ZLOutputStream> stream = ZLFile(configDir->itemPath(CHANGES_FILE)).outputStream();
	if (!stream.isNull() && stream->open()) {
		XMLConfigDeltaWriter(*myDelta, *stream).write();
		stream->close();
	}
	myDelta->myIsUpToDate = true;
}
Exemplo n.º 10
0
BookInfoDialog::BookInfoDialog(const BookCollection &collection, const std::string &fileName) : myCollection(collection), myBookInfo(fileName) {
    myDialog = ZLDialogManager::instance().createOptionsDialog(ZLResourceKey("InfoDialog"));

    ZLDialogContent &commonTab = myDialog->createTab(ZLResourceKey("Common"));
    commonTab.addOption(ZLResourceKey("file"),
                        new ZLStringInfoEntry(ZLFile::fileNameToUtf8(ZLFile(fileName).path()))
                       );
    commonTab.addOption(ZLResourceKey("title"), myBookInfo.TitleOption);

    myAuthorDisplayNameEntry = new AuthorDisplayNameEntry(*this);
    myAuthorSortKeyEntry = new AuthorSortKeyEntry(*this);
    myEncodingEntry = new EncodingEntry(myBookInfo.EncodingOption);
    myEncodingSetEntry =
        (myEncodingEntry->initialValue() != "auto") ?
        new EncodingSetEntry(*(EncodingEntry*)myEncodingEntry) : 0;
    std::vector<std::string> languageCodes = ZLLanguageList::languageCodes();
    languageCodes.push_back("de-traditional");
    myLanguageEntry = new ZLLanguageOptionEntry(myBookInfo.LanguageOption, languageCodes);
    mySeriesTitleEntry = new SeriesTitleEntry(*this);
    myBookNumberEntry = new ZLSimpleSpinOptionEntry(myBookInfo.NumberInSeriesOption, 1);

    commonTab.addOption(ZLResourceKey("authorDisplayName"), myAuthorDisplayNameEntry);
    commonTab.addOption(ZLResourceKey("authorSortKey"), myAuthorSortKeyEntry);
    commonTab.addOption(ZLResourceKey("language"), myLanguageEntry);
    if (myEncodingSetEntry != 0) {
        commonTab.addOption(ZLResourceKey("encodingSet"), myEncodingSetEntry);
    }
    commonTab.addOption(ZLResourceKey("encoding"), myEncodingEntry);

    ZLDialogContent &seriesTab = myDialog->createTab(ZLResourceKey("Series"));
    seriesTab.addOption(ZLResourceKey("seriesTitle"), mySeriesTitleEntry);
    seriesTab.addOption(ZLResourceKey("bookNumber"), myBookNumberEntry);

    mySeriesTitleEntry->onValueEdited(mySeriesTitleEntry->initialValue());
    /*
    ZLOrderOptionEntry *orderEntry = new ZLOrderOptionEntry();
    orderEntry->values().push_back("First");
    orderEntry->values().push_back("Second");
    orderEntry->values().push_back("Third");
    orderEntry->values().push_back("Fourth");
    orderEntry->values().push_back("Fifth");
    seriesTab.addOption(orderEntry);
    */

    ZLDialogContent &tagsTab = myDialog->createTab(ZLResourceKey("Tags"));
    tagsTab.addOption(ZLResourceKey("tags"), myBookInfo.TagsOption);

    FormatPlugin *plugin = PluginCollection::instance().plugin(ZLFile(fileName), false);
    if (plugin != 0) {
        myFormatInfoPage = plugin->createInfoPage(*myDialog, fileName);
    }
}
Exemplo n.º 11
0
void NetworkBookDownloadAction::bookDownloaded(DownloadBookRunnable *downloader) {
	if (downloader->hasErrors()) {
		downloader->showErrorMessage();
	//	finished(downloader->errorMessage());
	//	setListener(0);
		return;
	}

	FBReader &fbreader = FBReader::Instance();
	shared_ptr<Book> downloaderBook;
	const std::string fileName = downloader->fileName();
	fbreader.createBook(ZLFile(fileName), downloaderBook);
	if (downloaderBook.isNull()) {
		ZLFile(fileName).remove();
		ZLResourceKey boxKey("cantOpenDownloadedFile");
		const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title);
		ZLDialogManager::Instance().errorBox(boxKey, message);
		fbreader.refreshWindow();
	//	finished(message);
	//	setListener(0);
		return;
	}

	downloaderBook->removeAllAuthors();
	for (std::vector<NetworkBookItem::AuthorData>::const_iterator it = myBook.Authors.begin(); it != myBook.Authors.end(); ++it) {
		downloaderBook->addAuthor(it->DisplayName, it->SortKey);
	}
	std::string bookTitle = myBook.Title;
	if (!myTag.empty()) {
		bookTitle += " (" + myTag + ")";
	}
	downloaderBook->setTitle(bookTitle);
	downloaderBook->setLanguage(myBook.Language);
	for (std::vector<std::string>::const_iterator it = myBook.Tags.begin(); it != myBook.Tags.end(); ++it) {
		downloaderBook->addTag(*it);
	}
	if (!myTag.empty()) {
		downloaderBook->addTag(myTag);
	}
	Library::Instance().addBook(downloaderBook);

	fbreader.openBook(downloaderBook);
	fbreader.setMode(FBReader::BOOK_TEXT_MODE);
	fbreader.refreshWindow();
//	finished(std::string());
//	setListener(0);
	AppLog("bookDownloaded");
	//myNode->close();
}
Exemplo n.º 12
0
bool FBReader::createDescription(const std::string& fileName, BookDescriptionPtr &description) {
	ZLFile bookFile = ZLFile(fileName);

	FormatPlugin *plugin = PluginCollection::instance().plugin(ZLFile(fileName), false);
	if (plugin != 0) {
		std::string error = plugin->tryOpen(fileName);
		if (!error.empty()) {
			ZLResourceKey boxKey("openBookErrorBox");
			ZLDialogManager::instance().errorBox(
				boxKey,
				ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error)
			);
		} else {
			BookList().addFileName(bookFile.path());
			description = BookDescription::getDescription(bookFile.path());
		}
		return true;
	}

	if (!bookFile.isArchive()) {
		return false;
	}

	std::queue<std::string> archiveNames;
	archiveNames.push(bookFile.path());

	std::vector<std::string> items;

	while (!archiveNames.empty()) {
		shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory();
		archiveNames.pop();
		if (archiveDir.isNull()) {
			continue;
		}
		archiveDir->collectFiles(items, true);
		for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) {
			const std::string itemName = archiveDir->itemPath(*it);
			ZLFile subFile(itemName);
			if (subFile.isArchive()) {
				archiveNames.push(itemName);
			} else if (createDescription(itemName, description)) {
				return true;
			}
		}
		items.clear();
	}

	return 0;
}
Exemplo n.º 13
0
const shared_ptr<std::string> ZCompressedFileImage::stringData() const {
	shared_ptr<ZLInputStream> stream = ZLFile(myPath).inputStream();

	shared_ptr<std::string> imageData = new std::string();

	if (!stream.isNull() && stream->open()) {
		stream->seek(myOffset, false);
		ZLZDecompressor decompressor(myCompressedSize);

		static const size_t charBufferSize = 2048;
		char *charBuffer = new char[charBufferSize];
		std::vector<std::string> buffer;

		size_t s;
		do {
			s = decompressor.decompress(*stream, charBuffer, charBufferSize);
			if (s != 0) {
				buffer.push_back(std::string());
				buffer.back().append(charBuffer, s);
			}
		} while (s == charBufferSize);
		ZLStringUtil::append(*imageData, buffer);

		delete[] charBuffer;
	}

	return imageData;
}
Exemplo n.º 14
0
void FBReader::initWindow() {
	ZLApplication::initWindow();
	trackStylus(true);

	MigrationRunnable migration;
	if (migration.shouldMigrate()) {
		ZLDialogManager::Instance().wait(ZLResourceKey("migrate"), migration);
	}

	if (!myBookAlreadyOpen) {
		shared_ptr<Book> book;
		if (!myBookToOpen.empty()) {
			createBook(ZLFile(myBookToOpen), book);
		}
		if (book.isNull()) {
			const BookList &books = Library::Instance().recentBooks();
			if (!books.empty()) {
				book = books[0];
			}
		}
		if (book.isNull()) {
			book = BooksDBUtil::getBook(helpFileName(ZLibrary::Language()));
		}
		if (book.isNull()) {
			book = BooksDBUtil::getBook(helpFileName("en"));
		}
		openBook(book);
	}
	refreshWindow();

	ZLTimeManager::Instance().addTask(new TimeUpdater(), 1000);
}
Exemplo n.º 15
0
void ZLApplication::createToolbar(int index) {
	toolbar(index);
	std::string fileName = ZLibrary::DefaultFilesPathPrefix();
	const bool isWindowToolbar = index == ZLApplicationWindow::WINDOW_TOOLBAR;
	fileName += isWindowToolbar ? "toolbar.xml" : "fullscreen_toolbar.xml";
	ZLToolbarCreator(isWindowToolbar ? *myToolbar : *myFullscreenToolbar).readDocument(ZLFile(fileName));
}
Exemplo n.º 16
0
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
	const char *fileName = reader.attributeValue(xmlattributes, *myPredicate);
	if (fileName == 0) {
		return;
	}

	const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName);
	ZLFile imageFile(fullfileName);
	if (!imageFile.exists()) {
		return;
	}

	bool flag = bookReader(reader).paragraphIsOpen();
	if (flag) {
		endParagraph(reader);
	}
	if (std::strlen(fileName) > 2 && std::strncmp(fileName, "./", 2) == 0) {
		fileName +=2;
	}
	bookReader(reader).addImageReference(fullfileName);
	bookReader(reader).addImage(fullfileName, new ZLFileImage(ZLFile(fullfileName), 0));
	if (flag) {
		beginParagraph(reader);
	}
}
Exemplo n.º 17
0
FB2TagManager::FB2TagManager() {
	FB2TagInfoReader(myTagMap).readDocument(ZLFile(
		ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter +
		"formats" + ZLibrary::FileNameDelimiter + "fb2" +
		ZLibrary::FileNameDelimiter + "fb2genres.xml"
	));
}
Exemplo n.º 18
0
std::string ZLKeyUtil::keyName(int unicode, int key, int modifiersMask) {
	if (!ourInitialized) {
		KeyNamesReader().readDocument(ZLFile(ZLibrary::ZLibraryDirectory() + ZLibrary::FileNameDelimiter + ourKeyNamesFileName));
		ourInitialized = true;
	}

	std::string name;
	std::map<int,std::string>::const_iterator it = ourNames.find(key);
	if (it != ourNames.end()) {
		name = it->second;
	}

	if (ourUseAutoNames && name.empty()) {
		if (((unicode < 128) && isprint(unicode) && !isspace(unicode)) || ZLUnicodeUtil::isLetter(unicode)) {
			name += '<';
			char buf[5];
			name.append(buf, ZLUnicodeUtil::ucs4ToUtf8(buf, ZLUnicodeUtil::toUpper(unicode)));
			name += '>';
		}
	}

	if (name.empty()) {
		name += '[';
		ZLStringUtil::appendNumber(name, key);
		name += ']';
	}

	for (std::map<int,std::string>::iterator it = ourModifiers.begin(); it != ourModifiers.end(); ++it) {
		if ((modifiersMask & it->first) == it->first) {
			name = it->second + "+" + name;
		}
	}

	return name;
}
Exemplo n.º 19
0
void EReaderPlugin::readDocumentInternal(const ZLFile &file, BookModel &model, const PlainTextFormat &format, const std::string &encoding, ZLInputStream &stream) const {
	if (!stream.open())	{
		//TODO maybe anything else opens stream
		return;
	}
	BookReader bookReader(model);
	PmlBookReader pmlBookReader(bookReader, format, encoding);
	bookReader.setMainTextModel();
	pmlBookReader.readDocument(stream);
	EReaderStream &estream = (EReaderStream&)stream;
	const std::map<std::string, EReaderStream::ImageInfo>& imageIds = estream.images();
	for(std::map<std::string, EReaderStream::ImageInfo>::const_iterator it = imageIds.begin(); it != imageIds.end(); ++it) {
		const std::string id = it->first;
		bookReader.addImage(id, new ZLFileImage(ZLFile(file.path(), it->second.Type), it->second.Offset, it->second.Size));
	}
	const std::map<std::string, unsigned short>& footnoteIds = estream.footnotes();
	for(std::map<std::string, unsigned short>::const_iterator it = footnoteIds.begin(); it != footnoteIds.end(); ++it) {
		const std::string id = it->first;
		if (estream.switchStreamDestination(EReaderStream::FOOTNOTE, id)) {
			bookReader.setFootnoteTextModel(id);
			bookReader.addHyperlinkLabel(id);
			pmlBookReader.readDocument(estream);
		}
	}
	stream.close();
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
bool RtfReader::readDocument(const std::string &fileName) {
    myFileName = fileName;
    myStream = ZLFile(fileName).inputStream();
    if (!myStream || !myStream->open()) {
        return false;
    }

    fillKeywordMap();

    myStreamBuffer = new char[rtfStreamBufferSize];

    myIsInterrupted = false;

    mySpecialMode = false;

    myState.Alignment = ALIGN_UNDEFINED;
    myState.Italic = false;
    myState.Bold = false;
    myState.Underlined = false;
    myState.Destination = RtfReader::DESTINATION_NONE;
    myState.ReadDataAsHex = false;

    bool code = parseDocument();

    while (!myStateStack.empty()) {
        myStateStack.pop();
    }

    delete[] myStreamBuffer;
    myStream->close();

    return code;
}
Exemplo n.º 22
0
void FBReader::tryShowFootnoteView(const std::string &id, const std::string &type) {
	if (type == "external") {
		openLinkInBrowser(id);
	} else if (type == "internal") {
		if (myMode == BOOK_TEXT_MODE && !myModel.isNull()) {
			BookModel::Label label = myModel->label(id);
			if (!label.Model.isNull()) {
				if (label.Model == myModel->bookTextModel()) {
					bookTextView().gotoParagraph(label.ParagraphNumber);
				} else {
					FootnoteView &view = ((FootnoteView&)*myFootnoteView);
					view.setModel(label.Model);
					setMode(FOOTNOTE_MODE);
					view.gotoParagraph(label.ParagraphNumber);
				}
				setHyperlinkCursor(false);
				refreshWindow();
			}
		}
	} else if (type == "book") {
		DownloadBookRunnable downloader(id);
		downloader.executeWithUI();
		if (downloader.hasErrors()) {
			downloader.showErrorMessage();
		} else {
			shared_ptr<Book> book;
			createBook(ZLFile(downloader.fileName()), book);
			if (!book.isNull()) {
				Library::Instance().addBook(book);
				openBook(book);
				refreshWindow();
			}
		}
	}
}
Exemplo n.º 23
0
bool OEBPlugin::readModel(const DBBook &book, BookModel &model) const {
	model.addUserData(
		"inputStreamLock",
		new InputStreamLock(ZLFile(book.fileName()).inputStream())
	);
	return OEBBookReader(model).readBook(opfFileName(book.fileName()));
}
Exemplo n.º 24
0
void BookCollection::collectDirNames(std::set<std::string> &nameSet) {
  std::queue<std::string> nameQueue;

  std::string path = myPath;
  int pos = path.find(':');
  while (pos != -1) {
    nameQueue.push(path.substr(0, pos));
    path.erase(0, pos + 1);
    pos = path.find(':');
  }
  if (!path.empty()) {
    nameQueue.push(path);
  }

  while (!nameQueue.empty()) {
    std::string name = nameQueue.front();
    nameQueue.pop();
    if (nameSet.find(name) == nameSet.end()) {
      if (myScanSubdirs) {
        shared_ptr<ZLDir> dir = ZLFile(name).directory();
        if (!dir.isNull()) {
          std::vector<std::string> subdirs;
          dir->collectSubDirs(subdirs, false);
          for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); ++it) {
            nameQueue.push(dir->name() + '/' + *it);
          }
        }
      }
      nameSet.insert(name);
    }
  }
}
Exemplo n.º 25
0
void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
	static const std::string REL = "stylesheet";
	const char *rel = reader.attributeValue(xmlattributes, "rel");
	if ((rel == 0) || (REL != rel)) {
		return;
	}
	static const std::string TYPE = "text/css";

	const char *type = reader.attributeValue(xmlattributes, "type");
	if ((type == 0) || (TYPE != type)) {
		return;
	}

	const char *href = reader.attributeValue(xmlattributes, "href");
	if (href == 0) {
		return;
	}

	ZLLogger::Instance().println("CSS", "style file: " + reader.myPathPrefix + MiscUtil::decodeHtmlURL(href));
	shared_ptr<ZLInputStream> cssStream = ZLFile(reader.myPathPrefix + MiscUtil::decodeHtmlURL(href)).inputStream();
	if (cssStream.isNull()) {
		return;
	}
	ZLLogger::Instance().println("CSS", "parsing file");
	StyleSheetTableParser parser(reader.myStyleSheetTable);
	parser.parse(*cssStream);
	//reader.myStyleSheetTable.dump();
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
0
void ZLEncodingCollection::init() {
	if (mySets.empty()) {
		ZLEncodingCollectionReader(*this).readDocument(ZLFile(
			encodingDescriptionPath() + ZLibrary::FileNameDelimiter + "Encodings.xml"
		));
	}
}
Exemplo n.º 28
0
ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream &containerStream) : myContainerName(containerName) {
	//ZLLogger::Instance().println("ZipEntryCache", "creating cache for " + containerName);
	myLastModifiedTime = ZLFile(containerName).lastModified();
	if (!containerStream.open()) {
		return;
	}

	ZLZipHeader header;
	while (header.readFrom(containerStream)) {
		Info *infoPtr = 0;
		if (header.Signature == (unsigned long)ZLZipHeader::SignatureLocalFile) {
			std::string entryName(header.NameLength, '\0');
			if ((unsigned int)containerStream.read((char*)entryName.data(), header.NameLength) == header.NameLength) {
				entryName = AndroidUtil::convertNonUtfString(entryName);
				Info &info = myInfoMap[entryName];
				info.Offset = containerStream.offset() + header.ExtraLength;
				info.CompressionMethod = header.CompressionMethod;
				info.CompressedSize = header.CompressedSize;
				info.UncompressedSize = header.UncompressedSize;
				infoPtr = &info;
			}
		}
		ZLZipHeader::skipEntry(containerStream, header);
		if (infoPtr != 0) {
			infoPtr->UncompressedSize = header.UncompressedSize;
		}
	}
	containerStream.close();
}
Exemplo n.º 29
0
PlainTextInfoPage::PlainTextInfoPage(ZLOptionsDialog &dialog, const std::string &fileName, const ZLResourceKey &key, bool showContentsEntry) : myFormat(fileName) {
	if (!myFormat.initialized()) {
		PlainTextFormatDetector detector;
		shared_ptr<ZLInputStream> stream = ZLFile(fileName).inputStream();
		if (stream) {
			detector.detect(*stream, myFormat);
		}
	}

	ZLDialogContent &tab = dialog.createTab(key);

	BreakTypeOptionEntry *breakEntry = new BreakTypeOptionEntry(*this, myFormat.BreakTypeOption);
	myIgnoredIndentEntry = new ZLSimpleSpinOptionEntry(myFormat.IgnoredIndentOption, 1);
	tab.addOption(ZLResourceKey("breakType"), breakEntry);
	tab.addOption(ZLResourceKey("ignoreIndent"), myIgnoredIndentEntry);
	breakEntry->onValueSelected(breakEntry->initialIndex());

	if (showContentsEntry) {
		CreateContentsTableOptionEntry *contentsTableEntry = new CreateContentsTableOptionEntry(*this, myFormat.CreateContentsTableOption);
		myEmptyLinesBeforeNewSectionEntry = new ZLSimpleSpinOptionEntry(myFormat.EmptyLinesBeforeNewSectionOption, 1);
		tab.addOption(ZLResourceKey("buildTOC"), contentsTableEntry);
		tab.addOption(ZLResourceKey("emptyLines"), myEmptyLinesBeforeNewSectionEntry);
		contentsTableEntry->onStateChanged(contentsTableEntry->initialState());
	}
}
Exemplo n.º 30
0
shared_ptr<Book> BooksDB::loadBook(const std::string &fileName) {
	AppLog(" BooksDB::loadBook(const std::string &fileName)");
	if (!isInitialized()) {
		return 0;
	}

	myFindFileId->setFileName(fileName);
	if (!myFindFileId->run()) {
		return false;
	}
	((DBIntValue&)*myLoadBook->parameter("@file_id").value()) = myFindFileId->fileId();
	shared_ptr<DBDataReader> reader = myLoadBook->executeReader();

	if (reader.isNull() || !reader->next() ||
			reader->type(0) != DBValue::DBINT /* book_id */) {
		return 0;
	}
	const int bookId = reader->intValue(0);

	shared_ptr<Book> book = Book::createBook(
		ZLFile(fileName), bookId,
		reader->textValue(1, Book::AutoEncoding),
		reader->textValue(2, ZLLanguageUtil::OtherLanguageCode),
		reader->textValue(3, std::string())
	);

	loadSeries(*book);
	AppLog("loadSeries(*book);");
	loadAuthors(*book);
	AppLog("loadSeries(*book);");
	loadTags(*book);
	AppLog("loadSeries(*book);");

	return book;
}