mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Add the ability to cancel an update while it's downloading. Closes #3162
This commit is contained in:
@@ -111,6 +111,14 @@ void UpdateDialog::on_releaseNotes_clicked()
|
||||
|
||||
void UpdateDialog::on_close_clicked()
|
||||
{
|
||||
// if there's a pending request, we're cancelling so abort the request. The finished() handler will close the dialog
|
||||
if(m_Request)
|
||||
{
|
||||
m_Cancelled = true;
|
||||
m_Request->abort();
|
||||
return;
|
||||
}
|
||||
|
||||
reject();
|
||||
}
|
||||
|
||||
@@ -175,7 +183,7 @@ void UpdateDialog::on_update_clicked()
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressText->setText(tr("Preparing Download"));
|
||||
|
||||
ui->close->setEnabled(false);
|
||||
ui->close->setText(tr("Cancel"));
|
||||
ui->update->setEnabled(false);
|
||||
|
||||
delete m_DownloadTimer;
|
||||
@@ -183,26 +191,41 @@ void UpdateDialog::on_update_clicked()
|
||||
|
||||
m_DownloadTimer->start();
|
||||
|
||||
QNetworkReply *req = m_NetManager->get(QNetworkRequest(QUrl(m_URL)));
|
||||
m_Request = m_NetManager->get(QNetworkRequest(QUrl(m_URL)));
|
||||
|
||||
QObject::connect(req, &QNetworkReply::downloadProgress, [this](qint64 recvd, qint64 total) {
|
||||
QObject::connect(m_Request, &QNetworkReply::downloadProgress, [this](qint64 recvd, qint64 total) {
|
||||
UpdateTransferProgress(recvd, total, m_DownloadTimer, ui->progressBar, ui->progressText,
|
||||
tr("Downloading update..."));
|
||||
});
|
||||
|
||||
QObject::connect(req, OverloadedSlot<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
|
||||
[this, req](QNetworkReply::NetworkError err) {
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressText->setText(tr("Network error:\n%1").arg(req->errorString()));
|
||||
ui->update->setEnabled(true);
|
||||
ui->close->setEnabled(true);
|
||||
ui->update->setText(tr("Retry Update"));
|
||||
});
|
||||
QObject::connect(
|
||||
m_Request, OverloadedSlot<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
|
||||
[this](QNetworkReply::NetworkError err) {
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressText->setText(tr("Network error:\n%1").arg(m_Request->errorString()));
|
||||
ui->update->setEnabled(true);
|
||||
ui->close->setEnabled(true);
|
||||
ui->close->setText(tr("Close"));
|
||||
ui->update->setText(tr("Retry Update"));
|
||||
});
|
||||
|
||||
QObject::connect(m_Request, &QNetworkReply::finished, [this]() {
|
||||
// if we cancelled, close the dialog now
|
||||
if(m_Cancelled)
|
||||
{
|
||||
m_Request->deleteLater();
|
||||
m_Request = NULL;
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(req, &QNetworkReply::finished, [this, req]() {
|
||||
// don't do anything if we're finished after an error
|
||||
if(ui->update->isEnabled())
|
||||
{
|
||||
m_Request->deleteLater();
|
||||
m_Request = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
QDir dir(QDir::tempPath());
|
||||
|
||||
@@ -215,7 +238,7 @@ void UpdateDialog::on_update_clicked()
|
||||
QFile file(path);
|
||||
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
file.write(req->readAll());
|
||||
file.write(m_Request->readAll());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -225,6 +248,9 @@ void UpdateDialog::on_update_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
m_Request->deleteLater();
|
||||
m_Request = NULL;
|
||||
|
||||
QDir appDir = QFileInfo(QCoreApplication::applicationFilePath()).absoluteDir();
|
||||
|
||||
bool success = true;
|
||||
|
||||
@@ -64,4 +64,5 @@ private:
|
||||
|
||||
QNetworkAccessManager *m_NetManager;
|
||||
QNetworkReply *m_Request = NULL;
|
||||
bool m_Cancelled = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user