QString InstalledPackages::setPackageVersionPath(const QString& package, const Version& version, const QString& directory, bool updateRegistry) { this->mutex.lock(); QString err; InstalledPackageVersion* ipv = this->findNoCopy(package, version); if (!ipv) { ipv = new InstalledPackageVersion(package, version, directory); this->data.insert(package + "/" + version.getVersionString(), ipv); if (updateRegistry) err = saveToRegistry(ipv); } else { ipv->setPath(directory); if (updateRegistry) err = saveToRegistry(ipv); } this->mutex.unlock(); fireStatusChanged(package, version); return err; }
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); }
DWORD WINAPI checkForUpdatesAsync(LPVOID lpParam) { try { // Delay update checks for an hour since last check if (difftime(time(NULL), lastUpdateCheck) >= 3600) { Version newVersion; string url; if (checkForUpdate(true, newVersion, url)) { string updateMessage = "[color=blue]Guild Wars 2 plugin version " + newVersion.getVersionString() + " is now available.[/color] " + "[url=" + url + "]Click here to download.[/url]"; ts3Functions.printMessageToCurrentTab(updateMessage.c_str()); } lastUpdateCheck = time(NULL); } } catch (...) { ts3Functions.printMessageToCurrentTab("Error while checking for Guild Wars 2 plugin updates."); } return 0; }
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; }
QString InstalledPackages::notifyInstalled(const QString &package, const Version &version, bool success) const { QString err; QStringList paths = getAllInstalledPackagePaths(); QStringList env; env.append("NPACKD_PACKAGE_NAME"); env.append(package); env.append("NPACKD_PACKAGE_VERSION"); env.append(version.getVersionString()); env.append("NPACKD_CL"); env.append(AbstractRepository::getDefault_()-> computeNpackdCLEnvVar_(&err)); env.append("NPACKD_SUCCESS"); env.append(success ? "1" : "0"); err = ""; // ignore the error // searching for a file in all installed package versions may take up to 5 // seconds if the data is not in the cache and only 20 milliseconds // otherwise for (int i = 0; i < paths.size(); i++) { QString path = paths.at(i); QString file = path + "\\.Npackd\\InstallHook.bat"; QFileInfo fi(file); if (fi.exists()) { // qDebug() << file; Job* job = new Job("Notification"); WPMUtils::executeBatchFile( job, path, ".Npackd\\InstallHook.bat", ".Npackd\\InstallHook.log", env, true); // ignore the possible errors delete job; } } return ""; }
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; }