Merge pull request #1092 from kiwix/download_dir_checks

Detection and reporting of issues with the download directory
This commit is contained in:
Kelson 2024-04-19 18:12:41 +02:00 committed by GitHub
commit 073dd06937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 3 deletions

View File

@ -146,6 +146,8 @@
"delete-book-text": "Are you sure you want to delete <b>{{ZIM}}</b>?",
"download-storage-error": "Storage Error",
"download-storage-error-text": "The system doesn't have enough storage available.",
"download-dir-missing": "Download directory doesn't exist.",
"download-dir-not-writable": "Download directory is not writable.",
"download-unavailable": "Download Unavailable",
"download-unavailable-text": "This download is unavailable.",
"open-book": "Open book",

View File

@ -39,9 +39,11 @@
"videos": "{{identical|Video}}",
"yes": "{{identical|yes}}",
"no": "{{identical|no}}",
"download-dir-missing": "Error text displayed when it turns out that the download directory doesn't exist.",
"download-dir-not-writable": "Error text displayed when files cannot be created/saved in the download directory due to permissions",
"add-bookmark": "Represents the action of adding a page as a bookmark",
"remove-bookmark": "Represents the action of removing a page from the bookmarks",
"open-link-in-web-browser": "Ouvrir le lien dans le navigateur",
"open-link-in-web-browser": "Hint for the action of opening the link in a web browser",
"download-dir-dialog-msg": "Please note that <code><nowiki>{{DIRECTORY}}</nowiki></code> should be placed on a newline.",
"monitor-dir-dialog-title": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
"monitor-dir-dialog-msg": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",

View File

@ -53,8 +53,21 @@ void throwDownloadUnavailableError()
gt("download-unavailable-text"));
}
void checkEnoughStorageAvailable(const kiwix::Book& book, QString targetDir)
void checkThatBookCanBeSaved(const kiwix::Book& book, QString targetDir)
{
const QFileInfo targetDirInfo(targetDir);
if ( !targetDirInfo.isDir() ) {
throw ContentManagerError(gt("download-storage-error"),
gt("download-dir-missing"));
}
// XXX: This may lie under Windows
// XXX: (see https://doc.qt.io/qt-5/qfile.html#platform-specific-issues)
if ( !targetDirInfo.isWritable() ) {
throw ContentManagerError(gt("download-storage-error"),
gt("download-dir-not-writable"));
}
QStorageInfo storage(targetDir);
auto bytesAvailable = storage.bytesAvailable();
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
@ -580,7 +593,7 @@ const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
std::string ContentManager::startDownload(const kiwix::Book& book)
{
auto downloadPath = getSettingsManager()->getDownloadDir();
checkEnoughStorageAvailable(book, downloadPath);
checkThatBookCanBeSaved(book, downloadPath);
typedef std::vector<std::pair<std::string, std::string>> DownloadOptions;
@ -600,6 +613,8 @@ void ContentManager::downloadBook(const QString &id)
std::string downloadId;
try {
downloadId = startDownload(book);
} catch (const ContentManagerError& ) {
throw;
} catch (std::exception& e) {
throwDownloadUnavailableError();
}

View File

@ -39,6 +39,9 @@ void ReadingListBar::setupList()
} catch (std::out_of_range& e) {
continue;
}
if ( !archive ) {
continue;
}
try {
auto illustration = archive->getIllustrationItem(48);
std::string content = illustration.getData();