void QgsServiceNativeLoader::loadModules( const QString &modulePath, QgsServiceRegistry ®istrar, QgsServerInterface *serverIface ) { QDir moduleDir( modulePath ); moduleDir.setSorting( QDir::Name | QDir::IgnoreCase ); moduleDir.setFilter( QDir::Files ); #if defined(Q_OS_WIN) || defined(__CYGWIN__) moduleDir.setNameFilters( QStringList( "*.dll" ) ); #else moduleDir.setNameFilters( QStringList( "*.so" ) ); #endif qDebug() << QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ); //QgsDebugMsg( QString( "Checking %1 for native services modules" ).arg( moduleDir.path() ) ); for ( const QFileInfo &fi : moduleDir.entryInfoList() ) { QgsServiceModule *module = loadNativeModule( fi.filePath() ); if ( module ) { // Register services module->registerSelf( registrar, serverIface ); } } }
// returns a path to the application module's directory // with either the given fileName or the module's name // (module is the EXE or DLL in which path::GetAppPath resides) WCHAR *GetAppPath(const WCHAR *fileName) { WCHAR modulePath[MAX_PATH]; modulePath[0] = '\0'; GetModuleFileName(CURRENT_HMODULE, modulePath, dimof(modulePath)); modulePath[dimof(modulePath) - 1] = '\0'; if (!fileName) return str::Dup(modulePath); ScopedMem<WCHAR> moduleDir(path::GetDir(modulePath)); return path::Join(moduleDir, fileName); }
void Host::CopyModuleAppResources(std::string& modulePath) { this->logger->Trace("CopyModuleAppResources: %s", modulePath.c_str()); std::string appDir = this->application->path; Path appPath(this->application->path); try { Path moduleDir(modulePath); moduleDir = moduleDir.parent(); std::string mds(moduleDir.toString()); const char* platform = this->GetPlatform(); std::string resources_dir = FileUtils::Join(mds.c_str(), "AppResources", NULL); std::string plt_resources_dir = FileUtils::Join(resources_dir.c_str(), platform, NULL); std::string all_resources_dir = FileUtils::Join(resources_dir.c_str(), "all", NULL); File platformAppResourcesDir(plt_resources_dir); File allAppResourcesDir(all_resources_dir); if (platformAppResourcesDir.exists() && platformAppResourcesDir.isDirectory()) { std::vector<File> files; platformAppResourcesDir.list(files); for (size_t i = 0; i < files.size(); i++) { File f = files.at(i); Path targetPath(appPath, Path(Path(f.path()).getBaseName())); File targetFile(targetPath); this->logger->Trace("target: %s", targetFile.path().c_str()); if (!targetFile.exists()) { this->logger->Trace("Copying : %s to %s", f.path().c_str(), appDir.c_str()); f.copyTo(appDir); } else { this->logger->Trace("SKIP Copying : %s to %s", f.path().c_str(), appDir.c_str()); } } } if (allAppResourcesDir.exists() && allAppResourcesDir.isDirectory()) { std::vector<File> files; allAppResourcesDir.list(files); for (size_t i = 0; i < files.size(); i++) { File f = files.at(i); Path targetPath(appPath, Path(Path(f.path()).getBaseName())); File targetFile(targetPath); this->logger->Trace("target: %s", targetFile.path().c_str()); if (!targetFile.exists()) { this->logger->Trace("Copying: %s to %s", f.path().c_str(), appDir.c_str()); f.copyTo(appDir); } else { this->logger->Trace("SKIP Copying : %s to %s", f.path().c_str(), appDir.c_str()); } } } } catch (Poco::Exception &exc) { // Handle.. } }
Module* Module::fromDescriptor( const QVariantMap& moduleDescriptor, const QString& instanceId, const QString& configFileName, const QString& moduleDirectory ) { std::unique_ptr<Module> m; QString typeString = moduleDescriptor.value( "type" ).toString(); QString intfString = moduleDescriptor.value( "interface" ).toString(); if ( typeString.isEmpty() || intfString.isEmpty() ) { cError() << "Bad module descriptor format" << instanceId; return nullptr; } if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) ) { if ( intfString == "qtplugin" ) m.reset( new ViewModule() ); else if ( intfString == "pythonqt" ) { #ifdef WITH_PYTHONQT m.reset( new PythonQtViewModule() ); #else cError() << "PythonQt view modules are not supported in this version of Calamares."; #endif } else cError() << "Bad interface" << intfString << "for module type" << typeString; } else if ( typeString == "job" ) { if ( intfString == "qtplugin" ) m.reset( new CppJobModule() ); else if ( intfString == "process" ) m.reset( new ProcessJobModule() ); else if ( intfString == "python" ) { #ifdef WITH_PYTHON m.reset( new PythonJobModule() ); #else cError() << "Python modules are not supported in this version of Calamares."; #endif } else cError() << "Bad interface" << intfString << "for module type" << typeString; } else cError() << "Bad module type" << typeString; if ( !m ) { cError() << "Bad module type (" << typeString << ") or interface string (" << intfString << ") for module " << instanceId; return nullptr; } QDir moduleDir( moduleDirectory ); if ( moduleDir.exists() && moduleDir.isReadable() ) m->m_directory = moduleDir.absolutePath(); else { cError() << "Bad module directory" << moduleDirectory << "for" << instanceId; return nullptr; } m->m_instanceId = instanceId; m->initFrom( moduleDescriptor ); try { m->loadConfigurationFile( configFileName ); } catch ( YAML::Exception& e ) { cError() << "YAML parser error " << e.what(); return nullptr; } return m.release(); }
Module* Module::fromDescriptor( const QVariantMap& moduleDescriptor, const QString& instanceId, const QString& configFileName, const QString& moduleDirectory ) { Module* m = nullptr; QString typeString = moduleDescriptor.value( "type" ).toString(); QString intfString = moduleDescriptor.value( "interface" ).toString(); if ( typeString.isEmpty() || intfString.isEmpty() ) { cLog() << Q_FUNC_INFO << "bad module descriptor format" << instanceId; return nullptr; } if ( typeString == "view" && intfString == "qtplugin" ) { m = new ViewModule(); } else if ( typeString == "job" ) { if ( intfString == "process" ) { m = new ProcessJobModule(); } #ifdef WITH_PYTHON else if ( intfString == "python" ) { m = new PythonJobModule(); } #endif } if ( !m ) { cLog() << Q_FUNC_INFO << "bad module type or interface string" << instanceId << typeString << intfString; return nullptr; } QDir moduleDir( moduleDirectory ); if ( moduleDir.exists() && moduleDir.isReadable() ) m->m_directory = moduleDir.absolutePath(); else { cLog() << Q_FUNC_INFO << "bad module directory" << instanceId; return nullptr; } m->m_instanceId = instanceId; m->initFrom( moduleDescriptor ); try { m->loadConfigurationFile( configFileName ); } catch ( YAML::Exception& e ) { cDebug() << "WARNING: YAML parser error " << e.what(); delete m; return nullptr; } return m; }