Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix md5 hashing for large download files #844

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,16 +985,39 @@ void DownloadManager::queryInfoMd5(int index)
downloadFile.setFileName(m_OrganizerCore->downloadsPath() + "\\" + info->m_FileName);
}
if (!downloadFile.exists()) {
log::debug("Can't find download file {}", info->m_FileName);
log::error("Can't find download file '{}'", info->m_FileName);
return;
}
if (!downloadFile.open(QIODevice::ReadOnly)) {
log::debug("Can't open download file {}", info->m_FileName);
log::error("Can't open download file '{}'", info->m_FileName);
return;
}
info->m_Hash = QCryptographicHash::hash(downloadFile.readAll(), QCryptographicHash::Md5);

QCryptographicHash hash(QCryptographicHash::Md5);
const qint64 progressStep = 10 * 1024 * 1024;
QProgressDialog progress(tr("Hashing download file '%1'").arg(info->m_FileName),
tr("Cancel"),
0,
downloadFile.size() / progressStep);
progress.setWindowModality(Qt::WindowModal);
progress.setMinimumDuration(1000);

for (qint64 i = 0; i < downloadFile.size(); i += progressStep) {
progress.setValue(progress.value()+1);
if (progress.wasCanceled()) {
break;
}
hash.addData(downloadFile.read(progressStep));
}
if (progress.wasCanceled()) {
downloadFile.close();
return;
}

progress.close();
downloadFile.close();

info->m_Hash = hash.result();
info->m_ReQueried = true;
setState(info, STATE_FETCHINGMODINFO_MD5);
}
Expand Down