mirror of https://github.com/kiwix/libkiwix.git
+ last imp. of contentManager
This commit is contained in:
parent
c7fbc52e7a
commit
ca1713d609
|
@ -35,7 +35,8 @@ namespace kiwix {
|
||||||
creator(""),
|
creator(""),
|
||||||
url(""),
|
url(""),
|
||||||
articleCount(""),
|
articleCount(""),
|
||||||
mediaCount("") {
|
mediaCount(""),
|
||||||
|
readOnly(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace kiwix {
|
||||||
string url;
|
string url;
|
||||||
string articleCount;
|
string articleCount;
|
||||||
string mediaCount;
|
string mediaCount;
|
||||||
|
bool readOnly;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Library {
|
class Library {
|
||||||
|
|
|
@ -23,14 +23,15 @@
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Manager::Manager() {
|
Manager::Manager() :
|
||||||
|
writableLibraryPath("") {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
Manager::~Manager() {
|
Manager::~Manager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::readFile(const string path) {
|
bool Manager::readFile(const string path, const bool readOnly) {
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
||||||
|
|
||||||
|
@ -42,11 +43,12 @@ namespace kiwix {
|
||||||
|
|
||||||
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")) {
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
|
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();
|
||||||
book.last = bookNode.attribute("last").value();
|
book.last = bookNode.attribute("last").value();
|
||||||
book.indexPath = bookNode.attribute("indexPath").value();
|
book.indexPath = bookNode.attribute("indexPath").value();
|
||||||
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN: CLUCENE;
|
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN : CLUCENE;
|
||||||
book.title = bookNode.attribute("title").value();
|
book.title = bookNode.attribute("title").value();
|
||||||
book.description = bookNode.attribute("description").value();
|
book.description = bookNode.attribute("description").value();
|
||||||
book.language = bookNode.attribute("language").value();
|
book.language = bookNode.attribute("language").value();
|
||||||
|
@ -67,6 +69,9 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!readOnly)
|
||||||
|
this->writableLibraryPath = path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -78,8 +83,9 @@ namespace kiwix {
|
||||||
/* Add the library node */
|
/* Add the library node */
|
||||||
pugi::xml_node libraryNode = doc.append_child("library");
|
pugi::xml_node libraryNode = doc.append_child("library");
|
||||||
|
|
||||||
if (library.current != "")
|
if (library.current != "") {
|
||||||
libraryNode.append_attribute("current") = library.current.c_str();
|
libraryNode.append_attribute("current") = library.current.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
if (library.version != "")
|
if (library.version != "")
|
||||||
libraryNode.append_attribute("version") = library.version.c_str();
|
libraryNode.append_attribute("version") = library.version.c_str();
|
||||||
|
@ -87,6 +93,8 @@ namespace kiwix {
|
||||||
/* Add each book */
|
/* Add each book */
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
|
||||||
|
if (!itr->readOnly) {
|
||||||
pugi::xml_node bookNode = libraryNode.append_child("book");
|
pugi::xml_node bookNode = libraryNode.append_child("book");
|
||||||
bookNode.append_attribute("id") = itr->id.c_str();
|
bookNode.append_attribute("id") = itr->id.c_str();
|
||||||
bookNode.append_attribute("path") = itr->path.c_str();
|
bookNode.append_attribute("path") = itr->path.c_str();
|
||||||
|
@ -127,6 +135,7 @@ namespace kiwix {
|
||||||
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* saving file */
|
/* saving file */
|
||||||
doc.save_file(path.c_str());
|
doc.save_file(path.c_str());
|
||||||
|
@ -200,4 +209,14 @@ namespace kiwix {
|
||||||
return this->library;
|
return this->library;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Manager::getBookById(const string id, Book &book) {
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
if ( itr->id == id) {
|
||||||
|
book = *itr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace kiwix {
|
||||||
Manager();
|
Manager();
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
bool readFile(const string path);
|
bool readFile(const string path, 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);
|
||||||
|
@ -44,6 +44,9 @@ namespace kiwix {
|
||||||
string getCurrentBookId();
|
string getCurrentBookId();
|
||||||
bool addBookFromPath(const string path, const string url = "");
|
bool addBookFromPath(const string path, const string url = "");
|
||||||
Library cloneLibrary();
|
Library cloneLibrary();
|
||||||
|
bool getBookById(const string id, Book &book);
|
||||||
|
|
||||||
|
string writableLibraryPath;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
|
|
Loading…
Reference in New Issue