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; }
/* <MSGTYPE TYPE="NOMALMSG"> <WHO NAME="ME" /> <TOWHO NAME="YOU" /> <MSG CONTEXT="hello,this is a test" /> <TTIME TIME="2012-06-21 13:26:30" /> </MSGTYPE> */ void CMsg::BuildNomal() { CMarkup m_xml(m_strText); CMarkupNode root = m_xml.GetRoot(); if( !root.IsValid() ) return ; LPCTSTR pstrClass = NULL; LPCTSTR pstrName = NULL; LPCTSTR pstrValue = NULL; for(CMarkupNode node=root.GetChild();node.IsValid();node=node.GetSibling()) { pstrClass = node.GetName(); if(_tcscmp(pstrClass, _T("WHO")) == 0 ) { pstrName = node.GetAttributeName(0); if(_tcscmp(pstrName, _T("NAME")) == 0 ) { pstrValue = node.GetAttributeValue(0); m_nomalMsg.who = pstrValue; } } if(_tcscmp(pstrClass, _T("TOWHO")) == 0 ) { pstrName = node.GetAttributeName(0); if(_tcscmp(pstrName, _T("NAME")) == 0 ) { pstrValue = node.GetAttributeValue(0); m_nomalMsg.toWho = pstrValue; } } if(_tcscmp(pstrClass, _T("MSG")) == 0 ) { pstrName = node.GetAttributeName(0); if(_tcscmp(pstrName, _T("CONTEXT")) == 0 ) { pstrValue = node.GetAttributeValue(0); m_nomalMsg.msgItem = pstrValue; } } if(_tcscmp(pstrClass, _T("TTIME")) == 0 ) { pstrName = node.GetAttributeName(0); if(_tcscmp(pstrName, _T("TIME")) == 0 ) { pstrValue = node.GetAttributeValue(0); m_nomalMsg.sndTime = pstrValue; } } } }
BOOL CResourceManager::LoadResource(CMarkupNode Root) { if( !Root.IsValid() ) return FALSE; LPCTSTR pstrClass = NULL; int nAttributes = 0; LPCTSTR pstrName = NULL; LPCTSTR pstrValue = NULL; LPTSTR pstr = NULL; //╪стьм╪ф╛вйт╢ LPCTSTR pstrId = NULL; LPCTSTR pstrPath = NULL; for( CMarkupNode node = Root.GetChild() ; node.IsValid(); node = node.GetSibling() ) { pstrClass = node.GetName(); CMarkupNode ChildNode = node.GetChild(); if(ChildNode.IsValid()) LoadResource(node); else if ((_tcsicmp(pstrClass,_T("Image")) == 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("path")) == 0 ) { pstrPath = pstrValue; } } if( pstrId == NULL || pstrPath == NULL) continue; CDuiString * pstrFind = static_cast<CDuiString *>(m_mImageHashMap.Find(pstrId)); if(pstrFind != NULL) continue; m_mImageHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrPath)); } else if( _tcsicmp(pstrClass,_T("Xml")) == 0 && node.HasAttributes()) { //╪стьXMLеДжцнд╪Ч 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("path")) == 0 ) { pstrPath = pstrValue; } } if( pstrId == NULL || pstrPath == NULL) continue; CDuiString * pstrFind = static_cast<CDuiString *>(m_mXmlHashMap.Find(pstrId)); if(pstrFind != NULL) continue; m_mXmlHashMap.Insert(pstrId, (LPVOID)new CDuiString(pstrPath)); } else continue; } return TRUE; }