BOOL CAutoUpdateDlg::CheckVersionUpdate(CString& strUpdateURL) { BOOL bHasUpdate = FALSE; HRESULT hr = S_OK; IXMLHTTPRequestPtr pHttpRequest; IDispatchPtr pDispatch; MSXML2::IXMLDOMDocumentPtr pXmlDoc; MSXML2::IXMLDOMNodeListPtr pList; MSXML2::IXMLDOMElementPtr pChild; UINT nFileSize; CString strFileName, strFileVer, strMD5String; LONG lElementCount = 0L; try { hr = pHttpRequest.CreateInstance(TEXT("Msxml2.XMLHTTP.3.0")); if( FAILED(hr) ) _com_issue_error(hr); hr = pHttpRequest->open(TEXT("GET"), (_bstr_t)strUpdateURL, false); if( FAILED(hr) ) _com_issue_error(hr); hr = pHttpRequest->send(); if( FAILED(hr) ) _com_issue_error(hr); if (pHttpRequest->Getstatus() != 200) throw (0); pDispatch = pHttpRequest->GetresponseXML(); hr = pDispatch->QueryInterface(pXmlDoc.GetIID(), (void**)&pXmlDoc); if( FAILED(hr) ) _com_issue_error(hr); pList = pXmlDoc->selectNodes("/manifest/filelist/file"); lElementCount = pList->Getlength(); for( LONG i = 0; i < lElementCount; i++ ) { pChild = pList->Getitem(i); strFileName = pChild->getAttribute("filename"); nFileSize = pChild->getAttribute("filesize"); strFileVer = pChild->getAttribute("fileversion"); strMD5String = pChild->getAttribute("md5"); //如果本地文件存在则效验文件,不存在就下载这个文件 if (PathFileExists(m_strCurrentDir+strFileName)) { //效验文件,如果MD5码不相同则重新下载 if (CMD5Checksum::GetMD5(m_strCurrentDir+strFileName) != strMD5String) { m_ulTotalLength += nFileSize; m_DownloadMgr.AddTask(strFileName); bHasUpdate = TRUE; } } else { m_ulTotalLength += nFileSize; m_DownloadMgr.AddTask(strFileName); bHasUpdate = TRUE; } } return bHasUpdate; } #ifdef _DEBUG catch(_com_error& e) { CString strError; strError.Format(_T("Error code:%d\nMessage:%s\nDescrption:%s"), (int)e.WCode(), e.ErrorMessage(), (TCHAR*)e.Description()); MessageBox(strError, _T("提示"), MB_OK|MB_ICONWARNING); return FALSE; } #endif catch(...) { return FALSE; } }
void CShootManagerSys::LoadShootSolutionSector(int iSector, LPCTSTR szFilename) { if(iSector >= m_ShootSolutionSectorArray.Num()) return; int i; MSXML2::IXMLDOMDocument2Ptr pDoc; pDoc.CreateInstance(__uuidof(DOMDocument40)); pDoc->load((_variant_t)szFilename); // 성공한 슛부터 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListSuccess = pDoc->selectNodes(L"root/success"); for(i=0; i<pNodeListSuccess->Getlength(); i++) { MSXML2::IXMLDOMNodePtr pNodeSuccess = pNodeListSuccess->Getitem(i); CShootSolution Solution; Solution.Create(pNodeSuccess, true, this); m_ShootSolutionSectorArray[iSector].first.push_back(Solution); } MSXML2::IXMLDOMNodeListPtr pNodeListFail = pDoc->selectNodes(L"root/fail"); for(i=0; i<pNodeListFail->Getlength(); i++) { MSXML2::IXMLDOMNodePtr pNodeFail = pNodeListFail->Getitem(i); CShootSolution Solution; Solution.Create(pNodeFail, false, this); m_ShootSolutionSectorArray[iSector].second.push_back(Solution); } pDoc.Release(); }
//遍历指定节点列表的数据 BOOL CXmlBase::FetchNodeList(LPCTSTR lpszXmlPathFile, LPCTSTR lpszNamespace , LPCTSTR lpszNodeListXPath, DWORD dwFlag) { MSXML2::IXMLDOMDocument2Ptr pDoc = NULL; MSXML2::IXMLDOMNodeListPtr pNodeList = NULL; MSXML2::IXMLDOMNodePtr pNode = NULL; long lNodeCount = 0; HRESULT hr = S_OK; if (!IsAccessibleFile(lpszXmlPathFile)) return FALSE; pDoc = GetXmlDocPtrByFile(lpszXmlPathFile, lpszNamespace); if (pDoc == NULL) return FALSE; pNodeList = GetNodeListPtr(lpszNodeListXPath, pDoc); if (pNodeList == NULL) return FALSE; lNodeCount = pNodeList->Getlength(); for (int i=0; i<lNodeCount; i++) { hr = pNodeList->get_item(i, &pNode); if (FAILED(hr) || NULL == pNode) return FALSE; if (!OnFetchNodeList(pNode, dwFlag)) return FALSE; } return TRUE;//(lNodeCount != 0); }
//遍历指定节点列表的数据 BOOL CXmlBase::FetchNodeList2(MSXML2::IXMLDOMNodePtr pParentNode, DWORD dwFlag) { MSXML2::IXMLDOMNodeListPtr pNodeList = NULL; MSXML2::IXMLDOMNodePtr pNode = NULL; long lNodeCount = 0; HRESULT hr = S_OK; if (NULL == pParentNode) { return FALSE; } pNodeList = GetNodeListPtr(pParentNode); if (pNodeList == NULL) { return FALSE; } lNodeCount = pNodeList->Getlength(); for (long i=0; i<lNodeCount; i++) { hr = pNodeList->get_item(i, &pNode); if (FAILED(hr) || NULL == pNode) { return FALSE; } if (!OnFetchNodeList2(pNode, dwFlag)) { return FALSE; } } return TRUE; }
//设置指定xpath的节点值 BOOL CXmlBase::SetNodeValue(LPCTSTR lpszValue, LPCTSTR lpszXPath , MSXML2::IXMLDOMDocument2Ptr pDoc) { if (pDoc == NULL || lpszXPath == NULL) return FALSE; MSXML2::IXMLDOMNodeListPtr pNodeList = pDoc->selectNodes(lpszXPath); long lCnt = pNodeList->Getlength(); if (lCnt == 0) return FALSE; MSXML2::IXMLDOMNodePtr pNode = pNodeList->Getitem(0); return SetNodeValue(lpszValue, pNode); }
BOOL CIconImgList::PickUpGroups( MSXML2::IXMLDOMElementPtr& piGroup, int& nIndex) { MSXML2::IXMLDOMNodeListPtr piGroupList; piGroupList = piGroup->GetchildNodes(); MSXML2::IXMLDOMElementPtr piNode; MSXML2::IXMLDOMElementPtr piChild; int nParent = nIndex; _bstr_t cBstr; _variant_t cVariant; long lCount = piGroupList->Getlength(); for( long lIndex = 0; lIndex < lCount; lIndex++) { piNode = piGroupList->Getitem( lIndex); if( _bstr_t( _T( "GROUP")) == piNode->GetbaseName()) { cBstr = piNode->getAttribute( _bstr_t( _T( "TITLE"))); cVariant = piNode->getAttribute( _bstr_t( _T( "ENABLE"))); cVariant.ChangeType( VT_BOOL); m_astGroupData[ nIndex] = ( GROUPDATA*)malloc( sizeof( GROUPDATA) + ( sizeof( TCHAR) * ( cBstr.length() + 1))); m_astGroupData[ nIndex]->nParent = nParent; if( 1 <= nIndex) { if( FALSE == m_astGroupData[ nParent]->blEnable) { cVariant.boolVal = VARIANT_FALSE; } } m_astGroupData[ nIndex]->blEnable = ( VARIANT_FALSE == cVariant.boolVal) ? FALSE : TRUE; lstrcpy( m_astGroupData[ nIndex]->szName, cBstr); nIndex++; PickUpGroups( piNode, nIndex); } else if( _bstr_t( _T( "ITEM")) == piNode->GetbaseName()) { cVariant = piNode->getAttribute( _bstr_t( _T( "REF"))); cVariant.ChangeType( VT_I4); for( int nIndex = 0; nIndex < m_nEnableCount; nIndex++) { if( cVariant.intVal == ( m_astIconStatus[ nIndex].nID + 1)) { m_astIconStatus[ nIndex].nParent = nParent; } } } } return TRUE; }
void CShootManagerSys::LoadShootSolutionSector(int iSector, SFullName nameFile) { if(iSector >= m_ShootSolutionSectorArray.Num()) return; int i; MSXML2::IXMLDOMDocument2Ptr pDoc = NULL; DFileGPack packFile; packFile.Open(nameFile); CFileSys::LoadBinaryXML(pDoc, packFile.GetFile(), packFile.GetSize()); packFile.Close(); // 성공한 슛부터 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListSuccess = pDoc->selectNodes(L"root/success"); for(i=0; i<pNodeListSuccess->Getlength(); i++) { MSXML2::IXMLDOMNodePtr pNodeSuccess = pNodeListSuccess->Getitem(i); CShootSolution Solution; Solution.Create(pNodeSuccess, true, this); Solution.SetSectorIndex(iSector); m_ShootSolutionSectorArray[iSector].first.push_back(Solution); } MSXML2::IXMLDOMNodeListPtr pNodeListFail = pDoc->selectNodes(L"root/fail"); for(i=0; i<pNodeListFail->Getlength(); i++) { MSXML2::IXMLDOMNodePtr pNodeFail = pNodeListFail->Getitem(i); CShootSolution Solution; Solution.Create(pNodeFail, false, this); Solution.SetSectorIndex(iSector); m_ShootSolutionSectorArray[iSector].second.push_back(Solution); } CFileSys::UnloadXML(pDoc); }
//装入项目 void CUpdateBuilderDlg::OnBnClickedLoadItem() { CFileDialog dlg(TRUE, _T("*.xml"), _T("update.xml"), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("XML File(*.xml)|*.xml||")); if (dlg.DoModal() == IDOK) { HRESULT hr = S_OK; MSXML2::IXMLDOMDocumentPtr pXmlDoc; MSXML2::IXMLDOMNodeListPtr pNodeList; MSXML2::IXMLDOMElementPtr pElement; try { hr = pXmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30)); if( FAILED( hr ) ) _com_issue_error(hr); pXmlDoc->load(CComVariant(dlg.GetPathName())); pNodeList = pXmlDoc->selectNodes("/manifest/filelist/file"); m_FileListCtrl.DeleteAllItems(); LONG lItemCount = pNodeList->Getlength(); int nItem; for (LONG lIndex = 0; lIndex < lItemCount; lIndex++) { pElement = pNodeList->Getitem(lIndex); nItem = m_FileListCtrl.InsertItem(0, CString(pElement->getAttribute("filename"))); m_FileListCtrl.SetItemText(nItem, 1, CString(pElement->getAttribute("filesize"))); m_FileListCtrl.SetItemText(nItem, 2, CString(pElement->getAttribute("fileversion"))); m_FileListCtrl.SetItemText(nItem, 3, CString(pElement->getAttribute("md5"))); m_FileListCtrl.SetItemData(nItem, (ULONG)pElement->getAttribute("filesize")); } SetWindowText(dlg.GetPathName()); GetDlgItem(IDC_UPDATE_ITEM)->EnableWindow(TRUE); } catch(_com_error& e) { CString strError; strError.Format(_T("Error code:%d\nError Message:%s\nError Description:%s"), (int)e.WCode(), e.ErrorMessage(), (char*)e.Description()); MessageBox(strError, _T("错误"),MB_OK|MB_ICONSTOP); } } }
void CXmlNodeWrapper::RemoveNodes(LPCTSTR searchStr) { if (!IsValid()) return; MSXML2::IXMLDOMNodeListPtr nodeList = m_xmlnode->selectNodes(searchStr); for (int i = 0; i < nodeList->Getlength(); i++) { try { MSXML2::IXMLDOMNode* pNode = nodeList->Getitem(i).Detach(); pNode->GetparentNode()->removeChild(pNode); } catch (_com_error er) { AfxMessageBox(er.ErrorMessage()); } } }
//设置指定xpath的节点属性 BOOL CXmlBase::SetAttrValue(LPCTSTR lpszValue, LPCTSTR lpszAttrName, LPCTSTR lpszXPath , MSXML2::IXMLDOMDocument2Ptr pDoc) { MSXML2::IXMLDOMNodePtr pNode = NULL; MSXML2::IXMLDOMNodeListPtr pNodeList = NULL; long lCnt = 0; if (pDoc == NULL || lpszXPath == NULL) return FALSE; try { pNodeList = pDoc->selectNodes(lpszXPath); lCnt = pNodeList->Getlength(); if (lCnt == 0) return FALSE; pNode = pNodeList->Getitem(0); } catch (_com_error e) { ::MessageBox(NULL, e.ErrorMessage(), NULL, MB_OK|MB_ICONERROR); return FALSE; } return SetAttrValue(lpszValue, lpszAttrName, pNode); }
long CIconImgList::GetGroupCount( MSXML2::IXMLDOMElementPtr piGroups) { long lCount = 0; MSXML2::IXMLDOMNodeListPtr piGroupsList; piGroupsList = piGroups->selectNodes( _bstr_t( _T( "GROUP"))); if( NULL != piGroupsList) { long lChildCount = piGroupsList->Getlength(); lCount = lChildCount; MSXML2::IXMLDOMElementPtr piGroupChild; for( long lIndex = 0; lIndex < lChildCount; lIndex++) { piGroupChild = piGroupsList->Getitem( lIndex); lCount += GetGroupCount( piGroupChild); } } return lCount; }
void CQuickConnection::Initial(void) { IXMLDOMDocument2Ptr pConfig; #ifdef _DEBUG CFileSys::ConvertBinaryXML( "script\\QuickConnection.xml","script\\QuickConnection.bml" ); FILE* fIn; if( NULL != (fIn=fopen( "script\\QuickConnection.bml","rb" ))) { CFileSys::LoadBinaryXML( pConfig, fIn ); } fclose( fIn ); #else DFileGPack packFile; packFile.Open(SFullName("script","QuickConnection.bml")); CFileSys::LoadBinaryXML(pConfig, packFile.GetFile(), packFile.GetSize()); packFile.Close(); #endif MSXML2::IXMLDOMNodePtr pNode = NULL; if( pNode = pConfig->selectSingleNode( L"./root/quick_mode" ) ) { long nIsQuickMode = pNode->GetnodeTypedValue(); m_nIsQuickMode = nIsQuickMode; } if( pNode = pConfig->selectSingleNode( L"./root/frame_speed_on" ) ) { long nFrameSpeedOn = pNode->GetnodeTypedValue(); m_nFrameSpeedOn = nFrameSpeedOn; } if( pNode = pConfig->selectSingleNode( L"./root/full_court" ) ) { long nFullCourt = pNode->GetnodeTypedValue(); m_nIsFullCourt = nFullCourt; } if( pNode = pConfig->selectSingleNode( L"./root/select_host" ) ) { long nIsHost = pNode->GetnodeTypedValue(); // long, short. m_nIsHost = nIsHost; // } // 중앙 서버의 ip 주소를 얻어 온다. if(pNode = pConfig->selectSingleNode(L"./root/server_option/server_addr")) { _bstr_t server_addr = pNode->GetnodeTypedValue(); m_sServerAddr = server_addr; } // 중앙 서버의 Port 를 얻어 온다. if(pNode = pConfig->selectSingleNode(L"./root/server_option/server_port")) { long nServerPort = pNode->GetnodeTypedValue(); m_iServerPort = nServerPort; } if(pNode = pConfig->selectSingleNode( L"./root/host_config/host_port" )) { long nHostPort = pNode->GetnodeTypedValue(); m_nHostPort = nHostPort; } if(pNode = pConfig->selectSingleNode( L"./root/host_config/player_on_player" )) { long nPlayerOn = pNode->GetnodeTypedValue(); m_nPlayerOn = nPlayerOn; } if(pNode = pConfig->selectSingleNode( L"./root/host_config/play_mode" )) { _bstr_t sPlayMode = pNode->GetnodeTypedValue(); m_sPlayMode = sPlayMode; } ///// MSXML2::IXMLDOMNodeListPtr pObjectList = pConfig->selectNodes(L"./root/host_db/character"); int nObject = pObjectList->Getlength(); for( int j = 0; j < nObject; j++ ) { MSXML2::IXMLDOMNodePtr pNode; MSXML2::IXMLDOMNodePtr pObject = pObjectList->Getitem(j); pNode = pObject->selectSingleNode(L"./position/x"); m_vecPos[j].X = pNode->GetnodeTypedValue(); pNode = pObject->selectSingleNode(L"./position/y"); m_vecPos[j].Y = pNode->GetnodeTypedValue(); pNode = pObject->selectSingleNode(L"./position/z"); m_vecPos[j].Z = pNode->GetnodeTypedValue(); } ///// if(pNode = pConfig->selectSingleNode( L"./root/client_option/connection_addr" )) { _bstr_t sConnectAddr = pNode->GetnodeTypedValue(); m_sConnectAddr = sConnectAddr; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/connection_id" )) { _bstr_t sConnectionId = pNode->GetnodeTypedValue(); m_sConnectionId = sConnectionId; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/char_id" )) { long nCharID = pNode->GetnodeTypedValue(); m_nCharID = nCharID; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/char_type" )) { long nCharType = pNode->GetnodeTypedValue(); m_nCharType = nCharType; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/client_port" )) { long nClientPort = pNode->GetnodeTypedValue(); m_nClientPort = nClientPort; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/with_ball" )) { long nWithBall = pNode->GetnodeTypedValue(); m_nWithBall = nWithBall; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/teamID" )) { long dwTeamID = pNode->GetnodeTypedValue(); m_dwTeamID = dwTeamID; } if(pNode = pConfig->selectSingleNode( L"./root/client_option/scale" )) { m_fScale = pNode->GetnodeTypedValue(); } if(pNode = pConfig->selectSingleNode( L"./root/client_option/latency" )) { m_fLatency = pNode->GetnodeTypedValue(); } ///// MSXML2::IXMLDOMNodeListPtr pItemList = pConfig->selectNodes(L"./root/client_option/item"); int nItemCnt = pItemList->Getlength(); m_nHaveItemCnt = nItemCnt; for( int k = 0; k < nItemCnt; k++ ) { MSXML2::IXMLDOMNodePtr pItemNode; MSXML2::IXMLDOMNodePtr pItmeObj = pItemList->Getitem(k); pItemNode = pItmeObj->selectSingleNode(L"./path"); _bstr_t ItemName = pItemNode->GetnodeTypedValue(); m_sHaveItemList[k] = ItemName; } //// pConfig.Release(); }
void CShootManagerSys::LoadShootSolutionSet(SFullName nameFile) { int i; MSXML2::IXMLDOMDocument2Ptr pDoc = NULL; DFileGPack packFile; packFile.Open(nameFile); CFileSys::LoadBinaryXML(pDoc, packFile.GetFile(), packFile.GetSize()); packFile.Close(); // 시뮬레이터에서 사용하는 거리 범위들을 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListDistance; MSXML2::IXMLDOMNodePtr pNodeDistance; float fDistance; pNodeListDistance = pDoc->selectNodes(L"root/distance_range/distance"); for(i=0; i<pNodeListDistance->Getlength(); i++) { pNodeDistance = pNodeListDistance->Getitem(i); _bstr_t distance = pNodeDistance->GetnodeTypedValue(); sscanf((LPCTSTR)distance, "%f", &fDistance); m_DistanceList.push_back(fDistance); } // 시뮬레이터에서 사용하는 각도 범위들을 로드한다. // 여기서 각도는 (골대 - 슈터) 와 양의 z 축 사이의 각도를 말한다. // degree 로 저장되어 있으므로 Angle 로 변환시킨다. MSXML2::IXMLDOMNodeListPtr pNodeListAngle; MSXML2::IXMLDOMNodePtr pNodeAngle; float fDegree; int iAngle; pNodeListAngle = pDoc->selectNodes(L"root/angle_range/degree"); for(i=0; i<pNodeListAngle->Getlength(); i++) { pNodeAngle = pNodeListAngle->Getitem(i); _bstr_t degree = pNodeAngle->GetnodeTypedValue(); sscanf((LPCTSTR)degree, "%f", &fDegree); iAngle = Degree2Angle(fDegree); // degree 에서 Angle 로 변환한다. m_AngleList.push_back(iAngle); } // 전체 섹터 개수를 계산하고 여기에 맞게 메모리를 생성한다. int iNumSector = m_DistanceList.size() * (m_AngleList.size() + 1) + 6; for(i=0; i<iNumSector; i++) { ShootSolutionSector *pShootSolutionSector = new (m_ShootSolutionSectorArray) ShootSolutionSector; } // 각 섹터별로 섹터안의 Shoot Solution 들을 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListSector = pDoc->selectNodes(L"root/sector"); MSXML2::IXMLDOMNodePtr pNodeSector; MSXML2::IXMLDOMNodePtr pNodeIndex; MSXML2::IXMLDOMNodePtr pNodePath; for(i=0; i<pNodeListSector->Getlength(); i++) { pNodeSector = pNodeListSector->Getitem(i); pNodeIndex = pNodeSector->selectSingleNode(L"index"); pNodePath = pNodeSector->selectSingleNode(L"path"); _bstr_t index = pNodeIndex->GetnodeTypedValue(); _bstr_t path = pNodePath->GetnodeTypedValue(); SString strName = (LPCTSTR)path; DCutPath(strName); DCutFileExt(strName); strName[strName.Len()-3] = 'b'; int iIndex = atoi((LPCTSTR)index); LoadShootSolutionSector(iIndex, SFullName("simulator",strName)); // int iIndex = atoi((LPCTSTR)index); // SString sFilePath = szFilename; // sFilePath = DGetPathOnly(sFilePath); // sFilePath += "\\"; // sFilePath += (LPCTSTR)path; // sFilePath.Format("%s\\%s\\%s", g_szCurrentPath, g_szSimulatorPath, (LPCTSTR)path); // LoadShootSolutionSector(iIndex, (LPCTSTR)sFilePath); } CFileSys::UnloadXML(pDoc); }
void CShootManagerSys::LoadShootSolutionSet(LPCTSTR szFilename) { int i; MSXML2::IXMLDOMDocument2Ptr pDoc; pDoc.CreateInstance(__uuidof(DOMDocument40)); pDoc->load((_variant_t)szFilename); // 시뮬레이터에서 사용하는 거리 범위들을 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListDistance; MSXML2::IXMLDOMNodePtr pNodeDistance; float fDistance; pNodeListDistance = pDoc->selectNodes(L"root/distance_range/distance"); for(i=0; i<pNodeListDistance->Getlength(); i++) { pNodeDistance = pNodeListDistance->Getitem(i); _bstr_t distance = pNodeDistance->GetnodeTypedValue(); sscanf((LPCTSTR)distance, "%f", &fDistance); m_DistanceList.push_back(fDistance); } // 시뮬레이터에서 사용하는 각도 범위들을 로드한다. // 여기서 각도는 (골대 - 슈터) 와 양의 z 축 사이의 각도를 말한다. // degree 로 저장되어 있으므로 Angle 로 변환시킨다. MSXML2::IXMLDOMNodeListPtr pNodeListAngle; MSXML2::IXMLDOMNodePtr pNodeAngle; float fDegree; int iAngle; pNodeListAngle = pDoc->selectNodes(L"root/angle_range/degree"); for(i=0; i<pNodeListAngle->Getlength(); i++) { pNodeAngle = pNodeListAngle->Getitem(i); _bstr_t degree = pNodeAngle->GetnodeTypedValue(); sscanf((LPCTSTR)degree, "%f", &fDegree); iAngle = Degree2Angle(fDegree); // degree 에서 Angle 로 변환한다. m_AngleList.push_back(iAngle); } // 전체 섹터 개수를 계산하고 여기에 맞게 메모리를 생성한다. int iNumSector = m_DistanceList.size() * (m_AngleList.size() + 1) + 6; for(i=0; i<iNumSector; i++) { ShootSolutionSector *pShootSolutionSector = new (m_ShootSolutionSectorArray) ShootSolutionSector; } // 각 섹터별로 섹터안의 Shoot Solution 들을 로드한다. MSXML2::IXMLDOMNodeListPtr pNodeListSector = pDoc->selectNodes(L"root/sector"); MSXML2::IXMLDOMNodePtr pNodeSector; MSXML2::IXMLDOMNodePtr pNodeIndex; MSXML2::IXMLDOMNodePtr pNodePath; for(i=0; i<pNodeListSector->Getlength(); i++) { pNodeSector = pNodeListSector->Getitem(i); pNodeIndex = pNodeSector->selectSingleNode(L"index"); pNodePath = pNodeSector->selectSingleNode(L"path"); _bstr_t index = pNodeIndex->GetnodeTypedValue(); _bstr_t path = pNodePath->GetnodeTypedValue(); int iIndex = atoi((LPCTSTR)index); SString sFilePath = szFilename; sFilePath = DGetPathOnly(sFilePath); sFilePath += "\\"; sFilePath += (LPCTSTR)path; // sFilePath.Format("%s\\%s\\%s", g_szCurrentPath, g_szSimulatorPath, (LPCTSTR)path); LoadShootSolutionSector(iIndex, (LPCTSTR)sFilePath); } pDoc.Release(); }
bool Engine::LoadContent() { // Setup our SpriteBatch. m_pSpriteBatch = new DirectX::SpriteBatch(d3dContext_); m_pFont->Initialize(d3dDevice_, std::wstring(L"Calibri18.spritefont")); m_pSprite->Initialize(d3dDevice_, std::wstring(L"Test.dds"), 10.0f, 10.0f); m_textToDisplay = Text(); m_textToDisplay.Initialize(std::wstring(L"Sarah"), DirectX::SimpleMath::Vector2(200.0f, 200.0f)); try { MSXML2::IXMLDOMDocument2Ptr xmlDoc; HRESULT hr = xmlDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER); teamStats.InitializeTeam("Players.xml"); // Make sure the file was loaded correctly before trying to load the players. if (xmlDoc->load("Players.xml") == VARIANT_TRUE) { //xmlDoc->setProperty("SelectionLanguage", "XPath"); //teamStats.LoadPlayers(xmlDoc); } if (xmlDoc->load("input.xml") != VARIANT_TRUE) { DXTRACE_MSG("Unable to load input.xml\n"); xmlDoc->save("input.xml"); //xmlDoc-> } else { DXTRACE_MSG("XML was successfully loaded \n"); xmlDoc->setProperty("SelectionLanguage", "XPath"); MSXML2::IXMLDOMNodeListPtr wheels = xmlDoc->selectNodes("/Car/Wheels/*"); DXTRACE_MSG("Car has %u wheels\n", wheels->Getlength()); DXTRACE_MSG(wheels->Getitem(0)->text); //ptr-> MSXML2::IXMLDOMNodePtr node; node = xmlDoc->createNode(MSXML2::NODE_ELEMENT, ("Engine"), ("")); node->text = ("Engine 1.0"); xmlDoc->documentElement->appendChild(node); hr = xmlDoc->save("output.xml"); if (SUCCEEDED(hr)) { DXTRACE_MSG("output.xml successfully saved\n"); } } } catch (_com_error &e) { DXTRACE_MSG(e.ErrorMessage()); } return true; }
BOOL CVoucherFile::LoadXml(const CString& strFileName, VoucherFileInfo &voucherInfo) { CString strFullPath = strFileName; BOOL bRet = FALSE; try { voucherInfo.Reset(); ::CoInitialize(NULL); MSXML2::IXMLDOMDocumentPtr pXmlDoc(__uuidof(MSXML2::DOMDocument)); MSXML2::IXMLDOMElementPtr pRootNode = NULL; CString strTemp; pXmlDoc->put_async(VARIANT_FALSE); pXmlDoc->load(_bstr_t(strFullPath.AllocSysString())); pRootNode = pXmlDoc->GetdocumentElement(); if (pRootNode == NULL) return FALSE; // 错误类型 MSXML2::IXMLDOMElementPtr pNode = pRootNode->selectSingleNode(_T("error")); if (pNode != NULL) { voucherInfo.strError = _GetNodeText(pNode); } // 模型信息 pNode = pRootNode->selectSingleNode(_T("model")); if (pNode != NULL) { // 版本 MSXML2::IXMLDOMElementPtr pChildNode = pNode->selectSingleNode(_T("version")); if (pChildNode != NULL) voucherInfo.strModelVersion = _GetNodeText(pChildNode); // 日期 pChildNode = pNode->selectSingleNode(_T("date")); if (pChildNode != NULL) voucherInfo.strModelDate = _GetNodeText(pChildNode); // 时间 pChildNode = pNode->selectSingleNode(_T("time")); if (pChildNode != NULL) voucherInfo.strModelTime = _GetNodeText(pChildNode); // 大小 pChildNode = pNode->selectSingleNode(_T("size")); if (pChildNode != NULL) voucherInfo.strModelSize = _GetNodeText(pChildNode); } // 用户列表 MSXML2::IXMLDOMElementPtr pUserNode = pRootNode->selectSingleNode(_T("nodeinfo")); if (pUserNode != NULL) { CString strText; MSXML2::IXMLDOMNodeListPtr pList = pUserNode->selectNodes(_bstr_t("username")); if (pList != NULL) { int nUserCount = pList->Getlength(); for(int i = 0; i < nUserCount; i++) { MSXML2::IXMLDOMNodePtr pChiledNode = pList->Getitem(i); if (pChiledNode != NULL) { strText = _GetNodeText(pChiledNode); voucherInfo.vecUser.push_back(strText); } } } } bRet = TRUE; } catch (...) { bRet = FALSE; } return bRet; }
BOOL CIconImgList::LoadIcons( MSXML2::IXMLDOMDocumentPtr& piDocument) { BOOL blResult = FALSE; MSXML2::IXMLDOMElementPtr piRoot; piRoot = piDocument->GetdocumentElement(); if( NULL == piRoot) { return FALSE; } MSXML2::IXMLDOMElementPtr piGroups; piGroups = piRoot->selectSingleNode( _bstr_t( _T( "GROUPS"))); MSXML2::IXMLDOMElementPtr piIcons; piIcons = piRoot->selectSingleNode( _bstr_t( _T( "ICONS"))); if( NULL == piIcons) { return FALSE; } MSXML2::IXMLDOMNodeListPtr piIconsList; piIconsList = piIcons->GetchildNodes(); if( NULL == piIconsList) { return FALSE; } long lIconsCount; lIconsCount = piIconsList->Getlength(); if( 0 >= lIconsCount) { return FALSE; } m_nCountExtend = lIconsCount; if( 0 < m_nCountExtend) { m_astIconStatus = new ICONSTATUS[ m_nCountExtend]; if( NULL != m_astIconStatus) { /* ZeroMemory( m_astIconStatus, sizeof( ICONSTATUS) * m_nCountExtend); */ for( int nIndex = 0; nIndex < m_nCountExtend; nIndex++) { m_astIconStatus[ m_nEnableCount].nID = 0; m_astIconStatus[ m_nEnableCount].blEnable = FALSE; m_astIconStatus[ m_nEnableCount].nParent = 0; m_astIconStatus[ m_nEnableCount].nPosition = 0; m_astIconStatus[ m_nEnableCount].cStrIconName.Empty(); } int nHeight = ( m_nCountExtend / 10) + ( ( m_nCountExtend % 10) ? 1 : 0); m_hBmpExtend = ::CreateBitmap( _ICON_WIDTH * 10, _ICON_HEIGHT * nHeight, 1, 1, NULL); HDC hExtDC = ::CreateCompatibleDC( NULL); HDC hDefDC = ::CreateCompatibleDC( NULL); HDC hWorkDC = ::CreateCompatibleDC( NULL); HBITMAP hOldExtBmp = ( HBITMAP)::SelectObject( hExtDC, m_hBmpExtend); HBITMAP hOldDefBmp = ( HBITMAP)::SelectObject( hDefDC, m_hBmpDefault); m_nEnableCount = 0; CString cStrEntry; LPBYTE lpabyData; TCHAR szWork[ 64]; MSXML2::IXMLDOMElementPtr piIcon; MSXML2::IXMLDOMElementPtr piImage; MSXML2::IXMLDOMElementPtr piParent; _variant_t cVariant; _bstr_t cBstr; CString strTitle; for( int nIndex = 0; nIndex < m_nCountExtend; nIndex++) { cVariant = VARIANT_TRUE; if( NULL != piGroups) { wsprintf( szWork, _T( "//ITEM[@REF='%d']"), nIndex + 1); piIcon = piGroups->selectSingleNode( _bstr_t( szWork)); if( NULL != piIcon) { cVariant = piIcon->getAttribute( _bstr_t( _T( "ENABLE"))); if( cVariant.vt != VT_NULL) { VariantChangeType( &cVariant, &cVariant, 0, VT_BOOL); } else { cVariant = VARIANT_TRUE; } } } if( VARIANT_FALSE != cVariant.boolVal) { wsprintf( szWork, _T( "//ICON[@ID='%d']"), nIndex + 1); piIcon = piRoot->selectSingleNode( _bstr_t( szWork)); if( NULL == piIcon) { continue; } cVariant = piIcon->getAttribute( _bstr_t( _T( "TITLE"))); if( cVariant.vt != VT_NULL) { strTitle = cVariant; } else { strTitle = _T( "NoTitle"); } piImage = piIcon->selectSingleNode( _bstr_t( _T( "IMAGE"))); if( NULL == piImage) { continue; } cBstr = piImage->Gettext(); int nSize = Base64Decode( NULL, 0, cBstr); lpabyData = new BYTE [ nSize]; Base64Decode( lpabyData, nSize, cBstr); HBITMAP hWork = ::CreateBitmap( _ICON_WIDTH, _ICON_HEIGHT, 1, 1, lpabyData); delete [] lpabyData; HBITMAP hOldWorkBmp = ( HBITMAP)::SelectObject( hWorkDC, hWork); ::BitBlt( hExtDC, ( nIndex % 10) * _ICON_WIDTH, ( nIndex / 10) * _ICON_HEIGHT, _ICON_WIDTH, _ICON_HEIGHT, hWorkDC, 0, 0, SRCCOPY); ::SelectObject( hWorkDC, hOldWorkBmp); ::DeleteObject( hWork); m_astIconStatus[ m_nEnableCount].nID = nIndex; m_astIconStatus[ m_nEnableCount].blEnable = TRUE; m_astIconStatus[ m_nEnableCount].cStrIconName = strTitle; m_nEnableCount++; continue; } ::BitBlt( hExtDC, ( nIndex % 10) * _ICON_WIDTH, ( nIndex / 10) * _ICON_HEIGHT, _ICON_WIDTH, _ICON_HEIGHT, hDefDC, ( COUNT_DEFAULTICON) * _ICON_WIDTH, 0, SRCCOPY); } ::SelectObject( hExtDC, hOldExtBmp); ::SelectObject( hDefDC, hOldDefBmp); ::DeleteDC( hExtDC); ::DeleteDC( hDefDC); ::DeleteDC( hWorkDC); m_astIconStatus4Menu = new ICONSTATUS*[ m_nEnableCount]; if( m_astIconStatus4Menu) { for( int nIndex = 0; nIndex < m_nEnableCount; nIndex++) { m_astIconStatus4Menu[ nIndex] = &m_astIconStatus[ nIndex]; } qsort( m_astIconStatus4Menu, m_nEnableCount, sizeof( ICONSTATUS*), IconCompare); blResult = TRUE; } } } return blResult; }