mirror of https://github.com/kiwix/libkiwix.git
Fix a wrong behaviour in case of two portable kiwix consecutive runs (ID: 3442083)
This commit is contained in:
parent
fb12ac5eb1
commit
74caed4811
|
@ -23,23 +23,7 @@ namespace kiwix {
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Book::Book():
|
Book::Book():
|
||||||
id(""),
|
readOnly(false) {
|
||||||
path(""),
|
|
||||||
last(""),
|
|
||||||
indexPath(""),
|
|
||||||
indexType(UNKNOWN),
|
|
||||||
title(""),
|
|
||||||
description(""),
|
|
||||||
language(""),
|
|
||||||
date(""),
|
|
||||||
creator(""),
|
|
||||||
publisher(""),
|
|
||||||
url(""),
|
|
||||||
articleCount(""),
|
|
||||||
mediaCount(""),
|
|
||||||
readOnly(false),
|
|
||||||
size(""),
|
|
||||||
faviconMimeType("") {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
|
@ -77,7 +61,6 @@ namespace kiwix {
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Library::Library():
|
Library::Library():
|
||||||
current(""),
|
|
||||||
version(KIWIX_LIBRARY_VERSION) {
|
version(KIWIX_LIBRARY_VERSION) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#define KIWIX_LIBRARY_VERSION "20110515"
|
#define KIWIX_LIBRARY_VERSION "20110515"
|
||||||
|
|
||||||
|
@ -76,12 +77,22 @@ namespace kiwix {
|
||||||
Library();
|
Library();
|
||||||
~Library();
|
~Library();
|
||||||
|
|
||||||
string current;
|
|
||||||
string version;
|
string version;
|
||||||
bool addBook(const Book &book);
|
bool addBook(const Book &book);
|
||||||
bool removeBookByIndex(const unsigned int bookIndex);
|
bool removeBookByIndex(const unsigned int bookIndex);
|
||||||
vector <kiwix::Book> books;
|
vector <kiwix::Book> 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<string> current;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace kiwix {
|
||||||
pugi::xml_node libraryNode = doc.child("library");
|
pugi::xml_node libraryNode = doc.child("library");
|
||||||
|
|
||||||
if (strlen(libraryNode.attribute("current").value()))
|
if (strlen(libraryNode.attribute("current").value()))
|
||||||
library.current = libraryNode.attribute("current").value();
|
this->setCurrentBookId(libraryNode.attribute("current").value());
|
||||||
|
|
||||||
string libraryVersion = libraryNode.attribute("version").value();
|
string libraryVersion = libraryNode.attribute("version").value();
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ 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.empty()) {
|
if (!getCurrentBookId().empty()) {
|
||||||
libraryNode.append_attribute("current") = library.current.c_str();
|
libraryNode.append_attribute("current") = getCurrentBookId().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!library.version.empty())
|
if (!library.version.empty())
|
||||||
|
@ -193,12 +193,18 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::setCurrentBookId(const string id) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Manager::getCurrentBookId() {
|
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 */
|
/* Add a book to the library. Return empty string if failed, book id otherwise */
|
||||||
|
|
|
@ -51,9 +51,9 @@ namespace kiwix {
|
||||||
bool removeBookByIndex(const unsigned int bookIndex);
|
bool removeBookByIndex(const unsigned int bookIndex);
|
||||||
bool removeBookById(const string id);
|
bool removeBookById(const string id);
|
||||||
bool setCurrentBookId(const string id);
|
bool setCurrentBookId(const string id);
|
||||||
|
string getCurrentBookId();
|
||||||
bool setBookIndex(const string id, const string path, const supportedIndexType type);
|
bool setBookIndex(const string id, const string path, const supportedIndexType type);
|
||||||
bool setBookPath(const string id, const string path);
|
bool setBookPath(const string id, const string path);
|
||||||
string getCurrentBookId();
|
|
||||||
string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "",
|
string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "",
|
||||||
const bool checkMetaData = false);
|
const bool checkMetaData = false);
|
||||||
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",
|
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",
|
||||||
|
|
Loading…
Reference in New Issue