Exemplo n.º 1
0
BOOL CKADmerge::HasNode(IXMLDOMNode * pXMLNode, string sPatternString, IXMLDOMNode ** pXMLTarget)
{
    BOOL bRet = FALSE;
    HRESULT hRes = 0;
    LONG lListLength = 0;

    IXMLDOMNodeList * pXMLNodeList = NULL;
    _bstr_t bPatternString(sPatternString.c_str());
    hRes = pXMLNode->selectNodes(bPatternString, &pXMLNodeList);

    if(SUCCEEDED(hRes))
    {
        hRes = pXMLNodeList->get_length(&lListLength);
        if(lListLength)
        {
            hRes = pXMLNodeList->nextNode(pXMLTarget);
            bRet = TRUE;
        }
        else
        {
            string str01 = GetName(pXMLNode);
            string str02 = GetName(*pXMLTarget);
            bRet = FALSE;
        }
    }

    if(pXMLNodeList)
        pXMLNodeList->Release();

    return bRet;
}
Exemplo n.º 2
0
extern "C" HRESULT CatalogsParseFromXml(
    __in BURN_CATALOGS* pCatalogs,
    __in IXMLDOMNode* pixnBundle
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pixnNodes = NULL;
    IXMLDOMNode* pixnNode = NULL;
    DWORD cNodes = 0;
    LPWSTR scz = NULL;

    // select catalog nodes
    hr = XmlSelectNodes(pixnBundle, L"Catalog", &pixnNodes);
    ExitOnFailure(hr, "Failed to select catalog nodes.");

    // get catalog node count
    hr = pixnNodes->get_length((long*)&cNodes);
    ExitOnFailure(hr, "Failed to get payload node count.");
    if (!cNodes)
    {
        ExitFunction();
    }

    // allocate memory for catalogs
    pCatalogs->rgCatalogs = (BURN_CATALOG*)MemAlloc(sizeof(BURN_CATALOG) * cNodes, TRUE);
    ExitOnNull(pCatalogs->rgCatalogs, hr, E_OUTOFMEMORY, "Failed to allocate memory for payload structs.");

    pCatalogs->cCatalogs = cNodes;

    // parse catalog elements
    for (DWORD i = 0; i < cNodes; ++i)
    {
        BURN_CATALOG* pCatalog = &pCatalogs->rgCatalogs[i];
        pCatalog->hFile = INVALID_HANDLE_VALUE;

        hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
        ExitOnFailure(hr, "Failed to get next node.");

        // @Id
        hr = XmlGetAttributeEx(pixnNode, L"Id", &pCatalog->sczKey);
        ExitOnFailure(hr, "Failed to get @Id.");

        // @Payload
        hr = XmlGetAttributeEx(pixnNode, L"Payload", &pCatalog->sczPayload);
        ExitOnFailure(hr, "Failed to get @Payload.");

        // prepare next iteration
        ReleaseNullObject(pixnNode);
    }

LExit:
    ReleaseObject(pixnNodes);
    ReleaseObject(pixnNode);
    ReleaseStr(scz);

    return hr;
}
Exemplo n.º 3
0
static HRESULT ParseWxlControls(
    __in IXMLDOMElement* pElement,
    __in WIX_LOCALIZATION* pWixLoc
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNode* pixn = NULL;
    IXMLDOMNodeList* pixnl = NULL;
    DWORD dwIdx = 0;

    hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl);
    ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File.");

    hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls));
    ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File.");

    if (0 < pWixLoc->cLocControls)
    {
        pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE));
        ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls.");

        while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL)))
        {
            hr = ParseWxlControl(pixn, dwIdx, pWixLoc);
            ExitOnFailure(hr, "Failed to parse localized control.");

            ++dwIdx;
            ReleaseNullObject(pixn);
        }

        hr = S_OK;
        ExitOnFailure(hr, "Failed to enumerate all localized controls.");
    }

LExit:
    if (FAILED(hr) && pWixLoc->rgLocControls)
    {
        for (DWORD idx = 0; idx < pWixLoc->cLocControls; ++idx)
        {
            ReleaseStr(pWixLoc->rgLocControls[idx].wzControl);
            ReleaseStr(pWixLoc->rgLocControls[idx].wzText);
        }

        ReleaseMem(pWixLoc->rgLocControls);
    }

    ReleaseObject(pixn);
    ReleaseObject(pixnl);

    return hr;
}
long lvDCOMInterface::nParams()
{
	long n = 0;
	char control_name_xpath[MAX_PATH_LEN];
	_snprintf(control_name_xpath, sizeof(control_name_xpath), "/lvinput/section[@name='%s']/vi/param", m_configSection.c_str());
	IXMLDOMNodeList* pXMLDomNodeList = NULL;
	HRESULT hr = m_pxmldom->selectNodes(_bstr_t(control_name_xpath), &pXMLDomNodeList);
	if (SUCCEEDED(hr) && pXMLDomNodeList != NULL)
	{
		pXMLDomNodeList->get_length(&n);
		pXMLDomNodeList->Release();
	}
	return n;
}
Exemplo n.º 5
0
/*
	Function name	: CXML::GetNoOfChildNodes
	Description	    :Get the no of childs of the current node 
	Return type		: bool 
	Argument        : long &nNodes
	Tested			: Ok
*/
bool CXML::GetNoOfChildNodes(long &nNodes)
{
	if(!m_pICurrentNode)
		return false;

	IXMLDOMNodeList * pNodeList = NULL;

	m_hr = m_pICurrentNode->get_childNodes(&pNodeList);

	if(!SUCCEEDED(m_hr ) || !pNodeList)
		return false;

	m_hr = pNodeList->get_length(&nNodes);

	if(!SUCCEEDED(m_hr ))
		return false;
	else
		return true;
}
Exemplo n.º 6
0
QStringList DicomImageSet::getOrderedDcmFiles(const QString &datasetFileName, const QString & queryString)
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pFileNodes = NULL;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
	BSTR bstrQuery;

	QStringList fileList;

    CHK_HR(CreateAndInitDOM(&pXMLDom));

	CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

    bstrQuery = SysAllocString(queryString.toStdWString().c_str());
    CHK_ALLOC(bstrQuery);
    CHK_HR(pXMLDom->selectNodes(bstrQuery, &pFileNodes));
	if (pFileNodes)
	{
		long nFiles;
		CHK_HR(pFileNodes->get_length(&nFiles));
		for (long i=0; i<nFiles; ++i)
		{
			VARIANT varValue;
			IXMLDOMNode * pFile = NULL;
			CHK_HR(pFileNodes->get_item(i, &pFile));
			CHK_HR(GetAttributeFromNode(pFile, L"path", &varValue));
			fileList <<QString::fromWCharArray(_bstr_t(varValue));
			SAFE_RELEASE(pFile);
		}
	}

CleanUp:
	SAFE_RELEASE(pXMLDom);
	SAFE_RELEASE(pFileNodes);
	return fileList;
}
void lvDCOMInterface::getParams(std::map<std::string,std::string>& res)
{
	res.clear();
	char control_name_xpath[MAX_PATH_LEN];
	_snprintf(control_name_xpath, sizeof(control_name_xpath), "/lvinput/section[@name='%s']/vi/param", m_configSection.c_str());
	IXMLDOMNodeList* pXMLDomNodeList = NULL;
	HRESULT hr = m_pxmldom->selectNodes(_bstr_t(control_name_xpath), &pXMLDomNodeList);
	if (FAILED(hr) || pXMLDomNodeList == NULL)
	{
		return;
	}
	IXMLDOMNode *pNode, *pAttrNode1, *pAttrNode2;
	long n = 0;
	pXMLDomNodeList->get_length(&n);
	for(long i=0; i<n; ++i)
	{
		pNode = NULL;
		hr = pXMLDomNodeList->get_item(i, &pNode);
		if (SUCCEEDED(hr) && pNode != NULL)
		{
			IXMLDOMNamedNodeMap *attributeMap = NULL;
			pAttrNode1 = pAttrNode2 = NULL;
			pNode->get_attributes(&attributeMap);
			hr = attributeMap->getNamedItem(_bstr_t("name"), &pAttrNode1);
			hr = attributeMap->getNamedItem(_bstr_t("type"), &pAttrNode2);
			BSTR bstrValue1 = NULL, bstrValue2 = NULL;
			hr=pAttrNode1->get_text(&bstrValue1);
			hr=pAttrNode2->get_text(&bstrValue2);
			res[std::string(COLE2CT(bstrValue1))] = COLE2CT(bstrValue2);
			SysFreeString(bstrValue1);
			SysFreeString(bstrValue2);
			pAttrNode1->Release();
			pAttrNode2->Release();
			attributeMap->Release();
			pNode->Release();
		}
	}	
	pXMLDomNodeList->Release();
}
Exemplo n.º 8
0
// эта функция, если значения нет (или тип некорректный) *value НЕ трогает
bool SettingsXML::Load(const wchar_t *regName, wchar_t **value)
{
	bool lbRc = false;
	HRESULT hr = S_OK;
	IXMLDOMNode* pChild = NULL;
	IXMLDOMNamedNodeMap* pAttrs = NULL;
	IXMLDOMAttribute *pIXMLDOMAttribute = NULL;
	IXMLDOMNode *pNode = NULL;
	IXMLDOMNodeList* pList = NULL;
	BSTR bsType = NULL;
	BSTR bsData = NULL;
	size_t nLen = 0;

	//if (*value) {free(*value); *value = NULL;}

	if (mp_Key)
		pChild = FindItem(mp_Key, L"value", regName, false);

	if (!pChild)
		return false;

	hr = pChild->get_attributes(&pAttrs);

	if (SUCCEEDED(hr) && pAttrs)
	{
		bsType = GetAttr(pChild, pAttrs, L"type");
	}

	if (SUCCEEDED(hr) && bsType)
	{
		if (!lstrcmpi(bsType, L"multi"))
		{
			// Тут значения хранятся так:
			//<value name="CmdLineHistory" type="multi">
			//	<line data="C:\Far\Far.exe"/>
			//	<line data="cmd"/>
			//</value>
			wchar_t *pszData = NULL, *pszCur = NULL;
			size_t nMaxLen = 0, nCurLen = 0;
			long nCount = 0;

			if (pAttrs) { pAttrs->Release(); pAttrs = NULL; }

			// Получить все дочерние элементы нужного типа
			bsData = ::SysAllocString(L"line");
			hr = pChild->selectNodes(bsData, &pList);
			::SysFreeString(bsData); bsData = NULL;

			if (SUCCEEDED(hr) && pList)
			{
				hr = pList->get_length(&nCount);

				if (SUCCEEDED(hr) && (nCount > 0))
				{
					HEAPVAL;
					nMaxLen = ((MAX_PATH+1) * nCount) + 1;
					pszData = (wchar_t*)malloc(nMaxLen * sizeof(wchar_t));
					pszCur = pszData;
					pszCur[0] = 0; pszCur[1] = 0;
					nCurLen = 2; // сразу посчитать DoubleZero
					HEAPVAL;
				}
			}

			if (SUCCEEDED(hr) && pList)
			{
				hr = pList->reset();

				while ((hr = pList->nextNode(&pNode)) == S_OK && pNode)
				{
					bsData = GetAttr(pNode, L"data");
					pNode->Release(); pNode = NULL;

					if (SUCCEEDED(hr) && bsData)
					{
						nLen = _tcslen(bsData) + 1;

						if ((nCurLen + nLen) > nMaxLen)
						{
							// Нужно пересоздать!
							nMaxLen = nCurLen + nLen + MAX_PATH + 1;
							wchar_t *psz = (wchar_t*)malloc(nMaxLen * sizeof(wchar_t));
							_ASSERTE(psz);

							if (!psz) break;  // Не удалось выделить память!

							wmemmove(psz, pszData, nCurLen);
							pszCur = psz + (pszCur - pszData);
							HEAPVAL;
							free(pszData);
							pszData = psz;
							HEAPVAL;
						}

						lstrcpy(pszCur, bsData);
						pszCur += nLen; // указатель - на место для следующей строки
						nCurLen += nLen;
						*pszCur = 0; // ASCIIZZ
						HEAPVAL;
						::SysFreeString(bsData); bsData = NULL;
					}
				}

				pList->Release(); pList = NULL;
			}

			// значит что-то прочитать удалось
			if (pszData)
			{
				if (*value) {free(*value); *value = NULL;}
				*value = pszData;
				lbRc = true;
			}
		}
		else if (!lstrcmpi(bsType, L"string"))
		{
			bsData = GetAttr(pChild, pAttrs, L"data");

			if (SUCCEEDED(hr) && bsData)
			{
				nLen = _tcslen(bsData);
				if (!*value || (_tcslen(*value) <= nLen))
				{
					*value = (wchar_t*)realloc(*value, (nLen+2)*sizeof(wchar_t));
				}
				if (*value)
				{
					lstrcpy(*value, bsData);
					(*value)[nLen] = 0; // уже должен быть после lstrcpy
					(*value)[nLen+1] = 0; // ASCIIZZ
					lbRc = true;
				}
			}
		}

		// Все остальные типы - не интересуют. Нам нужны только строки
	}

	if (bsType) { ::SysFreeString(bsType); bsType = NULL; }

	if (bsData) { ::SysFreeString(bsData); bsData = NULL; }

	if (pChild) { pChild->Release(); pChild = NULL; }

	if (pAttrs) { pAttrs->Release(); pAttrs = NULL; }

	//if (!lbRc)
	//{
	//	_ASSERTE(*value == NULL);
	//	*value = (wchar_t*)malloc(sizeof(wchar_t)*2);
	//	(*value)[0] = 0; (*value)[1] = 0; // На случай REG_MULTI_SZ
	//}

	return lbRc;
}
Exemplo n.º 9
0
int DicomImageSet::readDatasetFile(const QString &datasetFileName, QTreeWidget *treeWidget)
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pPatients = NULL;
    IXMLDOMNode *pPatient = NULL;
	DOMNodeType nodeType;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
	VARIANT varValue;
	BSTR bstrQuery;

    VariantInit(&varFileName);
    VariantInit(&varValue);

	QString queryPatient, queryDate, queryProtocol, queryCollection;

    CHK_HR(CreateAndInitDOM(&pXMLDom));

	CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

	treeWidget->clear();
	treeWidget->setColumnCount(1);
	CHK_HR(pXMLDom->getElementsByTagName(L"Patient", &pPatients));
	if (pPatients)
	{
		long nPatients;
		CHK_HR(pPatients->get_length(&nPatients));
		for (long i=0; i<nPatients; ++i)
		{
			CHK_HR(pPatients->get_item(i, &pPatient));
			CHK_HR(GetAttributeFromNode(pPatient, L"patients_name", &varValue));
			queryPatient = QString::fromWCharArray(_bstr_t(varValue));
			QTreeWidgetItem * patientItem = new QTreeWidgetItem(treeWidget, QStringList(queryPatient));
			patientItem->setExpanded(true);

			IXMLDOMNodeList * pDates = NULL;
			CHK_HR(pPatient->get_childNodes(&pDates));
			long nDates;
			CHK_HR(pDates->get_length(&nDates));
			for (long j=0; j<nDates; ++j)
			{
				IXMLDOMNode * pDate = NULL;
				CHK_HR(pDates->get_item(j, &pDate));
				CHK_HR(pDate->get_nodeType(&nodeType));
				if(nodeType!=NODE_ELEMENT)
				{
					continue;
				}
				CHK_HR(GetAttributeFromNode(pDate, L"acquisition_date", &varValue));
				queryDate = QString::fromWCharArray(_bstr_t(varValue));
				int intDate = queryDate.toInt();
				QDate date = (QDate::fromString("1900-01-01", "yyyy-MM-dd")).addDays(intDate-693962);
				QTreeWidgetItem * dateItem = new QTreeWidgetItem(patientItem, QStringList(date.toString("yyyy-MM-dd")));
				dateItem->setExpanded(true);

				IXMLDOMNodeList * pProtocols = NULL;
				CHK_HR(pDate->get_childNodes(&pProtocols));
				long nProtocols;
				CHK_HR(pProtocols->get_length(&nProtocols));
				for (long j=0; j<nProtocols; ++j)
				{
					IXMLDOMNode * pProtocol = NULL;
					CHK_HR(pProtocols->get_item(j, &pProtocol));
					CHK_HR(pProtocol->get_nodeType(&nodeType));
					if(nodeType!=NODE_ELEMENT)
					{
						continue;
					}
					CHK_HR(GetAttributeFromNode(pProtocol, L"protocol_name", &varValue));
					queryProtocol = QString::fromWCharArray(_bstr_t(varValue));
					QTreeWidgetItem * protocolItem = new QTreeWidgetItem(dateItem, QStringList(queryProtocol));
					protocolItem->setExpanded(true);

					IXMLDOMNodeList * pCollections = NULL;
					CHK_HR(pProtocol->get_childNodes(&pCollections));
					long nCollections;
					CHK_HR(pCollections->get_length(&nCollections));
					for (long j=0; j<nCollections; ++j)
					{
						IXMLDOMNode * pCollection = NULL;
						CHK_HR(pCollections->get_item(j, &pCollection));
						CHK_HR(pCollection->get_nodeType(&nodeType));
						if(nodeType!=NODE_ELEMENT)
						{
							continue;
						}
						CHK_HR(GetAttributeFromNode(pCollection, L"acquisition_number", &varValue));
						queryCollection = QString::fromWCharArray(_bstr_t(varValue));
						QTreeWidgetItem * collectionItem = new QTreeWidgetItem(protocolItem);
						QString queryStr = QString("root/Patient[@patients_name = '%1']/Date[@acquisition_date = '%2']/Protocol[@protocol_name = '%3']/Collection[@acquisition_number = '%4']")
							.arg(queryPatient).arg(queryDate).arg(queryProtocol).arg(queryCollection);

						IXMLDOMElement * pDtiNode = NULL;
						bstrQuery = SysAllocString(QString(queryStr+"/DTI").toStdWString().c_str());
						CHK_ALLOC(bstrQuery);
						CHK_HR(pXMLDom->selectSingleNode(bstrQuery, (IXMLDOMNode**)&pDtiNode));
						SysFreeString(bstrQuery);
						if (pDtiNode)
						{
							collectionItem->setText(0,queryCollection+"*");
						} else
						{
							collectionItem->setText(0, queryCollection);
						}

						collectionItem->setData(0, Qt::UserRole, queryStr);
						collectionItem->setExpanded(true);


						protocolItem->addChild(collectionItem);
						SAFE_RELEASE(pCollection);
					}

					dateItem->addChild(protocolItem);
					SAFE_RELEASE(pProtocol);
				}

				patientItem->addChild(dateItem);
				SAFE_RELEASE(pDate);
			}
			treeWidget->insertTopLevelItem(i, patientItem);
			SAFE_RELEASE(pPatient);
		}
	}

CleanUp:
    SAFE_RELEASE(pXMLDom);
    SAFE_RELEASE(pPatients);
    SAFE_RELEASE(pPatient);
    VariantClear(&varFileName);

	return SUCCEEDED(hr);
}
Exemplo n.º 10
0
void Explorerplusplus::LoadDialogStatesFromXML(IXMLDOMDocument *pXMLDom)
{
	IXMLDOMNodeList		*pNodes = NULL;
	IXMLDOMNode			*pNode = NULL;
	IXMLDOMNamedNodeMap	*am = NULL;
	IXMLDOMNode			*pChildNode = NULL;
	BSTR						bstrName;
	BSTR						bstrValue;
	BSTR						bstr = NULL;
	HRESULT						hr;
	long						length;
	long						lChildNodes;

	if(pXMLDom == NULL)
		goto clean;

	TCHAR tempNodeSelector[64];
	StringCchPrintf(tempNodeSelector, SIZEOF_ARRAY(tempNodeSelector),
		_T("//%s/*"), DIALOGS_XML_KEY);
	bstr = SysAllocString(tempNodeSelector);
	pXMLDom->selectNodes(bstr,&pNodes);

	if(!pNodes)
	{
		goto clean;
	}
	else
	{
		pNodes->get_length(&length);

		for(long i = 0;i < length;i++)
		{
			/* This should never fail, as the number
			of nodes has already been counted (so
			they must exist). */
			hr = pNodes->get_item(i,&pNode);

			if(SUCCEEDED(hr))
			{
				hr = pNode->get_attributes(&am);

				if(SUCCEEDED(hr))
				{
					/* Retrieve the total number of attributes
					attached to this node. */
					am->get_length(&lChildNodes);

					if(lChildNodes >= 1)
					{
						am->get_item(0,&pChildNode);

						pChildNode->get_nodeName(&bstrName);
						pChildNode->get_text(&bstrValue);

						for(CDialogSettings *ds : DIALOG_SETTINGS)
						{
							TCHAR settingsKey[64];
							bool success = ds->GetSettingsKey(settingsKey, SIZEOF_ARRAY(settingsKey));
							assert(success);

							if(!success)
							{
								continue;
							}

							if(lstrcmpi(bstrValue, settingsKey) == 0)
							{
								ds->LoadXMLSettings(am, lChildNodes);
							}
						}
					}
				}
			}

			pNode->Release();
			pNode = NULL;
		}
	}

clean:
	if (bstr) SysFreeString(bstr);
	if (pNodes) pNodes->Release();
	if (pNode) pNode->Release();
}
Exemplo n.º 11
0
///////////////////////////////////////////////////////
// RADEventsXML::ProcessEvents
//
// Method to process a list of events, either transforming XML
// into RADEvents, or RADEvents into XML event nodes.
// Invoked by the Populate and Persist methods.
//
// When transforming the RADEvent objects on the list 'rel' into
// XML Event nodes, a new XML Event node is created, and appended
// to the XML Events node of the XML document.
// 
// When transforming the XML Events node with XML Event nodes, each
// XML Event node is transformed to a RADEvent object, and the RADEvent
// object is appended to the RADEventsList 'rel'.
//
// Input/Output:
//	rel	- the RADEventsList instance
//  bExtract - processing toggle:
//		When true, run through the XML event nodes, creating
//		RADEvent objects on 'rel'.
//		When false, run through the RADEvent objects, creating
//		XML event nodes on the XML document.
//
///////////////////////////////////////////////////////
bool RADEventsXML::ProcessEvents(RADEventsList& rel, bool bExtract)
{

	// if bExtract, we want to read the XML events and populate the list of event objects
	// first: get count of events nodes
	// second:
	//	for each event node
	//    get the node
	//    create a RADEvent, using the node attributes to populate it
	//	  insert the RADEvent object into the RADEventsList 'rel'
	// end
	// else, not bExtract, we want to transform the list of RADEvent objects into an XML document
	// for each RADEvent on the RADEventsList 'rel,
	//    create a new XML Event Node, using each stirng value as an attribute value
	//    append the XML Event node to the <IR/Events> node
	//  end

	HRESULT hr;
	_bstr_t xbstr = m_xirevsevpath;

	if (bExtract)  // converting from XML <Event> to RADEvent
	{
		IXMLDOMNodeList* pXMLDomNodeList = NULL;
		HRCALL(m_pXMLDom->selectNodes(xbstr, &pXMLDomNodeList), "selectNodes");
		if (pXMLDomNodeList)
		{
			long count = 0;
			HRCALL(pXMLDomNodeList->get_length(&count), "get_length");
			IXMLDOMNode *pEventNode=NULL;
			for (long i=0; i<count; i++)
			{
				HRCALL(pXMLDomNodeList->get_item(i, &pEventNode), "get_item: ");
				if (bDebug)
				{
					BSTR dbg1str;
					BSTR dbg2str;
					HRCALL(pEventNode->get_nodeName(&dbg1str), "get_nodeName: ");
					dprintf("Node (%d), <%S>:\n",i, static_cast<wchar_t*>(dbg1str));
					HRCALL(pEventNode->get_xml(&dbg2str), "get_xml: ");
					dprintf("\t%S\n",  static_cast<wchar_t*>(dbg2str));
				}

				RADEvent* p = XMLToEvent(pEventNode);
				rel.AddToEnd(p);
				if (bDebug)
				{
					dprintf(p->Image());
				}
				if (pEventNode) pEventNode->Release();
			}
			pXMLDomNodeList->Release();
		}
		else
		{
			ReportParseError(m_pXMLDom, "Error while calling ProcessEvents/selectNodes ");
		}
	}
	else // converting from RADEvent to XML <Event>
	{
		IXMLDOMElement * pE;
		IXMLDOMNode *pIXMLDOMNode = NULL;
		long i = 0;
		POSITION pos = rel.GetHeadPosition();
		while( pos != NULL )
		{
			RADEvent* p = (RADEvent*)rel.GetNext( pos );
			pE = ConstructEventNode(p);
			if (pE)
			{
				HRCALL(m_pIRNode->appendChild(pE,&pIXMLDOMNode), ""); 
				AddWhiteSpaceToNode(bstr_wsnt, m_pIRNode);
				i++;
			}
		}
	}

clean: 
	if (FAILED(hr))
		return false;
	else
		return true;
}
void CStrokeRecognition::DecodePointFromXML(std::vector<POINT> &rgPoints, BSTR strXML)
{
	IXMLDOMDocument*		pDoc;
	IXMLDOMNodeList*		pNodeList;
	IXMLDOMNode*			pNode;
	IXMLDOMNode*			pInputNode;
	IXMLDOMNode*			pAttrNode;
	IXMLDOMNamedNodeMap*	pNodeMap;
	VARIANT_BOOL			bLoaded;
	VARIANT					value;
	BSTR					nodeName;
	POINT					pt;
	long					n;

	if (SUCCEEDED(CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (LPVOID*)&pDoc)))
	{
		pDoc->put_async(VARIANT_FALSE);
		pDoc->loadXML(strXML, &bLoaded);

		if (bLoaded == VARIANT_TRUE)
		{
			if (SUCCEEDED(pDoc->get_childNodes(&pNodeList)))
			{
				pInputNode = NULL;

				pNodeList->get_length(&n);

				for (int i = 0; i < n; i++)
				{
					if (SUCCEEDED(pNodeList->get_item(i, &pNode)))
					{
						nodeName = NULL;
						if (SUCCEEDED(pNode->get_nodeName(&nodeName)))
						{
							if (CComBSTR(nodeName) == L"input")
							{
								pInputNode = pNode;
								pInputNode->AddRef();
								break;
							}
							SysFreeString(nodeName);
						}
						pNode->Release();
					}
				}

				pNodeList->Release();

				if (pInputNode != NULL)
				{
					if (SUCCEEDED(pInputNode->get_childNodes(&pNodeList)))
					{
						pNodeList->get_length(&n);

						for (int i = 0; i < n; i++)
						{
							if (SUCCEEDED(pNodeList->get_item(i, &pNode)))
							{
								pt.x = 0;
								pt.y = 0;

								if (SUCCEEDED(pNode->get_attributes(&pNodeMap)))
								{
									if (SUCCEEDED(pNodeMap->getNamedItem(L"x", &pAttrNode)))
									{
										pAttrNode->get_nodeValue(&value);
										pt.x = _wtoi(value.bstrVal);
										pAttrNode->Release();
									}

									if (SUCCEEDED(pNodeMap->getNamedItem(L"y", &pAttrNode)))
									{
										pAttrNode->get_nodeValue(&value);
										pt.y = _wtoi(value.bstrVal);
										pAttrNode->Release();
									}

									pNodeMap->Release();
								}

								rgPoints.push_back(pt);

								pNode->Release();
							}
						}

						pNodeList->Release();
					}

					pInputNode->Release();
				}
			}
		}

		pDoc->Release();
	}
}
Exemplo n.º 13
0
extern "C" HRESULT ExeEngineParsePackageFromXml(
    __in IXMLDOMNode* pixnExePackage,
    __in BURN_PACKAGE* pPackage
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pixnNodes = NULL;
    IXMLDOMNode* pixnNode = NULL;
    DWORD cNodes = 0;
    LPWSTR scz = NULL;

    // @DetectCondition
    hr = XmlGetAttributeEx(pixnExePackage, L"DetectCondition", &pPackage->Exe.sczDetectCondition);
    ExitOnFailure(hr, "Failed to get @DetectCondition.");

    // @InstallArguments
    hr = XmlGetAttributeEx(pixnExePackage, L"InstallArguments", &pPackage->Exe.sczInstallArguments);
    ExitOnFailure(hr, "Failed to get @InstallArguments.");

    // @UninstallArguments
    hr = XmlGetAttributeEx(pixnExePackage, L"UninstallArguments", &pPackage->Exe.sczUninstallArguments);
    ExitOnFailure(hr, "Failed to get @UninstallArguments.");

    // @RepairArguments
    hr = XmlGetAttributeEx(pixnExePackage, L"RepairArguments", &pPackage->Exe.sczRepairArguments);
    ExitOnFailure(hr, "Failed to get @RepairArguments.");

    // @Repairable
    hr = XmlGetYesNoAttribute(pixnExePackage, L"Repairable", &pPackage->Exe.fRepairable);
    if (E_NOTFOUND != hr)
    {
        ExitOnFailure(hr, "Failed to get @Repairable.");
    }

    // @Protocol
    hr = XmlGetAttributeEx(pixnExePackage, L"Protocol", &scz);
    if (SUCCEEDED(hr))
    {
        if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"burn", -1))
        {
            pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_BURN;
        }
        else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"netfx4", -1))
        {
            pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_NETFX4;
        }
        else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"none", -1))
        {
            pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_NONE;
        }
        else
        {
            hr = E_UNEXPECTED;
            ExitOnFailure1(hr, "Invalid protocol type: %ls", scz);
        }
    }
    else if (E_NOTFOUND != hr)
    {
        ExitOnFailure(hr, "Failed to get @Protocol.");
    }

    // select exit code nodes
    hr = XmlSelectNodes(pixnExePackage, L"ExitCode", &pixnNodes);
    ExitOnFailure(hr, "Failed to select exit code nodes.");

    // get exit code node count
    hr = pixnNodes->get_length((long*)&cNodes);
    ExitOnFailure(hr, "Failed to get exit code node count.");

    if (cNodes)
    {
        // allocate memory for exit codes
        pPackage->Exe.rgExitCodes = (BURN_EXE_EXIT_CODE*)MemAlloc(sizeof(BURN_EXE_EXIT_CODE) * cNodes, TRUE);
        ExitOnNull(pPackage->Exe.rgExitCodes, hr, E_OUTOFMEMORY, "Failed to allocate memory for exit code structs.");

        pPackage->Exe.cExitCodes = cNodes;

        // parse package elements
        for (DWORD i = 0; i < cNodes; ++i)
        {
            BURN_EXE_EXIT_CODE* pExitCode = &pPackage->Exe.rgExitCodes[i];

            hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
            ExitOnFailure(hr, "Failed to get next node.");

            // @Type
            hr = XmlGetAttributeEx(pixnNode, L"Type", &scz);
            ExitOnFailure(hr, "Failed to get @Type.");

            if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"success", -1))
            {
                pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_SUCCESS;
            }
            else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"error", -1))
            {
                pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_ERROR;
            }
            else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"scheduleReboot", -1))
            {
                pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_SCHEDULE_REBOOT;
            }
            else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"forceReboot", -1))
            {
                pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_FORCE_REBOOT;
            }
            else
            {
                hr = E_UNEXPECTED;
                ExitOnFailure1(hr, "Invalid exit code type: %ls", scz);
            }

            // @Code
            hr = XmlGetAttributeEx(pixnNode, L"Code", &scz);
            ExitOnFailure(hr, "Failed to get @Code.");

            if (L'*' == scz[0])
            {
                pExitCode->fWildcard = TRUE;
            }
            else
            {
                hr = StrStringToUInt32(scz, 0, (UINT*)&pExitCode->dwCode);
                ExitOnFailure1(hr, "Failed to parse @Code value: %ls", scz);
            }

            // prepare next iteration
            ReleaseNullObject(pixnNode);
        }
    }

    hr = S_OK;

LExit:
    ReleaseObject(pixnNodes);
    ReleaseObject(pixnNode);
    ReleaseStr(scz);

    return hr;
}
Exemplo n.º 14
0
bool CModelToolCharDataTable::LoadProperty(const char * lpszFullPathFileName)
{
	CNtlXMLDoc doc;
	if(doc.Create() == false)
	{
		_ASSERT(0);
		return false;
	}
	
	if(doc.Load( const_cast<char *>(lpszFullPathFileName) ) == false)
	{
		_ASSERT(0);
		return false;
	}
	
	char szBuffer[1024];

	if( !doc.GetDataWithXPath(const_cast<char *>(XML_PROP_NAME_ATTRIBUTE), szBuffer, sizeof(szBuffer)) )
	{
		_ASSERT(0);
		return false;
	}

	sMODELTOOL_CHAR_TBLDAT	*pModelToolCharData = new sMODELTOOL_CHAR_TBLDAT;

	Add(szBuffer, pModelToolCharData);

	IXMLDOMNodeList *pAnimDataList = doc.SelectNodeList(XML_PROP_ANIM_DATA_ELEMENT);
	IXMLDOMNode* pAnimDataNode = NULL;

	IXMLDOMNodeList *pAnimEventList = NULL;
	IXMLDOMNode* pAnimEventNode = NULL;

	long	lAnimDataNodeNum = 0;
	long	lAnimEventNodeNum = 0;

	int		nAnimKeyID = 0;
	float	fDurationTime = 0.f;

	BYTE	byPushCount = 0;
	BYTE	byKnockDownCount = 0;
    bool    bKB2Push = false;
	BYTE	byHitCount = 0;
	float	aHitTime[NTL_MAX_SIZE_HIT];

	pAnimDataList->get_length(&lAnimDataNodeNum);
	for(long m = 0; m < lAnimDataNodeNum ; ++m)
	{
		pAnimDataList->get_item(m,&pAnimDataNode);

		if(!doc.GetTextWithAttributeName(pAnimDataNode, XML_PROP_ANIM_DATA_ELEMENT_KEYID_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
		{
			_ASSERT(0);
			return false;
		}
		nAnimKeyID = atoi(szBuffer);

		if(!doc.GetTextWithAttributeName(pAnimDataNode, XML_PROP_ANIM_DATA_ELEMENT_PLAYTIME_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
		{
			_ASSERT(0);
			return false;
		}

		fDurationTime = (float)atof(szBuffer);
		
		pAnimDataNode->selectNodes(L"ANIM_EVENT", &pAnimEventList);
		pAnimEventList->get_length(&lAnimEventNodeNum);

		memset(aHitTime, 0, sizeof(aHitTime));
		for(long n = 0; n < lAnimEventNodeNum; ++n)
		{
			pAnimEventList->get_item(n, &pAnimEventNode);

			if(!doc.GetTextWithAttributeName(pAnimEventNode, XML_PROP_ANIM_DATA_ELEMENT_EVENTID_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
			{
				_ASSERT(0);
				return false;
			}
	
			int nAnimEventID = EVENT_ANIM_NONE;
			int nBehavior = TARGET_BEHAVIOR_NONE;

			nAnimEventID = atoi(szBuffer);

			if(nAnimEventID == EVENT_ANIM_HIT)
			{
				if(!doc.GetTextWithAttributeName(pAnimEventNode, XML_PROP_ANIM_DATA_ELEMENT_HITBEHAVIOR_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
				{
					_ASSERT(0);
					return false;
				}
				
				nBehavior = atoi(szBuffer);

				if(nBehavior == TARGET_BEHAVIOR_PUSH)
				{
					byPushCount++;
				}
				else if(nBehavior == TARGET_BEHAVIOR_KNOCK_DOWN)
				{
					byKnockDownCount++;
					if( byKnockDownCount > 1 )
					{
						_ASSERT(0);
						return false;
					}
				}

				// Hit time
				if(!doc.GetTextWithAttributeName(pAnimEventNode, XML_PROP_ANIM_DATA_ELEMENT_HITTIME_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
				{
					_ASSERT(0);
					return false;
				}

				aHitTime[byHitCount] = (float)atof(szBuffer);
				byHitCount++;

				if(byHitCount > NTL_MAX_SIZE_HIT)
					_ASSERT(0);


				// KB2PUSH
				if(!doc.GetTextWithAttributeName(pAnimEventNode, XML_PROP_ANIM_DATA_ELEMENT_HITKB2PUSH_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
				{
					_ASSERT(0);
					return false;
				}

				if(atoi(szBuffer) == 0)
				{
					bKB2Push = false;
				}
				else
				{
					bKB2Push = true;
				}
			}
            else if(nAnimEventID == EVENT_ANIM_SKILL_CANCEL)
            {
                // time
                if(!doc.GetTextWithAttributeName(pAnimEventNode, XML_PROP_ANIM_DATA_ELEMENT_HITTIME_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
                {
                    _ASSERT(0);
                    return false;
                }

                pModelToolCharData->AddSkillCancelTime(nAnimKeyID, (float)atof(szBuffer));
            }
			
			if(pAnimEventNode)
			{
				pAnimEventNode->Release();
				pAnimEventNode = NULL;
			}
		}

		if( nAnimKeyID != -1 )
			pModelToolCharData->Add(nAnimKeyID, fDurationTime, byPushCount, byKnockDownCount, byHitCount, aHitTime, bKB2Push);

		nAnimKeyID = 0;
		fDurationTime = 0;
		byPushCount = 0;
		byKnockDownCount = 0;
		byHitCount = 0;

		if(pAnimEventList)
		{
			pAnimEventList->Release();
			pAnimEventList = NULL;
		}
		
		if(pAnimDataNode)
		{
			pAnimDataNode->Release(); 
			pAnimDataNode = NULL;
		}
	}

	//pModelToolCharData->GetChainAttack(PC_CLASS_HUMAN_FIGHTER, ITEM_TYPE_UNKNOWN, 6);
	if(pAnimDataList)
	{
		pAnimDataList->Release(); 
		pAnimDataList = NULL;
	}

	char *pTokenStart = NULL;
	char *pTokenEnd = NULL;
	char szToken[64];

	if( !doc.GetDataWithXPath("MODEL_SCRIPT/HEADER/ANIM_BBOX", szBuffer, sizeof(szBuffer)) )
	{
		_ASSERT(0);
		return false;
	}
	
	CNtlVector vTemp;
	pTokenStart = szBuffer;
	pTokenEnd = strstr( szBuffer, ";");
	strncpy_s(szToken, sizeof(szToken), pTokenStart, pTokenEnd - pTokenStart);
	vTemp.x = (float) atof(szToken);

	pTokenStart = pTokenEnd + 1;
	pTokenEnd = strstr( pTokenStart, ";");
	strncpy_s(szToken, sizeof(szToken), pTokenStart, pTokenEnd - pTokenStart);
	vTemp.y = (float) atof(szToken);

	pTokenStart = pTokenEnd + 1;
	strncpy_s(szToken, sizeof(szToken), pTokenStart, strlen(szBuffer));
	vTemp.z = (float) atof(szToken);

	pModelToolCharData->m_vMin.x = -(vTemp.x / 2.0f);
	pModelToolCharData->m_vMin.y = 0.0f;
	pModelToolCharData->m_vMin.z = -(vTemp.z / 2.0f);
	
	pModelToolCharData->m_vMax.x = vTemp.x / 2.0f;
	pModelToolCharData->m_vMax.y = vTemp.y;
	pModelToolCharData->m_vMax.z = vTemp.z / 2.0f;

	if( !doc.GetDataWithXPath("MODEL_SCRIPT/BONE_DATA/BASE_SCALE", szBuffer, sizeof(szBuffer)) )
	{
		_ASSERT(0);
		return false;
	}

	pModelToolCharData->m_fScale = (float) atof(szBuffer);
	
	return true;
}
Exemplo n.º 15
0
DAPI_(HRESULT) BalConditionsParseFromXml(
    __in BAL_CONDITIONS* pConditions,
    __in IXMLDOMDocument* pixdManifest,
    __in_opt WIX_LOCALIZATION* pWixLoc
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pNodeList = NULL;
    IXMLDOMNode* pNode = NULL;
    BAL_CONDITION* prgConditions = NULL;
    DWORD cConditions = 0;

    hr = XmlSelectNodes(pixdManifest, L"/BootstrapperApplicationData/WixBalCondition", &pNodeList);
    ExitOnFailure(hr, "Failed to select all conditions.");

    hr = pNodeList->get_length(reinterpret_cast<long*>(&cConditions));
    ExitOnFailure(hr, "Failed to get the condition count.");

    if (!cConditions)
    {
        ExitFunction();
    }

    prgConditions = static_cast<BAL_CONDITION*>(MemAlloc(sizeof(BAL_CONDITION) * cConditions, TRUE));
    ExitOnNull(prgConditions, hr, E_OUTOFMEMORY, "Failed to allocate memory for conditions.");

    DWORD iCondition = 0;
    while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL)))
    {
        hr = XmlGetAttributeEx(pNode, L"Condition", &prgConditions[iCondition].sczCondition);
        ExitOnFailure(hr, "Failed to get condition for condition.");

        hr = XmlGetAttributeEx(pNode, L"Message", &prgConditions[iCondition].sczMessage);
        ExitOnFailure(hr, "Failed to get message for condition.");

        if (pWixLoc && prgConditions[iCondition].sczMessage && *prgConditions[iCondition].sczMessage)
        {
            hr = LocLocalizeString(pWixLoc, &prgConditions[iCondition].sczMessage);
            ExitOnFailure(hr, "Failed to localize condition message.");
        }

        ++iCondition;
        ReleaseNullObject(pNode);
    }
    ExitOnFailure(hr, "Failed to parse all condition elements.");

    if (S_FALSE == hr)
    {
        hr = S_OK;
    }

    pConditions->cConditions = cConditions;
    pConditions->rgConditions = prgConditions;
    prgConditions = NULL;

LExit:
    ReleaseMem(prgConditions);
    ReleaseObject(pNode);
    ReleaseObject(pNodeList);

    return hr;
}
Exemplo n.º 16
0
IXMLDOMNode* SettingsXML::FindItem(IXMLDOMNode* apFrom, const wchar_t* asType, const wchar_t* asName, bool abAllowCreate)
{
	HRESULT hr = S_OK;
	IXMLDOMNodeList* pList = NULL;
	IXMLDOMNode* pChild = NULL;
	IXMLDOMNamedNodeMap* pAttrs = NULL;
	IXMLDOMAttribute *pIXMLDOMAttribute = NULL;
	IXMLDOMNode *pIXMLDOMNode = NULL;
	IXMLDOMNode *pName = NULL;
	BSTR bsText = NULL;
	BSTR bsCheck = NULL;
	DOMNodeType nodeTypeCheck = NODE_INVALID;
	BOOL lbEmpty = TRUE;
	int iLastIndent = 1;

	// Получить все дочерние элементы нужного типа
	if (apFrom == NULL)
	{
		hr = S_FALSE;
	}
	else
	{
		long lFound = 0;
		// key[@name="abc"], but it is case-sensitive, and may fails in theory
		bsText = lstrmerge(asType, L"[@name=\"", asName, L"\"]");
		hr = apFrom->selectNodes(bsText, &pList);
		if (SUCCEEDED(hr) && pList)
		{
			hr = pList->get_length(&lFound);
			if (FAILED(hr) || (lFound < 1))
			{
				SafeRelease(pList);
			}
		}
		SafeFree(bsText);
		// May be case-insensitive search will be succeeded?
		// However, it is very slow
		if (!pList)
		{
			bsText = ::SysAllocString(asType);
			hr = apFrom->selectNodes(bsText, &pList);
			::SysFreeString(bsText); bsText = NULL;
		}
	}

	if (SUCCEEDED(hr) && pList)
	{
		hr = pList->reset();

		while ((hr = pList->nextNode(&pIXMLDOMNode)) == S_OK && pIXMLDOMNode)
		{
			lbEmpty = FALSE;
			hr = pIXMLDOMNode->get_attributes(&pAttrs);

			if (SUCCEEDED(hr) && pAttrs)
			{
				bsText = GetAttr(pIXMLDOMNode, pAttrs, L"name");

				if (bsText)
				{
					if (lstrcmpi(bsText, asName) == 0)
					{
						::SysFreeString(bsText); bsText = NULL;
						pChild = pIXMLDOMNode; pIXMLDOMNode = NULL;
						break;
					}

					::SysFreeString(bsText); bsText = NULL;
				}
			}

			pIXMLDOMNode->Release(); pIXMLDOMNode = NULL;
		}

		pList->Release();
		//pList = NULL; -- для отладки
	}

	if (lbEmpty && abAllowCreate && (asType[0] == L'k'))
	{
		bsText = ::SysAllocString(L"value");
		hr = apFrom->selectNodes(bsText, &pList);
		::SysFreeString(bsText); bsText = NULL;
		if (SUCCEEDED(hr) && pList)
		{
			hr = pList->reset();
			if ((hr = pList->nextNode(&pIXMLDOMNode)) == S_OK && pIXMLDOMNode)
			{
				lbEmpty = FALSE;
				pIXMLDOMNode->Release(); pIXMLDOMNode = NULL;
			}
			pList->Release();
			//pList = NULL; -- для отладки
		}
	}

	if (!pChild && abAllowCreate)
	{
		if (asType[0] == L'k')
		{
			hr = apFrom->get_lastChild(&pChild);
			if (SUCCEEDED(hr) && pChild)
			{
				hr = pChild->get_nodeType(&nodeTypeCheck);
				if (SUCCEEDED(hr) && (nodeTypeCheck == NODE_TEXT))
				{
					hr = pChild->get_text(&bsCheck);
					if (SUCCEEDED(hr) && bsCheck)
					{
						iLastIndent = 0;
						LPCWSTR pszTabs = bsCheck;
						while (*pszTabs)
						{
							if (*(pszTabs++) == L'\t')
								iLastIndent++;
						}
						::SysFreeString(bsCheck); bsCheck = NULL;
					}
				}
			}
			SafeRelease(pChild);
		}

		VARIANT vtType; vtType.vt = VT_I4;
		vtType.lVal = NODE_ELEMENT;
		bsText = ::SysAllocString(asType);
		hr = mp_File->createNode(vtType, bsText, L"", &pChild);
		::SysFreeString(bsText); bsText = NULL;

		if (SUCCEEDED(hr) && pChild)
		{
			if (SetAttr(pChild, L"name", asName))
			{
				if (asType[0] == L'k')
				{
					AppendNewLine(pChild);
					mb_KeyEmpty = true;
					TouchKey(pChild);
				}

				if (asType[0] == L'k')
				{
					//if (mb_KeyEmpty)
					//AppendIndent(apFrom, lbEmpty ? (mi_Level-1) : mi_Level);
					AppendIndent(apFrom, (mi_Level-iLastIndent));
				}
				else if (mb_KeyEmpty)
				{
					AppendIndent(apFrom, !lbEmpty ? (mi_Level-1) : mi_Level);
				}
				else
				{
					AppendIndent(apFrom, 1);
				}
				hr = apFrom->appendChild(pChild, &pIXMLDOMNode);
				pChild->Release(); pChild = NULL;

				if (FAILED(hr))
				{
					pAttrs->Release(); pAttrs = NULL;
				}
				else
				{
					pChild = pIXMLDOMNode;
					pIXMLDOMNode = NULL;
				}

				AppendNewLine(apFrom);
				AppendIndent(apFrom, mi_Level-1);
				if ((asType[0] != L'k') && mb_KeyEmpty)
					mb_KeyEmpty = false;
			}
			else
			{
				pChild->Release(); pChild = NULL;
			}
		}
	}

	return pChild;
}
Exemplo n.º 17
0
void queryNodes()
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pNodes = NULL;
    IXMLDOMNode *pNode = NULL;

    BSTR bstrQuery1 = NULL;
    BSTR bstrQuery2 = NULL;
    BSTR bstrNodeName = NULL;
    BSTR bstrNodeValue = NULL;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
    VariantInit(&varFileName);

    CHK_HR(CreateAndInitDOM(&pXMLDom));

    CHK_HR(VariantFromString(L"stocks.xml", varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

    // Query a single node.
    bstrQuery1 = SysAllocString(L"//stock[1]/*");
    CHK_ALLOC(bstrQuery1);
    CHK_HR(pXMLDom->selectSingleNode(bstrQuery1, &pNode));
    if (pNode)
    {
        printf("Result from selectSingleNode:\n");
        CHK_HR(pNode->get_nodeName(&bstrNodeName));
        printf("Node, <%S>:\n", bstrNodeName);
        SysFreeString(bstrNodeName);

        CHK_HR(pNode->get_xml(&bstrNodeValue));
        printf("\t%S\n\n", bstrNodeValue);
        SysFreeString(bstrNodeValue);
        SAFE_RELEASE(pNode);
    }
    else
    {
        CHK_HR(ReportParseError(pXMLDom, "Error while calling selectSingleNode."));
    }

    // Query a node-set.
    bstrQuery2 = SysAllocString(L"//stock[1]/*");
    CHK_ALLOC(bstrQuery2);
    CHK_HR(pXMLDom->selectNodes(bstrQuery2, &pNodes));
    if(pNodes)
    {
        printf("Results from selectNodes:\n");
        //get the length of node-set
        long length;
        CHK_HR(pNodes->get_length(&length));
        for (long i = 0; i < length; i++)
        {
            CHK_HR(pNodes->get_item(i, &pNode));
            CHK_HR(pNode->get_nodeName(&bstrNodeName));
			/*if(0== wcscmp(bstrNodeValue, L"symbol"))
			{
				 
			}
           */
			printf("Node (%d), <%S>:\n", i, bstrNodeName);
            SysFreeString(bstrNodeName);

            CHK_HR(pNode->get_xml(&bstrNodeValue));
			
            printf("\t%S\n", bstrNodeValue);
            SysFreeString(bstrNodeValue);
            SAFE_RELEASE(pNode);
        }
    }
    else
    {
        CHK_HR(ReportParseError(pXMLDom, "Error while calling selectNodes."));
    }

CleanUp:
    SAFE_RELEASE(pXMLDom);
    SAFE_RELEASE(pNodes);
    SAFE_RELEASE(pNode);
    SysFreeString(bstrQuery1);
    SysFreeString(bstrQuery2);
    SysFreeString(bstrNodeName);
    SysFreeString(bstrNodeValue);
    VariantClear(&varFileName);
}
Exemplo n.º 18
0
string CKADmerge::GetPatternString(IXMLDOMNode * pXMLNode, BOOL bQuery)
{
    HRESULT hRes = 0;
    string sPatternString = "";
    string sElementName;

    if(pXMLNode)
    {
        // retrieve node name
        sElementName = GetName(pXMLNode);
        sPatternString = sElementName;

        if(SUCCEEDED(hRes))
        {
            // retrieve all attributes
            IXMLDOMNodeList * pNodeList = NULL;
            BSTR bPatternString = NULL;
            bPatternString = ::SysAllocString(L"@*");
            _bstr_t b2PatternString(bPatternString);
            hRes = pXMLNode->selectNodes(bPatternString, &pNodeList);
            ::SysFreeString(bPatternString);

            LONG lListLength = 0;
            hRes = pNodeList->get_length(&lListLength);

            if(SUCCEEDED(hRes) && lListLength)
            {
                // retrive attribute names
                IXMLDOMNode * pCurrentNode = NULL;
                hRes = pNodeList->nextNode(&pCurrentNode);
                string sAttributeName;
                while(pCurrentNode != NULL)
                {
                    // attach attibute names and values to pattern string
                    sAttributeName = GetName(pCurrentNode);

                    if(!bQuery)
                    {
                        // all attributes
                        if(sPatternString.find("[") == -1)
                        {
                            sPatternString += "[";
                        }
                        else
                        {
                            sPatternString += " and " ;
                        }
                        sPatternString += "@" + sAttributeName;
                        sPatternString += "=\"" + ExpandBackslash(GetValue(pCurrentNode)) + "\"";
                    }
                    else
                    {
                        // just "primary key" (only first attribute)
                        if(sPatternString.find("[") == -1)
                        {
                            sPatternString += "[";
                        }
                        sPatternString += "@" + sAttributeName;
                        sPatternString += "=\"" + ExpandBackslash(GetValue(pCurrentNode)) + "\"";

                        break;
                    }
                    hRes = pNodeList->nextNode(&pCurrentNode);
                }
                if(sPatternString.find("[") != -1)
                {
                    sPatternString += "]";
                }
            }
            if(pNodeList)
                pNodeList->Release();
        }
    }

    return sPatternString;
}
Exemplo n.º 19
0
HRESULT CKADmerge::GetKADFilenames(string * sFilenames[], LONG &lLength, string sLogFile)
{
    HRESULT hRes = S_FALSE;

    if(sLogFile != "")
    {
        // open log file
        OpenLog(sLogFile, sDescription + " GetKADFileNames");
    }

    IXMLDOMNode * pXMLRoot = NULL;
    hRes = GetRootElement(m_pXMLKad, &pXMLRoot);

    if(hRes == S_OK)
    {
        // find elements
        IXMLDOMNodeList * pElemList = NULL;
        _bstr_t bPatternString("/KAD4CE/KERNEL/ADDON[@KADFILE]");
        hRes = pXMLRoot->selectNodes(bPatternString, &pElemList);

        if(SUCCEEDED(hRes))
        {
            LONG lElements = 0;
            pElemList->get_length(&lElements);

            (*sFilenames) = new string[lElements];

            IXMLDOMNode * pCurrentElem = NULL;
            hRes = pElemList->nextNode(&pCurrentElem);
            int i = 0;
            while(pCurrentElem != NULL)
            {
                // find 'KADFILE' attribute
                IXMLDOMNodeList * pAttrList = NULL;
                _bstr_t bPatternString("@KADFILE");
                hRes = pCurrentElem->selectNodes(bPatternString, &pAttrList);

                if(SUCCEEDED(hRes))
                {
                    LONG lAtributes = 0;
                    pAttrList->get_length(&lAtributes);

                    IXMLDOMNode * pCurrentAttr = NULL;
                    hRes = pAttrList->nextNode(&pCurrentAttr);
                    if(lAtributes == 1)
                    {
                        (*sFilenames)[i++] = GetValue(pCurrentAttr);
                    }
                    if(pCurrentAttr)
                        pCurrentAttr->Release();
                }
                hRes = pElemList->nextNode(&pCurrentElem);
                if(pAttrList)
                    pAttrList->Release();
            }
            lLength = i;
            hRes = S_OK;

            if(pCurrentElem)
                pCurrentElem->Release();
        }

        if(pXMLRoot)
            pXMLRoot->Release();
        if(pElemList)
            pElemList->Release();
    }

    if(hRes == S_OK)
    {
        Log("GetKADFilenames:");
        for(int i = 0; i < (int)lLength; i++)
        {
            Log((*sFilenames)[i]);
        }
    }

    // close log file
    CloseLog();

    return hRes;
}
Exemplo n.º 20
0
HRESULT CKADmerge::CopyNode(IXMLDOMNode ** pXMLDest, IXMLDOMNode ** pXMLSrc, BOOL bOverwrite, string sPath)
{
    HRESULT hRes = 0;

    IXMLDOMNodeList * pNodeList = NULL;

    if(*pXMLDest == NULL || *pXMLSrc == NULL)
    {
        Log("ERROR: CopyNode " + GetName(*pXMLSrc) + " to " + GetName(*pXMLDest));
        hRes = S_FALSE;
        return hRes;
    }

    hRes = (*pXMLSrc)->get_childNodes(&pNodeList);

    if(SUCCEEDED(hRes))
    {
        LONG lListLength = 0;
        hRes = pNodeList->get_length(&lListLength);

        IXMLDOMNode * pCurrentNode = NULL;
        hRes = pNodeList->nextNode(&pCurrentNode);

        while(pCurrentNode != NULL)
        {
            // iterate through the xml tree
            string sPatternString = GetPatternString(pCurrentNode, TRUE);

            IXMLDOMNode * pDestNode = NULL;
            BOOL bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);
            if(bHasNode && (!m_Overwriteable[GetName(pCurrentNode)] || !bOverwrite ))
            {
                // copy child elements
                CopyNode(&pDestNode, &pCurrentNode, bOverwrite, sPath + "/" + sPatternString);
            }
            else if(bHasNode && m_Overwriteable[GetName(pCurrentNode)] && bOverwrite)
            {
                // compare element
                sPatternString = GetPatternString(pCurrentNode, TRUE);
                bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);

                if(bHasNode)
                {
                    sPatternString = GetPatternString(pCurrentNode, FALSE);
                    bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);

                    if(!bHasNode)
                    {
                        // replace element
                        IXMLDOMNode * pNewNode = NULL;
                        IXMLDOMNode * pXMLOldChild = NULL;

                        hRes = pCurrentNode->cloneNode(VARIANT_TRUE, &pNewNode);
                        hRes = (*pXMLDest)->replaceChild(pNewNode,          // new child
                                                         pDestNode,         // old child
                                                         &pXMLOldChild);    // out old child

                        // log changes
                        Log("Replace Element: " + sPath + "/" + sPatternString);

                        if(pNewNode)
                            pNewNode->Release();
                        if(pXMLOldChild)
                            pXMLOldChild->Release();
                        m_bIsDirty = TRUE;
                    }
                }
            }
            else if(!bHasNode)
            {
                // attach entire sub tree
                IXMLDOMNode * pDestNode = NULL;
                IXMLDOMNode * pXMLNewChild = NULL;
                hRes = pCurrentNode->cloneNode(VARIANT_TRUE, &pDestNode);
                hRes = (*pXMLDest)->appendChild(pDestNode,          // new child
                                                &pXMLNewChild);     // out new child

                // log changes
                sPatternString = GetPatternString(pCurrentNode, FALSE);
                Log("Attach Element: " + sPath + "/" + sPatternString);

                if(pDestNode)
                    pDestNode->Release();
                if(pXMLNewChild)
                    pXMLNewChild->Release();
                m_bIsDirty = TRUE;
            }

            hRes = pNodeList->nextNode(&pCurrentNode);
        }
    }

    return hRes;
}
Exemplo n.º 21
0
// Checks whether at least one of required supported frameworks is installed via the NETFX registry keys.
static HRESULT CheckSupportedFrameworks(
    __in LPCWSTR wzConfigPath
    )
{
    HRESULT hr = S_OK;
    IXMLDOMDocument* pixdManifest = NULL;
    IXMLDOMNodeList* pNodeList = NULL;
    IXMLDOMNode* pNode = NULL;
    DWORD cSupportedFrameworks = 0;
    LPWSTR sczSupportedFrameworkVersion = NULL;
    LPWSTR sczFrameworkRegistryKey = NULL;
    HKEY hkFramework = NULL;
    DWORD dwFrameworkInstalled = 0;
    BOOL fUpdatedManifest = FALSE;

    hr = XmlInitialize();
    ExitOnFailure(hr, "Failed to initialize XML.");

    hr = XmlLoadDocumentFromFile(wzConfigPath, &pixdManifest);
    ExitOnFailure1(hr, "Failed to load bootstrapper config file from path: %ls", wzConfigPath);

    hr = XmlSelectNodes(pixdManifest, L"/configuration/wix.bootstrapper/host/supportedFramework", &pNodeList);
    ExitOnFailure(hr, "Failed to select all supportedFramework elements.");

    hr = pNodeList->get_length(reinterpret_cast<long*>(&cSupportedFrameworks));
    ExitOnFailure(hr, "Failed to get the supported framework count.");

    if (cSupportedFrameworks)
    {
        while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL)))
        {
            hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion);
            ExitOnFailure(hr, "Failed to get supportedFramework/@version.");

            hr = StrAllocFormatted(&sczFrameworkRegistryKey, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\%ls", sczSupportedFrameworkVersion);
            ExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key.");

            hr = RegOpen(HKEY_LOCAL_MACHINE, sczFrameworkRegistryKey, KEY_READ, &hkFramework);
            if (SUCCEEDED(hr))
            {
                hr = RegReadNumber(hkFramework, L"Install", &dwFrameworkInstalled);
                if (dwFrameworkInstalled)
                {
                    hr = S_OK;
                    break;
                }
            }

            ReleaseNullObject(pNode);
        }

        // If we looped through all the supported frameworks but didn't find anything, ensure we return a failure.
        if (S_FALSE == hr)
        {
            hr = E_NOTFOUND;
            ExitOnRootFailure(hr, "Failed to find a supported framework.");
        }

        hr = UpdateSupportedRuntime(pixdManifest, pNode, &fUpdatedManifest);
        ExitOnFailure(hr, "Failed to update supportedRuntime.");
    }
    // else no supported frameworks specified, so the startup/supportedRuntime must be enough.

    if (fUpdatedManifest)
    {
        hr = XmlSaveDocument(pixdManifest, wzConfigPath);
        ExitOnFailure1(hr, "Failed to save updated manifest over config file: %ls", wzConfigPath);
    }

LExit:
    ReleaseRegKey(hkFramework);
    ReleaseStr(sczFrameworkRegistryKey);
    ReleaseStr(sczSupportedFrameworkVersion);
    ReleaseObject(pNode);
    ReleaseObject(pNodeList);
    ReleaseObject(pixdManifest);

    XmlUninitialize();

    return hr;
}
Exemplo n.º 22
0
/*
	Function name	: CXML::ReplaceNodeText
	Description	    : This Helper function replaces the existing text with the given text of 
					: the given node. 
	Return type		: bool 
	Argument        : IXMLDOMNode **pNode
	Argument        : CString &rcsNodeText
	Tested			: 
*/
bool CXML::ReplaceNodeText(IXMLDOMNode **pNode,CString &rcsNodeText)
{
	IXMLDOMText  * pTextNode = NULL;
	if(!(*pNode))
		return false;

	IXMLDOMNode * pTempNode = NULL;
	DOMNodeType nodeType;
	IXMLDOMNode * pINewNode = NULL;
	IXMLDOMNode * pIOldNode = NULL;
	IXMLDOMNodeList * pChildList = NULL;
	long nLen = 0,i=0;


	_bstr_t bstrData(rcsNodeText);

	m_hr = m_pXMLDoc->createTextNode(bstrData,&pTextNode);
	if(!SUCCEEDED(m_hr) || !pTextNode)
		goto on_Error;	


	m_hr = (*pNode)->get_childNodes(&pChildList);
	if(!SUCCEEDED(m_hr) || !pChildList)
		goto on_Error;
	
	m_hr = pChildList->get_length(&nLen);
	if(!SUCCEEDED(m_hr))
		goto on_Error;

	if(nLen == 0)	// no childs, if the tag is empty
	{
		bool bRet = CreateNodeText(pNode,rcsNodeText);
		if(pChildList)
			pChildList->Release();
		if(pTextNode)
			pTextNode->Release();
		return bRet;		
	}

	for(i =0; i< nLen;++i)
	{
		m_hr = pChildList->nextNode(&pTempNode);
		if(!SUCCEEDED(m_hr))
			goto on_Error;

		m_hr = pTempNode->get_nodeType(&nodeType);
		if(!SUCCEEDED(m_hr))
			goto on_Error;

		if(nodeType == NODE_TEXT)
			break;

		if(pTempNode)
		{
			pTempNode->Release();
			pTempNode = NULL;
		}
	}

	m_hr = (*pNode)->replaceChild(pTextNode,pTempNode,&pINewNode);
	if(!SUCCEEDED(m_hr) || !pINewNode)
			goto on_Error;

	if(pChildList)
		pChildList->Release();
	if(pTextNode)
		pTextNode->Release();
	if(pINewNode)
		pINewNode->Release();
	if(pTempNode)
		pTempNode->Release();

	return true;


on_Error:	// Release all the References

	if(pChildList)
		pChildList->Release();
	if(pTextNode)
		pTextNode->Release();
	if(pINewNode)
		pINewNode->Release();
	if(pTempNode)
		pTempNode->Release();
	
	return false; 
}
Exemplo n.º 23
0
bool CModelToolCharDataTable::LoadPropertyList(const char *lpszPath, const char * lpszFileName)
{
	CNtlXMLDoc doc;
	std::string strPath( lpszPath );
	std::string strFileName;
	
	if(doc.Create() == false)
	{
		_ASSERT(0);
		return false;
	}
	
	strFileName = strPath;
	strFileName += "/";
	strFileName += lpszFileName;

	if(doc.Load( const_cast<char *>(strFileName.c_str()) ) == false)
	{
		_ASSERT(0);
		return false;
	}
	
	

	IXMLDOMNodeList *pList = doc.SelectNodeList(XML_PROP_LIST_ELEMENT);
	IXMLDOMNode* pNode = NULL;
	char szBuffer[1024];

	long  lNum;
	pList->get_length(&lNum);
	for(long i = 0; i < lNum ; ++i)
	{
		pList->get_item(i,&pNode);

		if(!doc.GetTextWithAttributeName(pNode, XML_PROP_LIST_ELEMENT_NAME_ATTRIBUTE, szBuffer, sizeof(szBuffer)))
		{
			_ASSERT(0);
			return false;
		}
		strFileName = strPath + "/" + szBuffer;
		
		if( LoadProperty( strFileName.c_str() ) == false )
		{
			_ASSERT(0);
			return false;
		}

		if(pNode)
		{
			pNode->Release(); 
			pNode = NULL;
		}
	}

	if(pList)
	{
		pList->Release(); 
		pList = NULL;
	}

	return true;
}
Exemplo n.º 24
0
extern "C" HRESULT ApprovedExesParseFromXml(
    __in BURN_APPROVED_EXES* pApprovedExes,
    __in IXMLDOMNode* pixnBundle
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pixnNodes = NULL;
    IXMLDOMNode* pixnNode = NULL;
    DWORD cNodes = 0;
    LPWSTR scz = NULL;

    // select approved exe nodes
    hr = XmlSelectNodes(pixnBundle, L"ApprovedExeForElevation", &pixnNodes);
    ExitOnFailure(hr, "Failed to select approved exe nodes.");

    // get approved exe node count
    hr = pixnNodes->get_length((long*)&cNodes);
    ExitOnFailure(hr, "Failed to get approved exe node count.");

    if (!cNodes)
    {
        ExitFunction();
    }

    // allocate memory for approved exes
    pApprovedExes->rgApprovedExes = (BURN_APPROVED_EXE*)MemAlloc(sizeof(BURN_APPROVED_EXE) * cNodes, TRUE);
    ExitOnNull(pApprovedExes->rgApprovedExes, hr, E_OUTOFMEMORY, "Failed to allocate memory for approved exe structs.");

    pApprovedExes->cApprovedExes = cNodes;

    // parse approved exe elements
    for (DWORD i = 0; i < cNodes; ++i)
    {
        BURN_APPROVED_EXE* pApprovedExe = &pApprovedExes->rgApprovedExes[i];

        hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
        ExitOnFailure(hr, "Failed to get next node.");

        // @Id
        hr = XmlGetAttributeEx(pixnNode, L"Id", &pApprovedExe->sczId);
        ExitOnFailure(hr, "Failed to get @Id.");

        // @Key
        hr = XmlGetAttributeEx(pixnNode, L"Key", &pApprovedExe->sczKey);
        ExitOnFailure(hr, "Failed to get @Key.");

        // @ValueName
        hr = XmlGetAttributeEx(pixnNode, L"ValueName", &pApprovedExe->sczValueName);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get @ValueName.");
        }

        // @Win64
        hr = XmlGetYesNoAttribute(pixnNode, L"Win64", &pApprovedExe->fWin64);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get @Win64.");
        }

        // prepare next iteration
        ReleaseNullObject(pixnNode);
        ReleaseNullStr(scz);
    }

    hr = S_OK;

LExit:
    ReleaseObject(pixnNodes);
    ReleaseObject(pixnNode);
    ReleaseStr(scz);
    return hr;
}
Exemplo n.º 25
0
static HRESULT ParsePackagesFromXml(
    __in BAL_INFO_PACKAGES* pPackages,
    __in IXMLDOMDocument* pixdManifest
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pNodeList = NULL;
    IXMLDOMNode* pNode = NULL;
    BAL_INFO_PACKAGE* prgPackages = NULL;
    DWORD cPackages = 0;
    LPWSTR sczType = NULL;

    hr = XmlSelectNodes(pixdManifest, L"/BootstrapperApplicationData/WixPackageProperties", &pNodeList);
    ExitOnFailure(hr, "Failed to select all packages.");

    hr = pNodeList->get_length(reinterpret_cast<long*>(&cPackages));
    ExitOnFailure(hr, "Failed to get the package count.");

    prgPackages = static_cast<BAL_INFO_PACKAGE*>(MemAlloc(sizeof(BAL_INFO_PACKAGE) * cPackages, TRUE));
    ExitOnNull(prgPackages, hr, E_OUTOFMEMORY, "Failed to allocate memory for packages.");

    DWORD iPackage = 0;
    while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL)))
    {
        hr = XmlGetAttributeEx(pNode, L"Package", &prgPackages[iPackage].sczId);
        ExitOnFailure(hr, "Failed to get package identifier for package.");

        hr = XmlGetAttributeEx(pNode, L"DisplayName", &prgPackages[iPackage].sczDisplayName);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get description for package.");
        }

        hr = XmlGetAttributeEx(pNode, L"Description", &prgPackages[iPackage].sczDescription);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get description for package.");
        }

        hr = XmlGetAttributeEx(pNode, L"PackageType", &sczType);
        ExitOnFailure(hr, "Failed to get description for package.");

        if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Exe", -1, sczType, -1))
        {
            prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_EXE;
        }
        else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msi", -1, sczType, -1))
        {
            prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSI;
        }
        else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msp", -1, sczType, -1))
        {
            prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSP;
        }
        else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msu", -1, sczType, -1))
        {
            prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSU;
        }

        hr = XmlGetYesNoAttribute(pNode, L"Permanent", &prgPackages[iPackage].fPermanent);
        ExitOnFailure(hr, "Failed to get permanent setting for package.");

        hr = XmlGetYesNoAttribute(pNode, L"Vital", &prgPackages[iPackage].fVital);
        ExitOnFailure(hr, "Failed to get vital setting for package.");

        hr = XmlGetYesNoAttribute(pNode, L"DisplayInternalUI", &prgPackages[iPackage].fDisplayInternalUI);
        ExitOnFailure(hr, "Failed to get DisplayInternalUI setting for package.");

        ++iPackage;
        ReleaseNullObject(pNode);
    }
    ExitOnFailure(hr, "Failed to parse all package property elements.");

    if (S_FALSE == hr)
    {
        hr = S_OK;
    }

    pPackages->cPackages = cPackages;
    pPackages->rgPackages = prgPackages;
    prgPackages = NULL;

LExit:
    ReleaseStr(sczType);
    ReleaseMem(prgPackages);
    ReleaseObject(pNode);
    ReleaseObject(pNodeList);

    return hr;
}
Exemplo n.º 26
0
LRESULT CAddVideoHtmlDlg::OnLoadCatalog(WPARAM wParam, LPARAM lParam)
{
	if(wParam == NULL)
	{
		MessageBox(TEXT("获取视频分类数据失败,请检查您的网络情况。"), TEXT("错误"), MB_OK|MB_ICONERROR);
		return 0;
	}

	try
	{
		TSTLSTRING strCatalogHtml;
		int iSelectedIndex = -1;

		IXMLDOMDocument* pDOM = NULL;
		HRESULT hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&pDOM);
		if(hr != S_OK)
		{
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		VARIANT_BOOL loaded = VARIANT_FALSE;
		hr = pDOM->loadXML(CComBSTR((LPCOLESTR)wParam), &loaded);
		if(hr != S_OK || loaded == VARIANT_FALSE)
		{
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNodeList* pNodeList = NULL;
		hr = pDOM->get_childNodes(&pNodeList);
		if(hr != S_OK)
		{
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNode* pRoot = NULL;
		hr = pNodeList->get_item(1, &pRoot);
		if(hr != S_OK)
		{
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNodeList* pRootChildren = NULL;
		hr = pRoot->get_childNodes(&pRootChildren);
		if(hr != S_OK)
		{
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNode* pResultNote = NULL;
		hr = pRootChildren->get_item(0, &pResultNote);
		if(hr != S_OK)
		{
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNodeList* pResultChildren = NULL;
		hr = pResultNote->get_childNodes(&pResultChildren);
		if(hr != S_OK)
		{
			pResultNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNode* pResultStatusNote = NULL;
		hr = pRootChildren->get_item(0, &pResultStatusNote);
		if(hr != S_OK)
		{
			pResultChildren->Release();
			pResultNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		CComBSTR bstrResultStatus;
		hr = pResultStatusNote->get_text(&bstrResultStatus);
		if(hr != S_OK)
		{
			pResultStatusNote->Release();
			pResultChildren->Release();
			pResultNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}
		pResultStatusNote->Release();

		if(bstrResultStatus != TEXT("o"))
		{
			IXMLDOMNode* pResultMessageNote = NULL;
			hr = pRootChildren->get_item(1, &pResultMessageNote);
			if(hr != S_OK)
			{
				pResultChildren->Release();
				pResultNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}

			CComBSTR bstrResultMessage;
			hr = pResultMessageNote->get_text(&bstrResultMessage);
			if(hr != S_OK)
			{
				pResultMessageNote->Release();
				pResultChildren->Release();
				pResultNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}
			pResultMessageNote->Release();
			pResultChildren->Release();
			pResultNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();

			throw Exception(bstrResultMessage.m_str);
		}

		pResultChildren->Release();
		pResultNote->Release();

		IXMLDOMNode* pItemNote = NULL;
		hr = pRootChildren->get_item(1, &pItemNote);
		if(hr != S_OK)
		{
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		IXMLDOMNodeList* pItemChildren = NULL;
		hr = pItemNote->get_childNodes(&pItemChildren);
		if(hr != S_OK)
		{
			pItemNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		long ItemCount = 0;
		pItemChildren->get_length(&ItemCount);
		if(hr != S_OK)
		{
			pItemChildren->Release();
			pItemNote->Release();
			pRootChildren->Release();
			pRoot->Release();
			pNodeList->Release();
			pDOM->Release();
			throw Exception(TEXT("解析视频分类数据失败。"));
		}

		for(int i=0; i<ItemCount; ++i)
		{
			IXMLDOMNode* pCatalogItemNote = NULL;
			hr = pItemChildren->get_item(i, &pCatalogItemNote);
			if(hr != S_OK)
			{
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}

			IXMLDOMNodeList* pCatalogItemChildren = NULL;
			hr = pCatalogItemNote->get_childNodes(&pCatalogItemChildren);
			if(hr != S_OK)
			{
				pCatalogItemNote->Release();
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}

			IXMLDOMNode* pCatalogIdNote = NULL;
			hr = pCatalogItemChildren->get_item(0, &pCatalogIdNote);
			if(hr != S_OK)
			{
				pCatalogItemChildren->Release();
				pCatalogItemNote->Release();
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}

			CComBSTR bstrCatalogId;
			hr = pCatalogIdNote->get_text(&bstrCatalogId);
			if(hr != S_OK)
			{
				pCatalogIdNote->Release();
				pCatalogItemChildren->Release();
				pCatalogItemNote->Release();
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}
			pCatalogIdNote->Release();

			IXMLDOMNode* pCatalogNameNote = NULL;
			hr = pCatalogItemChildren->get_item(1, &pCatalogNameNote);
			if(hr != S_OK)
			{
				pCatalogItemChildren->Release();
				pCatalogItemNote->Release();
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}
			CComBSTR bstrCatalogName;
			hr = pCatalogNameNote->get_text(&bstrCatalogName);
			if(hr != S_OK)
			{
				pCatalogNameNote->Release();
				pCatalogItemChildren->Release();
				pCatalogItemNote->Release();
				pItemChildren->Release();
				pItemNote->Release();
				pRootChildren->Release();
				pRoot->Release();
				pNodeList->Release();
				pDOM->Release();
				throw Exception(TEXT("解析视频分类数据失败。"));
			}
			pCatalogNameNote->Release();

			pCatalogItemChildren->Release();
			pCatalogItemNote->Release();

			TSTLSTRING strCurrID = TSTLSTRING(COLE2T(bstrCatalogId));

			TSTLSTRING strLastCatalog = ConfigureManager::GetInstance().GetLastCatalog();
			TSTLSTRING strCurrName = TSTLSTRING(COLE2T(bstrCatalogName));
			bool IsSelected = ((strLastCatalog.empty() && strCurrName == TEXT("其他")) ||
				(!strLastCatalog.empty() && strLastCatalog.compare(strCurrID) == 0));

			strCatalogHtml.append(TEXT("<div class=\"ComboxListItem\" onmouseover=\"this.className='ComboxListItemSelected';\" onclick=\"OnCatalogComboxClick();\" onmouseout=\"this.className='ComboxListItem';\" Value=\""));
			strCatalogHtml.append(strCurrID);
			strCatalogHtml.append(TEXT("\">"));
			strCatalogHtml.append(strCurrName);
			strCatalogHtml.append(TEXT("</div>"));

			if(IsSelected)
				iSelectedIndex = i;
		}

		pItemChildren->Release();
		pItemNote->Release();

		pRootChildren->Release();
		pRoot->Release();
		pNodeList->Release();
		pDOM->Release();

		DISPPARAMS dp;
		memset(&dp, 0, sizeof(DISPPARAMS));
		dp.cArgs = 2;
		dp.cNamedArgs = 0;

		VARIANTARG arg[2];
		memset(arg, 0, sizeof(VARIANTARG) * 2);
		dp.rgvarg = arg;

		CComBSTR bstr(strCatalogHtml.c_str());
		arg[0].vt = VT_BSTR;
		bstr.CopyTo(&arg[0].bstrVal);
		arg[1].vt = VT_INT;
		arg[1].intVal = iSelectedIndex;

		m_lpCatalogInvoke->Invoke(
			0, 
			IID_NULL, 
			LOCALE_SYSTEM_DEFAULT,
			DISPATCH_METHOD,
			&dp,
			NULL, NULL, NULL);

	}
	catch(Exception& error)
	{
		MessageBox(error.GetMessage().c_str(), TEXT("错误"), MB_OK|MB_ICONERROR);
	}

	return 0;
}
Exemplo n.º 27
0
extern "C" HRESULT DependencyParseProvidersFromXml(
    __in BURN_PACKAGE* pPackage,
    __in IXMLDOMNode* pixnPackage
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNodeList* pixnNodes = NULL;
    DWORD cNodes = 0;
    IXMLDOMNode* pixnNode = NULL;

    // Select dependency provider nodes.
    hr = XmlSelectNodes(pixnPackage, L"Provides", &pixnNodes);
    ExitOnFailure(hr, "Failed to select dependency provider nodes.");

    // Get dependency provider node count.
    hr = pixnNodes->get_length((long*)&cNodes);
    ExitOnFailure(hr, "Failed to get the dependency provider node count.");

    if (!cNodes)
    {
        ExitFunction1(hr = S_OK);
    }

    // Allocate memory for dependency provider pointers.
    pPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER) * cNodes, TRUE);
    ExitOnNull(pPackage->rgDependencyProviders, hr, E_OUTOFMEMORY, "Failed to allocate memory for dependency providers.");

    pPackage->cDependencyProviders = cNodes;

    // Parse dependency provider elements.
    for (DWORD i = 0; i < cNodes; i++)
    {
        BURN_DEPENDENCY_PROVIDER* pDependencyProvider = &pPackage->rgDependencyProviders[i];

        hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
        ExitOnFailure(hr, "Failed to get the next dependency provider node.");

        // @Key
        hr = XmlGetAttributeEx(pixnNode, L"Key", &pDependencyProvider->sczKey);
        ExitOnFailure(hr, "Failed to get the Key attribute.");

        // @Version
        hr = XmlGetAttributeEx(pixnNode, L"Version", &pDependencyProvider->sczVersion);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get the Version attribute.");
        }

        // @DisplayName
        hr = XmlGetAttributeEx(pixnNode, L"DisplayName", &pDependencyProvider->sczDisplayName);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get the DisplayName attribute.");
        }

        // @Imported
        hr = XmlGetYesNoAttribute(pixnNode, L"Imported", &pDependencyProvider->fImported);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get the Imported attribute.");
        }
        else
        {
            pDependencyProvider->fImported = FALSE;
            hr = S_OK;
        }

        // Prepare next iteration.
        ReleaseNullObject(pixnNode);
    }

    hr = S_OK;

LExit:
    ReleaseObject(pixnNode);
    ReleaseObject(pixnNodes);

    return hr;
}
Exemplo n.º 28
0
bool TextTable::InitializeFromXmlDoc(XMLDoc* pXmlDoc, WCHAR* pwszFileName, bool bReload)
{
	if (NULL == pXmlDoc)
	{
		return false;
	}

	BSTR rowXPathFormat;
	rowXPathFormat = ::SysAllocString(L"/dataroot/%s/F%d");
	WCHAR wszXPath[MAX_UNICODE_XPATH_LENGTH + 1];

	DWORD dwSheetIndex = 0;
	WCHAR** ppwszSheetList = GetSheetListInWChar();

	BSTR bstr = NULL;

	while (ppwszSheetList[dwSheetIndex])
	{
		swprintf_s<_countof(wszXPath)>(wszXPath, rowXPathFormat, ppwszSheetList[dwSheetIndex], m_nField);

		IXMLDOMNodeList* pIndexNodeList = NULL;
		pIndexNodeList = pXmlDoc->SelectNodeList(wszXPath);
		if (!pIndexNodeList)
		{
			::SysFreeString(rowXPathFormat);

			return false;
		}

		LONG nIndexLength = 0;
		if (FAILED(pIndexNodeList->get_length(&nIndexLength)))
		{
			pIndexNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		swprintf_s<_countof(wszXPath)>(wszXPath, rowXPathFormat, ppwszSheetList[dwSheetIndex], m_nField + 1);

		IXMLDOMNodeList* pTextNodeList = NULL;
		pTextNodeList = pXmlDoc->SelectNodeList(wszXPath);
		if (!pTextNodeList)
		{
			pIndexNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		LONG nTextLength = 0;
		if (FAILED(pTextNodeList->get_length(&nTextLength)))
		{
			pIndexNodeList->Release();
			pTextNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		if (nTextLength != nIndexLength)
		{
			pIndexNodeList->Release();
			pTextNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		// 제목은 버린다.
		for (INT j = 1; j < nIndexLength; ++j)
		{
			VOID* pvTable = AllocNewTable(ppwszSheetList[dwSheetIndex], m_dwCodePage);
			if (!pvTable)
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				::SysFreeString(rowXPathFormat);

				return false;
			}

			IXMLDOMNode* pCellNode = NULL;
			IXMLDOMNode* pDataNode = NULL;

			if (FAILED(pIndexNodeList->get_item(j, &pCellNode)))
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pCellNode)
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pCellNode->get_firstChild(&pDataNode)))
			{
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pDataNode)
			{
				pCellNode->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pDataNode->get_text(&bstr)))
			{
				::SysFreeString(bstr);
				pDataNode->Release();
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			SetTableData(pvTable, ppwszSheetList[dwSheetIndex], INDEX, bstr);

			::SysFreeString(bstr);
			pCellNode->Release();
			pDataNode->Release();

			pCellNode = NULL;
			pDataNode = NULL;

			if (FAILED(pTextNodeList->get_item(j, &pCellNode)))
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pCellNode)
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pCellNode->get_firstChild(&pDataNode)))
			{
				//- yoshiki : TODO!(Get the field name)
				Table::CallErrorCallbackFunction("[File] : %S\n[Error] : Table data is null.(Row Index : %d, Field Name = %S)", pwszFileName, j - 1, L"FIELD_NAME!");

				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pDataNode)
			{
				//- yoshiki : TODO!(Get the field name)
				Table::CallErrorCallbackFunction("[File] : %S\n[Error] : Table data is null.(Row Index : %d, Field Name = %S)", pwszFileName, j - 1, L"FIELD_NAME!");

				pCellNode->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				_ASSERT(0);		// Index는 있고 Data는 공란인경우.
				break;
			}

			if (FAILED(pDataNode->get_text(&bstr)))
			{
				::SysFreeString(bstr);
				pDataNode->Release();
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			SetTableData(pvTable, ppwszSheetList[dwSheetIndex], TEXT, bstr);

			::SysFreeString(bstr);
			pCellNode->Release();
			pDataNode->Release();

			if (!AddTable(pvTable, bReload))
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
			}
		}

		pIndexNodeList->Release();
		pTextNodeList->Release();
		++dwSheetIndex;
	}

	::SysFreeString(rowXPathFormat);

	return true;
}
STDMETHODIMP CStrokeRecognition::put_RecognitionParam(BSTR newVal)
{
	double		Segment_Error_Threshold;
	double		Arc_Error_Threshold;
	double		Arc_Min_Length;
	double		Arc_Min_Curve;
	double		Stroke_Min_Length;
	double		Min_Turning_Angle;
	double		Segmentation_Penalty;
	VARIANT		value;
	BSTR		nodeName;
	long		n;

	IXMLDOMDocument*		pDoc;
	IXMLDOMNodeList*		pNodeList;
	IXMLDOMNode*			pNode;
	IXMLDOMNode*			pParamNode;
	IXMLDOMNode*			pAttrNode;
	IXMLDOMNamedNodeMap*	pNodeMap;
	VARIANT_BOOL			bLoaded;

	GetFittingParam(Segment_Error_Threshold, Arc_Error_Threshold, Arc_Min_Length, Arc_Min_Curve, Stroke_Min_Length, Min_Turning_Angle, Segmentation_Penalty);

	if (SUCCEEDED(CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (LPVOID*)&pDoc)))
	{
		pDoc->put_async(VARIANT_FALSE);
		pDoc->loadXML(newVal, &bLoaded);

		if (bLoaded == VARIANT_TRUE)
		{
			if (SUCCEEDED(pDoc->get_childNodes(&pNodeList)))
			{
				pParamNode = NULL;

				pNodeList->get_length(&n);

				for (int i = 0; i < n; i++)
				{
					if (SUCCEEDED(pNodeList->get_item(i, &pNode)))
					{
						nodeName = NULL;
						if (SUCCEEDED(pNode->get_nodeName(&nodeName)))
						{
							if (CComBSTR(nodeName) == L"param")
							{
								pParamNode = pNode;
								pParamNode->AddRef();
								break;
							}
							SysFreeString(nodeName);
						}
						pNode->Release();
					}
				}

				pNodeList->Release();

				if (pParamNode != NULL)
				{
					if (SUCCEEDED(pParamNode->get_attributes(&pNodeMap)))
					{
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Segment_Error_Threshold", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Segment_Error_Threshold = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Arc_Error_Threshold", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Arc_Error_Threshold = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Arc_Min_Length", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Arc_Min_Length = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Arc_Min_Curve", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Arc_Min_Curve = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Stroke_Min_Length", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Stroke_Min_Length = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Min_Turning_Angle", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Min_Turning_Angle = _wtof(value.bstrVal);
							pAttrNode->Release();
						}
						if (SUCCEEDED(pNodeMap->getNamedItem(L"Segmentation_Penalty", &pAttrNode)))
						{
							pAttrNode->get_nodeValue(&value);
							Segmentation_Penalty = _wtof(value.bstrVal);
							pAttrNode->Release();
						}

						pNodeMap->Release();
					}

					pParamNode->Release();
				}
			}
		}

		pDoc->Release();
	}

	SetFittingParam(Segment_Error_Threshold, Arc_Error_Threshold, Arc_Min_Length, Arc_Min_Curve, Stroke_Min_Length, Min_Turning_Angle, Segmentation_Penalty);

	return S_OK;
}
Exemplo n.º 30
0
bool CKADInfo::load(
    CGT_CDiagMsg*   pdm,
	const TCHAR*    pszKADFileAndPath,
	const TCHAR*    pszTargetType,
    unsigned long   ulTrgVer
)
{
    long                i, o;
    long                len;
    long                len2;
    long                len3;
    IXMLDOMNodeList*    pNList;
    IXMLDOMNodeList*    pNList2;
    IXMLDOMNodeList*    pNList3;
    IXMLDOMNode*        pNode;
    IXMLDOMNode*        pNode2;
    int                 nCurrErrors;
    FC_CString          jot(MAX_PATH);
    bool                bTargetTypeFound = false;


    nCurrErrors = pdm->getTotalErrors();
    
	//clear possible old content:
    clear();

    m_szKADFile.load(pszKADFileAndPath);
    CG_InitSTEdipos(&m_KADEdp, m_szKADFile, 1);


    pNode = CGT_XMLLoadFile(pdm, NULL, m_szKADFile, L"KAD4VM");
    if(!pNode)
        return false;

    
    // read targets
    pNList = NULL;
    len = 0;
    pNode->selectNodes(L"TRGTYP", &pNList);
    assert(pNList);
    FC_RELEASE_PTR(pNode);

    pNList->get_length(&len);
    for(i=0;i<len;i++)
    {
        pNList->get_item(i, &pNode);

        if ( ! isCurrentTrgType(pdm, pszTargetType, pNode))
            continue;

        bTargetTypeFound = true;


        // <IEC_FEATURES> : read IEC features : dadta types , languages
        pNList2 = NULL;
        pNode->selectNodes(L"IEC_FEATURES", &pNList2);
        assert(pNList2);

        ReadIecFeatures(pdm, 
            m_szKADFile, 
            pNList2, 
            &m_AllowedIEClanguages, 
            &m_AllowedIECtypes, 
            &m_AllowedArrayIndexIECtypes,
            &m_lMaxTasks,
            &m_bLocalRetain,
            &m_CheckAddressSpace
        );

        FC_RELEASE_PTR(pNList2);

        

        // <TASKIMAGE> : read task image features : segments, size, optimize
        pNList2 = NULL;
        pNode->selectNodes(L"TASKIMAGE", &pNList2);
        assert(pNList2);

        ReadTaskImageFeature(pdm, 
            m_szKADFile, 
            pNList2, 
            &m_useTIforSegm,
            &m_optimizeTIforSegm,
            m_lMaxRegionsWR,
            m_lMaxRegionsRD,
            ulTrgVer);

        FC_RELEASE_PTR(pNList2);



        // <IOCOMPONENTS>
        pNList2 = NULL;
        pNode->selectNodes(L"IOCOMPONENTS", &pNList2);
        assert(pNList2);

        len2 = 0;
        pNList2->get_length(&len2);
        for(o=0;o<len2;o++)
        {
            pNList2->get_item(o, &pNode2);
            // <CHANNEL>
            pNList3 = NULL;
            pNode2->selectNodes(L"CHANNEL", &pNList3);
            ReadChannels(pdm, pNList3, &m_channels);
            FC_RELEASE_PTR(pNList3);
        }
        FC_RELEASE_PTR(pNList2);


        // <VM_SETTINGS> : read target features 
        pNList2 = NULL;
        pNode->selectNodes(L"VM_SETTINGS", &pNList2);
        assert(pNList2);

        ReadVmSettings(pdm, pNList2, &m_VmSettings);
        FC_RELEASE_PTR(pNList2);


        // <CG_OPTIONS> : read target code generator features 
        pNList2 = NULL;
        pNode->selectNodes(L"CG_OPTIONS", &pNList2);
        assert(pNList2);
        pNList2->get_length(&len3);
        if (len3 != 0)
        {
            // <CG_OPTIONS> is optional
            ReadCgOptions(pdm, pNList2, &m_CgOptions);
            FC_RELEASE_PTR(pNList2);
        }

        FC_RELEASE_PTR(pNode);
    }
    FC_RELEASE_PTR(pNList);

    if ( ! bTargetTypeFound)
    {
        pdm->msg1(CG_E_XML_TARGET_NOT_FOUND_IN_KAD, &m_KADEdp, pszTargetType);
        return false;
    }

    //finally check usage of channels if no error so far:
    if(nCurrErrors==pdm->getTotalErrors())
        ValidateChannels(pdm, &m_KADEdp, &m_channels, &m_VmSettings);

    return nCurrErrors==pdm->getTotalErrors();
}