Mercurial > trustbridge
diff ui/mainwindow.cpp @ 1373:00fcb9c4d16b
(issue179) Handle SW verify failures and try to redownload the update
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 24 Nov 2014 16:46:08 +0100 |
parents | 23df332b2a4c |
children | 831d28c2291d |
line wrap: on
line diff
--- a/ui/mainwindow.cpp Mon Nov 24 15:49:18 2014 +0100 +++ b/ui/mainwindow.cpp Mon Nov 24 16:46:08 2014 +0100 @@ -128,7 +128,8 @@ mTrayMode(trayMode), mManualDetailsShown(false), mFailedConnections(0), - mSigDt(sigDt) + mSigDt(sigDt), + mDownloadSWAccepted(false) { createActions(); createTrayIcon(); @@ -175,15 +176,21 @@ void MainWindow::messageClicked() { if (mCurState == NewSoftwareAvailable) { + mDownloadSWAccepted = true; verifySWData(); - QString swFileName = mSettings.value("Software/available").toString(); - if (swFileName.isEmpty()) { - checkUpdates(true); - mCurState = DownloadingSW; - return; + if (mFailedConnections == 0) { + /* If we have a failed connection cound verifySWData has + * triggered an invalid software recovery and an update is already + * scheduled. */ + QString swFileName = mSettings.value("Software/available").toString(); + if (swFileName.isEmpty()) { + checkUpdates(); + mCurState = DownloadingSW; + return; + } + installNewSW(swFileName, + mSettings.value("Software/availableDate").toDateTime()); } - installNewSW(swFileName, - mSettings.value("Software/availableDate").toDateTime()); } else { show(); } @@ -293,6 +300,7 @@ if (verifyResult.fptr) { fclose(verifyResult.fptr); } + scheduleFailureRetryOrClose(!isVisible()); } QFile::remove(swFileName); mSettings.remove("Software/available"); @@ -436,6 +444,7 @@ if (vres.fptr) { fclose(vres.fptr); } + scheduleFailureRetryOrClose(!isVisible()); } QFile::remove(filePath); mSettings.remove("Software/available"); @@ -547,9 +556,14 @@ #endif } -void MainWindow::checkUpdates(bool downloadSW) +void MainWindow::checkUpdates() { verifyListData(); + bool downloadSW = false; + + if (mDownloadSWAccepted == true) { + downloadSW = true; + } /* Delete old temporary installers if they exist */ QString oldUpdater = mSettings.value("Software/Updater").toString(); @@ -1790,6 +1804,18 @@ return closeApp(); } +void MainWindow::scheduleFailureRetryOrClose(bool close) { + int waitInterval = getNextUpdateInterval(mFailedConnections++); + if (waitInterval <= 0 && close) { + qDebug() << "Shutting down after " << mFailedConnections << + " tries to get an update connection."; + closeApp(); + } else if (waitInterval > 0) { + qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try."; + QTimer::singleShot(waitInterval, this, SLOT(checkUpdates())); + } +} + void MainWindow::updateCheckSuccess() { if (getState() != TransferError) { @@ -1802,17 +1828,8 @@ handleLTE(lteNoConnection, true); /* Reset error state */ handleLTE(lteInvalidCertificate, true); mFailedConnections = 0; - } else if (!isVisible()) { - int waitInterval = getNextUpdateInterval(mFailedConnections++); - if (waitInterval < 0) { - qDebug() << "Shutting down after " << mFailedConnections << - " tries to get an update connection."; - closeApp(); - return; - } - qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try."; - QTimer::singleShot(waitInterval, this, SLOT(checkUpdates())); - return; + } else { + scheduleFailureRetryOrClose(!isVisible()); } if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode) && !isVisible()) {