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; } }
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 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); } } }
// loads items (values) from XML DOM Node - elements with type <item value="(new item)"> BOOL CStringTableImpl::loadItemsFromXML(MSXML2::IXMLDOMNodeListPtr & pNodeList) { Clear(); // smazani puvodniho obsahu MSXML2::IXMLDOMElementPtr pChild = NULL; _variant_t Atr_val; // textova hodnota atributu while((pChild = pNodeList->nextNode()) != NULL) { if(pChild->baseName == (_bstr_t) "item") // definice jedne polozky { Atr_val = pChild->getAttribute("value"); if(Atr_val.vt != VT_NULL) { CString new_item = (LPCTSTR) (_bstr_t) Atr_val; Add(new_item); } } } return TRUE; }
BOOL CXMLParser3::GetRoot(LPCTSTR &strName, LPCTSTR strPara) { try { MSXML2::IXMLDOMElementPtr pRoot = m_pXMLDom->documentElement; CString ss; ss = ((LPCTSTR)pRoot->nodeName); strName = (LPCTSTR)pRoot->nodeName; _variant_t var = pRoot->getAttribute(_T("Interface")); strPara = (LPCTSTR)var.bstrVal; return TRUE; } catch (_com_error &e) { m_nError = e.Error(); m_strError = e.ErrorMessage(); return FALSE; } catch (...) { return FALSE; } }
void CTransformationsDialog::AddOptionToPropetryEditor( MSXML2::IXMLDOMElementPtr & option_element, MSXML2::IXMLDOMElementPtr & transformation_element, CPropertyEditor & property_editor) { CString option_type = (LPCTSTR) option_element->nodeName; CString variable_name = (LPCTSTR) (_bstr_t) option_element->getAttribute("variable_name"); CString value_query_str; //dotaz na default value value_query_str.Format("visualization_values/variable[@name=\"%s\"]/@value", (LPCTSTR) variable_name); CString value; try { value = (LPCTSTR) transformation_element->selectSingleNode((LPCTSTR) value_query_str)->text; } catch (_com_error &) { CString err_msg; err_msg.Format("Value of variable \"%s\" is missing.", variable_name); throw err_msg; } if (option_type == "enum_option") { //enum property_editor.AddProperty( CreateEnumProperty(option_element, value)); } else if (option_type == "string_option") { //string property_editor.AddProperty(new CStringProperty( (_bstr_t) option_element->getAttribute("title"), //label value)); //default value } else if (option_type == "color_option") { //color property_editor.AddProperty(new CColorProperty( (_bstr_t) option_element->getAttribute("title"), //label value)); //default value } else if (option_type == "number_option") { if ((_bstr_t) option_element->getAttribute("num_type") == _bstr_t("float")) { //float property_editor.AddProperty( CreateDoubleProperty(option_element, value)); } else if ((_bstr_t) option_element->getAttribute("num_type") == _bstr_t("integer")) { //integer property_editor.AddProperty( CreateIntProperty(option_element, value)); } } }
// InitSourcesTab BOOL CDataSourcesManager::initSourcesTab(LPCTSTR config_file_path) { CString FName; // jmeno (cesta) ke konfig. souboru FName = config_file_path; BSTR FileName = FName.AllocSysString(); // nacteni konfiguracniho souboru zdroju MSXML2::IXMLDOMDocumentPtr pXMLDom; // koren XML stromu MSXML2::IXMLDOMElementPtr pNode; // korenovy element MSXML2::IXMLDOMNodeListPtr pChildren; // seznam podelementu korenoveho elementu MSXML2::IXMLDOMElementPtr pChild; // podelement korenoveho elementu int i = 0; // indexova promenna _variant_t Atr_val; // textova hodnota atributu HRESULT hr; //Vytvori COM objekt (resp. instanci objektu) hr = pXMLDom.CreateInstance(_T("Msxml2.DOMDocument")); if (FAILED(hr)) return FALSE; pXMLDom->async = VARIANT_FALSE; //nacti DOM ze souboru if ( pXMLDom->load((LPCTSTR) FName) == VARIANT_TRUE) { pNode = pXMLDom->GetdocumentElement(); if (pNode != NULL) { if (pNode->baseName == (_bstr_t) "SOURCES_LIST") // spravny nazev korenoveho elementu { pChildren = pNode->childNodes; // ziskani seznamu potomku pChild = NULL; while((pChild = pChildren->nextNode()) != NULL) // zpracovavaji se potomci { if(pChild->baseName == (_bstr_t) "SOURCE") // definice polozky v tabulce zdroju { // pridani prvku do tabulky zdroju SourcesTab.Add(new CSourceRec); // PUBLIC_ID Atr_val = pChild->getAttribute("PUBLIC_ID"); if(Atr_val.vt != VT_NULL) SourcesTab[i]->PublicID = (BSTR) (_bstr_t) Atr_val; // PERZISTENT_ID Atr_val = pChild->getAttribute("PERZISTENT_ID"); if(Atr_val.vt != VT_NULL) SourcesTab[i]->PerzistID = (BSTR) (_bstr_t) Atr_val; // PLUGIN_ID Atr_val = pChild->getAttribute("PLUGIN_ID"); if(Atr_val.vt != VT_NULL) SourcesTab[i]->PluginID = (BSTR) (_bstr_t) Atr_val; i++; } } } //dedek: nacteni default source MSXML2::IXMLDOMElementPtr el_default_source = pNode->selectSingleNode("DEFAULT_SOURCE"); if (el_default_source) setDefaultSource((public_source_id_t) (LPCTSTR) (_bstr_t) el_default_source->getAttribute("PUBLIC_ID")); } } SysFreeString(FileName); pXMLDom.Release(); // nastaveni odkazu na tabulku zasuvek prvkum z tabulky zdroju for(int j=0; j<= SourcesTab.GetUpperBound(); j++) // pres polozky v tabulce zdroju { for(int k=0; k<=PlugsTab.GetUpperBound(); k++) { if(SourcesTab[j]->PluginID == PlugsTab[k].PluginName) { SourcesTab[j]->PluginIndex = k; // nastaveni indexu v tabulce zasuvek break; } } } return TRUE; }
BOOL CAttributeLinkTableDialog::OnInitDialog() { CDialog::OnInitDialog(); if (! m_bShowTarget) m_TargetCombo.EnableWindow(FALSE); InitBaseDialog(m_AttributesList, m_TargetCombo); //dedek: inicializuj CaptionsList CRect r; m_CaptionsList.GetWindowRect(& r); m_CaptionsList.InsertColumn(CAPTLIST_CL_CAPTION, "caption", LVCFMT_LEFT, r.Width()/3 -3); m_CaptionsList.InsertColumn(CAPTLIST_CL_VALUE, "value", LVCFMT_LEFT, r.Width()/3 -3); m_CaptionsList.InsertColumn(CAPTLIST_CL_NAME, "name", LVCFMT_LEFT, r.Width()/3 -3); //napln CaptionsList hodnotami m_CaptionsList.SetExtendedStyle(LVS_EX_FULLROWSELECT); MSXML2::IXMLDOMNodeListPtr links = m_SelXMLElm->selectNodes("link"); CString target_id; m_TargetCombo.GetWindowText(target_id); int a; for (a=0; a < links->length; a++) { MSXML2::IXMLDOMElementPtr link = links->item[a]; //caption int item = m_CaptionsList.InsertItem(a, (_bstr_t) link->getAttribute("caption")); //attr_name CString attr_name = (LPCTSTR) (_bstr_t) link->getAttribute("attr_name"); m_CaptionsList.SetItemText(item, CAPTLIST_CL_NAME, attr_name); //value CString query_str; query_str.Format("id(\"%s\")/attributes/element_attributes/attribute[@name=\"%s\"]/@value", target_id, attr_name); MSXML2::IXMLDOMNodePtr value_attr = m_SelXMLElm->ownerDocument->selectSingleNode((LPCTSTR) query_str); if (value_attr != NULL) { m_CaptionsList.SetItemText(item, CAPTLIST_CL_VALUE, value_attr->text); value_attr.Release(); } link.Release(); } //napln style combo CElementManager & m = ((CReportAsistentApp *) AfxGetApp())->m_pGeneralManager->ElementManager; int item = CB_ERR; for (a=0; a < m.getAttrLinkTableStylesCount(); a++) { item = m_StyleCombo.AddString(m.getAttrLinkTableStyleName(a)); } //vyber style int sel = m_StyleCombo.SelectString(-1, (_bstr_t) m_SelXMLElm->getAttribute("style")); //vyber se nezdaril => kdyz exituje nejaky styl vyber prvni if ((sel == CB_ERR) && (item != CB_ERR)) { m_StyleCombo.SelectString(-1, m.getAttrLinkTableStyleName(0)); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
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; }