void mainWin::slotUpdateFinished() { qDebug() << "Updates all Finished"; QFile sysTrig( SYSTRIGGER ); if ( sysTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &sysTrig ); streamTrig << "INSTALLFINISHED: "; } sysTrig.close(); progressUpdate->setHidden(true); slotRescanUpdates(); }
void UpdaterTray::slotAutoUpdateStatusChanged() { QString line; QFile file( SYSTRIGGER ); if ( file.open( QIODevice::ReadOnly ) ) { QTextStream stream( &file ); while ( !stream.atEnd() ) { line = stream.readLine(); // line of text excluding '\n' if ( line.indexOf("DOWNLOADING: " ) == 0) { line.replace("DOWNLOADING: ", ""); autoStatus = AUTODOWNLOAD; autoCurrentUpdate = line; } if ( line.indexOf("INSTALLFAILED: " ) == 0) { autoStatus = AUTOFINISHED; QTimer::singleShot(2000, this, SLOT(slotStartUpdateCheck())); qDebug() << "FAILED INSTALLING UPDATES"; } if ( line.indexOf("INSTALLFINISHED: " ) == 0) { autoStatus = AUTOFINISHED; QTimer::singleShot(2000, this, SLOT(slotStartUpdateCheck())); qDebug() << "DONE INSTALLING UPDATES"; } } contextMenuRefresh(); } file.close(); if ( ! file.exists() ) { QFile sysTrig( SYSTRIGGER ); if ( sysTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &sysTrig ); streamTrig << QDateTime::currentDateTime().toString("hhmmss"); } sysTrig.close(); // Start our file watchers fileWatcherAutoUpdate = new QFileSystemWatcher(); fileWatcherAutoUpdate->addPath(SYSTRIGGER); connect(fileWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() )); }
void mainWin::slotPkgDone() { if ( uProc->exitCode() != 0 ) pkgHasFailed=true; // Run the next command on the stack if necessary if ( pkgCmdList.size() > 1 ) { pkgCmdList.removeAt(0); startPkgProcess(); return; } // Nothing left to run! Lets wrap up QFile sysTrig( SYSTRIGGER ); if ( sysTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &sysTrig ); streamTrig << "INSTALLFINISHED: "; } if ( pkgHasFailed ) { QFile file( "/tmp/pkg-output.log" ); if ( file.open( QIODevice::WriteOnly ) ) { QTextStream stream( &file ); stream << textDisplayOut->toPlainText(); file.close(); } QMessageBox::warning(this, tr("Failed!"), tr("The package commands failed. A copy of the output was saved to /tmp/pkg-output.log")); } else QMessageBox::warning(this, tr("Finished!"), tr("Package changes complete!" )); // Clear out the old commands pkgCmdList.clear(); // Switch back to our main display stackedTop->setCurrentIndex(0); // Re-init the meta-widget initMetaWidget(); }
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(); }
void mainWin::slotReadPkgOutput() { QString line, tmp, cur, tot, fname; int curItem, totItem; bool ok; while (uProc->canReadLine()) { line = uProc->readLine().simplified(); qDebug() << line; // Empty line? We can skip it if ( line.isEmpty() ) continue; tmp = line; tmp.truncate(50); // Flags we can parse out and not show the user // Check if we have crashed into a conflict and ask the user what to do if ( line.indexOf("PKGCONFLICTS: ") == 0 ) { tmp = line; tmp.replace("PKGCONFLICTS: ", ""); ConflictList = tmp; continue; } if ( line.indexOf("PKGREPLY: ") == 0 ) { QString ans; tmp = line; tmp.replace("PKGREPLY: ", ""); QMessageBox msgBox; msgBox.setText(tr("The following packages are causing conflicts with the selected changes and can be automatically removed. Continue?") + "\n" + ConflictList); msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); msgBox.setDetailedText(getConflictDetailText()); msgBox.setDefaultButton(QMessageBox::No); if ( msgBox.exec() == QMessageBox::Yes) { // We will try to fix conflicts ans="yes"; } else { // We will fail :( QMessageBox::warning(this, tr("Package Conflicts"), tr("You may need to manually fix the conflicts before trying again."), QMessageBox::Ok, QMessageBox::Ok); ans="no"; } QFile pkgTrig( tmp ); if ( pkgTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &pkgTrig ); streamTrig << ans; pkgTrig.close(); } continue; } if ( line.indexOf("FETCH: ") == 0 ) { progressUpdate->setValue(progressUpdate->value() + 1); tmp = line; tmp = tmp.remove(0, tmp.lastIndexOf("/") + 1); progressUpdate->setRange(0, 0); progressUpdate->setValue(0); curFileText = tr("Downloading: %1").arg(tmp); textStatus->setText(tr("Downloading: %1").arg(tmp)); continue; } if ( line.indexOf("FETCHDONE") == 0 ) continue; if ( line.indexOf("SIZE: ") == 0 ) { bool ok, ok2; line.replace("SIZE: ", ""); line.replace("DOWNLOADED: ", ""); line.replace("SPEED: ", ""); line.section(" ", 0, 0).toInt(&ok); line.section(" ", 1, 1).toInt(&ok2); if ( ok && ok2 ) { QString unit; int tot = line.section(" ", 0, 0).toInt(&ok); int cur = line.section(" ", 1, 1).toInt(&ok2); QString percent = QString::number( (float)(cur * 100)/tot ); QString speed = line.section(" ", 2, 3); // Get the MB downloaded / total if ( tot > 2048 ) { unit="MB"; tot = tot / 1024; cur = cur / 1024; } else { unit="KB"; } QString ProgressString=QString("(%1" + unit + " of %2" + unit + " at %3)").arg(cur).arg(tot).arg(speed); progressUpdate->setRange(0, tot); progressUpdate->setValue(cur); textStatus->setText(curFileText + " " + ProgressString); } continue; } // Now show output on GUI textDisplayOut->insertPlainText(line + "\n"); textDisplayOut->moveCursor(QTextCursor::End); // Any other flags to look for? ///////////////////////////////////////////////////// if ( line.indexOf("to be downloaded") != -1 ) { textStatus->setText(tr("Downloading packages...")); curUpdate = 0; progressUpdate->setValue(0); continue; } if ( line.indexOf("Checking integrity") == 0 ) { textStatus->setText(line); uPackages = true; dPackages = false; curUpdate = 0; progressUpdate->setValue(0); progressUpdate->setRange(0, 0); progressUpdate->setValue(0); continue; } if ( uPackages ) { if ( line.indexOf("[") == 0 ) { tmp=line.section("]", 1, 1); textStatus->setText(tmp); tmp=line.section("/", 0, 0).replace("[", ""); tmp.toInt(&ok); if (ok) { curItem=tmp.toInt(&ok); tmp=line.section("/", 1, 1).section("]", 0, 0); tmp.toInt(&ok); if (ok) { totItem=tmp.toInt(&ok); progressUpdate->setRange(0, totItem); progressUpdate->setValue(curItem); } } } continue; } } // end of while }
void DLProcess::parsePKGLine(QString line){ // KPM!! // TODO 12-12-2013 // No JSON in Qt4, once we move to Qt5, replace this hack // with the new JSON parser // Moved 2/18/14 to this class from pc-pkgmanager by Ken Moore //qDebug() << " -- pkg line:" << line; // Look for a download status update if ( line.indexOf("\"INFO_FETCH") != -1 && line.indexOf("\"url\"") != -1 ) { QString file, dl, tot; line.remove(0, line.indexOf("\"url") + 8); line.truncate(line.lastIndexOf("}")); // Get the file basename file = line; //qDebug() << "DL File:" << file; file.truncate(line.indexOf("\"")); file = file.section("/",-1).section(".txz",0,0); //replace the QFileInfo method below (Ken) //QFileInfo tFile; //tFile.setFile(file); //file = tFile.baseName(); // Get the download / total dl = line.section(":", 2, 2).section(",", 0, 0); tot = line.section(":", 3, 3).section("}", 0, 0); dl = dl.simplified(); tot = tot.simplified(); //These are in bytes, need to convert to kilobytes before sending it on... dl = QString::number( dl.toLongLong()/1024 ); tot = QString::number( tot.toLongLong()/1024 ); //Now calculate the stats and emit the signal calculateStats(dl, tot, "", file); } else if ( line.indexOf("PKGCONFLICTS: ") == 0 ) { QString tmp = line; tmp.replace("PKGCONFLICTS: ", ""); ConflictList = tmp; } else if ( line.indexOf("PKGREPLY: ") == 0 ) { QString ans; QString tmp = line; tmp.replace("PKGREPLY: ", ""); QMessageBox msgBox(parentW); msgBox.setText(tr("The following packages are causing conflicts with the selected changes and can be automatically removed. Continue?") + "\n" + ConflictList); msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); msgBox.setDetailedText(getConflictDetailText()); msgBox.setDefaultButton(QMessageBox::No); if ( msgBox.exec() == QMessageBox::Yes) { // We will try to fix conflicts ans="yes"; } else { // We will fail :( QMessageBox::warning(parentW, tr("Package Conflicts"), tr("You may need to manually fix the conflicts before trying again."), QMessageBox::Ok, QMessageBox::Ok); ans="no"; } QFile pkgTrig( tmp ); if ( pkgTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &pkgTrig ); streamTrig << ans; pkgTrig.close(); ConflictList.clear(); //already sent an answer - clear the internal list } }else{ //Just emit the message //line.remove(0, line.indexOf("\"msg") + 8); //line.truncate(line.lastIndexOf("\"")); emit UpdateMessage(line); return; } }
void UpdaterTray::programInit() { QString tmp, command; autoStatus = AUTOINACTIVE; doingCheck=false; shownPopup=false; // Use built-in frequency until we load another updateFrequency = -1; sysTimer = new QTimer(this); pbiTimer = new QTimer(this); connect( sysTimer, SIGNAL(timeout()), this, SLOT(slotScheduledSystemCheck()) ); connect( pbiTimer, SIGNAL(timeout()), this, SLOT(slotScheduledPBICheck()) ); // Get the username of the person running X username = getlogin(); // Setup our Context Menu QIcon contextIcon; contextIcon.addFile(":/images/updated.png"); trayIconMenu = new QMenu(this); trayIconMenu->setIcon(contextIcon); trayIconMenu->addSeparator(); trayIconMenu->addAction( QIcon(":/images/sysupdater.png"), tr("Start the Update Manager"), this, SLOT(slotOpenUpdateManager())); trayIconMenu->addAction( QIcon(":/images/pkgmanager.png"), tr("Start the Package Manager"), this, SLOT(slotOpenPackageManager())); trayIconMenu->addSeparator(); trayIconMenu->addAction( QIcon(":/images/appcafe.png"), tr("Start the AppCafe"), this, SLOT(slotOpenSoftwareManager())); trayIconMenu->addAction( QIcon(":/images/warden.png"), tr("Start the Warden"), this, SLOT(slotOpenJailManager())); trayIconMenu->addSeparator(); trayIconMenu->addAction( QIcon(":/images/view-refresh.png"),tr("Check for updates"),this, SLOT(slotCheckAllUpdates())); trayIconMenu->addSeparator(); runAction = trayIconMenu->addAction( tr("Run at startup"), this, SLOT(slotChangeRunStartup()) ); runAction->setCheckable( TRUE ); runAction->setChecked( TRUE ); popAction = trayIconMenu->addAction( tr("Display notifications"), this, SLOT(slotChangePopup()) ); popAction->setCheckable( TRUE ); popAction->setChecked( TRUE ); trayIconMenu->addSeparator(); trayIconMenu->addAction( tr("Quit"), this, SLOT(slotQuitTray()) ); // Init the tray icon trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayIconMenu); QIcon Icon(":/images/working.png"); trayIcon->setIcon(Icon); trayIcon->show(); connect( trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason) ) ); // Load the program preferences loadUpdaterPrefs(); // Start the monitor service for system updates QTimer::singleShot(1000, this, SLOT(slotScheduledSystemCheck())); // Start the monitor service for PBI updates QTimer::singleShot(60000, this, SLOT(slotScheduledPBICheck())); // Monitor if we need to start any update checks QTimer::singleShot(500, this, SLOT(slotMonitorForChanges())); // Watch our trigger file, to see if any automated updates are being downloaded QFile sysTrig( SYSTRIGGER ); if ( sysTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &sysTrig ); streamTrig << QDateTime::currentDateTime().toString("hhmmss"); } sysTrig.close(); // Start our file watchers fileWatcherAutoUpdate = new QFileSystemWatcher(); fileWatcherAutoUpdate->addPath(SYSTRIGGER); connect(fileWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() )); // Watch for PBI updates and refresh QFile pbiTrig( PBITRIGGER ); if ( pbiTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig1( &pbiTrig ); streamTrig1 << QDateTime::currentDateTime().toString("hhmmss"); pbiTrig.close(); } pbiWatcherAutoUpdate = new QFileSystemWatcher(); pbiWatcherAutoUpdate->addPath(PBITRIGGER); connect(pbiWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledPBICheck() )); // Watch our trigger file, to see if any automated updates are being downloaded fileWatcherSys = new QFileSystemWatcher(); fileWatcherSys->addPath(PREFIX + "/share/pcbsd/pc-updatemanager/conf/sysupdate.conf"); connect(fileWatcherSys, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledSystemCheck() )); }