comparison 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
comparison
equal deleted inserted replaced
1372:96f640c88d10 1373:00fcb9c4d16b
126 126
127 MainWindow::MainWindow(bool trayMode, const QDateTime& sigDt): 127 MainWindow::MainWindow(bool trayMode, const QDateTime& sigDt):
128 mTrayMode(trayMode), 128 mTrayMode(trayMode),
129 mManualDetailsShown(false), 129 mManualDetailsShown(false),
130 mFailedConnections(0), 130 mFailedConnections(0),
131 mSigDt(sigDt) 131 mSigDt(sigDt),
132 mDownloadSWAccepted(false)
132 { 133 {
133 createActions(); 134 createActions();
134 createTrayIcon(); 135 createTrayIcon();
135 setupGUI(); 136 setupGUI();
136 resize(900, 600); 137 resize(900, 600);
173 } 174 }
174 175
175 void MainWindow::messageClicked() 176 void MainWindow::messageClicked()
176 { 177 {
177 if (mCurState == NewSoftwareAvailable) { 178 if (mCurState == NewSoftwareAvailable) {
179 mDownloadSWAccepted = true;
178 verifySWData(); 180 verifySWData();
179 QString swFileName = mSettings.value("Software/available").toString(); 181 if (mFailedConnections == 0) {
180 if (swFileName.isEmpty()) { 182 /* If we have a failed connection cound verifySWData has
181 checkUpdates(true); 183 * triggered an invalid software recovery and an update is already
182 mCurState = DownloadingSW; 184 * scheduled. */
183 return; 185 QString swFileName = mSettings.value("Software/available").toString();
184 } 186 if (swFileName.isEmpty()) {
185 installNewSW(swFileName, 187 checkUpdates();
186 mSettings.value("Software/availableDate").toDateTime()); 188 mCurState = DownloadingSW;
189 return;
190 }
191 installNewSW(swFileName,
192 mSettings.value("Software/availableDate").toDateTime());
193 }
187 } else { 194 } else {
188 show(); 195 show();
189 } 196 }
190 } 197 }
191 198
291 qDebug() << "Software update was signed at: " << sigDt; 298 qDebug() << "Software update was signed at: " << sigDt;
292 qDebug() << "But the installed software was signed on: " << mSigDt; 299 qDebug() << "But the installed software was signed on: " << mSigDt;
293 if (verifyResult.fptr) { 300 if (verifyResult.fptr) {
294 fclose(verifyResult.fptr); 301 fclose(verifyResult.fptr);
295 } 302 }
303 scheduleFailureRetryOrClose(!isVisible());
296 } 304 }
297 QFile::remove(swFileName); 305 QFile::remove(swFileName);
298 mSettings.remove("Software/available"); 306 mSettings.remove("Software/available");
299 mSettings.remove("Software/availableDate"); 307 mSettings.remove("Software/availableDate");
300 return; 308 return;
434 qDebug() << "Software update was signed at: " << sigDt; 442 qDebug() << "Software update was signed at: " << sigDt;
435 qDebug() << "But the installed software was signed on: " << mSigDt; 443 qDebug() << "But the installed software was signed on: " << mSigDt;
436 if (vres.fptr) { 444 if (vres.fptr) {
437 fclose(vres.fptr); 445 fclose(vres.fptr);
438 } 446 }
447 scheduleFailureRetryOrClose(!isVisible());
439 } 448 }
440 QFile::remove(filePath); 449 QFile::remove(filePath);
441 mSettings.remove("Software/available"); 450 mSettings.remove("Software/available");
442 mSettings.remove("Software/availableDate"); 451 mSettings.remove("Software/availableDate");
443 return; 452 return;
545 #ifdef WIN32 554 #ifdef WIN32
546 closeApp(); 555 closeApp();
547 #endif 556 #endif
548 } 557 }
549 558
550 void MainWindow::checkUpdates(bool downloadSW) 559 void MainWindow::checkUpdates()
551 { 560 {
552 verifyListData(); 561 verifyListData();
562 bool downloadSW = false;
563
564 if (mDownloadSWAccepted == true) {
565 downloadSW = true;
566 }
553 567
554 /* Delete old temporary installers if they exist */ 568 /* Delete old temporary installers if they exist */
555 QString oldUpdater = mSettings.value("Software/Updater").toString(); 569 QString oldUpdater = mSettings.value("Software/Updater").toString();
556 570
557 if (!oldUpdater.isEmpty()) { 571 if (!oldUpdater.isEmpty()) {
1788 return; 1802 return;
1789 } 1803 }
1790 return closeApp(); 1804 return closeApp();
1791 } 1805 }
1792 1806
1807 void MainWindow::scheduleFailureRetryOrClose(bool close) {
1808 int waitInterval = getNextUpdateInterval(mFailedConnections++);
1809 if (waitInterval <= 0 && close) {
1810 qDebug() << "Shutting down after " << mFailedConnections <<
1811 " tries to get an update connection.";
1812 closeApp();
1813 } else if (waitInterval > 0) {
1814 qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
1815 QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
1816 }
1817 }
1818
1793 void MainWindow::updateCheckSuccess() 1819 void MainWindow::updateCheckSuccess()
1794 { 1820 {
1795 if (getState() != TransferError) { 1821 if (getState() != TransferError) {
1796 const QDateTime now = QDateTime::currentDateTime(); 1822 const QDateTime now = QDateTime::currentDateTime();
1797 mSettings.setValue("lastUpdateCheck", now); 1823 mSettings.setValue("lastUpdateCheck", now);
1800 mLastUpdateCheck->show(); 1826 mLastUpdateCheck->show();
1801 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData()); 1827 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData());
1802 handleLTE(lteNoConnection, true); /* Reset error state */ 1828 handleLTE(lteNoConnection, true); /* Reset error state */
1803 handleLTE(lteInvalidCertificate, true); 1829 handleLTE(lteInvalidCertificate, true);
1804 mFailedConnections = 0; 1830 mFailedConnections = 0;
1805 } else if (!isVisible()) { 1831 } else {
1806 int waitInterval = getNextUpdateInterval(mFailedConnections++); 1832 scheduleFailureRetryOrClose(!isVisible());
1807 if (waitInterval < 0) {
1808 qDebug() << "Shutting down after " << mFailedConnections <<
1809 " tries to get an update connection.";
1810 closeApp();
1811 return;
1812 }
1813 qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
1814 QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
1815 return;
1816 } 1833 }
1817 if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode) 1834 if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode)
1818 && !isVisible()) { 1835 && !isVisible()) {
1819 qDebug() << "Shutting down as no list or Software is available."; 1836 qDebug() << "Shutting down as no list or Software is available.";
1820 closeApp(); 1837 closeApp();

http://wald.intevation.org/projects/trustbridge/