[Kde-cygwin-cvs] CVS: tools/installer/shared installer.cpp,1.1,1.2 installer.h,1.1,1.2 packagelist.c
Status: Inactive
Brought to you by:
habacker
From: Ralf H. <hab...@us...> - 2006-01-22 18:42:23
|
Update of /cvsroot/kde-cygwin/tools/installer/shared In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8626/installer/shared Modified Files: installer.cpp installer.h packagelist.cpp packagelist.h Log Message: version 0.5.2 Index: installer.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/installer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- installer.cpp 22 Jan 2006 18:40:04 -0000 1.1 +++ installer.cpp 22 Jan 2006 18:42:15 -0000 1.2 @@ -21,93 +21,38 @@ ** ****************************************************************************/ -// @TODO load installer config from manifest dir - - #include <QtCore> #include "installer.h" #include "packagelist.h" +#define DEBUG Installer::Installer(PackageList *_packageList) : QObject() { + root = "."; packageList = _packageList; + packageList->installer = this; connect (packageList,SIGNAL(loadedConfig()),this,SLOT(updatePackageList())); - installedList = new QList<QString>(); - -// if (QFile::exists("installed.txt")) -// readFromFile("installed.txt"); -// else -// loadConfig(); } Installer::~Installer() { -// writeToFile("installed.txt"); - delete installedList; } -/* -void Installer::printList(const QString &title) -{ -#ifdef DEBUG - qDebug() << __PRETTY_FUNCTION__; -#endif - qDebug() << title; - QList<QString>::iterator i; - for (i = installedList->begin(); i != installedList->end(); ++i) - qWarning(i->toLatin1()); +void Installer::setRoot(const QString &_root) +{ + root = _root; } -*/ -/* not required at now -bool Installer::readFromFile(QString const &fileName) -{ -#ifdef DEBUG - qDebug() << __PRETTY_FUNCTION__; -#endif - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly| QIODevice::Text)) - return false; - - installedList->clear(); - - while (!file.atEnd()) { - QByteArray line = file.readLine(); - if (line.startsWith("#")) - continue; - installedList->append(line); - } - return true; -} - -bool Installer::writeToFile(QString const &fileName) -{ -#ifdef DEBUG - qDebug() << __PRETTY_FUNCTION__; -#endif - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return false; - - QTextStream out(&file); - out << "# installed package list" << "\n"; - QList<QString>::iterator i; - for (i = installedList->begin(); i != installedList->end(); ++i) - out << i->toLatin1() << "\n"; - return true; -} -*/ -bool Installer::loadConfig(const QString &destdir) +bool Installer::loadConfig() { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif - installedList->clear(); - - QDir dir(destdir + "manifest"); + + QDir dir(root + "/manifest"); dir.setFilter(QDir::Files); dir.setNameFilters(QStringList("*.ver")); dir.setSorting(QDir::Size | QDir::Reversed); @@ -118,27 +63,29 @@ Package pkg; pkg.setFromVersionFile(fileInfo.fileName()); packageList->updatePackage(pkg); -// installedList->append(fileInfo.fileName()); } -// printList("installed packages"); return true; } -void Installer::install(const QString &fileName, const QString &destdir) +bool Installer::install(const QString &fileName) { QString cmd = "bin\\unzip.exe -o"; - if (destdir != "") - cmd += " -d " + destdir; + if (root != "") + cmd += " -d " + root; cmd += " " + fileName; qDebug() << cmd; QProcess unzip; unzip.setReadChannelMode(QProcess::MergedChannels); unzip.start(cmd); - if (!unzip.waitForFinished()) + if (!unzip.waitForFinished()) { qDebug() << "unzip failed:" << unzip.errorString(); - else + return false; + } + else { qDebug() << "unzip output:" << unzip.readAll(); + return true; + } } void Installer::updatePackageList() Index: installer.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/installer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- installer.h 22 Jan 2006 18:40:04 -0000 1.1 +++ installer.h 22 Jan 2006 18:42:15 -0000 1.2 @@ -33,18 +33,20 @@ Installer(PackageList *packageList); virtual ~Installer(); - void install(const QString &fileName, const QString &destdir=""); + // set installation root + void setRoot(const QString &_root="."); + bool install(const QString &fileName); // installPackage(Package *pkg) // bool readFromFile(QString const &fileName); // bool writeToFile(QString const &fileName); - bool loadConfig(const QString &destdir=""); + bool loadConfig(); public slots: void updatePackageList(); private: - QList<QString> *installedList; PackageList *packageList; + QString root; }; Index: packagelist.cpp =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/packagelist.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- packagelist.cpp 22 Jan 2006 18:40:04 -0000 1.2 +++ packagelist.cpp 22 Jan 2006 18:42:15 -0000 1.3 @@ -25,14 +25,45 @@ #include <QtNetwork> #include "packagelist.h" +#include "downloader.h" +#include "installer.h" //#define DEBUG -PackageList::PackageList() +QStringList filterPackageFiles(const QStringList &list,const QString &mode) +{ + QStringList result; + for (int j = 0; j < list.size(); ++j) { + QUrl url(list.at(j)); + QFileInfo fileInfo(url.path()); + QString fileName = fileInfo.fileName(); + + // only download package not already downloaded and only bin and lib packages + if (mode == "URL" && QFile::exists(fileName)) + qDebug() << fileName << " - already downloaded"; + else if(fileName.contains("src") ) + qDebug() << fileName << " - ignored"; + else { + if (mode == "URL") + qDebug() << fileName << " - downloading"; + else + qDebug() << fileName << " - installing"; + if (mode == "URL") + result << list.at(j); + else + result << fileName; + } + } + return result; +} + + +PackageList::PackageList(Downloader *_downloader) : QObject() { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; #endif + downloader = _downloader; packageList = new QList<Package>; } @@ -52,6 +83,18 @@ packageList->append(package); } +Package *PackageList::getPackage(QString const &pkgName) +{ +#ifdef DEBUG + qDebug() << __PRETTY_FUNCTION__; +#endif + QList<Package>::iterator i; + for (i = packageList->begin(); i != packageList->end(); ++i) + if (i->Name() == pkgName) + return &*i; + return 0; +} + void PackageList::listPackages(const QString &title) { #ifdef DEBUG @@ -137,19 +180,7 @@ return true; } -Package *PackageList::getPackage(QString const &pkgName) -{ -#ifdef DEBUG - qDebug() << __PRETTY_FUNCTION__; -#endif - QList<Package>::iterator i; - for (i = packageList->begin(); i != packageList->end(); ++i) - if (i->Name() == pkgName) - return &*i; - return 0; -} - -QStringList PackageList::getFilesToInstall(QString const &pkgName) +QStringList PackageList::getFilesForInstall(QString const &pkgName) { #ifdef DEBUG qDebug() << __PRETTY_FUNCTION__; @@ -191,3 +222,27 @@ pkg->addInstalledTypes(apkg); return true; } + +bool PackageList::downloadPackage(const QString &pkgName) +{ + QStringList files = getFilesForDownload(pkgName); + files = filterPackageFiles(files,"URL"); + bool ret = true; + for (int j = 0; j < files.size(); ++j) { + if (!downloader->start(files.at(j))) + ret = false; + } + return true; +} + +bool PackageList::installPackage(const QString &pkgName) +{ + QStringList files = getFilesForInstall(pkgName); + files = filterPackageFiles(files,"PATH"); + bool ret = true; + for (int j = 0; j < files.size(); ++j) { + if (!installer->install(files.at(j))) + ret = false; + } + return true; +} Index: packagelist.h =================================================================== RCS file: /cvsroot/kde-cygwin/tools/installer/shared/packagelist.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- packagelist.h 22 Jan 2006 18:40:04 -0000 1.2 +++ packagelist.h 22 Jan 2006 18:42:15 -0000 1.3 @@ -26,30 +26,43 @@ #include "package.h" +class Downloader; +class Installer; + class PackageList : public QObject { Q_OBJECT public: - PackageList(); + PackageList(Downloader *downloader); virtual ~PackageList(); + void addPackage(Package const &package); + Package *getPackage(QString const &pkgName); void listPackages(const QString &title=""); + bool readFromFile(QString const &fileName); bool readFromHTMLFile(const QString &fileName); bool writeToFile(QString const &fileName); -// static bool downloadPackage(QString const &pkgName); - QStringList getPackageFiles(QString const &pkgName); - Package *getPackage(QString const &pkgName); - QStringList getFilesToInstall(QString const &pkgName); + + QStringList getFilesForInstall(QString const &pkgName); QStringList getFilesForDownload(QString const &pkgName); + bool updatePackage(Package &pkg); + /// download a package + bool downloadPackage(const QString &pkgName); +// bool downloadPackages(const QStringList &pkgNames); + bool installPackage(const QString &pkgName); + signals: void loadedConfig(); private: + Downloader *downloader; + Installer *installer; QList<Package> *packageList; - + friend class Installer; + }; #endif |