CA_API UINT __stdcall Xml_DeleteNodes(MSIHANDLE hInstall) { MSI_EXCEPTION_HANDLER_PROLOG; MsiInstall msiInstall(hInstall); std::wstring filename = msiInstall.GetProperty(L"XML_FILENAME"); AppSecInc::Xml::XmlDocument doc; doc.Load(filename); std::wstring xpath = msiInstall.GetProperty(L"XML_XPATH"); MSXML2::IXMLDOMNodeListPtr nodes = doc.FindNodes(xpath); int count = 0; if (NULL != nodes) { MSXML2::IXMLDOMNodePtr node = NULL; while (NULL != (node = nodes->nextNode())) { node->parentNode->removeChild(node); count++; } } if (count > 0) { CHECK_HR(doc->save(CComVariant(filename.c_str())), L"Error saving '" << filename << L"'"); } msiInstall.SetProperty(L"XML_DELETED", AppSecInc::StringUtils::toWString(count)); MSI_EXCEPTION_HANDLER_EPILOG; return ERROR_SUCCESS; }
CA_API UINT __stdcall TemplateFiles_Deferred(MSIHANDLE hInstall) { MSI_EXCEPTION_HANDLER_PROLOG; MsiInstall msiInstall(hInstall); AppSecInc::Xml::XmlDocument xmlDocument; xmlDocument.LoadXml(msiInstall.GetActionData()); MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"//TemplateFile[@execute='true']"); // \todo //Row[@rollback='false'] MSXML2::IXMLDOMNodePtr row = NULL; while (NULL != (row = rows->nextNode())) { std::wstring id = xmlDocument.GetAttributeValue(L"id", row); std::wstring source = xmlDocument.GetNodeValue(L"Source", row); std::wstring target = xmlDocument.GetNodeValue(L"Target", row, source); msiInstall.LogInfo(L"TemplateFiles_Deferred", source + L" => " + target); std::map<std::wstring, std::wstring> properties; { MSXML2::IXMLDOMNodeListPtr property_rows = xmlDocument.SelectNodes(L"Properties/Property", row); MSXML2::IXMLDOMNodePtr property_row = NULL; while (NULL != (property_row = property_rows->nextNode())) { std::wstring name = xmlDocument.GetAttributeValue(L"name", property_row); std::wstring value = xmlDocument.GetAttributeValue(L"value", property_row); long escape = AppSecInc::StringUtils::stringToLong(xmlDocument.GetAttributeValue(L"escape", property_row, L"0")); properties[name] = escape == 1 ? AppSecInc::StringUtils::escape(value) : value; } } std::wstring data; bool utf8 = AppSecInc::File::ReadAndConvertToEnd(source, data); data = AppSecInc::Formatter::FormatTemplate(data, properties); std::string char_data; if (utf8) { char_data = AppSecInc::StringUtils::wc2utf8(data); char_data.insert(0, std::string(reinterpret_cast<char *>(AppSecInc::File::utf8_bom))); } else { char_data = AppSecInc::StringUtils::wc2mb(data); } std::vector<char> binary_data; binary_data.assign(char_data.begin(), char_data.end()); AppSecInc::File::FileWrite(target, binary_data); } MSI_EXCEPTION_HANDLER_EPILOG; return ERROR_SUCCESS; }
// loads lists of Word styles from configuration XML file BOOL CWordManager::loadStylesFromXML(LPCTSTR XMLFilePath) { BOOL result = FALSE; // return value CString FName; // jmeno (cesta) ke konfig. souboru FName = XMLFilePath; MSXML2::IXMLDOMDocumentPtr pXMLDom; // koren XML stromu MSXML2::IXMLDOMElementPtr pNode; // korenovy element MSXML2::IXMLDOMNodeListPtr pChildren; // seznam podelementu korenoveho elementu MSXML2::IXMLDOMNodeListPtr pChildrenItems; // seznam podelementu elementu - vstupuje do funkce pro nacitani StringTable 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) "word_styles") // spravny nazev korenoveho elementu { pChildren = pNode->childNodes; // ziskani seznamu potomku pChild = NULL; while((pChild = pChildren->nextNode()) != NULL) // zpracovavaji se potomci { pChildrenItems = pChild->childNodes; if (pChild->baseName == (_bstr_t) "templates") m_WordTemplates.loadItemsFromXML(pChildrenItems); else if (pChild->baseName == (_bstr_t) "paragraph_styles") m_WordParagraphStyles.loadItemsFromXML(pChildrenItems); else if (pChild->baseName == (_bstr_t) "character_styles") m_WordCharacterStyles.loadItemsFromXML(pChildrenItems); } result = TRUE; } } } pXMLDom.Release(); return result; }
// 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; }
void CreateToolbars() { if (Glb_toolbarArray.GetCount() > 0) return; IAcadMenuGroup *mnuGrp = NULL; if (!getAcadMenuGroup(&mnuGrp)) return ; IAcadToolbars *tlbrs = NULL; HRESULT hr = S_OK; hr = mnuGrp->get_Toolbars(&tlbrs); mnuGrp->Release(); // 得到arx所在路径 TCHAR lpPath[MAX_PATH] = {0}; GetModuleFileName(GetModuleHandle("DistToolBar.arx"), lpPath, MAX_PATH); PathRemoveFileSpec(lpPath); PathAddBackslash(lpPath); CString strXmlFile = lpPath; strXmlFile += "toolbar.xml"; // 得到icon路径 PathAppend(lpPath, "icon"); PathAddBackslash(lpPath); MSXML2::IXMLDOMDocumentPtr lpDocument; hr = lpDocument.CreateInstance(__uuidof(DOMDocument)); if ( FAILED(hr) ) _com_raise_error(hr); VARIANT_BOOL isSuccessful; // 装载XML字符串 if (!lpDocument->load(_variant_t(strXmlFile))) { OutputDebugString("LoadXML failed!"); return; } MSXML2::IXMLDOMElementPtr lpDocElement = NULL; lpDocument->get_documentElement(&lpDocElement); // toolbar list MSXML2::IXMLDOMNodeListPtr lpToolbarList = lpDocElement->getElementsByTagName(_bstr_t("toolbar")); MSXML2::IXMLDOMNodePtr lpToolbar = NULL; for ( ; (lpToolbar = lpToolbarList->nextNode()) != NULL ; ) { MSXML2::IXMLDOMNodePtr lpCaptionNode = lpToolbar->attributes->getNamedItem("caption"); CString strCaption = (char*)lpCaptionNode->text; OutputDebugString(strCaption); // 添加工具条 IAcadToolbar *tlbr = NULL; hr = tlbrs->Add(CComBSTR(strCaption), &tlbr); if FAILED(hr) continue; Glb_toolbarArray.Add(strCaption); // button list MSXML2::IXMLDOMNodeListPtr lpButtonList = lpToolbar->GetchildNodes(); MSXML2::IXMLDOMNodePtr lpButton = NULL; for ( ; (lpButton = lpButtonList->nextNode()) != NULL ; ) { MSXML2::IXMLDOMNodePtr lpToolTipNode = lpButton->attributes->getNamedItem("tooltip"); CString strToolTip = (char*)lpToolTipNode->text; MSXML2::IXMLDOMNodePtr lpCommandNode = lpButton->attributes->getNamedItem("command"); CString strCommand = (char*)lpCommandNode->text; strCommand += " "; MSXML2::IXMLDOMNodePtr lpIconNode = lpButton->attributes->getNamedItem("icon"); CString strIcon = (char*)lpIconNode->text; OutputDebugStringX("tooltip=%s, command=%s, icon=%s", strToolTip, strCommand, strIcon); // 添加工具按钮 IAcadToolbarItem *button=NULL; VARIANT index; index.vt = VT_I4; index.lVal = 100l; VARIANT vtFalse; vtFalse.vt = VT_BOOL; vtFalse.boolVal = VARIANT_FALSE; CString strIconFile = lpPath; strIconFile += strIcon; if (!PathFileExists(strIconFile)) { strIconFile = lpPath; strIconFile += "dist.ico"; } if (!PathFileExists(strIconFile)) continue; hr = tlbr->AddToolbarButton(index, CComBSTR(strToolTip), CComBSTR(strToolTip), CComBSTR(strCommand), vtFalse, &button); hr = button->SetBitmaps(CComBSTR(strIconFile), CComBSTR(strIconFile)); button->Release(); } tlbr->Dock(acToolbarDockRight);//acToolbarFloating tlbr->Release(); } tlbrs->Release(); return; }
//--------------------------------------------------------------------------- BOOL CVCAMetaParserMSXML::ParseCE( ) { CComBSTR bsTag; MSXML2::IXMLDOMNodePtr pNode, pSubNode, pSubSubNode; // Great names eh ;~) MSXML2::IXMLDOMNodeListPtr pNodeList; // See if we have any objects this time round bsTag = CComBSTR( _XML_VCA ) += CComBSTR("/") += CComBSTR( _XML_COUNTEVENTS ); pNode = m_pDOMDoc->selectSingleNode( bsTag.operator BSTR() ); if( pNode ) { // There are some event specified in this packet... take a look... memset(&m_vcaCountLineEvents, 0, sizeof(m_vcaCountLineEvents)); // Select all events bsTag = CComBSTR( _XML_CE ); pNodeList = pNode->selectNodes( bsTag.operator BSTR() ); // Iterate through all the nodes pNode = pNodeList->nextNode(); while( pNode ) { VCA5_COUNTLINE_EVENT clEvent; memset( &clEvent, 0, sizeof( VCA5_COUNTLINE_EVENT ) ); // pClEvent bsTag = CComBSTR( _XML_ID ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarUI4FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (unsigned long *)&clEvent.uiId ); } bsTag = CComBSTR( _XML_P ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarUI2FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (unsigned short *)&clEvent.usPos ); } bsTag = CComBSTR( _XML_W ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarUI2FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (unsigned short *)&clEvent.usWidth ); } bsTag = CComBSTR( _XML_N ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarUI2FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (unsigned short *)&clEvent.usNum ); } m_vcaCountLineEvents.CountLineEvents[m_vcaCountLineEvents.ulTotalCountLineEvents] = clEvent; m_vcaCountLineEvents.ulTotalCountLineEvents++; pNode = pNodeList->nextNode(); } } return TRUE; }
CA_API UINT __stdcall TemplateFiles_Immediate(MSIHANDLE hInstall) { MSI_EXCEPTION_HANDLER_PROLOG; MsiInstall msiInstall(hInstall); // combined xml document AppSecInc::Xml::XmlDocument combined_xml_document; combined_xml_document.Create(); MSXML2::IXMLDOMNodePtr combined_xml_root = combined_xml_document.AppendChild(L"TemplateFiles"); std::wstring xml = msiInstall.GetViewData(L"SELECT * FROM `TemplateFiles`"); AppSecInc::Xml::XmlDocument xmlDocument; xmlDocument.LoadXml(xml); { MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"//Row"); MSXML2::IXMLDOMNodePtr row = NULL; while (NULL != (row = rows->nextNode())) { // id std::wstring templatefile_id = xmlDocument.GetNodeValue(L"Data[@Column=\"Id\"]", row, L""); // component id std::wstring component_id = xmlDocument.GetNodeValue(L"Data[@Column=\"ComponentId\"]", row, L""); // node condition std::wstring condition = xmlDocument.GetNodeValue(L"Data[@Column=\"Condition\"]", row); // operational attributes long attributes = AppSecInc::StringUtils::stringToLong(xmlDocument.GetNodeValue(L"Data[@Column=\"Attributes\"]", row)); // no condition (executes by default) or condition evaluates to true bool execute_per_condition = condition.empty() || msiInstall.EvaluateCondition(condition); if (! condition.empty()) { // set the evaluated value for debugging purposes xmlDocument.SelectNode(L"Data[@Column=\"Condition\"]", row)->text = _bstr_t(execute_per_condition ? L"1" : L"0"); } // execute on install bool execute_per_component_install = (component_id.empty() || msiInstall.IsComponentInstalling(component_id)); // execute on uninstall bool execute_per_component_uninstall = (component_id.empty() || msiInstall.IsComponentUnInstalling(component_id)); // execute on reinstall bool execute_per_component_reinstall = (component_id.empty() || msiInstall.IsComponentReInstalling(component_id)); bool execute = execute_per_condition && ( (execute_per_component_install && (attributes & ExecuteOnInstall) && msiInstall.IsInstalling()) || (execute_per_component_uninstall && (attributes & ExecuteOnUnInstall) && msiInstall.IsUnInstalling()) || (execute_per_component_reinstall && (attributes & ExecuteOnReInstall) && msiInstall.IsReInstalling()) ); MSXML2::IXMLDOMNodePtr templatefile_node = combined_xml_document.AppendChild(L"TemplateFile", combined_xml_root); combined_xml_document.SetAttribute(L"id", templatefile_id, templatefile_node); std::wstring source = xmlDocument.GetNodeValue(L"Data[@Column=\"Source\"]", row); std::wstring target = xmlDocument.GetNodeValue(L"Data[@Column=\"Target\"]", row, source); combined_xml_document.AppendChild(L"Source", templatefile_node)->text = _bstr_t(source.c_str()); combined_xml_document.AppendChild(L"Target", templatefile_node)->text = _bstr_t(target.c_str()); combined_xml_document.SetAttribute(L"execute", execute ? L"true" : L"false", templatefile_node); MSXML2::IXMLDOMNodePtr properties_node = combined_xml_document.AppendChild(L"Properties", templatefile_node); // append built-in properties { AppSecInc::Xml::XmlDocument xmlPropertiesDocument; xmlPropertiesDocument.LoadXml(msiInstall.GetViewData(L"SELECT * FROM `Property`")); MSXML2::IXMLDOMNodeListPtr property_rows = xmlPropertiesDocument.SelectNodes(L"//Row"); MSXML2::IXMLDOMNodePtr property_row = NULL; while (NULL != (property_row = property_rows->nextNode())) { std::wstring name = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"Property\"]", property_row); std::wstring value = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"Value\"]", property_row); MSXML2::IXMLDOMNodePtr property_node = combined_xml_document.AppendChild(L"Property", properties_node); combined_xml_document.SetAttribute(L"name", name, property_node); combined_xml_document.SetAttribute(L"value", value, property_node); } } // append properties from this TemplateFile { AppSecInc::Xml::XmlDocument xmlPropertiesDocument; xmlPropertiesDocument.LoadXml(msiInstall.GetViewData(L"SELECT * FROM `TemplateFileProperties`")); MSXML2::IXMLDOMNodeListPtr property_rows = xmlPropertiesDocument.SelectNodes(L"//Row"); MSXML2::IXMLDOMNodePtr property_row = NULL; while (NULL != (property_row = property_rows->nextNode())) { // \todo Change XPATH to fetch only rows that match ID std::wstring id = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"TemplateFileId\"]", property_row); if (id != templatefile_id) continue; std::wstring name = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"Name\"]", property_row); std::wstring value = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"Value\"]", property_row); std::wstring escape = xmlPropertiesDocument.GetNodeValue(L"Data[@Column=\"Escape\"]", property_row); MSXML2::IXMLDOMNodePtr property_node = combined_xml_document.AppendChild(L"Property", properties_node); combined_xml_document.SetAttribute(L"name", name, property_node); combined_xml_document.SetAttribute(L"value", value, property_node); combined_xml_document.SetAttribute(L"escape", escape, property_node); } } } } msiInstall.SetActionData(L"TemplateFiles_Deferred", combined_xml_document.GetXml()); MSI_EXCEPTION_HANDLER_EPILOG; return ERROR_SUCCESS; }
// 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; }
CA_API UINT __stdcall LocalGroupMembers_Deferred(MSIHANDLE hInstall) { MSI_EXCEPTION_HANDLER_PROLOG; MsiInstall msiInstall(hInstall); AppSecInc::Xml::XmlDocument xmlDocument; xmlDocument.LoadXml(msiInstall.GetActionData()); MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"/LocalGroupMembers/LocalGroupMember"); MSXML2::IXMLDOMNodePtr row = NULL; while (NULL != (row = rows->nextNode())) { std::wstring id = xmlDocument.GetAttributeValue(L"id", row); std::wstring username = xmlDocument.GetNodeValue(L"Username", row); std::wstring groupname = xmlDocument.GetNodeValue(L"Group", row, L""); bool add_member = xmlDocument.GetAttributeBoolValue(L"add", row); bool remove_member = xmlDocument.GetAttributeBoolValue(L"remove", row); bool check = xmlDocument.GetAttributeBoolValue(L"check", row); if (remove_member && (! check || AppSecInc::LSA::LocalGroup::IsMember(groupname, username))) { msiInstall.LogInfo(_T(__FUNCTION__), L"Removing \"" + username + L"\" from \"" + groupname + L"\""); AppSecInc::LSA::LocalGroup::DeleteMember(groupname, username); } if (add_member && (! check || ! AppSecInc::LSA::LocalGroup::IsMember(groupname, username))) { msiInstall.LogInfo(_T(__FUNCTION__), L"Adding \"" + username + L"\" to \"" + groupname + L"\""); AppSecInc::LSA::LocalGroup::AddMember(groupname, username); } } MSI_EXCEPTION_HANDLER_EPILOG; return ERROR_SUCCESS; }