comparison ui/mainwindow.cpp @ 1252:9a482182f80f

(issue54) Monitor update installation and restart afterwards on Linux
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 25 Sep 2014 15:57:25 +0200
parents 8748223990eb
children 8ceaa189570d f1e461340ede
comparison
equal deleted inserted replaced
1251:3b433a350092 1252:9a482182f80f
340 qDebug() << "Failed to create temporary copy of installer."; 340 qDebug() << "Failed to create temporary copy of installer.";
341 } 341 }
342 return targetPath; 342 return targetPath;
343 } 343 }
344 344
345 void MainWindow::updaterFinished(int exitCode, QProcess::ExitStatus status)
346 {
347 if (status != QProcess::NormalExit) {
348 syslog_error_printf("Update failed.\n");
349 qDebug() << "Failed to install update.";
350 return;
351 }
352 if (exitCode != 0) {
353 qDebug() << "Update not installed with error: " << exitCode;
354 return;
355 }
356 qDebug() << "Restarting";
357 ProcessHelp::cleanUp();
358 QProcess::startDetached(qApp->applicationFilePath());
359 qApp->quit();
360 }
361
345 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { 362 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) {
346 QFileInfo instProcInfo = QFileInfo(fileName); 363 QFileInfo instProcInfo = QFileInfo(fileName);
347 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); 364 QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
348 365
349 /* Copy the file to a temporary name for installation */ 366 /* Copy the file to a temporary name for installation */
408 installDir.cdUp(); 425 installDir.cdUp();
409 parameters << "--prefix" << installDir.path(); 426 parameters << "--prefix" << installDir.path();
410 parameters << "--update"; 427 parameters << "--update";
411 bool sudo_started = false; 428 bool sudo_started = false;
412 bool use_sudo = is_admin() && is_system_install(); 429 bool use_sudo = is_admin() && is_system_install();
430
431 QProcess *updaterProcess = new QProcess();
432
413 if (use_sudo) { 433 if (use_sudo) {
414 QStringList sudoPrograms; 434 QStringList sudoPrograms;
415 sudoPrograms << "pkexec" << "kdesudo" << "sudo"; 435 sudoPrograms << "pkexec" << "kdesudo" << "sudo";
416 QStringList sudoParams; 436 QStringList sudoParams;
417 sudoParams << filePath + " " + parameters.join(" "); 437 sudoParams << filePath;
438 sudoParams << parameters;
439 updaterProcess->setArguments(sudoParams);
418 440
419 foreach (const QString &sProg, sudoPrograms) { 441 foreach (const QString &sProg, sudoPrograms) {
420 qDebug() << "Starting process " << sProg <<" params: " << sudoParams; 442 qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
421 if (!QProcess::startDetached(sProg, sudoParams)) { 443 updaterProcess->setProgram(sProg);
444 updaterProcess->start();
445 if (!updaterProcess->waitForStarted() ||
446 updaterProcess->state() == QProcess::NotRunning) {
422 continue; 447 continue;
423 } else { 448 } else {
424 sudo_started = true; 449 sudo_started = true;
450 connect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
451 this, SLOT(updaterFinished(int, QProcess::ExitStatus)));
425 break; 452 break;
426 } 453 }
427 } 454 }
428 } 455 }
429 qDebug() << "Starting process " << filePath <<" params: " << parameters; 456 if (!sudo_started) {
430 if (!sudo_started && !QProcess::startDetached(filePath, parameters)) { 457 qDebug() << "Starting process " << filePath <<" params: " << parameters;
431 qDebug() << "Failed to start process."; 458 updaterProcess->setArguments(parameters);
432 fclose(vres.fptr); 459 updaterProcess->setProgram(filePath);
460 updaterProcess->start();
461
462 if (!updaterProcess->waitForStarted() ||
463 updaterProcess->state() == QProcess::NotRunning) {
464 qDebug() << "Failed to start process.";
465 }
466 connect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
467 this, SLOT(restart()));
433 return; 468 return;
434 } 469 }
435 470
436 #endif 471 #endif
437 if (isVisible()) { 472 if (isVisible()) {
440 } 475 }
441 476
442 syslog_info_printf ("Installing update: %s\n", fileName.toUtf8().constData()); 477 syslog_info_printf ("Installing update: %s\n", fileName.toUtf8().constData());
443 /* Installer process should now be running. We exit */ 478 /* Installer process should now be running. We exit */
444 fclose(vres.fptr); 479 fclose(vres.fptr);
480 #ifdef WIN32
445 closeApp(); 481 closeApp();
482 #endif
446 } 483 }
447 484
448 void MainWindow::checkUpdates(bool downloadSW) 485 void MainWindow::checkUpdates(bool downloadSW)
449 { 486 {
450 verifyListData(); 487 verifyListData();

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