QString InstalledPackages::findPath_npackdcl(const Dependency& dep)
{
    QString ret;

    QString err;
    WindowsRegistry packagesWR;
    LONG e;
    err = packagesWR.open(HKEY_LOCAL_MACHINE,
            "SOFTWARE\\Npackd\\Npackd\\Packages", false, KEY_READ, &e);

    if (e == ERROR_FILE_NOT_FOUND || e == ERROR_PATH_NOT_FOUND) {
        err = "";
    } else if (err.isEmpty()) {
        Version found = Version::EMPTY;

        QStringList entries = packagesWR.list(&err);
        for (int i = 0; i < entries.count(); ++i) {
            QString name = entries.at(i);
            int pos = name.lastIndexOf("-");
            if (pos <= 0)
                continue;

            QString packageName = name.left(pos);
            if (packageName != dep.package)
                continue;

            QString versionName = name.right(name.length() - pos - 1);
            Version version;
            if (!version.setVersion(versionName))
                continue;

            if (!dep.test(version))
                continue;

            if (found != Version::EMPTY) {
                if (version.compare(found) < 0)
                    continue;
            }

            WindowsRegistry entryWR;
            err = entryWR.open(packagesWR, name, KEY_READ);
            if (!err.isEmpty())
                continue;

            QString p = entryWR.get("Path", &err).trimmed();
            if (!err.isEmpty())
                continue;

            QString dir;
            if (p.isEmpty())
                dir = "";
            else {
                QDir d(p);
                if (d.exists()) {
                    dir = p;
                } else {
                    dir = "";
                }
            }

            if (dir.isEmpty())
                continue;

            found = version;
            ret = dir;
        }
    }

    return ret;
}
QString InstalledPackages::readRegistryDatabase()
{
    // qDebug() << "start reading registry database";

    // "data" is only used at the bottom of this method

    QString err;

    WindowsRegistry packagesWR;
    LONG e;
    err = packagesWR.open(HKEY_LOCAL_MACHINE,
            "SOFTWARE\\Npackd\\Npackd\\Packages", false, KEY_READ, &e);

    QList<InstalledPackageVersion*> ipvs;
    if (e == ERROR_FILE_NOT_FOUND || e == ERROR_PATH_NOT_FOUND) {
        err = "";
    } else if (err.isEmpty()) {
        QStringList entries = packagesWR.list(&err);
        for (int i = 0; i < entries.count(); ++i) {
            QString name = entries.at(i);
            int pos = name.lastIndexOf("-");
            if (pos <= 0)
                continue;

            QString packageName = name.left(pos);
            if (!Package::isValidName(packageName))
                continue;

            QString versionName = name.right(name.length() - pos - 1);
            Version version;
            if (!version.setVersion(versionName))
                continue;

            WindowsRegistry entryWR;
            err = entryWR.open(packagesWR, name, KEY_READ);
            if (!err.isEmpty())
                continue;

            QString p = entryWR.get("Path", &err).trimmed();
            if (!err.isEmpty())
                continue;

            QString dir;
            if (p.isEmpty())
                dir = "";
            else {
                QDir d(p);
                if (d.exists()) {
                    dir = p;
                } else {
                    dir = "";
                }
            }

            if (dir.isEmpty()) {
                packagesWR.remove(name);
            } else {
                dir = WPMUtils::normalizePath(dir, false);

                InstalledPackageVersion* ipv = new InstalledPackageVersion(
                        packageName, version, dir);
                ipv->detectionInfo = entryWR.get("DetectionInfo", &err);
                if (!err.isEmpty()) {
                    // ignore
                    ipv->detectionInfo = "";
                    err = "";
                }

                if (!ipv->directory.isEmpty()) {
                    /*
                    qDebug() << "adding " << ipv->package <<
                            ipv->version.getVersionString() << "in" <<
                            ipv->directory;*/
                    ipvs.append(ipv);
                } else {
                    delete ipv;
                }
            }
        }
    }

    this->mutex.lock();
    qDeleteAll(this->data);
    this->data.clear();
    for (int i = 0; i < ipvs.count(); i++) {
        InstalledPackageVersion* ipv = ipvs.at(i);
        this->data.insert(PackageVersion::getStringId(ipv->package,
                ipv->version), ipv->clone());
    }
    this->mutex.unlock();

    for (int i = 0; i < ipvs.count(); i++) {
        InstalledPackageVersion* ipv = ipvs.at(i);
        fireStatusChanged(ipv->package, ipv->version);
    }
    qDeleteAll(ipvs);

    // qDebug() << "stop reading";

    return err;
}
void ControlPanelThirdPartyPM::detectOneControlPanelProgram(
        QList<InstalledPackageVersion*>* installed,
        Repository *rep,
        const QString& registryPath,
        WindowsRegistry& k,
        const QString& keyName) const
{
    // see http://msdn.microsoft.com/en-us/library/aa372105(v=vs.85).aspx

    // find the package name
    QString package = keyName;
    package.replace('.', '_');
    package = WPMUtils::makeValidFullPackageName(
            "control-panel." + package);

    // find the version number
    bool versionFound = false;
    Version version;
    QString err;
    QString version_ = k.get("DisplayVersion", &err);
    if (err.isEmpty()) {
        if (version.setVersion(version_)) {
            version.normalize();
            versionFound = true;
        }
    }
    if (!versionFound) {
        DWORD major = k.getDWORD("VersionMajor", &err);
        if (err.isEmpty()) {
            DWORD minor = k.getDWORD("VersionMinor", &err);
            if (err.isEmpty())
                version.setVersion(major, minor);
            else
                version.setVersion(major, 0);
            version.normalize();
            versionFound = true;
        }
    }
    if (!versionFound) {
        QString major = k.get("VersionMajor", &err);
        if (err.isEmpty()) {
            QString minor = k.get("VersionMinor", &err);
            if (err.isEmpty()) {
                if (version.setVersion(major)) {
                    versionFound = true;
                    version.normalize();
                }
            } else {
                if (version.setVersion(major + "." + minor)) {
                    versionFound = true;
                    version.normalize();
                }
            }
        }
    }
    if (!versionFound) {
        QString displayName = k.get("DisplayName", &err);
        if (err.isEmpty()) {
            QStringList parts = displayName.split(' ');
            if (parts.count() > 1 && parts.last().contains('.')) {
                version.setVersion(parts.last());
                version.normalize();
            }
        }
    }

    //qDebug() << "InstalledPackages::detectOneControlPanelProgram.0";

    QScopedPointer<Package> p(new Package(package, package));

    QString title = k.get("DisplayName", &err);
    if (!err.isEmpty() || title.isEmpty())
        title = keyName;
    p->title = title;
    p->description = "[Control Panel] " + p->title;

    QString url = k.get("URLInfoAbout", &err);
    if (!err.isEmpty() || url.isEmpty() || !QUrl(url).isValid())
        url = "";
    if (url.isEmpty())
        url = k.get("URLUpdateInfo", &err);
    if (!err.isEmpty() || url.isEmpty() || !QUrl(url).isValid())
        url = "";
    p->url = url;

    p->setChangeLog(k.get("URLUpdateInfo", &err));
    if (!err.isEmpty() || !Package::isValidURL(p->getChangeLog()))
        p->setChangeLog("");

    p->categories.append(QObject::tr("Control panel software"));

    QString icon = k.get("DisplayIcon", &err);
    if (err.isEmpty())
        p->setIcon(WPMUtils::extractIconURL(icon));

    // Crystal Icons
    // p->icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR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4vof2NJWuEles6UGJXHTELHUonT9TJCaLOyuhWRagWglcnJhUaY1DaEQG3y10oZ7BLuLUMDnRwBNwxlIu+nT0lGi24ouOBpClhoooRCmiVtzIsmx5gJlmgklNY82QRilNuauKH15yZOCaTV2cOz3O9ESdUkeBwbUDF0/MC4vQ5H1Ee7RaaUtELQ/QUfRJExM3WzGVcgkX1bHWW9Jt+3qLhB6UOwoQN+e8dX57Tw0gxMZRbyXNNE2zZQFMkhDHSeQcoHyq67cg7Z3JQivIgRcZsGu/IiAI1lpMHCNK04pMVCn4y0fg7ESDSihNZQw2aTI6PkF/tdRWzzuhKIXyQpzN8lyLQmmNNWl7SY5qs4zxCw16OgtgUuIobnqesssCfOOHu9x377n90MpqeE4k/6va6Kzv69xQ2kcfl2U4ay//UNGOwjQO5xz7/33m1Tj+H0UIcPh89uDBP438WYl4opbucpcmY7mHSzDWkWV2oqekW4un/wuEUYYlFig+ygAAAABJRU5ErkJggg==";

    //qDebug() << "CP: adding package " << p.data()->name << p.data()->title;

    rep->savePackage(p.data());

    QDir d;

    bool useThisEntry = true;

    QString uninstall;
    if (useThisEntry) {
        uninstall = k.get("QuietUninstallString", &err);
        if (!err.isEmpty())
            uninstall = "";
        if (uninstall.isEmpty())
            uninstall = k.get("UninstallString", &err);
        if (!err.isEmpty())
            uninstall = "";

        // some programs store in UninstallString the complete path to
        // the uninstallation program with spaces
        if (!uninstall.isEmpty() && uninstall.contains(" ") &&
                !uninstall.contains("\"") &&
                d.exists(uninstall))
            uninstall = "\"" + uninstall + "\"";

        if (uninstall.trimmed().isEmpty())
            useThisEntry = false;

        // qDebug() << uninstall;
    }

    // already detected as an MSI package
    if (uninstall.length() == 14 + 38 &&
            (uninstall.indexOf("MsiExec.exe /X", 0, Qt::CaseInsensitive) == 0 ||
            uninstall.indexOf("MsiExec.exe /I", 0, Qt::CaseInsensitive) == 0) &&
            WPMUtils::validateGUID(uninstall.right(38)) == "") {
        useThisEntry = false;
    }

    QString dir;
    if (useThisEntry) {
        dir = k.get("InstallLocation", &err);
        if (!err.isEmpty() || dir.trimmed().isEmpty() || !d.exists(dir))
            dir = "";

        if (dir.isEmpty() && !uninstall.isEmpty()) {
            QStringList params = WPMUtils::parseCommandLine(uninstall, &err);
            // qDebug() << uninstall << params.count();
            if (err.isEmpty() && params.count() > 0) {
                if (!params[0].trimmed().isEmpty() && d.exists(params[0])) {
                    dir = WPMUtils::parentDirectory(params[0]);
                } else
                    useThisEntry = false;
            } /* DEBUG else {
                qDebug() << "cannot parse " << uninstall << " " << err <<
                        " " << params.count();
                if (params.count() > 0)
                    qDebug() << "cannot parse2 " << params[0] << " " <<
                            d.exists(params[0]);
            }*/
        }
    }

    if (useThisEntry) {
        if (!dir.isEmpty()) {
            dir = WPMUtils::normalizePath(dir, false);
        }
    }

    if (useThisEntry) {
        // qDebug() << "adding " << registryPath << package << dir;

        // qDebug() << package << version.getVersionString() << dir;
        InstalledPackageVersion* ipv = new InstalledPackageVersion(package,
                version, dir);
        ipv->detectionInfo = "control-panel:" + registryPath;
        installed->append(ipv);

        QScopedPointer<PackageVersion> pv(new PackageVersion(package));
        pv->version = version;

        PackageVersionFile* pvf = new PackageVersionFile(
                ".Npackd\\Uninstall.bat", uninstall + "\r\n");
        pv->files.append(pvf);

        pvf = new PackageVersionFile(
                ".Npackd\\Stop.bat",
                "rem the program should be stopped by the uninstaller\r\n");
        pv->files.append(pvf);

        rep->savePackageVersion(pv.data());
    }
}
Example #4
0
void CBSThirdPartyPM::detectOneCBSPackage(
        QList<InstalledPackageVersion*>* installed,
        Repository *rep,
        const QString& registryPath,
        WindowsRegistry& k,
        const QString& keyName) const
{
    QString err;

    QStringList keyNameParts = keyName.split('~');

    if (keyNameParts.size() != 5) {
        err = "Wrong number of parts";
    }

    // find the package name
    QString package;

    if (err.isEmpty()) {
        package = keyNameParts.at(0);
        package.replace('-', '.');
        package = WPMUtils::makeValidFullPackageName(
                "cbs." + package);
    }

    if (err.isEmpty()) {
        QString title = keyNameParts.at(0);
        title.replace('-', ' ');
        QScopedPointer<Package> p(new Package(package, title));
        p->categories.append(QObject::tr("Component-Based Servicing"));
        rep->savePackage(p.data(), true);
    }

    // find the version number
    Version version;
    if (err.isEmpty()) {
        if (version.setVersion(keyNameParts.at(4))) {
            version.normalize();
        } else {
            err = "Invalid version number";
        }
    }

    if (err.isEmpty()) {
        QScopedPointer<PackageVersion> pv(new PackageVersion(package));
        pv->version = version;
        PackageVersionFile* pvf = new PackageVersionFile(
                ".Npackd\\Uninstall.bat", "\r\n"); // TODO
        pv->files.append(pvf);
        rep->savePackageVersion(pv.data(), true);
    }

    DWORD state = 0;
    if (err.isEmpty()) {
        state = k.getDWORD("CurrentState", &err);
    }

    bool packageInstalled = false;

    if (err.isEmpty()) {
        if (state & 0x20) {
            InstalledPackageVersion* ipv = new InstalledPackageVersion(package,
                    version, "");
            ipv->detectionInfo = "cbs:" + registryPath;
            installed->append(ipv);

            packageInstalled = true;
        }
    }

    if (!err.isEmpty()) {
        qDebug() << keyName << err;
    }

    if (err.isEmpty()) {
        WindowsRegistry updates;
        err = updates.open(k, "Updates", KEY_READ);
        if (err.isEmpty())
            detectOneCBSPackageUpdate(package, installed, rep,
                    registryPath + "\\Updates",
                    updates, packageInstalled);
    }
}
Example #5
0
void App::test()
{
    Version a;
    Version b;
    b.setVersion("1.0.0");
    QVERIFY(a == b);

    a.setVersion("4.5.6.7.8.9.10");
    QVERIFY(a.getVersionString() == "4.5.6.7.8.9.10");

    a.setVersion("1.1");
    QVERIFY(a == Version(1, 1));

    a.setVersion("5.0.0.1");
    Version c(a);
    QVERIFY(c.getVersionString() == "5.0.0.1");

    Version* d = new Version();
    d->setVersion(7, 8, 9, 10);
    delete d;

    a.setVersion(1, 17);
    QVERIFY(a.getVersionString() == "1.17");

    a.setVersion(2, 18, 3);
    QVERIFY(a.getVersionString() == "2.18.3");

    a.setVersion(3, 1, 3, 8);
    QVERIFY(a.getVersionString() == "3.1.3.8");

    a.setVersion("17.2.8.4");
    a.prepend(8);
    a.prepend(38);
    a.prepend(0);
    QVERIFY(a.getVersionString() == "0.38.8.17.2.8.4");

    a.setVersion("2.8.3");
    QVERIFY(a.getVersionString(7) == "2.8.3.0.0.0.0");

    a.setVersion("17.2");
    QVERIFY(a.getNParts() == 2);

    a.setVersion("8.4.0.0.0");
    a.normalize();
    QVERIFY(a.getVersionString() == "8.4");
    QVERIFY(a.isNormalized());

    a.setVersion("2.8.7.4.8.9");
    b.setVersion("2.8.6.4.8.8");
    QVERIFY(a > b);
}