Exemple #1
0
void mainWin::slotUpdateLoop()
{
  QString tmp, tmp2, mUrl, PkgSet, Version, Arch;

  // Check if the last update process finished
  if ( curUpdate != -1 ) {
    qDebug() << "Finished Update";
    if ( uProc->exitStatus() != QProcess::NormalExit || uProc->exitCode() != 0)
    {
      // Read any remaining buffers
      slotReadUpdateOutput();

      // Warn user that this update failed
      if ( lastError.isEmpty() )
         QMessageBox::critical(this, tr("Update Failed!"), tr("Failed to install:") + listUpdates.at(curUpdate).at(0) + " " + tr("An unknown error occured!")); 
      else
         QMessageBox::critical(this, tr("Update Failed!"), tr("Failed to install:") + listUpdates.at(curUpdate).at(0) + " " + lastError); 
    } else {
      // If successfull system update download
      if ( listUpdates.at(curUpdate).at(1) == "SYSUPDATE" )
        QMessageBox::information(this, tr("Update Ready"), tr("Please reboot to start the update to PC-BSD version \"") + listUpdates.at(curUpdate).at(0) + "\". " + tr("This process may take a while, please do NOT interrupt the process.")); 
    }

    // Remove the lock file
    if ( listUpdates.at(curUpdate).at(1) == "FBSDUPDATE" ) {
        system("rm /tmp/.fbsdup-lock");
    }

    listViewUpdates->item(curUpdate)->setIcon(QIcon());
    setWindowTitle(tr("Update Manager"));
  }

  // Start looking for the next update
  for (int z=0; z < listViewUpdates->count(); ++z) {
    if ( listViewUpdates->item(z)->checkState() == Qt::Checked && curUpdate < z ) 
    {
	
      // Check for a freebsd-update lock file
      if ( listUpdates.at(z).at(1) == "FBSDUPDATE" ) {
  	if ( QFile::exists("/tmp/.fbsdup-lock") ) {
          QMessageBox::critical(this, tr("Update Failed!"), tr("Could not run freebsd-update, another process is already running!")); 
          slotUpdateFinished();
     	  return;
  	} 
        // Lock out freebsd-update
        system("touch /tmp/.fbsdup-lock");
      }

      curUpdate = z;
      curUpdateIndex++;
      progressUpdate->setHidden(false);
      progressUpdate->setRange(0, 0);
      tmp.setNum(curUpdateIndex);
      tmp2.setNum(totUpdate);
      setWindowTitle(tr("Updating:") + " " + listUpdates.at(z).at(0));

      textLabel->setText(tr("Starting Update: %1 (%2 of %3)")
                         .arg(listUpdates.at(z).at(0))
 			 .arg(tmp)
		 	 .arg(tmp2));

      // Get the icon
      listViewUpdates->item(z)->setIcon(QIcon(":images/current-item.png"));

      // Get the install tag
      QString tag;
      if ( listUpdates.at(z).at(1) == "SYSUPDATE" )
        tag = listUpdates.at(z).at(4);
      if ( listUpdates.at(z).at(1) == "PATCH" )
        tag = listUpdates.at(z).at(3);

      // Show tray that we are doing a download
      QFile sysTrig( SYSTRIGGER );
      if ( sysTrig.open( QIODevice::WriteOnly ) ) {
        QTextStream streamTrig( &sysTrig );
        streamTrig << "DOWNLOADING: ";
      }

      // Setup the upgrade process
      labelIcon->setPixmap(QPixmap(":/images/sysinstall.png"));
      uProc = new QProcess();
      QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
      env.insert("PCFETCHGUI", "YES");
      uProc->setProcessEnvironment(env);
      uProc->setProcessChannelMode(QProcess::MergedChannels);

      // Connect the slots
      connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadUpdateOutput()) );
      connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotUpdateLoop()) );

      // If doing FreeBSD Update run freebsd-update cmd
      if ( wDir.isEmpty() ) {
         if ( listUpdates.at(z).at(1) == "FBSDUPDATE" ) {
           uProc->start("freebsd-update", QStringList() << "install"); 
	   system("touch /tmp/.fbsdup-reboot");
         } else {
           uProc->start("pc-updatemanager", QStringList() << "install" << tag ); 
	 }
      } else {
	 // Doing a warden update in a chroot environment
         if ( listUpdates.at(z).at(1) == "FBSDUPDATE" ) {
           uProc->start("chroot", QStringList() << wDir << "freebsd-update" << "install"); 
         } 
      }
      qDebug() << "Update started";
      return;
    }

  }

  // If we get here, no more updates to do
  slotUpdateFinished();
}
Exemple #2
0
void WindowMain::slotUpdateBtnOK()
{
    ui_->mainLayout_v->removeWidget(updateMessage_);
    ui_->mainLayout_v->removeWidget(questionBox_);
    questionBox_->close();
    updateMessage_->close();
    delete questionBox_;
    questionBox_ = NULL;
    delete updateMessage_;
    updateMessage_ = NULL;

    // We only update the binary on Windows. On Linux, the user has to take action (they got notified in update dialog).
    #ifdef PM_WINDOWS
      // TODO: Alex start update process here like
      // UPDATER = new updaterWidget;
      // ui_->mainLayout_v->addWidget(UPDATER);
      // connect(UPDATER,
      //         SIGNAL(finished(int)),
      //         this,
      //         SLOT(slotUpdateFinished()));
      // UPDATER->start()
      connect( FvUpdater::sharedUpdater(), SIGNAL( signalUpdateInstalled() ), this, SLOT( slotUpdateFinished() ) );
      FvUpdater::sharedUpdater()->slotTriggerUpdate();

    #endif
}