Changeset 3710

Show
Ignore:
Timestamp:
03/31/09 12:12:29 (12 months ago)
Author:
kris
Message:

Large update to the PBI updater and tray updater, fixed bugs with checking for updates not showing all the updates properly, due to buffering problems when getting the data back from server. Also added feature which will check the PBI's "made date", and not try to have the user install an older PBI on top of a newer copy. This is helpful when the user is running PBI's which are not yet in the online-update service

Location:
pcbsd/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pcbsd/trunk/SystemUpdaterTray/UpdaterTray.cpp

    r3571 r3710  
    7272QString PBIProgURL3[900]; 
    7373QString PBIProgMD5[900]; 
     74QString PBIProgMdate[900]; 
    7475QString PBIProgLoc[900]; 
    7576int     PBIProgUpdate[900]; 
    7677int     PBIProgFailed[900]; 
     78QString PBIBuffer; 
     79QString updatePBITextList; 
    7780 
    7881void UpdaterTray::programInit() 
     
    480483   if ( pbistatus == PBI_UPDATES_AVAIL )  
    481484   { 
    482       tooltipStr += "<br>" + tr("PBI updates available!"); 
     485      tooltipStr += "<br><br>" + tr("PBI updates available!") + "<br><br>"; 
     486      tooltipStr += updatePBITextList; 
    483487   } 
    484488    
     
    649653void UpdaterTray::slotPBICheckUpdate() 
    650654{ 
     655  // Read the buffer from the last PBI check 
     656  if (currentWorkingPBI != -1 ) 
     657  { 
     658    slotReadPBIBuffer(); 
     659  } 
     660 
     661  // Empty out our PBI buffer 
     662  PBIBuffer=""; 
    651663 
    652664    QString tmp, line; 
     
    715727   
    716728  checkPBIJob = KIO::http_post( PBIUrl, postData.utf8(), KIO::HideProgressInfo); 
    717   checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" ); 
    718  
    719  
    720729  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) ); 
    721730  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) ); 
     731  checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" ); 
     732 
     733 
    722734 
    723735} 
     
    725737void UpdaterTray::slotRecieveData(KIO::Job*, const QByteArray& data) 
    726738{ 
    727     QString output(data), line; 
     739    QString output(data); 
     740    PBIBuffer = PBIBuffer + output; 
     741} 
     742 
     743void UpdaterTray::slotReadPBIBuffer() 
     744{ 
     745    QString output = PBIBuffer; 
     746    QString line; 
     747 
    728748    QStringList outputList; 
    729749    if ( output.indexOf("Up2Date") == -1  && ! output.isEmpty()) 
     
    759779                 PBIProgMD5[currentWorkingPBI] = line.replace("MD5: ", ""); 
    760780             }  
     781             if ( line.find("MDATE:") == 0) 
     782             { 
     783                 PBIProgMdate[currentWorkingPBI] = line.replace("MDATE: ", ""); 
     784             }  
    761785        } // End of For loop reading line-by-line our data 
    762786 
     
    777801  int i = 0, foundUpdates = 0; 
    778802  QString text, tmp, newMsg, ProgDirName, iconPath; 
     803  bool updateAvail; 
    779804 
    780805    while (! PBIProgName[i].isEmpty() ) 
     
    792817          ProgDirName = ProgDirName + tmp; 
    793818          iconPath = "/Programs/" + ProgDirName + "/" + PBIProgIcon[i]; 
    794           foundUpdates++; 
     819          updateAvail=true; 
     820 
     821          // Now check if we have a *newer* PBI installed here, than is in the updater 
     822          QFile mdatefile( "/Programs/" + ProgDirName + "/.mdate"); 
     823          if ( mdatefile.exists() && ! PBIProgMdate[i].isEmpty() ) 
     824          { 
     825             if ( mdatefile.open( QIODevice::ReadOnly ) ) { 
     826               QTextStream stream( &mdatefile ); 
     827               QString line; 
     828               line = stream.readLine(); // line of text excluding '\n' 
     829               if ( ! line.isEmpty() ) { 
     830 
     831                 // Sort the dates from the .mdate file 
     832                 QString tmp2 = line; 
     833                 tmp2.truncate( tmp2.indexOf(" ") ); 
     834                 QString date1 = tmp2; 
     835                 tmp2 = line; 
     836                 QString date2 = tmp2.remove( 0, tmp2.indexOf(" ") ); 
     837 
     838                 // Sort the dates from the updater 
     839                 tmp2 = PBIProgMdate[i]; 
     840                 tmp2.truncate( tmp2.indexOf(" ") ); 
     841                 QString PBIdate1 = tmp2; 
     842                 tmp2 = PBIProgMdate[i]; 
     843                 QString PBIdate2 = tmp2.remove( 0, tmp2.indexOf(" ") ); 
     844 
     845                 // Check if the installed PBI is created later than the online update 
     846                 int ldate, odate; 
     847                 bool ok; 
     848                 ldate = date1.toInt(&ok); 
     849                 if ( ok ) 
     850                 { 
     851                   odate = PBIdate1.toInt(&ok); 
     852                   if ( ok ) 
     853                   { 
     854                     if ( ldate > odate ) 
     855                     { 
     856                       updateAvail = false; 
     857                     } else if (ldate == odate) { 
     858                        // We checked the year / day, now check the hours seconds 
     859                        ldate = date2.toInt(&ok); 
     860                        if ( ok ) 
     861                        { 
     862                           odate = PBIdate2.toInt(&ok); 
     863                           if ( ok ) 
     864                           { 
     865                             if ( ldate > odate ) 
     866                             { 
     867                               updateAvail = false; 
     868                             } 
     869                           } 
     870                        } 
     871                     } 
     872                   } 
     873                 } 
     874                
     875                 /* QMessageBox::critical( 0, tr("Online Update"), "date1: " + date1, QMessageBox::Ok ); 
     876                 QMessageBox::critical( 0, tr("Online Update"), "date2: " + date2, QMessageBox::Ok ); 
     877                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate1: " + PBIdate1, QMessageBox::Ok ); 
     878                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate2: " + PBIdate2, QMessageBox::Ok ); */ 
     879               } 
     880             } 
     881 
     882               
     883          } 
     884 
     885          // If this is a valid update, go ahead and increment our update counter 
     886          if ( updateAvail ) { 
     887            updatePBITextList = updatePBITextList + PBIProgName[i] + " " +  PBIProgNewVer[i] + "<br>"; 
     888            foundUpdates++; 
     889          } 
    795890       } 
    796891       i++; 
     
    798893 
    799894  if ( foundUpdates != 0 ) { 
    800   // Update our dialog that we are looking for PBI updates right now 
    801     if (foundUpdates == 1 ) { 
    802        newMsg = "<font color=\"#ff0000\">" + tmp.setNum(foundUpdates) + " " + tr("PBI Update available!") + "</font>"; 
    803        QImage Icon2; 
    804        Icon2.load("/PCBSD/SystemUpdater/images/pbiupdates.png"); 
    805        QPixmap PixmapIcon2; 
    806        PixmapIcon2.convertFromImage(Icon2.scaled(22,22)); 
    807  
    808        KPassivePopup::message(tr("System Update") , tr("A PBI update is available!"),  PixmapIcon2,  this); 
    809     } else { 
    810        newMsg = "<font color=\"#ff0000\">" + tmp.setNum(foundUpdates) + " " + tr("PBI Updates available!") + "</font>"; 
    811        QImage Icon2; 
    812        Icon2.load("/PCBSD/SystemUpdater/images/pbiupdates.png"); 
    813        QPixmap PixmapIcon2; 
    814        PixmapIcon2.convertFromImage(Icon2.scaled(22,22)); 
    815  
    816        KPassivePopup::message(tr("System Update") , tr("PBI updates are available!"),  PixmapIcon2,  this); 
    817     } 
    818  
     895    // Set the status that we have new PBIs 
    819896    pbistatus = PBI_UPDATES_AVAIL; 
    820897  } else { 
  • pcbsd/trunk/SystemUpdaterTray/UpdaterTray.h

    r3571 r3710  
    4040   void slotRecieveData(KIO::Job*, const QByteArray& data); 
    4141   void slotCheckAllUpdates(); 
     42   void slotReadPBIBuffer(); 
    4243    
    4344protected: 
  • pcbsd/trunk/kcmPBMsource/pbm.cpp

    r3164 r3710  
    20672067{ 
    20682068 
    2069     QString tmp, line; 
    2070     QString progName, Arch, Version, PBIUrl; 
     2069  // Read the buffer from the last PBI check 
     2070  if (currentWorkingPBI != -1 ) 
     2071  { 
     2072    slotReadPBIBuffer(); 
     2073  } 
     2074   
     2075  // Empty out our PBI buffer 
     2076  PBIBuffer=""; 
     2077 
     2078  QString tmp, line; 
     2079  QString progName, Arch, Version, PBIUrl; 
    20712080 
    20722081 
     
    21292138 
    21302139  QString postData = "PBIName=" + progName + "&PBIVer=" + PBIProgVer[currentWorkingPBI] + "&PCBSDVER=" + Version + "&OSARCH=" + Arch; 
     2140 
    21312141   
     2142 
    21322143  checkPBIJob = KIO::http_post( PBIUrl, postData.utf8(), KIO::HideProgressInfo); 
     2144  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) ); 
     2145  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) ); 
     2146 
    21332147  checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" ); 
    21342148   
    21352149  textPBIStatus->setText(tr("<font color=\"#ff0000\">Checking %1 for updates...</font>").arg(progName) ); 
    21362150 
    2137   connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) ); 
    2138   connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) ); 
    21392151 
    21402152} 
     
    21422154void PBM::slotRecieveData(KIO::Job*, const QByteArray& data) 
    21432155{ 
    2144     QString output(data), line; 
     2156    QString output(data); 
     2157 
     2158    PBIBuffer = PBIBuffer + output; 
     2159} 
     2160 
     2161void PBM::slotReadPBIBuffer() 
     2162{ 
     2163    QString output = PBIBuffer; 
     2164    QString line; 
    21452165    QStringList outputList; 
    21462166    if ( output.indexOf("Up2Date") == -1  && ! output.isEmpty()) 
    21472167    { 
     2168        //QMessageBox::critical( 0, tr("Online Update"), "line: " + output, QMessageBox::Ok ); 
     2169 
    21482170        outputList = QStringList::split("\n", output); 
    21492171        for ( int i = 0; i < outputList.size(); i++) 
    21502172        { 
    21512173            line = outputList.at(i); 
    2152             
     2174 
    21532175             if (line.find("NewVer:" ) ==  0 ) 
    21542176             { 
     
    21762198                 PBIProgMD5[currentWorkingPBI] = line.replace("MD5: ", ""); 
    21772199             }  
     2200             if ( line.find("MDATE:") == 0) 
     2201             { 
     2202                 PBIProgMdate[currentWorkingPBI] = line.replace("MDATE: ", ""); 
     2203             }  
    21782204        } // End of For loop reading line-by-line our data 
    21792205 
     
    21942220  int i = 0, foundUpdates = 0; 
    21952221  QString text, tmp, newMsg, ProgDirName, iconPath; 
     2222  bool updateAvail; 
    21962223 
    21972224    while (! PBIProgName[i].isEmpty() ) 
     
    22092236          ProgDirName = ProgDirName + tmp; 
    22102237          iconPath = "/Programs/" + ProgDirName + "/" + PBIProgIcon[i]; 
    2211  
    2212           QPixmap defaultIcon; 
    2213           Q3CheckListItem *item = new Q3CheckListItem ( listViewPBIUpdates, text, Q3CheckListItem::CheckBox  ) ; 
    2214           item->setText(1, tmp.setNum(i)); 
    2215  
    2216           defaultIcon.convertFromImage(QImage(iconPath).smoothScale(32,32)); 
    2217  
    2218           item->setPixmap ( 0, defaultIcon ) ; 
    2219           listViewPBIUpdates->setColumnAlignment ( 0, Qt::AlignVCenter); 
    2220  
    2221           foundUpdates++; 
     2238          updateAvail = true; 
     2239 
     2240          // Now check if we have a *newer* PBI installed here, than is in the updater 
     2241          QFile mdatefile( "/Programs/" + ProgDirName + "/.mdate"); 
     2242          if ( mdatefile.exists() && ! PBIProgMdate[i].isEmpty() ) 
     2243          { 
     2244             if ( mdatefile.open( QIODevice::ReadOnly ) ) { 
     2245               Q3TextStream stream( &mdatefile ); 
     2246               QString line; 
     2247               line = stream.readLine(); // line of text excluding '\n' 
     2248               if ( ! line.isEmpty() ) { 
     2249 
     2250                 // Sort the dates from the .mdate file 
     2251                 QString tmp2 = line; 
     2252                 tmp2.truncate( tmp2.indexOf(" ") ); 
     2253                 QString date1 = tmp2; 
     2254                 tmp2 = line; 
     2255                 QString date2 = tmp2.remove( 0, tmp2.indexOf(" ") ); 
     2256 
     2257                 // Sort the dates from the updater 
     2258                 tmp2 = PBIProgMdate[i]; 
     2259                 tmp2.truncate( tmp2.indexOf(" ") ); 
     2260                 QString PBIdate1 = tmp2; 
     2261                 tmp2 = PBIProgMdate[i]; 
     2262                 QString PBIdate2 = tmp2.remove( 0, tmp2.indexOf(" ") ); 
     2263 
     2264                 // Check if the installed PBI is created later than the online update 
     2265                 int ldate, odate; 
     2266                 bool ok; 
     2267                 ldate = date1.toInt(&ok); 
     2268                 if ( ok ) 
     2269                 { 
     2270                   odate = PBIdate1.toInt(&ok); 
     2271                   if ( ok ) 
     2272                   { 
     2273                     if ( ldate > odate ) 
     2274                     { 
     2275                       updateAvail = false; 
     2276                     } else if (ldate == odate) { 
     2277                        // We checked the year / day, now check the hours seconds 
     2278                        ldate = date2.toInt(&ok); 
     2279                        if ( ok ) 
     2280                        { 
     2281                           odate = PBIdate2.toInt(&ok); 
     2282                           if ( ok ) 
     2283                           { 
     2284                             if ( ldate > odate ) 
     2285                             { 
     2286                               updateAvail = false; 
     2287                             } 
     2288                           } 
     2289                        } 
     2290                     } 
     2291                   } 
     2292                 } 
     2293                
     2294                 /* QMessageBox::critical( 0, tr("Online Update"), "date1: " + date1, QMessageBox::Ok ); 
     2295                 QMessageBox::critical( 0, tr("Online Update"), "date2: " + date2, QMessageBox::Ok ); 
     2296                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate1: " + PBIdate1, QMessageBox::Ok ); 
     2297                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate2: " + PBIdate2, QMessageBox::Ok ); */ 
     2298               } 
     2299             } 
     2300 
     2301               
     2302          } 
     2303 
     2304          if ( updateAvail ) { 
     2305           QPixmap defaultIcon; 
     2306           Q3CheckListItem *item = new Q3CheckListItem ( listViewPBIUpdates, text, Q3CheckListItem::CheckBox  ) ; 
     2307           item->setText(1, tmp.setNum(i)); 
     2308 
     2309           defaultIcon.convertFromImage(QImage(iconPath).smoothScale(32,32)); 
     2310 
     2311           item->setPixmap ( 0, defaultIcon ) ; 
     2312           listViewPBIUpdates->setColumnAlignment ( 0, Qt::AlignVCenter); 
     2313 
     2314           foundUpdates++; 
     2315          } 
    22222316       } 
    22232317       i++; 
  • pcbsd/trunk/kcmPBMsource/pbm.h

    r3113 r3710  
    8787    void slotInstallUpdatesClicked(); 
    8888    void slotCheckSysUpdatesFlags(); 
     89    void slotReadPBIBuffer(); 
    8990private: 
    9091    void RemoveFiles( PBI * pbi ); 
     
    168169    QString PBIProgURL3[900]; 
    169170    QString PBIProgMD5[900]; 
     171    QString PBIProgMdate[900]; 
    170172    QString PBIProgLoc[900]; 
    171173    int     PBIProgUpdate[900]; 
    172174    int     PBIProgFailed[900]; 
     175    QString PBIBuffer; 
    173176signals: 
    174177