bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& result) { QFileInfo pluginFileInfo(pluginPath); if (!pluginFileInfo.exists()) return false; MetaDataResult::Tag metaDataResult = tryReadPluginMetaDataFromCacheFile(pluginFileInfo.canonicalFilePath(), result); if (metaDataResult == MetaDataResult::Available) return true; if (metaDataResult == MetaDataResult::Unloadable) return false; // Scan the plugin via the plugin process. QString commandLine = QString(executablePathOfPluginProcess()) % QLatin1Char(' ') % QStringLiteral("-scanPlugin") % QLatin1Char(' ') % pluginFileInfo.canonicalFilePath(); QProcess process; process.setReadChannel(QProcess::StandardOutput); process.start(commandLine); bool ranSuccessfully = process.waitForFinished() && process.exitStatus() == QProcess::NormalExit && process.exitCode() == EXIT_SUCCESS; if (ranSuccessfully) { QByteArray outputBytes = process.readAll(); ASSERT(!(outputBytes.size() % sizeof(UChar))); String output(reinterpret_cast<const UChar*>(outputBytes.constData()), outputBytes.size() / sizeof(UChar)); Vector<String> lines; output.split(UChar('\n'), true, lines); ASSERT(lines.size() == 3); result.name.swap(lines[0]); result.description.swap(lines[1]); result.mimeDescription.swap(lines[2]); } else process.kill(); QVariantMap map; map[QStringLiteral("path")] = QString(pluginFileInfo.canonicalFilePath()); map[QStringLiteral("timestamp")] = QDateTime::currentDateTime().toString(); if (!ranSuccessfully || result.mimeDescription.isEmpty()) { // We failed getting the meta data in some way. Cache this information, so we don't // need to rescan such plugins every time. We will retry it once the plugin is updated. map[QStringLiteral("unloadable")] = QStringLiteral("true"); appendToCacheFile(QJsonObject::fromVariantMap(map)); return false; } map[QStringLiteral("name")] = QString(result.name); map[QStringLiteral("description")] = QString(result.description); map[QStringLiteral("mimeDescription")] = QString(result.mimeDescription); appendToCacheFile(QJsonObject::fromVariantMap(map)); return true; }
bool WorkbenchUtil::SetDepartmentLogoPreference(const QString &logoResource, ctkPluginContext *context) { // The logo must be available in the local filesystem. We check if we have not already extracted the // logo from the plug-in or if this plug-ins timestamp is newer then the already extracted logo timestamp. // If one of the conditions is true, extract it and write it to the plug-in specific storage location. const QString logoFileName = logoResource.mid(logoResource.lastIndexOf('/')+1); const QString logoPath = context->getDataFile("").absoluteFilePath(); bool extractLogo = true; QFileInfo logoFileInfo(logoPath + "/" + logoFileName); if (logoFileInfo.exists()) { // The logo has been extracted previously. Check if the plugin timestamp is newer, which // means it might contain an updated logo. QString pluginLocation = QUrl(context->getPlugin()->getLocation()).toLocalFile(); if (!pluginLocation.isEmpty()) { QFileInfo pluginFileInfo(pluginLocation); if (logoFileInfo.lastModified() > pluginFileInfo.lastModified()) { extractLogo = false; } } } if (extractLogo) { // Extract the logo from the shared library and write it to disk. QFile logo(logoResource); if (logo.open(QIODevice::ReadOnly)) { QFile localLogo(logoPath + "/" + logoFileName); if (localLogo.open(QIODevice::WriteOnly)) { localLogo.write(logo.readAll()); } } } logoFileInfo.refresh(); if (logoFileInfo.exists()) { // Get the preferences service ctkServiceReference prefServiceRef = context->getServiceReference<berry::IPreferencesService>(); berry::IPreferencesService* prefService = NULL; if (prefServiceRef) { prefService = context->getService<berry::IPreferencesService>(prefServiceRef); } if (prefService) { prefService->GetSystemPreferences()->Put("DepartmentLogo", qPrintable(logoFileInfo.absoluteFilePath())); } else { BERRY_WARN << "Preferences service not available, unable to set custom logo."; return false; } } else { BERRY_WARN << "Custom logo at " << logoFileInfo.absoluteFilePath().toStdString() << " does not exist"; return false; } return true; }