mirror of https://github.com/kiwix/libkiwix.git
+ content mgmt. last dev.
This commit is contained in:
parent
804889d5dc
commit
e6ff96ecb4
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include <pugixml.hpp>
|
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
|
@ -31,18 +30,15 @@ namespace kiwix {
|
||||||
Manager::~Manager() {
|
Manager::~Manager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::readFile(const string path, const bool readOnly) {
|
bool Manager::parseXmlDom(const pugi::xml_document &doc, const bool readOnly) {
|
||||||
pugi::xml_document doc;
|
|
||||||
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
pugi::xml_node libraryNode = doc.child("library");
|
pugi::xml_node libraryNode = doc.child("library");
|
||||||
library.current = libraryNode.attribute("current").value();
|
library.current = libraryNode.attribute("current").value();
|
||||||
string libraryVersion = libraryNode.attribute("version").value();
|
string libraryVersion = libraryNode.attribute("version").value();
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
|
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
|
||||||
|
bool ok = true;
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
|
|
||||||
book.readOnly = readOnly;
|
book.readOnly = readOnly;
|
||||||
book.id = bookNode.attribute("id").value();
|
book.id = bookNode.attribute("id").value();
|
||||||
book.path = bookNode.attribute("path").value();
|
book.path = bookNode.attribute("path").value();
|
||||||
|
@ -65,17 +61,39 @@ namespace kiwix {
|
||||||
ok = this->readBookFromPath(book.path, book);
|
ok = this->readBookFromPath(book.path, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
library.addBook(book);
|
library.addBook(book);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Manager::readXml(const string xml, const bool readOnly) {
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result = doc.load_buffer_inplace((void*)xml.data(), xml.size());
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
this->parseXmlDom(doc, readOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Manager::readFile(const string path, const bool readOnly) {
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// this->parseXmlDom(doc, readOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
this->writableLibraryPath = path;
|
this->writableLibraryPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::writeFile(const string path) {
|
bool Manager::writeFile(const string path) {
|
||||||
|
@ -259,6 +277,13 @@ namespace kiwix {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::removeBookPaths() {
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
itr->path = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Manager::listBooks(const supportedListMode mode) {
|
bool Manager::listBooks(const supportedListMode mode) {
|
||||||
this->bookIdList.clear();
|
this->bookIdList.clear();
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
#include <kiwix/library.h>
|
#include <kiwix/library.h>
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
|
|
||||||
|
@ -45,6 +47,7 @@ namespace kiwix {
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
bool readFile(const string path, const bool readOnly = true);
|
bool readFile(const string path, const bool readOnly = true);
|
||||||
|
bool readXml(const string xml, const bool readOnly = true);
|
||||||
bool writeFile(const string path);
|
bool writeFile(const string path);
|
||||||
bool removeBookByIndex(const unsigned int bookIndex);
|
bool removeBookByIndex(const unsigned int bookIndex);
|
||||||
bool removeBookById(const string id);
|
bool removeBookById(const string id);
|
||||||
|
@ -55,6 +58,7 @@ namespace kiwix {
|
||||||
Library cloneLibrary();
|
Library cloneLibrary();
|
||||||
bool getBookById(const string id, Book &book);
|
bool getBookById(const string id, Book &book);
|
||||||
bool updateBookLastOpenDateById(const string id);
|
bool updateBookLastOpenDateById(const string id);
|
||||||
|
void removeBookPaths();
|
||||||
bool listBooks(const supportedListMode);
|
bool listBooks(const supportedListMode);
|
||||||
|
|
||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
@ -65,6 +69,7 @@ namespace kiwix {
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
|
|
||||||
bool readBookFromPath(const string path, Book &book);
|
bool readBookFromPath(const string path, Book &book);
|
||||||
|
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue