mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Add check to not open zim file (from command line arguments) if it is invalid
This commit is contained in:
parent
60effd4c84
commit
f14d633fd3
@ -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/"));
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user