Store in the book instance if the given path is valid.

The path may exist and not be valid if the zim file is not truncated
(ie, interrupted download)
This commit is contained in:
Matthieu Gautier 2018-10-16 17:35:51 +02:00
parent 9c0f9696ed
commit 829c34dd69
2 changed files with 6 additions and 1 deletions

View File

@ -51,6 +51,7 @@ class Book
bool readOnly() const { return m_readOnly; } bool readOnly() const { return m_readOnly; }
const std::string& getId() const { return m_id; } const std::string& getId() const { return m_id; }
const std::string& getPath() const { return m_path; } const std::string& getPath() const { return m_path; }
bool isPathValid() const { return m_pathValid; }
const std::string& getIndexPath() const { return m_indexPath; } const std::string& getIndexPath() const { return m_indexPath; }
const supportedIndexType& getIndexType() const { return m_indexType; } const supportedIndexType& getIndexType() const { return m_indexType; }
const std::string& getTitle() const { return m_title; } const std::string& getTitle() const { return m_title; }
@ -72,6 +73,7 @@ class Book
void setReadOnly(bool readOnly) { m_readOnly = readOnly; } void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
void setId(const std::string& id) { m_id = id; } void setId(const std::string& id) { m_id = id; }
void setPath(const std::string& path); void setPath(const std::string& path);
void setPathValid(bool valid) { m_pathValid = valid; }
void setIndexPath(const std::string& indexPath); void setIndexPath(const std::string& indexPath);
void setIndexType(supportedIndexType indexType) { m_indexType = indexType;} void setIndexType(supportedIndexType indexType) { m_indexType = indexType;}
void setTitle(const std::string& title) { m_title = title; } void setTitle(const std::string& title) { m_title = title; }
@ -93,6 +95,7 @@ class Book
protected: protected:
std::string m_id; std::string m_id;
std::string m_path; std::string m_path;
bool m_pathValid;
std::string m_indexPath; std::string m_indexPath;
supportedIndexType m_indexType; supportedIndexType m_indexType;
std::string m_title; std::string m_title;

View File

@ -213,8 +213,10 @@ bool Manager::readBookFromPath(const std::string& path, kiwix::Book* book)
try { try {
kiwix::Reader reader(path); kiwix::Reader reader(path);
book->update(reader); book->update(reader);
book->setPathValid(true);
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << "Invalid " << path << " : " << e.what() << std::endl;
book->setPathValid(false);
return false; return false;
} }