-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index 64a9c26..9a239a5 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp @@ -14,27 +14,22 @@ * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <iostream> -#include <fstream> -using namespace std; - #include "server.h" #include "datamgr.h" +#include <qfile.h> +#include <qtextstream.h> + #ifdef QWS #include <qpe/global.h> #include <qpe/applnk.h> #include <qlist.h> #endif #include "utils.h" @@ -68,32 +63,33 @@ void Server :: readStatusFile( QList<Destination> &destList ) bool rootRead = false; for ( ; dit.current(); ++dit ) { dest = dit.current(); bool installingToRoot = false; QString path = dest->getDestinationPath(); if ( path.right( 1 ) != "/" ) - path += "/"; + path.append( "/" ); if ( path == "/" ) { rootRead = true; installingToRoot = true; } - packageFile = path + "usr/lib/ipkg/status"; + packageFile = path; + packageFile.append( "usr/lib/ipkg/status" ); readPackageFile( 0, false, installingToRoot, &( *dest ) ); } // Ensure that the root status file is read if ( !rootRead ) { - cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; + //cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; packageFile = "/usr/lib/ipkg/status"; readPackageFile( 0, false, true ); } } void Server :: readLocalIpks( Server *local ) { cleanUp(); @@ -141,46 +137,42 @@ void Server :: readLocalIpks( Server *local ) #endif // build local packages buildLocalPackages( local ); } void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) { - ifstream in( packageFile ); - if ( !in.is_open() ) + QFile f( packageFile ); + if ( !f.open( IO_ReadOnly ) ) return; + QTextStream t( &f ); - char line[5001]; - char k[21]; - char v[5001]; + QString line; QString key; QString value; + int pos; if ( clearAll ) cleanUp(); Package *currPackage = 0; bool newPackage = true; - do + while ( !t.eof() ) { - in.getline( line, 5000 ); - if ( in.eof() ) - continue; - - k[0] = '\0'; - v[0] = '\0'; - - sscanf( line, "%[^:]: %[^\n]", k, v ); + line = t.readLine(); - key = k; - value = v; - key = key.stripWhiteSpace(); - value = value.stripWhiteSpace(); + pos = line.find( ':', 0 ); + if ( pos > -1 ) + key = line.mid( 0, pos ).stripWhiteSpace(); + else + key = QString::null; + value = line.mid( pos+1, line.length()-pos ).stripWhiteSpace(); + if ( key == "Package" && newPackage ) { newPackage = false; currPackage = getPackage( value ); if ( !currPackage ) { Package *package = new Package( value ); @@ -223,23 +215,23 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR } else if ( key == "Section" ) { if ( currPackage ) currPackage->setSection( value ); DataManager::setAvailableCategories( value ); } - else if ( key == "" ) + else if ( key == QString::null ) { newPackage = true; } - } while ( !in.eof() ); + } - in.close(); + f.close(); // build local packages buildLocalPackages( local ); } void Server :: buildLocalPackages( Server *local ) { Package *curr; |