mirror of https://github.com/kiwix/libkiwix.git
+ better deal with relative/absolute paths
This commit is contained in:
parent
cb95e1f2ee
commit
34d69ae2c2
|
@ -66,9 +66,9 @@ namespace kiwix {
|
||||||
this->checkAndCleanBookPaths(book, libraryPath);
|
this->checkAndCleanBookPaths(book, libraryPath);
|
||||||
|
|
||||||
/* Update the book properties with the new importer */
|
/* Update the book properties with the new importer */
|
||||||
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) < atoi(KIWIX_LIBRARY_VERSION)) {
|
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
|
||||||
if (!book.path.empty()) {
|
if (!book.path.empty()) {
|
||||||
ok = this->readBookFromPath(book.pathAbsolute, book);
|
ok = this->readBookFromPath(book.pathAbsolute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ namespace kiwix {
|
||||||
const string url, const bool checkMetaData) {
|
const string url, const bool checkMetaData) {
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
|
|
||||||
if (this->readBookFromPath(pathToOpen, book)) {
|
if (this->readBookFromPath(pathToOpen, &book)) {
|
||||||
|
|
||||||
if (pathToSave != pathToOpen) {
|
if (pathToSave != pathToOpen) {
|
||||||
book.path = pathToSave;
|
book.path = pathToSave;
|
||||||
|
@ -250,35 +250,38 @@ namespace kiwix {
|
||||||
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData).empty());
|
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::readBookFromPath(const string path, kiwix::Book &book) {
|
bool Manager::readBookFromPath(const string path, kiwix::Book *book) {
|
||||||
try {
|
try {
|
||||||
kiwix::Reader *reader = new kiwix::Reader(path);
|
kiwix::Reader *reader = new kiwix::Reader(path);
|
||||||
book.path = path;
|
|
||||||
book.pathAbsolute = path;
|
|
||||||
book.id = reader->getId();
|
|
||||||
book.description = reader->getDescription();
|
|
||||||
book.language = reader->getLanguage();
|
|
||||||
book.date = reader->getDate();
|
|
||||||
book.creator = reader->getCreator();
|
|
||||||
book.publisher = reader->getPublisher();
|
|
||||||
book.title = reader->getTitle();
|
|
||||||
|
|
||||||
std::ostringstream articleCountStream;
|
if (book != NULL) {
|
||||||
articleCountStream << reader->getArticleCount();
|
book->path = path;
|
||||||
book.articleCount = articleCountStream.str();
|
book->pathAbsolute = path;
|
||||||
|
book->id = reader->getId();
|
||||||
|
book->description = reader->getDescription();
|
||||||
|
book->language = reader->getLanguage();
|
||||||
|
book->date = reader->getDate();
|
||||||
|
book->creator = reader->getCreator();
|
||||||
|
book->publisher = reader->getPublisher();
|
||||||
|
book->title = reader->getTitle();
|
||||||
|
|
||||||
std::ostringstream mediaCountStream;
|
std::ostringstream articleCountStream;
|
||||||
mediaCountStream << reader->getMediaCount();
|
articleCountStream << reader->getArticleCount();
|
||||||
book.mediaCount = mediaCountStream.str();
|
book->articleCount = articleCountStream.str();
|
||||||
|
|
||||||
ostringstream convert; convert << reader->getFileSize();
|
std::ostringstream mediaCountStream;
|
||||||
book.size = convert.str();
|
mediaCountStream << reader->getMediaCount();
|
||||||
|
book->mediaCount = mediaCountStream.str();
|
||||||
|
|
||||||
string favicon;
|
ostringstream convert; convert << reader->getFileSize();
|
||||||
string faviconMimeType;
|
book->size = convert.str();
|
||||||
if (reader->getFavicon(favicon, faviconMimeType)) {
|
|
||||||
book.favicon = base64_encode(reinterpret_cast<const unsigned char*>(favicon.c_str()), favicon.length());
|
string favicon;
|
||||||
book.faviconMimeType = faviconMimeType;
|
string faviconMimeType;
|
||||||
|
if (reader->getFavicon(favicon, faviconMimeType)) {
|
||||||
|
book->favicon = base64_encode(reinterpret_cast<const unsigned char*>(favicon.c_str()), favicon.length());
|
||||||
|
book->faviconMimeType = faviconMimeType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete reader;
|
delete reader;
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace kiwix {
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
|
|
||||||
bool readBookFromPath(const string path, Book &book);
|
bool readBookFromPath(const string path, Book *book = NULL);
|
||||||
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath);
|
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue