CMarkup XMLSerialized::OpenFile(){ CMarkup xml; //nếu file chưa tồn tại thì kiểm tra trong listRole bool exist =PathFileExists(sFileName); if(!exist){ int begin = sFileName.ReverseFind('\\')+1; int end = sFileName.ReverseFind(L'.'); CString roleName = sFileName.Mid(begin,end-begin); if(roleName.Left(4)=="Role") return NULL; CString szLstRole = L"Character\\ListRole.xml"; ConvertFileName(szLstRole); //nếu không tồn tại file listRole thì tạo note root if(!PathFileExists(szLstRole)){ xml.AddElem(L"ListRoles"); } else{ xml.Load(szLstRole); xml.FindElem(L"ListRoles"); } xml.IntoElem(); while(xml.FindElem(L"Role")){ if(xml.GetAttrib(L"ID")==roleName){ sFileName=L"Character\\"+xml.GetAttrib(L"File"); ConvertFileName(sFileName); exist =true; break; } } //nếu trong listRole không có thì lưu trong listRole và tạo file if(!exist){ time_t timer; time(&timer); CTime t = timer; sFileName=t.Format(L"Role%d%m%Y%H%M%S.xml"); xml.AddElem(L"Role"); xml.AddAttrib(L"ID",roleName); xml.AddAttrib(L"File",sFileName); xml.Save(szLstRole); sFileName=L"Character\\"+sFileName; ConvertFileName(sFileName); return NULL; } } xml.Load(sFileName); if(xml.GetDoc().GetLength()>0) return xml; return NULL; }
int SaveLoadCNN::LoadAxonData(std::string FileName, AxonList* axon, std::vector<Group*>* cluster) { CMarkup axonXml; axonXml.Load(FileName); return GetAxonVec(axonXml, axon, cluster); }
void XMLFileRead() { CMarkup xml; xml.Load(L"ServerConnection.xml"); while (xml.FindChildElem(L"SERVER")) { _ConnectorInfo connectorInfo; xml.IntoElem(); xml.FindChildElem(L"IP"); connectorInfo.szIP = xml.GetChildData(); xml.FindChildElem(L"PORT"); connectorInfo.port = _ttoi(xml.GetChildData().c_str()); xml.FindChildElem(L"IDENTIFER"); connectorInfo.identifier = _ttoi(xml.GetChildData().c_str()); xml.FindChildElem(L"DESC"); connectorInfo.szDesc = xml.GetChildData(); xml.OutOfElem(); } }
bool CInstrOffsetData::Load(LPCTSTR filePath, bool isCreate) { m_data.clear(); CMarkup xml; if (!xml.Load(filePath)) { return false; } if (!xml.FindElem("root")) { return false; } xml.IntoElem(); if (!xml.FindElem("data")) { return false; } xml.IntoElem(); while (xml.FindElem("frequency")) { double frequency = atof(xml.GetAttrib("value")); xml.IntoElem(); while (xml.FindElem("power")) { double dest_power = atof(xml.GetAttrib("dest_power")); double offset = atof(xml.GetAttrib("offset")); m_data[frequency][dest_power] = offset; } xml.OutOfElem(); } return true; }
// 根据配置索引获取配置信息 CString CVCheckerClsConfig::fGetConfigData(int nConfigIndex) { if (m_strConfigFile == _T("")) return _T(""); CMarkup xml; BOOL bLoad = FALSE; bLoad = xml.Load(m_strConfigFile); if (!bLoad) return _T(""); xml.ResetPos(); while ( xml.FindChildElem(_T("System_Config"))) { xml.IntoElem(); //xml.ResetMainPos(); //xml.FindChildElem( "NAME" ); //// xml.FindChildElem(); //CString csName = xml.GetChildData(); //AfxMessageBox(csName); //xml.ResetMainPos(); //注意复位 //xml.FindChildElem( "SN" ); //// xml.FindChildElem(); //CString csSN = xml.GetChildData(); //AfxMessageBox(csSN); xml.OutOfElem(); } return CString(); }
bool SFServerConnectionManager::InitServerList(WCHAR* szFileName) { CMarkup xml; xml.Load(L"ServerConnection.xml"); while (xml.FindChildElem(L"SERVER")) { _ServerInfo serverInfo; xml.IntoElem(); xml.FindChildElem(L"IP"); serverInfo.szIP = xml.GetChildData(); xml.FindChildElem(L"PORT"); serverInfo.port = _ttoi(xml.GetChildData().c_str()); xml.FindChildElem(L"IDENTIFER"); serverInfo.identifer = _ttoi(xml.GetChildData().c_str()); xml.FindChildElem(L"DESC"); serverInfo.szDesc = xml.GetChildData(); xml.OutOfElem(); SFServerBridge* pServer = new SFServerBridge(serverInfo); m_mapServerInfo.insert(std::make_pair(serverInfo.identifer, pServer)); } return true; }
int SaveLoadCNN::LoadAxonData(std::string fileName, AxonList * axon, std::vector<Group*>* destCluster, std::vector<Group*>* srcCluster) { CMarkup axonXml; axonXml.Load(fileName); return GetAxonVec(axonXml, axon, destCluster, srcCluster); }
int SaveLoadCNN::LoadClusterData(std::string fileName, std::vector<Group*>* cluster) { CMarkup clusterXml; clusterXml.Load(fileName); return GetClusterVec(clusterXml, cluster); }
CMarkup XMLSerialized::OpenFile(CString sFile){ CMarkup xml; XMLSerialized::ConvertFileName(sFile); xml.Load(sFile); if(xml.GetDoc().GetLength()>0) return xml; return NULL; }
BOOL CResourceManager::LoadLanguage(LPCTSTR pstrXml) { CMarkup xml; if( *(pstrXml) == _T('<') ) { if( !xml.Load(pstrXml) ) return FALSE; } else { if( !xml.LoadFromFile(pstrXml) ) return FALSE; } CMarkupNode Root = xml.GetRoot(); if( !Root.IsValid() ) return FALSE; LPCTSTR pstrClass = NULL; int nAttributes = 0; LPCTSTR pstrName = NULL; LPCTSTR pstrValue = NULL; LPTSTR pstr = NULL; //¼ÓÔØͼƬ×ÊÔ´ LPCTSTR pstrId = NULL; LPCTSTR pstrText = NULL; for( CMarkupNode node = Root.GetChild() ; node.IsValid(); node = node.GetSibling() ) { pstrClass = node.GetName(); if ((_tcsicmp(pstrClass,_T("Text")) == 0) && node.HasAttributes()) { //¼ÓÔØͼƬ×ÊÔ´ nAttributes = node.GetAttributeCount(); for( int i = 0; i < nAttributes; i++ ) { pstrName = node.GetAttributeName(i); pstrValue = node.GetAttributeValue(i); if( _tcsicmp(pstrName, _T("id")) == 0 ) { pstrId = pstrValue; } else if( _tcsicmp(pstrName, _T("value")) == 0 ) { pstrText = pstrValue; } } if( pstrId == NULL || pstrText == NULL) continue; CDuiString *lpstrFind = static_cast<CDuiString *>(m_mTextResourceHashMap.Find(pstrId)); if(lpstrFind != NULL) { lpstrFind->Assign(pstrText); } else { m_mTextResourceHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrText)); } } else continue; } return TRUE; }
/* active squad visits the arms dealer */ void armsdealer(int loc) { music.play(MUSIC_SHOPPING); locatesquad(activesquad,loc); CMarkup xml; // -XML xml.Load(string(artdir) + "armsdealer.xml"); Shop armsdealer(xml.GetDoc()); armsdealer.enter(*activesquad); }
/* active squad visits the oubliette */ void halloweenstore(int loc) { music.play(MUSIC_SHOPPING); locatesquad(activesquad,loc); CMarkup xml; xml.Load(string(artdir) + "oubliette.xml"); Shop oubliette(xml.GetDoc()); oubliette.enter(*activesquad); }
/* active squad visits the department store */ void deptstore(int loc) { music.play(MUSIC_SHOPPING); locatesquad(activesquad,loc); CMarkup xml; // -XML xml.Load(string(artdir) + "deptstore.xml"); Shop deptstore(xml.GetDoc()); deptstore.enter(*activesquad); }
/* active squad visits the pawn shop */ void pawnshop(int loc) { music.play(MUSIC_SHOPPING); locatesquad(activesquad,loc); CMarkup xml; // -XML xml.Load(string(artdir) + "pawnshop.xml"); Shop pawnshop(xml.GetDoc()); pawnshop.enter(*activesquad); }
//This method allow you to load the XML file std::vector<Stage*>* Stage::LoadFromXML(std::string path) { //creating object std::vector<Stage*>* stages = nullptr; //creating a vector of stage object CMarkup xml; //if cant load file return if (!xml.Load(path)) return stages; //it cant find element return stages if (!xml.FindElem("Stages")) return stages; stages = new std::vector<Stage*>(); //creating a vector of stages object xml.IntoElem(); //go up 1 level while (xml.FindElem("Stage")) //find stage { Stage* stage = new Stage(); stages->push_back(stage); //push each stage into vector of stage xml.IntoElem(); //go up 1 level if (xml.FindElem("Flag")) //find the flag { int x, y; xml.IntoElem(); //go up 1 level xml.FindElem("x"); //find x x = atoi(xml.GetData().c_str()); //assign x cord from xml into int xml.FindElem("y"); //find y y = atoi(xml.GetData().c_str()); //assign y cord from xml into int stage->flagPosition = new Vector2(x, y); //push x and y into vector for flag position xml.OutOfElem(); //go back 1 level } while (xml.FindElem("Block")) //find block and do the same as flag { Block* block; int x; int y; xml.IntoElem(); xml.FindElem("x"); x = atoi(xml.GetData().c_str()); xml.FindElem("y"); y = atoi(xml.GetData().c_str()); block = new Block(x, y); stage->Blocks->push_back(block); xml.OutOfElem(); } xml.OutOfElem(); } return stages; }
//del device void CDeviceEditDlg::DeleteDevice() { HTREEITEM hItem = m_deviceTree.GetSelectedItem(); if ( hItem == NULL ) { return; } DEV_INFO *pDev = (DEV_INFO *)m_deviceTree.GetItemData(hItem); if ( pDev ) { if ( pDev->lLoginID > 0 ) { H264_DVR_Logout(pDev->lLoginID); } Devc_Map::iterator bIter = m_devMap.find( pDev->lID ); if ( bIter != m_devMap.end() ) { m_devMap.erase(bIter); } m_deviceTree.DeleteItem(hItem); CMarkup xml; if (xml.Load(GET_MODULE_FILE_INFO.strPath + "UserInfo.xml")) { while(xml.FindChildElem("ip")) { xml.IntoElem(); xml.FindChildElem("ip2"); if(xml.GetChildData()==pDev->szIpaddress) { xml.RemoveElem(); xml.Save(GET_MODULE_FILE_INFO.strPath + "UserInfo.xml"); } xml.OutOfElem(); } } delete pDev; pDev = NULL; } }
bool populate_from_xml(vector<Type*>& types,string file,Log& log) { CMarkup xml; if(!xml.Load(string(artdir)+file)) { // File is missing or not valid XML. addstr("Failed to load "+file+"!",log); getkey(); // Will cause abort here or else if file is missing all unrecognized types // loaded from a saved game will be deleted. Also, you probably don't want // to play with a whole category of things missing anyway. If the file // does not have valid xml, then behaviour is kind of undefined so it's // best to abort then too. return false; } xml.FindElem(); xml.IntoElem(); while(xml.FindElem()) types.push_back(new Type(xml.GetSubDoc())); return true; }
void CDlgLianHaoLanQiu::OnBnClickedJingxuanBtn() { CMarkup Xml; CString FormulaName=GetAppCurrentPath()+"FormulaNameList.xml"; Xml.Load(FormulaName.GetBuffer()); FormulaName.ReleaseBuffer(); vector<CString> NameList; while(Xml.FindChildElem("FormulaInfo")) { Xml.IntoElem(); Xml.FindChildElem("FormulaName"); CString Name=Xml.GetChildData().c_str(); Xml.FindChildElem("FormulaType"); CString StrType=Xml.GetChildData().c_str(); int Type = atoi(StrType.GetBuffer()); StrType.ReleaseBuffer(); if(Type == m_FormulaType && !Name.IsEmpty()) NameList.push_back(Name); Xml.OutOfElem(); } if(NameList.empty()) { m_FormulaInfoList=CFormulaCenter::GetInstance()->GetFormulaInfoByType(m_FormulaType); } else m_FormulaInfoList=CFormulaCenter::GetInstance()->GetFormulaInfoByName(m_FormulaType,NameList); m_CurrentIndex=0; FillData(m_FormulaInfoList); UpdateBtnStatus(); }
bool populate_masks_from_xml(vector<ArmorType*>& masks,string file,Log& log) { CMarkup xml; if(!xml.Load(string(artdir)+file)) { //File is missing or not valid XML. addstr("Failed to load "+file+"!",log); getkey(); return false; //Abort. } xml.FindElem(); xml.IntoElem(); int defaultindex; if(xml.FindElem("default")) defaultindex=getarmortype(xml.GetData()); else { addstr("Default missing for masks!",log); getkey(); return false; //Abort. } if(defaultindex==-1) { addstr("Default for masks is not a known armor type!",log); getkey(); return false; //Abort. } xml.ResetMainPos(); while(xml.FindElem("masktype")) armortype.push_back(new ArmorType(*armortype[defaultindex],xml.GetSubDoc())); return true; }
DEV_INFO CDeviceEditDlg::ReadXML() { CMarkup xml; DEV_INFO devInfo; devInfo.nPort=0; devInfo.lLoginID=0; devInfo.lID=0; if(xml.Load(GET_MODULE_FILE_INFO.strPath + "UserInfo.xml")) { while(xml.FindChildElem("ip")) { //read the information from XML CString strIP="",strUserName="",strPsw="",strDevName=""; UINT nPort; long byChanNum=0,lID=0; UINT bSerialID,nSerPort; CString szSerIP="",szSerialInfo=""; xml.IntoElem(); xml.FindChildElem("ip2"); strIP=xml.GetChildData(); xml.FindChildElem("DEVICENAME"); strDevName=xml.GetChildData(); xml.FindChildElem("username"); strUserName=xml.GetChildData(); xml.FindChildElem("port"); nPort=atoi(xml.GetChildData()); xml.FindChildElem("pwd"); strPsw=xml.GetChildData(); xml.FindChildElem("byChanNum"); byChanNum=atoi(xml.GetChildData()); xml.FindChildElem("lID"); lID=atoi(xml.GetChildData()); xml.FindChildElem("bSerialID"); bSerialID=atoi(xml.GetChildData()); xml.FindChildElem("szSerIP"); szSerIP=xml.GetChildData(); xml.FindChildElem("nSerPort"); nSerPort=atoi(xml.GetChildData()); xml.FindChildElem("szSerialInfo"); szSerialInfo=xml.GetChildData();//新增ddns记录 xml.OutOfElem(); devInfo.nTotalChannel =byChanNum; devInfo.nPort = nPort; devInfo.bSerialID=bSerialID; devInfo.nSerPort=nSerPort; strcpy(devInfo.szSerIP,szSerIP.GetBuffer(0)); strcpy(devInfo.szSerialInfo, szSerialInfo.GetBuffer(0));//新增ddns记录 strcpy(devInfo.szDevName, strDevName); strcpy(devInfo.szUserName, strUserName); strcpy(devInfo.szPsw, strPsw); strcpy(devInfo.szIpaddress, strIP); DEV_INFO *pDev = new DEV_INFO; memset( pDev, 0, sizeof(DEV_INFO) ); memcpy( pDev, &devInfo, sizeof(DEV_INFO) ); pDev->lID = (long)pDev; m_devMap[pDev->lID] = pDev; HTREEITEM hAddItem = m_deviceTree.InsertItem(strDevName); m_deviceTree.SetItemData(hAddItem, (DWORD)pDev); CString strName(""); for ( int i = 0; i < byChanNum; i ++) { strName.Format("CAM %d", i+1); HTREEITEM item = m_deviceTree.InsertItem(strName, 0, 0, hAddItem); m_deviceTree.SetItemData(item, i); } } } return devInfo; }
// 保存配置信息 BOOL COBDPNDConfigReadWrite::fSaveAppConfig(void) { CMarkup xml; CString strAppConfigFile = fCommGetAppPath() + _T("\\Config.xml"); if (!xml.Load(strAppConfigFile)) { return CONFIG_ERR_LOAD_FILE; } CString strText; xml.ResetMainPos(); xml.FindElem(); if(xml.FindChildElem(_T("System"))) { xml.IntoElem(); if(xml.FindChildElem(_T("COM_OBD"))) { strText.Format(_T("%d"),m_tagAppConfig.tagComOBD.wPort); xml.SetChildAttrib(_T("Port"),strText); //strText.Format(_T("%d"),m_tagAppConfig.tagComOBD.dwBPS); //xml.SetChildAttrib(_T("BPS"),strText); //strText.Format(_T("%d"),m_tagAppConfig.tagComOBD.wData_Bits); //xml.SetChildAttrib(_T("Data_Bits"),strText); //strText.Format(_T("%d"),m_tagAppConfig.tagComOBD.wStop_Bits); //xml.SetChildAttrib(_T("Stop_Bits"),strText); //xml.SetChildAttrib(_T("Parity"),_T("None")); } //if(xml.FindChildElem(_T("COM_GPS"))) //{ // strText.Format(_T("%d"),m_tagAppConfig.tagComGPS.wPort); // xml.SetChildAttrib(_T("Port"),strText); // strText.Format(_T("%d"),m_tagAppConfig.tagComGPS.dwBPS); // xml.SetChildAttrib(_T("BPS"),strText); // strText.Format(_T("%d"),m_tagAppConfig.tagComGPS.wData_Bits); // xml.SetChildAttrib(_T("Data_Bits"),strText); // strText.Format(_T("%d"),m_tagAppConfig.tagComGPS.wStop_Bits); // xml.SetChildAttrib(_T("Stop_Bits"),strText); // xml.SetChildAttrib(_T("Parity"),_T("None")); //} if(xml.FindChildElem(_T("Setting"))) { xml.SetChildAttrib(_T("LANGUAGE"),m_tagAppConfig.tagSetting.strLanguage); if (m_tagAppConfig.tagSetting.bSaveErrorLog) xml.SetChildAttrib(_T("Save_ErrorLog"),_T("ON")); else xml.SetChildAttrib(_T("Save_ErrorLog"),_T("OFF")); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.wBacklightDay); xml.SetChildAttrib(_T("BACKLIGHT_DAY"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.wBacklightNight); xml.SetChildAttrib(_T("BACKLIGHT_NIGHT"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.wBacklightDayStart); xml.SetChildAttrib(_T("BACKLIGHT_DAY_START"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.wBackLightDayEnd); xml.SetChildAttrib(_T("BACKLIGHT_DAY_END"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.dwSystemOffTime); xml.SetChildAttrib(_T("System_Off_Time"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.dwSystemOffMode); xml.SetChildAttrib(_T("System_Off_Mode"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.dwAutoSelPanelTime); xml.SetChildAttrib(_T("Auto_Sel_Panel_Time"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagSetting.dwDefaultStartPanel); xml.SetChildAttrib(_T("Default_Start_Panel"),strText); strText.Format(_T("%0.5f"),m_tagAppConfig.tagSetting.fInstantFuelParameter); xml.SetChildAttrib(_T("Parameter_Fuel_Instant"),strText); strText.Format(_T("%0.5f"),m_tagAppConfig.tagSetting.fAvgFuelParameter); xml.SetChildAttrib(_T("Parameter_Fuel_Avg"),strText); strText.Format(_T("%0.5f"),m_tagAppConfig.tagSetting.fFuelPrice); xml.SetChildAttrib(_T("Fuel_Price"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagSetting.dwActiveEcuID); xml.SetChildAttrib(_T("Active_ECU_ID"),strText); } if(xml.FindChildElem(_T("Set_Alarm"))) { if (m_tagAppConfig.tagAlarmSet.bTroubleCode) xml.SetChildAttrib(_T("TroubleCode"),_T("ON")); else xml.SetChildAttrib(_T("TroubleCode"),_T("OFF")); strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wSpeed); xml.SetChildAttrib(_T("Speed"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wCoolant); xml.SetChildAttrib(_T("Coolant"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wFatigue_Driving); xml.SetChildAttrib(_T("Fatigue_Driving"),strText); strText.Format(_T("%0.2f"),m_tagAppConfig.tagAlarmSet.dbFuel); xml.SetChildAttrib(_T("Fuel"),strText); xml.IntoElem(); if(xml.FindChildElem(_T("Shift"))) { strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wShiftRpm); xml.SetChildAttrib(_T("Shift_Rpm"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wShiftSpeed); xml.SetChildAttrib(_T("Shift_Speed"),strText); } if(xml.FindChildElem(_T("Volt"))) { strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wVoltMin); xml.SetChildAttrib(_T("Volt_Min"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagAlarmSet.wVoltMax); xml.SetChildAttrib(_T("Volt_Max"),strText); } xml.OutOfElem(); } xml.OutOfElem(); } if(xml.FindChildElem(_T("Mini_Dlg"))) { strText.Format(_T("%d"),m_tagAppConfig.tagMiniSpeed.dw480X272_X); xml.SetChildAttrib(_T("X_480X272"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagMiniSpeed.dw480X272_Y); xml.SetChildAttrib(_T("Y_480X272"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagMiniSpeed.dw800X480_X); xml.SetChildAttrib(_T("X_800X480"),strText); strText.Format(_T("%d"),m_tagAppConfig.tagMiniSpeed.dw800X480_Y); xml.SetChildAttrib(_T("Y_800X480"),strText); } if(xml.FindChildElem(_T("UiData"))) { xml.IntoElem(); if(xml.FindChildElem(_T("Idle"))) { strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwLeftUpID); xml.SetChildAttrib(_T("ID_Left_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwLeftMiddleID); xml.SetChildAttrib(_T("ID_Left_Middle"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwLeftDownID); xml.SetChildAttrib(_T("ID_Left_Down"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwRightUpID); xml.SetChildAttrib(_T("ID_Right_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwRightMiddleID); xml.SetChildAttrib(_T("ID_Right_Middle"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataIdle.dwRightDownID); xml.SetChildAttrib(_T("ID_Right_Down"),strText); } if(xml.FindChildElem(_T("Tour"))) { strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwLeftUpID); xml.SetChildAttrib(_T("ID_Left_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwLeftMiddleID); xml.SetChildAttrib(_T("ID_Left_Middle"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwLeftDownID); xml.SetChildAttrib(_T("ID_Left_Down"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwRightUpID); xml.SetChildAttrib(_T("ID_Right_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwRightMiddleID); xml.SetChildAttrib(_T("ID_Right_Middle"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataTour.dwRightDownID); xml.SetChildAttrib(_T("ID_Right_Down"),strText); } if(xml.FindChildElem(_T("Race"))) { strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwLeftUpID); xml.SetChildAttrib(_T("ID_Left_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwLeftDownID); xml.SetChildAttrib(_T("ID_Left_Down"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwMiddleUpID); xml.SetChildAttrib(_T("ID_Middle_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwMiddleMiddleID); xml.SetChildAttrib(_T("ID_Middle_Middle"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwMiddleDownID); xml.SetChildAttrib(_T("ID_Middle_Down"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwRightUpID); xml.SetChildAttrib(_T("ID_Right_Up"),strText); strText.Format(_T("0x%08X"),m_tagAppConfig.tagUiDataRace.dwRightDownID); xml.SetChildAttrib(_T("ID_Right_Down"),strText); } xml.OutOfElem(); } if(xml.FindChildElem(_T("APP_START_LIST"))) { xml.IntoElem(); while(xml.FindChildElem(_T("APP"))) { for (int i=0;i<m_vecAppList.size();i++) { if (xml.GetChildAttrib(_T("ID")) == m_vecAppList[i].strAppID) { xml.SetChildAttrib(_T("PATH"),m_vecAppList[i].strAppPath); if (m_vecAppList[i].bAutoRun) xml.SetChildAttrib(_T("AUTO_RUN"),_T("1")); else xml.SetChildAttrib(_T("AUTO_RUN"),_T("0")); } } } xml.OutOfElem(); } xml.Save(strAppConfigFile); return TRUE; }
// 初始化应用配置信息 BOOL COBDPNDConfigReadWrite::fInitAppConfig(void) { CMarkup xml; CString strAppPath = fCommGetAppPath() + _T("\\"); CString strAppConfigFile = strAppPath + _T("Config.xml"); if (!xml.Load(strAppConfigFile)) { return CONFIG_ERR_LOAD_FILE; } xml.ResetMainPos(); xml.FindElem(); if(xml.FindChildElem(_T("System"))) { xml.IntoElem(); if(xml.FindChildElem(_T("Base"))) { m_tagAppConfig.bIsDemo = (xml.GetChildAttrib(_T("Demo_Mode"))==_T("ON")?TRUE:FALSE); m_tagAppConfig.strTextFile = xml.GetChildAttrib(_T("File_Text")); m_tagAppConfig.strFilterAppList = xml.GetChildAttrib(_T("FILTER_APP_LIST")); } if(xml.FindChildElem(_T("COM_OBD"))) { m_tagAppConfig.tagComOBD.wPort = (WORD)_ttoi(xml.GetChildAttrib(_T("Port"))); m_tagAppConfig.tagComOBD.dwBPS =(WORD) _ttoi(xml.GetChildAttrib(_T("BPS"))); m_tagAppConfig.tagComOBD.wData_Bits = (WORD)_ttoi(xml.GetChildAttrib(_T("Data_Bits"))); m_tagAppConfig.tagComOBD.wStop_Bits = (WORD)_ttoi(xml.GetChildAttrib(_T("Stop_Bits"))); m_tagAppConfig.tagComOBD.wParity = 0;//_ttoi(xml.GetChildAttrib(_T("Parity"))); } if(xml.FindChildElem(_T("COM_GPS"))) { m_tagAppConfig.tagComGPS.wPort = (WORD)_ttoi(xml.GetChildAttrib(_T("Port"))); m_tagAppConfig.tagComGPS.dwBPS = (WORD)_ttoi(xml.GetChildAttrib(_T("BPS"))); m_tagAppConfig.tagComGPS.wData_Bits = (WORD)_ttoi(xml.GetChildAttrib(_T("Data_Bits"))); m_tagAppConfig.tagComGPS.wStop_Bits = (WORD)_ttoi(xml.GetChildAttrib(_T("Stop_Bits"))); m_tagAppConfig.tagComGPS.wParity = 0;//_ttoi(xml.GetChildAttrib(_T("Parity"))); } if(xml.FindChildElem(_T("Setting"))) { m_tagAppConfig.tagSetting.strLanguage = xml.GetChildAttrib(_T("LANGUAGE")); m_tagAppConfig.tagSetting.bSaveErrorLog = (xml.GetChildAttrib(_T("Save_ErrorLog"))==_T("OFF")?FALSE:TRUE); m_tagAppConfig.tagSetting.wBacklightDay = _ttoi(xml.GetChildAttrib(_T("BACKLIGHT_DAY"))); m_tagAppConfig.tagSetting.wBacklightNight = _ttoi(xml.GetChildAttrib(_T("BACKLIGHT_NIGHT"))); m_tagAppConfig.tagSetting.wBacklightDayStart = _ttoi(xml.GetChildAttrib(_T("BACKLIGHT_DAY_START"))); m_tagAppConfig.tagSetting.wBackLightDayEnd = _ttoi(xml.GetChildAttrib(_T("BACKLIGHT_DAY_END"))); m_tagAppConfig.tagSetting.dwActiveEcuID = _ttoi(xml.GetChildAttrib(_T("Active_EUC_ID"))); m_tagAppConfig.tagSetting.str24or12 = xml.GetChildAttrib(_T("Time_24_12Hour")); m_tagAppConfig.tagSetting.dwSystemOffTime = _ttoi(xml.GetChildAttrib(_T("System_Off_Time"))); m_tagAppConfig.tagSetting.dwSystemOffMode = _ttoi(xml.GetChildAttrib(_T("System_Off_Mode"))); m_tagAppConfig.tagSetting.dwAutoSelPanelTime = _ttoi(xml.GetChildAttrib(_T("Auto_Sel_Panel_Time"))); m_tagAppConfig.tagSetting.fAvgFuelParameter = wcstod(xml.GetChildAttrib(_T("Parameter_Fuel_Avg")),0); m_tagAppConfig.tagSetting.fInstantFuelParameter = wcstod(xml.GetChildAttrib(_T("Parameter_Fuel_Instant")),0); m_tagAppConfig.tagSetting.fFuelPrice = wcstod(xml.GetChildAttrib(_T("Fuel_Price")),0); m_tagAppConfig.tagSetting.dwActiveEcuID = _ttoi(xml.GetChildAttrib(_T("Active_ECU_ID"))); } if(xml.FindChildElem(_T("Language_list"))) { xml.IntoElem(); m_tagAppConfig.vecLanguage.clear(); while(xml.FindChildElem(_T("LANGUAGE"))) { _TagLanguage tagLanData; tagLanData.strLanID = xml.GetChildAttrib(_T("LANGUAGE_ID")); tagLanData.strLanName = xml.GetChildAttrib(_T("LANGUAGE_NAME")); tagLanData.strLanSN = xml.GetChildAttrib(_T("LANGUAGE_SN")); tagLanData.strResFiles = xml.GetChildAttrib(_T("LANGUAGE_RES")); m_tagAppConfig.vecLanguage.push_back(tagLanData); } xml.OutOfElem(); } if(xml.FindChildElem(_T("Set_Alarm"))) { m_tagAppConfig.tagAlarmSet.bTroubleCode = xml.GetChildAttrib(_T("TroubleCode"))==_T("ON")?TRUE:FALSE; m_tagAppConfig.tagAlarmSet.wSpeed = _ttoi(xml.GetChildAttrib(_T("Speed"))); m_tagAppConfig.tagAlarmSet.wCoolant = _ttoi(xml.GetChildAttrib(_T("Coolant"))); m_tagAppConfig.tagAlarmSet.wFatigue_Driving = _ttoi(xml.GetChildAttrib(_T("Fatigue_Driving"))); m_tagAppConfig.tagAlarmSet.dbFuel = wcstod(xml.GetChildAttrib(_T("Fuel")),0); xml.IntoElem(); if(xml.FindChildElem(_T("Shift"))) { m_tagAppConfig.tagAlarmSet.wShiftRpm = _ttoi(xml.GetChildAttrib(_T("Shift_Rpm"))); m_tagAppConfig.tagAlarmSet.wShiftSpeed = _ttoi(xml.GetChildAttrib(_T("Shift_Speed"))); } if(xml.FindChildElem(_T("Volt"))) { m_tagAppConfig.tagAlarmSet.wVoltMin = _ttoi(xml.GetChildAttrib(_T("Volt_Min"))); m_tagAppConfig.tagAlarmSet.wVoltMax = _ttoi(xml.GetChildAttrib(_T("Volt_Max"))); } xml.OutOfElem(); } xml.OutOfElem(); } if(xml.FindChildElem(_T("Mini_Dlg"))) { m_tagAppConfig.tagMiniSpeed.dw480X272_X = _ttoi(xml.GetChildAttrib(_T("X_480X272"))); m_tagAppConfig.tagMiniSpeed.dw480X272_Y = _ttoi(xml.GetChildAttrib(_T("Y_480X272"))); m_tagAppConfig.tagMiniSpeed.dw800X480_X = _ttoi(xml.GetChildAttrib(_T("X_800X480"))); m_tagAppConfig.tagMiniSpeed.dw800X480_Y = _ttoi(xml.GetChildAttrib(_T("Y_800X480"))); } if(xml.FindChildElem(_T("UiData"))) { xml.IntoElem(); if(xml.FindChildElem(_T("Idle"))) { m_tagAppConfig.tagUiDataIdle.dwLeftUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Up"))); m_tagAppConfig.tagUiDataIdle.dwLeftMiddleID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Middle"))); m_tagAppConfig.tagUiDataIdle.dwLeftDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Down"))); m_tagAppConfig.tagUiDataIdle.dwRightUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Up"))); m_tagAppConfig.tagUiDataIdle.dwRightMiddleID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Middle"))); m_tagAppConfig.tagUiDataIdle.dwRightDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Down"))); } if(xml.FindChildElem(_T("Tour"))) { m_tagAppConfig.tagUiDataTour.dwLeftUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Up"))); m_tagAppConfig.tagUiDataTour.dwLeftMiddleID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Middle"))); m_tagAppConfig.tagUiDataTour.dwLeftDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Down"))); m_tagAppConfig.tagUiDataTour.dwRightUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Up"))); m_tagAppConfig.tagUiDataTour.dwRightMiddleID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Middle"))); m_tagAppConfig.tagUiDataTour.dwRightDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Down"))); } if(xml.FindChildElem(_T("Race"))) { m_tagAppConfig.tagUiDataRace.dwLeftUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Up"))); m_tagAppConfig.tagUiDataRace.dwLeftDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Left_Down"))); m_tagAppConfig.tagUiDataRace.dwRightUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Up"))); m_tagAppConfig.tagUiDataRace.dwRightDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Right_Down"))); m_tagAppConfig.tagUiDataRace.dwMiddleUpID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Middle_Up"))); m_tagAppConfig.tagUiDataRace.dwMiddleMiddleID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Middle_Middle"))); m_tagAppConfig.tagUiDataRace.dwMiddleDownID = fCommStr2Hex(xml.GetChildAttrib(_T("ID_Middle_Down"))); } xml.OutOfElem(); } if(xml.FindChildElem(_T("Sound"))) { m_tagAppConfig.tagSoundFile.strDong = strAppPath + xml.GetChildAttrib(_T("Dong")); m_tagAppConfig.tagSoundFile.strInitialze = strAppPath + xml.GetChildAttrib(_T("Initialze")); m_tagAppConfig.tagSoundFile.strStart = strAppPath + xml.GetChildAttrib(_T("Start")); m_tagAppConfig.tagSoundFile.strGetData = strAppPath + xml.GetChildAttrib(_T("GetData")); m_tagAppConfig.tagSoundFile.strAlarmCoolant = strAppPath + xml.GetChildAttrib(_T("AlarmCoolant")); m_tagAppConfig.tagSoundFile.strAlarmFatigueDriving = strAppPath + xml.GetChildAttrib(_T("AlarmFatigueDriving")); m_tagAppConfig.tagSoundFile.strAlarmOverSpeed = strAppPath + xml.GetChildAttrib(_T("AlarmOverSpeed")); m_tagAppConfig.tagSoundFile.strAlarmVoltHigh = strAppPath + xml.GetChildAttrib(_T("AlarmVoltHigh")); m_tagAppConfig.tagSoundFile.strAlarmVoltLow = strAppPath + xml.GetChildAttrib(_T("AlarmVoltLow")); m_tagAppConfig.tagSoundFile.strAlarmTrouble = strAppPath + xml.GetChildAttrib(_T("AlarmTrouble")); } if(xml.FindChildElem(_T("GPS_LIST"))) { xml.IntoElem(); m_vecGPSList.clear(); while(xml.FindChildElem(_T("GPS"))) { TagAppInfo tagAppInfo; tagAppInfo.strAppID = xml.GetChildAttrib(_T("ID")); tagAppInfo.strAppName = xml.GetChildAttrib(_T("NAME_CHS")); tagAppInfo.strAppPath = xml.GetChildAttrib(_T("FOLDER")); tagAppInfo.strAppExe = xml.GetChildAttrib(_T("EXE")); tagAppInfo.bAutoRun = FALSE; m_vecGPSList.push_back(tagAppInfo); } xml.OutOfElem(); } if(xml.FindChildElem(_T("DSA_LIST"))) { xml.IntoElem(); m_vecDSAList.clear(); while(xml.FindChildElem(_T("DSA"))) { TagAppInfo tagAppInfo; tagAppInfo.strAppID = xml.GetChildAttrib(_T("ID")); tagAppInfo.strAppName = xml.GetChildAttrib(_T("NAME_CHS")); tagAppInfo.strAppPath = xml.GetChildAttrib(_T("FOLDER")); tagAppInfo.strAppExe= xml.GetChildAttrib(_T("EXE")); tagAppInfo.bAutoRun = FALSE; m_vecDSAList.push_back(tagAppInfo); } xml.OutOfElem(); } if(xml.FindChildElem(_T("APP_START_LIST"))) { xml.IntoElem(); m_vecAppList.clear(); while(xml.FindChildElem(_T("APP"))) { TagAppInfo tagAppInfo; tagAppInfo.strAppID = xml.GetChildAttrib(_T("ID")); if (tagAppInfo.strAppID == _T("1")) tagAppInfo.strAppName = theMainDlg->fGetBinText(DS_SETUP_GUIDE_DSA_TITLE); if (tagAppInfo.strAppID == _T("2")) tagAppInfo.strAppName = theMainDlg->fGetBinText(DS_SETUP_GUIDE_GPS_TITLE); tagAppInfo.strAppPath = xml.GetChildAttrib(_T("PATH")); if (xml.GetChildAttrib(_T("AUTO_RUN")) == _T("1")) tagAppInfo.bAutoRun = TRUE; else tagAppInfo.bAutoRun = FALSE; m_vecAppList.push_back(tagAppInfo); } xml.OutOfElem(); } return TRUE; }
int getChavesProfessor(string path, chavesProfessor *temp) { CMarkup xml; int nTrab = 0, nArt = 0; if(!xml.Load(path)){ cout << "Erro de abertura do arquivo xml." << endl; return 1; } strcpy (temp->nomeArquivo, path.c_str()); if (!xml.FindElem("CURRICULO-VITAE")){ cout << "Sem CV" << endl; return ERROR; } // ================ NOME =================== xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("DADOS-GERAIS")){ cout << "Sem DADOS-GERAIS." << endl; return ERROR; } strcpy (temp->nome, xml.GetAttrib("NOME-COMPLETO").c_str()); //cout << temp.nome << endl; xml.IntoElem(); // define DADOS-GERAIS como parent xml.ResetPos(); // ========= TRABALHOS EM EVENTOS =================== xml.FindElem("CURRICULO-VITAE"); // se passou pelo primeiro findelem(curriculo vitae) //passa por esse xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("PRODUCAO-BIBLIOGRAFICA")){ cout << "Sem PRODUCAO-BIBLIOGRAFICA." <<temp->nome<< endl; return ERROR; } xml.IntoElem(); if(!xml.FindElem("TRABALHOS-EM-EVENTOS")){ cout << "Sem TRABALHOS-EM-EVENTOS." << endl; return ERROR; } xml.IntoElem();// define TRABALHOS-EM-EVENTOS como parent while(xml.FindElem()){ nTrab++; } temp->nPEventos = nTrab; xml.ResetPos(); // ========= ARTIGOS PUBLICADOS =================== xml.FindElem("CURRICULO-VITAE"); // se passou pelo primeiro findelem(curriculo vitae) //passa por esse xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("PRODUCAO-BIBLIOGRAFICA")){ cout << "Sem PRODUCAO-BIBLIOGRAFICA."<<temp->nome << endl; return ERROR; } xml.IntoElem(); if(!xml.FindElem("ARTIGOS-PUBLICADOS")){ cout << "Sem ARTIGOS-PUBLICADOS."<<temp->nome << endl; return ERROR; } xml.IntoElem();// define ARTIGOS-PUBLICADOS como parent while(xml.FindElem()){ nArt++; } temp->nPPeriodicos = nArt; return SUCCESS; }
int parseProfessor(string path, dadosProfessor *temp){ CMarkup xml; int nTrab = 0, nArt = 0; if(!xml.Load(path)){ cout << "Erro de abertura do arquivo xml." << endl; return 1; } // ========= DADOS GERAIS =================== if (!xml.FindElem("CURRICULO-VITAE")){ cout << "Sem CV" << endl; return ERROR; } xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("DADOS-GERAIS")){ cout << "Sem DADOS-GERAIS." << endl; return ERROR; } temp->nome = xml.GetAttrib("NOME-COMPLETO"); //cout << temp.nome << endl; xml.IntoElem(); // define DADOS-GERAIS como parent if(!xml.FindElem("ATUACOES-PROFISSIONAIS")){ cout << "Sem ATUACOES-PROFISSIONAIS" <<endl; return ERROR; } if(!xml.FindChildElem("ATUACAO-PROFISSIONAL")){ cout << "Sem ATUACAO-PROFISSIONAL" << endl; return ERROR; } temp->instituicao = xml.GetChildAttrib("NOME-INSTITUICAO"); //cout << temp.instituicao << endl; xml.IntoElem(); // define ATUACAO-PROFISSIONAL como parent if(!xml.FindChildElem("ATIVIDADES-DE-PESQUISA-E-DESENVOLVIMENTO")){ cout << "Sem linha de pesquisa" << endl; return ERROR; } xml.IntoElem(); //define APD como parent if(!xml.FindChildElem("PESQUISA-E-DESENVOLVIMENTO")){ cout << "Sem linha de pesquisa" << endl; return ERROR; } xml.IntoElem(); // define PD como parent if(!xml.FindChildElem("LINHA-DE-PESQUISA")){ cout << "Sem linha de pesquisa" << endl; return ERROR; } temp->area = xml.GetChildAttrib("TITULO-DA-LINHA-DE-PESQUISA"); //cout << temp.area << endl; xml.ResetPos(); // ========= TRABALHOS EM EVENTOS =================== xml.FindElem("CURRICULO-VITAE"); // se passou pelo primeiro findelem(curriculo vitae) //passa por esse xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("PRODUCAO-BIBLIOGRAFICA")){ cout << "Sem PRODUCAO-BIBLIOGRAFICA." << endl; return ERROR; } xml.IntoElem(); if(!xml.FindElem("TRABALHOS-EM-EVENTOS")){ cout << "Sem TRABALHOS-EM-EVENTOS." << endl; return ERROR; } xml.IntoElem();// define TRABALHOS-EM-EVENTOS como parent while(xml.FindElem()){ Trabalho trab; xml.FindChildElem("DADOS-BASICOS-DO-TRABALHO"); trab.titulo = xml.GetChildAttrib("TITULO-DO-TRABALHO"); trab.ano = xml.GetChildAttrib("ANO-DO-TRABALHO"); temp->pubEventos.push_back(trab); nTrab++; } temp->nPubEventos = nTrab; xml.ResetPos(); // ========= ARTIGOS PUBLICADOS =================== xml.FindElem("CURRICULO-VITAE"); // se passou pelo primeiro findelem(curriculo vitae) //passa por esse xml.IntoElem(); //seta CV como tag pai if(!xml.FindElem("PRODUCAO-BIBLIOGRAFICA")){ cout << "Sem PRODUCAO-BIBLIOGRAFICA." << endl; return ERROR; } xml.IntoElem(); if(!xml.FindElem("ARTIGOS-PUBLICADOS")){ cout << "Sem ARTIGOS-PUBLICADOS." << endl; return ERROR; } xml.IntoElem();// define ARTIGOS-PUBLICADOS como parent while(xml.FindElem()){ Artigo artigo; xml.FindChildElem("DADOS-BASICOS-DO-ARTIGO"); artigo.titulo = xml.GetChildAttrib("TITULO-DO-ARTIGO"); artigo.ano = xml.GetChildAttrib("ANO-DO-ARTIGO"); temp->pubPeriodicos.push_back(artigo); nArt++; } temp->nPubPeriodicos = nArt; return SUCCESS; }
void GameSetting::LoadSetting() { TCHAR settingXMLPath[256]; CSVFile::GetAbsolutePath(L"settings.xml", settingXMLPath); CMarkup xml; if (xml.Load( settingXMLPath )) { xml.FindElem(); xml.IntoElem(); while (xml.FindElem(L"scene")) { if (xml.GetAttrib(L"name").compare(L"select") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.select, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"decide") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.decide, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"play") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.play, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"result") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.result, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"keysetting") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.keysetting, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"skinselect") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.skinselect, xml.GetData().c_str()); xml.OutOfElem(); } } while (xml.FindElem(L"setting")) { if (xml.GetAttrib(L"name").compare(L"screen")==0) { xml.IntoElem(); xml.FindElem(L"width"); screen.width = _wtoi(xml.GetData().c_str()); xml.FindElem(L"height"); screen.height = _wtoi(xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"key")==0) { // TODO: save key } else if (xml.GetAttrib(L"name").compare(L"play")==0) { xml.IntoElem(); xml.FindElem(L"speed"); play.speed = _wtoi(xml.GetData().c_str()); xml.FindElem(L"shutter"); play.shutter = _wtoi(xml.GetData().c_str()); xml.OutOfElem(); } } } }
int getIPfromXml(std::vector<nodeIp_t>& vecIpAddr) { CMarkup xml; const char *cfgConfig = "../config/FicsConfig.xml"; std::string strTmp; int ret = -1; char cmdBuf[256]; FILE *fp = NULL; char tmppath[256]={0}; int r=0; std::vector<string> pathList; vector<string>::iterator iter; vector<nodeIp_t>::iterator it; int nodeId; if (!FiIsExistFile(cfgConfig)) { // if ()//服务端不允许不存在 ut_err("file [%s] is not exist, try to auto generate\n", cfgConfig); //scan all FicsConfig.xml then connect all ip who is node[0-1]. #ifdef WIN32 sprintf(cmdBuf, "dir /s /b ..\\*FicsConfig.xml"); #else sprintf(cmdBuf, "find ../client/Config -name \'FicsConfig.xml\'"); #endif if (NULL == (fp = popen(cmdBuf, "r"))) { ut_err("popen error errno[%d]\n", errno); ret = -2; return ret; } do { r = fscanf(fp, "%[^\n]s", tmppath); fgetc(fp); if (r != EOF) { pathList.push_back(tmppath); } }while (r != EOF); pclose(fp); } else { pathList.push_back(cfgConfig); } for (iter = pathList.begin(); iter != pathList.end(); iter++) { if (!xml.Load(iter->c_str())) { ut_err("load ficsconfig xml[%s] failed\n", cfgConfig); return ret; } /*----------------------------------------------------------------------------- * parse extern IP from FicsConfig.xml *-----------------------------------------------------------------------------*/ if (xml.FindElem("fics")) { xml.IntoElem(); if (xml.FindElem("NodeServersInfo")) { xml.IntoElem(); while (xml.FindElem("OneNodeServer")) { xml.IntoElem(); if (xml.FindElem("NodeSeq")) { #ifdef WIN32 std::string nodeSeq; nodeSeq = xml.GetData(); nodeId = atoi(nodeSeq.c_str()); #else nodeId = atoi(xml.GetData().c_str()); #endif } xml.FindElem("ExternalIps"); xml.IntoElem(); while (xml.FindElem("IP")) { strTmp = xml.GetData(); unsigned long ip = inet_addr(strTmp.c_str()); bool exist = false; for (it = vecIpAddr.begin(); it != vecIpAddr.end(); it++) { if (it->ip == ip && it->nodeId == nodeId) { exist = true; break; } } if (exist == false) { nodeIp_t tmp; tmp.ip = ip; tmp.nodeId = nodeId; vecIpAddr.push_back(tmp); } } xml.OutOfElem(); xml.OutOfElem(); } } } } if (!vecIpAddr.empty()) { ret = 0; } return ret; }
FicsCfgParser::FicsCfgParser( MCD_CSTR cfgName ) { m_nodeNum = 0; CMarkup xml; tstring strTmp; const u32 invalidNodeNo = -1; u32 curNode = invalidNodeNo, backupNode = invalidNodeNo; bool brTmp = false; if (!xml.Load(cfgName)) { VTRACE(_T("load ficsconfig xml[%s] failed \n"), cfgName); return; } if (xml.FindElem(_T("/fics/NodeServersInfo"))){ xml.IntoElem(); while (xml.FindElem(_T("OneNodeServer"))) { xml.IntoElem(); brTmp = xml.FindElem(_T("NodeSeq")); assert(brTmp); strTmp = xml.GetData(); curNode = MCD_TTOI(strTmp.c_str()); //½âÎöInternalIPs brTmp = xml.FindElem(_T("InternalIPs")); assert(brTmp); xml.IntoElem(); vector<u32> tmp; tmp.clear(); while (xml.FindElem(_T("IP"))) { strTmp = xml.GetData(); CStdString ipTmp = strTmp.c_str(); tmp.push_back(ConvertIPtoDWORD(ipTmp)); m_ipToNode[ConvertIPtoDWORD(ipTmp)] = curNode; } if (isLocalNodeIp(tmp)){ m_internalIpLocal.insert(m_internalIpLocal.end(), tmp.begin(), tmp.end()); }else { m_internalIpOther.insert(m_internalIpOther.end(), tmp.begin(), tmp.end()); } m_nodeToInternalIp[curNode] = tmp; xml.OutOfElem(); //½âÎöExternalIps brTmp = xml.FindElem(_T("ExternalIps")); assert(brTmp); xml.IntoElem(); tmp.clear(); while (xml.FindElem(_T("IP"))) { strTmp = xml.GetData(); CStdString ipTmp = strTmp.c_str(); tmp.push_back(ConvertIPtoDWORD(ipTmp)); m_ipToNode[ConvertIPtoDWORD(ipTmp)] = curNode; } if (isLocalNodeIp(tmp)){ m_externalIpLocal.insert(m_externalIpLocal.end(), tmp.begin(), tmp.end()); }else { m_externalIpOther.insert(m_externalIpOther.end(), tmp.begin(), tmp.end()); } m_nodeToExternalIp[curNode] = tmp; brTmp = xml.FindElem(_T("MdsBackNodeSeq")); if (brTmp){ strTmp = xml.GetData(); backupNode = MCD_TTOI(strTmp.c_str()); }else{ backupNode = invalidNodeNo; } m_nodeToBackup[curNode] = backupNode; xml.OutOfElem(); xml.OutOfElem(); } } if (xml.FindElem(_T("/fics/nodeStripPar"))) { xml.IntoElem(); strTmp = xmlNode.GetData(); m_nodeStripPar = atoi(strTmp); xml.OutOfElem(); } else { m_nodeStripPar = 2 * 1024 * 1024; } }
int main() { CMarkup cfg; if(!cfg.Load("daq.conf")) err_exit("load config file failed"); while(cfg.FindElem("device")) { string devid; devid = cfg.GetAttrib("id"); if(devid.empty()) err_exit("device must have an id"); // add device dev *devp = new dev(devid); dev_pool::instance().add_dev(devp); // cfg.IntoElem(); while(cfg.FindElem("acqer")) { string proto; proto = cfg.GetAttrib("proto"); if(proto.empty()) err_exit("acqer must have a proto"); if(proto == "modbus") { acqer_modbus *amp = NULL; string ip; string serialportstr; string devaddrstr; uint8 devaddr; devaddrstr = cfg.GetAttrib("devaddr"); if(devaddrstr.empty()) err_exit("modbus acqer must have devaddr"); devaddr = str2uint(devaddrstr); ip = cfg.GetAttrib("ip"); if(!ip.empty()) { // acqer_modbus_tcp *amcp = new acqer_modbus_tcp; // acqer_modbus = acqer_modbus_tcp; } else if(!((serialportstr = cfg.GetAttrib("serialport")).empty())) { uint16 port; uint32 baudrate; uint8 databits; uint8 stopbits; uint8 flowctl; uint8 parity; string stemp; port = str2uint(serialportstr); // baudrate stemp = cfg.GetAttrib("baudrate"); if(stemp.empty()) err_exit("serialport must hav baudrate"); baudrate = str2uint(stemp); // databits stemp = cfg.GetAttrib("databits"); if(stemp.empty()) err_exit("serialport must have databits"); databits = str2uint(stemp); // stopbits stemp = cfg.GetAttrib("stopbits"); if(stemp.empty()) err_exit("serialport must have stopbits"); stopbits = str2uint(stemp); // flowctl stemp = cfg.GetAttrib("flowctl"); if(stemp.empty()) err_exit("serialport must have flowctl"); flowctl = str2uint(stemp); //create acqer acqer_modbus_serialport *amsp = new acqer_modbus_serialport(devaddr, port, baudrate, databits, stopbits, flowctl, parity); amp = amsp; devp->add_acqer(amsp); serialport_pool::instance().add_serialport(port); // items cfg.IntoElem(); while(cfg.FindElem("item")) { int itemid; string itemname; unsigned int itemcycle; uint8 funcode; uint8 startaddr; uint8 count; uint8 offset; string expr; string stemp; string valtypestr; ITEM_VALUE_TYPE ivt; // create item item_modbus *imp = NULL; stemp = cfg.GetAttrib("id"); if(stemp.empty()) err_exit("item must have id"); itemid = str2int(stemp); /* name */ itemname = cfg.GetAttrib("name"); /* cycle */ stemp = cfg.GetAttrib("cycle"); if(stemp.empty()) err_exit("item must have cycle"); itemcycle = str2uint(stemp); /* expression */ expr = cfg.GetAttrib("expr"); /* valuetype */ valtypestr = cfg.GetAttrib("valtype"); if(valtypestr.empty()) valtypestr = "integer"; if(valtypestr == "float") ivt = IVT_FLOAT; else if(valtypestr == "string") ivt = IVT_STRING; else ivt = IVT_INTEGER; /* modbus items */ stemp = cfg.GetAttrib("funcode"); if(!stemp.empty()) { funcode = str2uint(cfg.GetAttrib("funcode")); /* startaddr */ stemp = cfg.GetAttrib("startaddr"); if(stemp.empty()) err_exit("modbus item must have startaddr"); startaddr = str2uint(stemp); // count stemp = cfg.GetAttrib("count"); if(stemp.empty()) err_exit("modbus item must have count"); count = str2uint(stemp); // offset stemp = cfg.GetAttrib("offset"); offset = str2uint(stemp); imp = new item_modbus(itemid, itemname, itemcycle, expr, ivt, false, funcode, startaddr, offset, count); } else { imp = new item_modbus(itemid, itemname, itemcycle, expr, ivt); } // add an item to acqer amp->add_item(imp); } // cfg.Find("item") cfg.OutOfElem(); //test expression configuration if(!amp->calc_items()) err_exit("wrong expression config"); } else { err_exit("modbus acqer must have an ip or com"); } }// modbus else { err_exit("protocol %s not supported", proto.c_str()); } } cfg.OutOfElem(); } // acq loop while(run) { dev_pool::instance().acq_once(); dev_pool::instance().handle_item(); sleep(1); } err_exit("exited"); return 0; }
void CMISView::openXmlFile(CString& fileName,bool first) { CMarkup xml; xml.Load(fileName); xml.FindElem("Obj"); CString objPath=xml.GetData(); xml.ResetMainPos(); xml.FindElem("CollisionSafe"); CString cSafe=xml.GetData(); xml.ResetMainPos(); xml.FindElem("SupportThreshold"); para.supportThreshold=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("ObjType"); int ObjType=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("Thickness"); para.modelThickness=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("Name"); para.modelName=xml.GetData(); xml.ResetMainPos(); xml.FindElem("StepLen"); para.stepLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("EdgeLen"); para.maxEdgeLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("BoundEdgeLen"); para.boundEdgeLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("MatDensity"); para.matDensity=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("FluidDensity"); para.fluidDensity=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("DisruptAngle"); para.disruptAngle=atof(xml.GetData()); cout<<para.boundEdgeLen<<endl; if (cSafe=="true") para.collisionSafe=true; else para.collisionSafe=false; if (support!=NULL) { reset(); } switch (ObjType) { case 0: myObj.loadObjFromFile(objPath); break; case 1: myObj.loadObjFromFileEx(objPath); break; case 2: myObj.loadObjFromFileEx2(objPath); break; case 3: myObj.loadObjFromFileEx3(objPath); break; } BBox bbox=myObj.getBBox(); Vector3d boxCenter; boxCenter[0]=(bbox.H[0]+bbox.L[0])/2; boxCenter[1]=(bbox.H[1]+bbox.L[1])/2; boxCenter[2]=(bbox.H[2]+bbox.L[2])/2; boxCenter=-boxCenter; double maxW=-1; for (int i=0;i<3;i++) { if (bbox.H[i]-bbox.L[i]>maxW) { maxW=bbox.H[i]-bbox.L[i]; } } myObj.translate(boxCenter); myObj.scale(1/maxW); cout<<myObj.vertexNum<<endl; cout<<myObj.faceNum<<endl; //myObj.translate(Vector3d(0.5,0.5,0.5)); support=new Support(&myObj,para,mode,fluidHeight); support->setMeshRotation(meshRotation); cY=support->getLowestH(); updateCam(); if (!first) { defaultXml=fileName; CPaintDC dc(this); OnDraw(&dc); } }
bool XMLSerialized::Deserialize(){ if(m_mapping.size()==0) return false; CMarkup * xml = new CMarkup(); if(!xml->Load(sFileName)){ delete xml; xml = NULL; return false; } std::map<int,DATA*>::const_iterator item; for(item= m_mapping.begin(); item != m_mapping.end(); item ++){ DATA* data = item->second; if(data->_tagType== TagType::Attribute){ if(FindPath(data->_parent,xml)){ xml->OutOfElem(); switch(data->_dataType){ case DataType::Int: (*(int*)data->_value) = _ttoi(xml->GetAttrib(data->_tagName)); break; case DataType::Bool: (*(bool*)data->_value) = (bool)_ttoi(xml->GetAttrib(data->_tagName)); break; case DataType::ByteArray: StringToByteArray(xml->GetAttrib(data->_tagName),L"|",(byte*)data->_value); break; case DataType::IntArray: StringToIntArray(xml->GetAttrib(data->_tagName),L"|",(int*)data->_value); break; case DataType::String: (*(CString*)data->_value) = (CString)(xml->GetAttrib(data->_tagName)); break; } } } if(data->_tagType== TagType::Element && data->_dataType!=DataType::None){ if(FindPath(data->_parent,xml)){ if(xml->FindElem(data->_tagName)){ switch(data->_dataType){ case DataType::Int: (*(int*)data->_value) = _ttoi(xml->GetData()); break; case DataType::Bool: (*(bool*)data->_value) = (bool)_ttoi(xml->GetData()); break; case DataType::ByteArray: StringToByteArray(xml->GetData(),L"|",(byte*)data->_value); break; case DataType::IntArray: StringToIntArray(xml->GetData(),L"|",(int*)data->_value); break; case DataType::String: (*(CString*)data->_value) = (CString)(xml->GetData()); break; } } } } } delete xml; xml = NULL; return true; }