comparison ui/mainwindow.cpp @ 1081:edbf5e5e88f4

(issue118) Extend verify_binary to carry an open file * binverify.c: Change result to a structure containing an open fptr Use in Memory data for windows verification. * mainwindow.cpp, selftest.c: Handle the returend structure * binverifytest.cpp: Test for the exclusive read and update signature. * listutil.c: Add optional fptr parameter to read_file
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 11 Sep 2014 12:05:24 +0200
parents 51b97ebc5b06
children a12e6172d82c
comparison
equal deleted inserted replaced
1080:898b1ddcca11 1081:edbf5e5e88f4
232 mSettings.remove("Software/availableDate"); 232 mSettings.remove("Software/availableDate");
233 return; 233 return;
234 } 234 }
235 bin_verify_result verifyResult = verify_binary(swFileName.toUtf8().constData(), 235 bin_verify_result verifyResult = verify_binary(swFileName.toUtf8().constData(),
236 swFileName.toUtf8().size()); 236 swFileName.toUtf8().size());
237 qDebug() << "Binary verify result: " << verifyResult; 237 qDebug() << "Binary verify result: " << verifyResult.result;
238 if (verifyResult != VerifyValid) { 238 if (verifyResult.result != VerifyValid) {
239 qDebug() << "Failed to verify downloaded data."; 239 qDebug() << "Failed to verify downloaded data.";
240 QFile::remove(swFileName); 240 QFile::remove(swFileName);
241 mSettings.remove("Software/available"); 241 mSettings.remove("Software/available");
242 mSettings.remove("Software/availableDate"); 242 mSettings.remove("Software/availableDate");
243 return; 243 return;
244 } 244 }
245 fclose(verifyResult.fptr);
245 } 246 }
246 247
247 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { 248 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) {
248 qDebug() << "new list available"; 249 qDebug() << "new list available";
249 mSettings.setValue("List/available", fileName); 250 mSettings.setValue("List/available", fileName);
287 } 288 }
288 289
289 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { 290 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) {
290 QFileInfo instProcInfo = QFileInfo(fileName); 291 QFileInfo instProcInfo = QFileInfo(fileName);
291 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); 292 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
292 293 bin_verify_result vres = verify_binary(filePath.toUtf8().constData(),
293 if (verify_binary(filePath.toUtf8().constData(), 294 filePath.toUtf8().size());
294 filePath.toUtf8().size()) != VerifyValid) { 295
296 if (vres.result != VerifyValid) {
295 qDebug() << "Invalid software. Not installing"; 297 qDebug() << "Invalid software. Not installing";
296 return; 298 return;
297 } 299 }
298 QFileInfo fi(QCoreApplication::applicationFilePath()); 300 QFileInfo fi(QCoreApplication::applicationFilePath());
299 QDir installDir = fi.absoluteDir(); 301 QDir installDir = fi.absoluteDir();
326 char* errmsg = getLastErrorMsg(); 328 char* errmsg = getLastErrorMsg();
327 QString qerrmsg = QString::fromUtf8(errmsg); 329 QString qerrmsg = QString::fromUtf8(errmsg);
328 free(errmsg); 330 free(errmsg);
329 qDebug() << "Failed to start process: " << qerrmsg; 331 qDebug() << "Failed to start process: " << qerrmsg;
330 setState(NewSoftwareAvailable); 332 setState(NewSoftwareAvailable);
333 fclose(vres.fptr);
331 return; 334 return;
332 } 335 }
333 #else /* WIN32 */ 336 #else /* WIN32 */
334 /* On linux installDir is <prefix>/bin */ 337 /* On linux installDir is <prefix>/bin */
335 QStringList parameters; 338 QStringList parameters;
358 } 361 }
359 } 362 }
360 qDebug() << "Starting process " << filePath <<" params: " << parameters; 363 qDebug() << "Starting process " << filePath <<" params: " << parameters;
361 if (!sudo_started && !QProcess::startDetached(filePath, parameters)) { 364 if (!sudo_started && !QProcess::startDetached(filePath, parameters)) {
362 qDebug() << "Failed to start process."; 365 qDebug() << "Failed to start process.";
366 fclose(vres.fptr);
363 return; 367 return;
364 } 368 }
365 369
366 #endif 370 #endif
371
372 syslog_info_printf ("Installing update: %s\n", fileName.toUtf8().constData());
367 /* Installer process should now be running. We exit */ 373 /* Installer process should now be running. We exit */
368 374 fclose(vres.fptr);
369 closeApp(); 375 closeApp();
370 } 376 }
371 377
372 void MainWindow::checkUpdates(bool downloadSW) 378 void MainWindow::checkUpdates(bool downloadSW)
373 { 379 {

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