Пример #1
0
	void Plugin::Init (ICoreProxy_ptr)
	{
		const auto& path = Util::GetSysPath (Util::SysPath::Share, "dlniwe/desc", "device.xml");
		if (path.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "cannot find device description XML file.";
			return;
		}

		XSD_.reset (new Util::XmlSettingsDialog);
		XSD_->RegisterObject (&XmlSettingsManager::Instance (), "dlniwesettings.xml");

		HU::HDeviceConfiguration devConf;
		devConf.setPathToDeviceDescription (path);

		HAV::HAvDeviceModelCreator avCreator;
		HAV::HMediaServerDeviceConfiguration msConfig;

		auto fsSource = new HAV::HFileSystemDataSource ({});
		HAV::HContentDirectoryServiceConfiguration cdsConfig;
		cdsConfig.setDataSource (fsSource, true);
		msConfig.setContentDirectoryConfiguration (cdsConfig);

		avCreator.setMediaServerConfiguration (msConfig);

		HU::HDeviceHostConfiguration hostConf (devConf);
		hostConf.setDeviceModelCreator (avCreator);

		auto host = new HU::HDeviceHost ();
		if (!host->init (hostConf))
			qWarning () << Q_FUNC_INFO
					<< host->errorDescription ();

		auto pathsMgr = new FSPathsManager (fsSource);
		XSD_->SetDataSource ("RootPathsView", pathsMgr->GetModel ());
	}
Пример #2
0
bool DkUpnpDeviceHost::startDevicehost(QString pathToConfig) {
	qDebug() << "pathToConfig:" << pathToConfig;
	qDebug() << "starting DeviceHost";
	QFile f(pathToConfig);
	if (!f.exists()) {
		qDebug() << "DkUpnpDeviceHost: config file not found";
		return false;
	}

	QUuid uuid = QUuid::createUuid();
	QString uuidString = uuid.toString();
	uuidString.replace("{","");
	uuidString.replace("}","");
	QString newXMLpath = QDir::tempPath() + QDir::separator() + uuidString + ".xml";
	

	QByteArray fileData;
	f.open(QIODevice::ReadOnly);
	//f.seek(0);
	fileData = f.readAll();
	f.close();
	QString fileText(fileData);
	fileText.replace("insert-new-uuid-here", uuidString);
#ifdef WIN32
	fileText.replace("nomacs-service.xml", QDir::temp().dirName()+"/nomacs-service.xml");
#else
	fileText.replace("nomacs-service.xml", "/nomacs-service.xml");
#endif // WIN32
	
	QFile newDescriptorFile(newXMLpath);
	newDescriptorFile.open(QIODevice::WriteOnly);
	newDescriptorFile.write(fileText.toUtf8());
	qDebug() << "writing file:" << newXMLpath;
	newDescriptorFile.close();

	QFileInfo fileInfo = QFileInfo(f);
	QFile serviceXML(fileInfo.absolutePath() + QDir::separator() + "nomacs-service.xml");
	if (!serviceXML.open(QIODevice::ReadOnly))
		qDebug() << "nomacs-service.xml file does not exist";
	
	// copy the resource file to the user tmp folder
	QString newServiceXMLPath = QDir::tempPath()+ QDir::separator() + "nomacs-service.xml";
	QFile tmpServiceXmlFile(newServiceXMLPath);
	tmpServiceXmlFile.open(QIODevice::WriteOnly);
	tmpServiceXmlFile.write(serviceXML.readAll());
	tmpServiceXmlFile.close();
	serviceXML.close();
	
	//if(!QFile::exists(newServiceXMLPath)) {
	//	if (!serviceXML.copy(newServiceXMLPath))
	//		qDebug() << "unable to copy nomacs-service.xml to " << newServiceXMLPath << ", perhaps files already exists";
	//}
	QFile newServiceXMLFile(QDir::tempPath()+ QDir::separator() + "nomacs-service.xml");
	serviceXML.close();
	DkUpnpDeviceModelCreator creator;

	Herqq::Upnp::HDeviceHostConfiguration hostConfig;
	hostConfig.setDeviceModelCreator(creator);
	
	Herqq::Upnp::HDeviceConfiguration config;
	//config.setPathToDeviceDescription(pathToConfig);
	config.setPathToDeviceDescription(newXMLpath);
	
	hostConfig.add(config);
	
	bool retVal = init(hostConfig);
	if (!retVal) {
		qDebug() << "error while initializing device host:\n" << errorDescription();
	}

	if(!newDescriptorFile.remove()) 
		qDebug() << "unable to remove upnp device.xml file";
	// this->serviceXMLPath = newServiceXMLPath;

	if (!tmpServiceXmlFile.remove())
		qDebug() << tmpServiceXmlFile.errorString();

	//qDebug() << "newServiceXMLPath" << newServiceXMLPath;
	//if(!QFile::remove(newServiceXMLPath))
		//qDebug() << "unable to remove upnp service.xml file";
	return retVal;
}