comparison ui/mainwindow.cpp @ 587:02a89710a7cd

Split up list and software verification and use it
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 27 May 2014 16:31:29 +0000
parents aee3eb10bbba
children 26a18e3c3db4
comparison
equal deleted inserted replaced
586:ecfd77751daf 587:02a89710a7cd
51 #include "certificateitemdelegate.h" 51 #include "certificateitemdelegate.h"
52 #include "separatoritemdelegate.h" 52 #include "separatoritemdelegate.h"
53 #include "installwrapper.h" 53 #include "installwrapper.h"
54 #include "util.h" 54 #include "util.h"
55 #include "logging.h" 55 #include "logging.h"
56 #include "binverify.h"
56 57
57 MainWindow::MainWindow(bool trayMode): 58 MainWindow::MainWindow(bool trayMode):
58 mTrayMode(trayMode) 59 mTrayMode(trayMode)
59 { 60 {
60 createActions(); 61 createActions();
100 if (mCurState == NewListAvailable) { 101 if (mCurState == NewListAvailable) {
101 show(); 102 show();
102 } 103 }
103 104
104 if (mCurState == NewSoftwareAvailable) { 105 if (mCurState == NewSoftwareAvailable) {
105 checkUpdates(true); 106 verifySWData();
106 mCurState = DownloadingSW; 107 QString swFileName = mSettings.value("Software/available").toString();
108 if (swFileName.isEmpty()) {
109 checkUpdates(true);
110 mCurState = DownloadingSW;
111 return;
112 }
113 installNewSW(swFileName,
114 mSettings.value("Software/availableDate").toDateTime());
107 } 115 }
108 } 116 }
109 117
110 void MainWindow::showMessage() 118 void MainWindow::showMessage()
111 { 119 {
114 QSystemTrayIcon::Information, 5000); 122 QSystemTrayIcon::Information, 5000);
115 mMessageTimer->start(); // Restart the timer so that we don't spam 123 mMessageTimer->start(); // Restart the timer so that we don't spam
116 } 124 }
117 } 125 }
118 126
119 void MainWindow::verifyAvailableData() 127 void MainWindow::verifyListData()
120 { 128 {
121 QString availableFileName = mSettings.value("List/available").toString(); 129 QString availableFileName = mSettings.value("List/available").toString();
122 QString installedFileName = mSettings.value("List/installed").toString(); 130 QString installedFileName = mSettings.value("List/installed").toString();
123 QString swFileName = mSettings.value("Software/available").toString();
124
125 if (!availableFileName.isEmpty()) { 131 if (!availableFileName.isEmpty()) {
126 mListToInstall.readList(availableFileName.toLocal8Bit().constData()); 132 mListToInstall.readList(availableFileName.toLocal8Bit().constData());
127 if (!mListToInstall.isValid()) { 133 if (!mListToInstall.isValid()) {
128 mCurState = TransferError; 134 mCurState = TransferError;
129 // Probably a bug when Qt fileName is encoded and cFileName 135 // Probably a bug when Qt fileName is encoded and cFileName
151 } 157 }
152 } else { 158 } else {
153 mSettings.remove("List/installed"); 159 mSettings.remove("List/installed");
154 mSettings.remove("List/installedDate"); 160 mSettings.remove("List/installedDate");
155 } 161 }
162 }
163
164 void MainWindow::verifySWData()
165 {
166 QString swFileName = mSettings.value("Software/available").toString();
156 167
157 if (!swFileName.isEmpty()) { 168 if (!swFileName.isEmpty()) {
158 // TODO Verify integrity of the software 169 QFileInfo fi(swFileName);
170 if (!fi.exists()) {
171 mSettings.remove("Software/available");
172 mSettings.remove("Software/availableDate");
173 }
174 if (!fi.isExecutable()) {
175 qWarning() << "Downloaded file: " << swFileName << " is not executable.";
176 setState(TransferError);
177 return;
178 }
179 bin_verify_result verifyResult = verify_binary(swFileName.toUtf8().constData(),
180 swFileName.toUtf8().size());
181 qDebug() << "Binary verify result: " << verifyResult;
182 if (verifyResult != VerifyValid) {
183 qDebug() << "Failed to verify downloaded data. Retrying.";
184 QFile::remove(swFileName);
185 mSettings.remove("Software/available");
186 mSettings.remove("Software/availableDate");
187 }
159 } else { 188 } else {
160 mSettings.remove("Software/available"); 189 mSettings.remove("Software/available");
161 mSettings.remove("Software/availableDate"); 190 mSettings.remove("Software/availableDate");
162 } 191 }
163 } 192 }
164 193
165 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { 194 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) {
166 mSettings.setValue("List/available", fileName); 195 mSettings.setValue("List/available", fileName);
167 mSettings.setValue("List/availableDate", modDate); 196 mSettings.setValue("List/availableDate", modDate);
168 197
169 verifyAvailableData(); 198 verifyListData();
170 if (!mListToInstall.isValid()) { 199 if (!mListToInstall.isValid()) {
171 /* Downloader provided invalid files */ 200 /* Downloader provided invalid files */
172 /* TODO: Error count. Error handling. Otherwise 201 /* TODO: Error count. Error handling. Otherwise
173 * we can go into an endless loop here */ 202 * we can go into an endless loop here */
174 203
194 showMessage(); 223 showMessage();
195 } 224 }
196 225
197 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { 226 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) {
198 QFileInfo instProcInfo = QFileInfo(fileName); 227 QFileInfo instProcInfo = QFileInfo(fileName);
199 if (!instProcInfo.isExecutable()) { 228 verifySWData();
200 qWarning() << "Downloaded file: " << fileName << " is not executable.";
201 setState(TransferError);
202 return;
203 }
204 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); 229 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
205 #ifdef WIN32 230 #ifdef WIN32
206 SHELLEXECUTEINFOW shExecInfo; 231 SHELLEXECUTEINFOW shExecInfo;
207 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW)); 232 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW));
208 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); 233 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
241 closeApp(); 266 closeApp();
242 } 267 }
243 268
244 void MainWindow::checkUpdates(bool downloadSW) 269 void MainWindow::checkUpdates(bool downloadSW)
245 { 270 {
246 verifyAvailableData(); 271 verifyListData();
247 272
248 if (!mSettings.contains("Software/installedDate") || 273 if (!mSettings.contains("Software/installedDate") ||
249 mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) { 274 mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) {
250 /* This should only happen on initial startup and after an update has 275 /* This should only happen on initial startup and after an update has
251 * been installed */ 276 * been installed */

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