Do not crash if the zim file is invalid or corrupted.

This commit is contained in:
Matthieu Gautier 2018-06-12 19:23:30 +02:00
parent 84e5124ae6
commit 7c8d475d24
2 changed files with 9 additions and 1 deletions

View File

@ -19,7 +19,11 @@ void KiwixApp::openZimFile(const QString &zimfile)
delete reader;
const std::string zimfile_ = zimfile.toLocal8Bit().constData();
std::cout << "Opening " << zimfile_ << std::endl;
try {
reader = new kiwix::Reader(zimfile_);
} catch (...) {
reader = nullptr;
}
}
kiwix::Reader* KiwixApp::getReader()

View File

@ -20,6 +20,10 @@ KiwixSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
zim::Article art;
std::cout << "Url is " << url << std::endl;
auto reader = static_cast<KiwixApp*>(KiwixApp::instance())->getReader();
if ( reader == nullptr) {
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
return;
}
if ( !reader->getArticleObjectByDecodedUrl(url, art))
{
url = "A/" + url;