From 74caed4811d3b278be20d8b198db9b253e104e6e Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sat, 26 Nov 2011 09:32:02 +0000 Subject: [PATCH] Fix a wrong behaviour in case of two portable kiwix consecutive runs (ID: 3442083) --- src/common/kiwix/library.cpp | 19 +------------------ src/common/kiwix/library.h | 13 ++++++++++++- src/common/kiwix/manager.cpp | 16 +++++++++++----- src/common/kiwix/manager.h | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 0388f76c8..eb6295a1b 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -23,23 +23,7 @@ namespace kiwix { /* Constructor */ Book::Book(): - id(""), - path(""), - last(""), - indexPath(""), - indexType(UNKNOWN), - title(""), - description(""), - language(""), - date(""), - creator(""), - publisher(""), - url(""), - articleCount(""), - mediaCount(""), - readOnly(false), - size(""), - faviconMimeType("") { + readOnly(false) { } /* Destructor */ @@ -77,7 +61,6 @@ namespace kiwix { /* Constructor */ Library::Library(): - current(""), version(KIWIX_LIBRARY_VERSION) { } diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h index 5fdeebd99..8f3493fad 100644 --- a/src/common/kiwix/library.h +++ b/src/common/kiwix/library.h @@ -25,6 +25,7 @@ #include #include #include +#include #define KIWIX_LIBRARY_VERSION "20110515" @@ -76,12 +77,22 @@ namespace kiwix { Library(); ~Library(); - string current; string version; bool addBook(const Book &book); bool removeBookByIndex(const unsigned int bookIndex); vector books; + /* + * 'current' is the variable storing the current content/book id + * in the library. This is used to be able to load per default a + * content. As Kiwix may work with many library XML files, you may + * have "current" defined many time with different values. The + * last XML file read has the priority, Although we do not have an + * library object for each file, we want to be able to fallback to + * an 'old' current book if the one which should be load + * failed. That is the reason why we need a stack here + */ + stack current; }; } diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index fb02927e4..3e75921fb 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -34,7 +34,7 @@ namespace kiwix { pugi::xml_node libraryNode = doc.child("library"); if (strlen(libraryNode.attribute("current").value())) - library.current = libraryNode.attribute("current").value(); + this->setCurrentBookId(libraryNode.attribute("current").value()); string libraryVersion = libraryNode.attribute("version").value(); @@ -118,8 +118,8 @@ namespace kiwix { /* Add the library node */ pugi::xml_node libraryNode = doc.append_child("library"); - if (!library.current.empty()) { - libraryNode.append_attribute("current") = library.current.c_str(); + if (!getCurrentBookId().empty()) { + libraryNode.append_attribute("current") = getCurrentBookId().c_str(); } if (!library.version.empty()) @@ -193,12 +193,18 @@ namespace kiwix { } bool Manager::setCurrentBookId(const string id) { - library.current = id; + if (library.current.empty() || library.current.top() != id) { + if (id.empty() && !library.current.empty()) + library.current.pop(); + else + library.current.push(id); + } return true; } string Manager::getCurrentBookId() { - return library.current; + return library.current.empty() ? + "" : library.current.top(); } /* Add a book to the library. Return empty string if failed, book id otherwise */ diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index 09a6269d6..19dfcbdd2 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -51,9 +51,9 @@ namespace kiwix { bool removeBookByIndex(const unsigned int bookIndex); bool removeBookById(const string id); bool setCurrentBookId(const string id); + string getCurrentBookId(); bool setBookIndex(const string id, const string path, const supportedIndexType type); bool setBookPath(const string id, const string path); - string getCurrentBookId(); string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "", const bool checkMetaData = false); bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",