void CBSThirdPartyPM:: detectCBSPackagesFrom(QList<InstalledPackageVersion*>* installed, Repository* rep, HKEY root, const QString& path, bool useWoWNode) const { WindowsRegistry wr; QString err; err = wr.open(root, path, useWoWNode, KEY_READ); if (err.isEmpty()) { QString fullPath; if (root == HKEY_CLASSES_ROOT) fullPath = "HKEY_CLASSES_ROOT"; else if (root == HKEY_CURRENT_USER) fullPath = "HKEY_CURRENT_USER"; else if (root == HKEY_LOCAL_MACHINE) fullPath = "HKEY_LOCAL_MACHINE"; else if (root == HKEY_USERS) fullPath = "HKEY_USERS"; else if (root == HKEY_PERFORMANCE_DATA) fullPath = "HKEY_PERFORMANCE_DATA"; else if (root == HKEY_CURRENT_CONFIG) fullPath = "HKEY_CURRENT_CONFIG"; else if (root == HKEY_DYN_DATA) fullPath = "HKEY_DYN_DATA"; else fullPath = QString("%1").arg((uintptr_t) root); fullPath += "\\" + path; QStringList entries = wr.list(&err); for (int i = 0; i < entries.count(); i++) { WindowsRegistry k; err = k.open(wr, entries.at(i), KEY_READ); if (err.isEmpty()) { detectOneCBSPackage(installed, rep, fullPath + "\\" + entries.at(i), k, entries.at(i)); } } } }
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; }