Add check to not open zim file (from command line arguments) if it is invalid

This commit is contained in:
Nikhil Tanwar 2022-01-04 13:33:41 +05:30 committed by Matthieu Gautier
parent 60effd4c84
commit f14d633fd3
2 changed files with 12 additions and 1 deletions

View File

@ -176,7 +176,15 @@ void KiwixApp::openZimFile(const QString &zimfile)
try {
zimId = m_library.openBookFromPath(validZimFile);
} catch (const std::exception& e) {
showMessage("Cannot open " + validZimFile + ": \n" + e.what());
auto text = gt("zim-open-fail-text");
text = text.replace("{{ZIM}}", validZimFile);
QMessageBox msgBox(
QMessageBox::Warning, //Icon
gt("zim-open-fail-title"), //Title
text, //Text
QMessageBox::Ok //Buttons
);
msgBox.exec();
return;
}
openUrl(QUrl("zim://"+zimId+".zim/"));

View File

@ -48,6 +48,9 @@ QString Library::openBookFromPath(const QString &zimPath)
kiwix::Manager manager(&m_library);
auto id = manager.addBookFromPathAndGetId(zimPath.toStdString());
if (id == "") {
throw std::invalid_argument("invalid zim file");
}
save();
emit(booksChanged());
return QString::fromStdString(id);