Example #1
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);
}
QString InstalledPackages::saveToRegistry(InstalledPackageVersion *ipv)
{
    WindowsRegistry machineWR(HKEY_LOCAL_MACHINE, false);
    QString r;
    QString keyName = "SOFTWARE\\Npackd\\Npackd\\Packages";
    Version v = ipv->version;
    v.normalize();
    QString pn = ipv->package + "-" + v.getVersionString();

    /*WPMUtils::outputTextConsole(
            "InstalledPackages::saveToRegistry " + ipv->directory + " " +
            ipv->package + " " + ipv->version.getVersionString() + " " +
            ipv->detectionInfo + "\r\n");*/

    if (!ipv->directory.isEmpty()) {
        WindowsRegistry wr = machineWR.createSubKey(keyName + "\\" + pn, &r);
        if (r.isEmpty()) {
            wr.set("DetectionInfo", ipv->detectionInfo);

            // for compatibility with Npackd 1.16 and earlier. They
            // see all package versions by default as "externally installed"
            wr.setDWORD("External", 0);

            r = wr.set("Path", ipv->directory);
        }
        // qDebug() << "saveToRegistry 1 " << r;
    } else {
        // qDebug() << "deleting " << pn;
        WindowsRegistry packages;
        r = packages.open(machineWR, keyName, KEY_ALL_ACCESS);
        if (r.isEmpty()) {
            r = packages.remove(pn);
        }
        // qDebug() << "saveToRegistry 2 " << r;
    }
    //qDebug() << "InstalledPackageVersion::save " << pn << " " <<
    //        this->directory;

    // qDebug() << "saveToRegistry returns " << r;

    return r;
}
Example #3
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);
    }
}
void PackageVersionForm::fillForm(PackageVersion* pv)
{
    delete this->pv;
    this->pv = pv;

    // qDebug() << pv.data()->toString();

    DBRepository* r = DBRepository::getDefault();

    this->ui->lineEditTitle->setText(pv->getPackageTitle());
    Version v = pv->version;
    v.normalize();
    this->ui->lineEditVersion->setText(v.getVersionString());
    this->ui->lineEditInternalName->setText(pv->package);

    Package* p = r->findPackage_(pv->package);

    QString licenseTitle = QObject::tr("unknown");
    if (p) {
        QString err;
        License* lic = r->findLicense_(p->license, &err);
        if (!err.isEmpty())
            MainWindow::getInstance()->addErrorMessage(err, err, true,
                    QMessageBox::Critical);
        if (lic) {
            licenseTitle = "<a href=\"http://www.example.com\">" +
                    lic->title.toHtmlEscaped() + "</a>";
            delete lic;
        }
    }
    this->ui->labelLicense->setText(licenseTitle);

    if (p) {
        this->ui->textEditDescription->setText(p->description);
    }

    updateStatus();

    QString dl;
    if (!pv->download.isValid())
        dl = QObject::tr("n/a");
    else {
        dl = pv->download.toString();        
        dl = "<a href=\"" + dl.toHtmlEscaped() + "\">" +
                dl.toHtmlEscaped() + "</a>";
    }
    this->ui->labelDownloadURL->setText(dl);

    QString sha1;
    if (pv->sha1.isEmpty())
        sha1 = QObject::tr("n/a");
    else {
        sha1 = pv->sha1;
        if (pv->hashSumType == QCryptographicHash::Sha1)
            sha1.prepend("SHA-1: ");
        else
            sha1.prepend("SHA-256: ");
    }
    this->ui->lineEditSHA1->setText(sha1);

    this->ui->lineEditType->setText(pv->type == 0 ? "zip" : "one-file");

    QString details;
    for (int i = 0; i < pv->importantFiles.count(); i++) {
        details.append(pv->importantFilesTitles.at(i));
        details.append(" (");
        details.append(pv->importantFiles.at(i));
        details.append(")\n");
    }
    this->ui->textEditImportantFiles->setText(details);

    details = "";
    for (int i = 0; i < pv->dependencies.count(); i++) {
        Dependency* d = pv->dependencies.at(i);
        details.append(d->toString());
        details.append("\n");
    }
    this->ui->textEditDependencies->setText(details);

    updateIcons();

    this->ui->tabWidgetTextFiles->clear();
    for (int i = 0; i < pv->files.count(); i++) {
        QTextEdit* w = new QTextEdit(this->ui->tabWidgetTextFiles);
        w->setText(pv->files.at(i)->content);
        w->setReadOnly(true);
        this->ui->tabWidgetTextFiles->addTab(w, pv->files.at(i)->path);
    }

    delete p;
}
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,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gMBDgUoWaC7/wAAB6RJREFUWMO1l1uMXVUZx3/fWvtybjNz5tIZphem5WKLpUCLFDSSGiVEg/HBBIkmxgQTXzTRxKgPhsc+SNT4IIjBSwRDUbSUAgYvDTdrSypCkVY6Lb0wnU7pdKYzZ85lX9Zey4d9pnPpdAwQV7LPJWud8/+t7/v2/1tbWGYcOTL82c6uzpu1UiCyYE6AJE3/tmrlyr38v8a+fft3u/aw1rr5I01TNzExOTN89Nin5v/m1DsjV70XDbXcpLWZBkjTlKnpaaIowloLgHOOQiGs9HRXd715+PAnAd56e+SjK1b0Hdy775Uf733tiP7AALNC9UaDwA8wxhBFEWlqEBHiOKFUKlW6q9Wn/vr8S/f2d5d3vTUWVbZsvulbHSE7/nHwaOEDA9TrubgIKJUvNyYlTQ1hGLTfC5WPbb35F4fH0v6f7tM88h9f1q0duttLas89+ew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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());
    }
}