| 60 | void PluginRepository::init(QString location) { pinstance_->_init(location); } |
| 61 | |
| 62 | void PluginRepository::_init(QString location) |
| 63 | { |
| 64 | qInfo(CAT_PLUGINREPOSTIORY) << "initializing plugins from: " << location; |
| 65 | const QString pluginMetaFileName = "plugin.json"; |
| 66 | QString pluginMetaFilePath = ""; |
| 67 | QFileInfoList plugins = PkgManager::listFilesInfo(QStringList() << "plugins"); |
| 68 | if(!location.isEmpty() && QFile::exists(location)) { |
| 69 | QDir loc(location); |
| 70 | plugins.append(loc.entryInfoList(QDir::Files)); |
| 71 | } |
| 72 | QStringList pluginFiles; |
| 73 | |
| 74 | for(const QFileInfo &p : qAsConst(plugins)) { |
| 75 | if(p.fileName() == pluginMetaFileName) { |
| 76 | pluginMetaFilePath = p.absoluteFilePath(); |
| 77 | continue; |
| 78 | } |
| 79 | pluginFiles.append(p.absoluteFilePath()); |
| 80 | } |
| 81 | |
| 82 | if(!pluginMetaFilePath.isEmpty()) { |
| 83 | QFile f(pluginMetaFilePath); |
| 84 | f.open(QFile::ReadOnly); |
| 85 | QString json = f.readAll(); |
| 86 | QJsonParseError err; |
| 87 | QJsonDocument pluginMetaDocument = QJsonDocument::fromJson(json.toUtf8(), &err); |
| 88 | if(err.error != QJsonParseError::NoError) { |
| 89 | qCritical(CAT_PLUGINREPOSTIORY) << "JSON Parse error !" << err.errorString(); |
| 90 | qCritical(CAT_PLUGINREPOSTIORY) << json; |
| 91 | qCritical(CAT_PLUGINREPOSTIORY) << QString(" ").repeated(err.offset) + "^"; |
| 92 | } else { |
| 93 | qDebug(CAT_PLUGINREPOSTIORY) << "Found valid json @ " << pluginMetaFilePath; |
| 94 | } |
| 95 | metadata = pluginMetaDocument.object(); |
| 96 | pm->setMetadata(metadata); |
| 97 | } |
| 98 | |
| 99 | #ifdef Q_OS_WINDOWS |
| 100 | bool b = SetDllDirectoryA(QApplication::applicationDirPath().toStdString().c_str()); |
| 101 | if(!b) { |
| 102 | DWORD error = ::GetLastError(); |
| 103 | std::string message = std::system_category().message(error); |
| 104 | qWarning(CAT_PLUGINREPOSTIORY) |
| 105 | << "cannot add .exe folder to library search path - " << QString::fromStdString(message); |
| 106 | ; |
| 107 | } |
| 108 | #endif |
| 109 | |
| 110 | pm->clear(); |
| 111 | pm->add(pluginFiles); |
| 112 | pm->sort(); |
| 113 | } |
| 114 | |
| 115 | PluginManager *PluginRepository::getPluginManager() { return pinstance_->_getPluginManager(); } |
| 116 | |