BOOL CCollectionFile::File::Parse(CXMLElement* pRoot) { //if ( ! pRoot->IsNamed( L"file" ) ) return FALSE; // Discards DC++ for ( POSITION pos = pRoot->GetElementIterator(); pos; ) { CXMLElement* pXML = pRoot->GetNextElement( pos ); if ( pXML->IsNamed( L"id" ) ) { if ( ! m_oSHA1 ) m_oSHA1.fromUrn( pXML->GetValue() ); if ( ! m_oTiger ) m_oTiger.fromUrn( pXML->GetValue() ); if ( ! m_oED2K ) m_oED2K.fromUrn( pXML->GetValue() ); if ( ! m_oMD5 ) m_oMD5.fromUrn( pXML->GetValue() ); if ( ! m_oBTH ) m_oBTH.fromUrn( pXML->GetValue() ); if ( ! m_oBTH ) m_oBTH.fromUrn< Hashes::base16Encoding >( pXML->GetValue() ); } else if ( pXML->IsNamed( L"description" ) ) { if ( CXMLElement* pName = pXML->GetElementByName( L"name" ) ) m_sName = pName->GetValue(); if ( CXMLElement* pSize = pXML->GetElementByName( L"size" ) ) { if ( _stscanf( pSize->GetValue(), L"%I64i", &m_nSize ) != 1 ) return FALSE; } } else if ( pXML->IsNamed( L"metadata" ) ) { if ( m_pMetadata ) delete m_pMetadata; m_pMetadata = CCollectionFile::CloneMetadata( pXML ); } //else if ( pXML->IsNamed( L"packaged" ) ) //{ // if ( CXMLElement* pSource = pXML->GetElementByName( L"source" ) ) // /*m_sSource =*/ pSource->GetValue(); // ToDo: Use Sources? //} } // DC++ format if ( m_sName.IsEmpty() && ! m_oTiger && m_nSize == SIZE_UNKNOWN ) { m_sName = pRoot->GetAttributeValue( L"Name" ); _stscanf( pRoot->GetAttributeValue( L"Size" ), L"%I64i", &m_nSize ); m_oTiger.fromString( pRoot->GetAttributeValue( L"TTH" ) ); } return HasHash(); }
BOOL CRichDocument::LoadXMLStyles(CXMLElement* pParent) { for ( POSITION pos = pParent->GetElementIterator() ; pos ; ) { CXMLElement* pXML = pParent->GetNextElement( pos ); if ( ! pXML->IsNamed( _T("style") ) ) continue; CString strName = pXML->GetAttributeValue( _T("name") ); CharLower( strName.GetBuffer() ); strName.ReleaseBuffer(); CString strFontFace = theApp.m_sDefaultFont; int nFontSize = theApp.m_nDefaultFontSize + 1; int nFontWeight = FW_BOLD; if ( CXMLElement* pFont = pXML->GetElementByName( _T("font") ) ) { strFontFace = pFont->GetAttributeValue( _T("face") ); CString strTemp = pFont->GetAttributeValue( _T("size") ); _stscanf( strTemp, _T("%i"), &nFontSize ); strTemp = pFont->GetAttributeValue( _T("weight") ); _stscanf( strTemp, _T("%i"), &nFontWeight ); } CXMLElement* pColours = pXML->GetElementByName( _T("colours") ); if ( pColours == NULL ) pColours = pXML; if ( strName == _T("default") || strName.IsEmpty() ) { LoadXMLColour( pColours, _T("text"), &m_crText ); LoadXMLColour( pColours, _T("link"), &m_crLink ); LoadXMLColour( pColours, _T("hover"), &m_crHover ); CreateFonts( strFontFace, nFontSize ); } else if ( strName == _T("heading") ) { LoadXMLColour( pColours, _T("text"), &m_crHeading ); if ( m_fntHeading.m_hObject ) m_fntHeading.DeleteObject(); m_fntHeading.CreateFont( -nFontSize, 0, 0, 0, nFontWeight, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, strFontFace ); } } return TRUE; }
CPlayProfilePage::CPlayProfilePage(CXMLElement* pXML) : CSettingsPage( CPlayProfilePage::IDD ), m_pXML( pXML ) { //{{AFX_DATA_INIT(CPlayProfilePage) //}}AFX_DATA_INIT CXMLElement* pParent = m_pXML->GetParent(); m_pXMLChat = pParent->GetElementByName( "ChatRoom" ); }
CXMLElement* CPlayerWnd::LoadXML(LPCTSTR lpszName, BOOL bCreate) { CXMLElement* pXML = CXMLElement::FromFile( _T("Xhistory.xml"), TRUE ); CXMLElement* pOrder = NULL; if ( pXML ) pOrder = pXML->GetElementByName( lpszName, bCreate ); else if ( bCreate ) pOrder = new CXMLElement( NULL, lpszName ); if ( pOrder ) pOrder->Detach(); pXML->Delete(); return pOrder; }
CString CBitziDownloader::LookupValue(LPCTSTR pszPath) { CString strName, strPath( pszPath ); CXMLElement* pXML = m_pXML; BOOL bFirst = TRUE; while ( strPath.GetLength() ) { strName = strPath.SpanExcluding( _T("/") ); strPath = strPath.Mid( strName.GetLength() ); if ( strPath.IsEmpty() ) { return pXML->GetAttributeValue( strName, NULL ); } if ( bFirst ) { bFirst = FALSE; if ( strName.CompareNoCase( pXML->GetName() ) ) pXML = NULL; } else { pXML = pXML->GetElementByName( strName ); } if ( ! pXML ) { strName.Empty(); return strName; } strPath = strPath.Mid( 1 ); } strName.Empty(); if ( pXML ) strName = pXML->GetValue(); return strName; }
BOOL CPlayerWnd::SaveXML(CXMLElement* pXML) { ASSERT( pXML != NULL ); CFile pFile; if ( ! pFile.Open( _T("Xhistory.xml"), CFile::modeWrite|CFile::modeCreate ) ) return FALSE; CXMLElement* pParent = LoadXML( pXML->GetName() ); if ( ! pParent ) pParent = CreateXML(); pParent->GetElementByName( pXML->GetName() )->Delete(); pParent->AddElement( pXML ); CString strXML; strXML = pParent->ToString( TRUE, TRUE ); pFile.Write( (LPCSTR)strXML, strXML.GetLength() ); pFile.Close(); pXML->Detach(); pParent->Delete(); return TRUE; }
BOOL CEmoticons::LoadXML(LPCTSTR pszFile) { CString strPath, strValue; CXMLElement* pXML = CXMLElement::FromFile( pszFile, TRUE ); if ( pXML == NULL ) return FALSE; strPath = pszFile; int nSlash = strPath.ReverseFind( '\\' ); if ( nSlash >= 0 ) strPath = strPath.Left( nSlash + 1 ); CXMLElement* pBitmap = pXML->GetElementByName( _T("bitmap") ); if ( pBitmap == NULL ) { delete pXML; return FALSE; } strValue = pBitmap->GetAttributeValue( _T("file") ); nSlash = strValue.ReverseFind( '/' ); if ( nSlash >= 0 ) strValue = strValue.Mid( nSlash + 1 ); strValue = strPath + strValue; CImageFile pImage; if ( ! pImage.LoadFromFile( strValue ) || ! pImage.EnsureRGB( GetSysColor( COLOR_WINDOW ) ) || ! pImage.SwapRGB() ) { delete pXML; return FALSE; } COLORREF crBack = RGB( pImage.m_pImage[2], pImage.m_pImage[1], pImage.m_pImage[0] ); for ( POSITION pos = pXML->GetElementIterator() ; pos ; ) { CXMLElement* pEmoticon = pXML->GetNextElement( pos ); if ( ! pEmoticon->IsNamed( _T("emoticon") ) ) continue; CXMLElement* pSource = pEmoticon->GetElementByName( _T("source") ); CString strText = pEmoticon->GetAttributeValue( _T("text") ); CRect rc( 0, 0, 0, 0 ); strValue = pSource->GetAttributeValue( _T("left"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.left ); strValue = pSource->GetAttributeValue( _T("top"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.top ); strValue = pSource->GetAttributeValue( _T("right"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.right ); strValue = pSource->GetAttributeValue( _T("bottom"), _T("0") ); _stscanf( strValue, _T("%i"), &rc.bottom ); BOOL bButton = pEmoticon->GetAttributeValue( _T("button") ).CompareNoCase( _T("yes") ) == 0; AddEmoticon( strText, &pImage, &rc, crBack, bButton ); } delete pXML; return TRUE; }
BOOL CCollectionFile::LoadCollection(LPCTSTR pszFile) { m_nType = EnvyCollection; CZIPFile pZIP; if ( ! pZIP.Open( pszFile ) ) return FALSE; CZIPFile::File* pFile = pZIP.GetFile( L"Collection.xml", TRUE ); if ( ! pFile ) return FALSE; if ( pZIP.GetCount() == 1 ) // xml-only m_nType = SimpleCollection; augment::auto_ptr< CBuffer > pBuffer ( pFile->Decompress() ); if ( ! pBuffer.get() ) return FALSE; augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer->ReadString( pBuffer->m_nLength, CP_UTF8 ), TRUE ) ); if ( ! pXML.get() ) return FALSE; if ( ! pXML->IsNamed( L"collection" ) ) return FALSE; CXMLElement* pProperties = pXML->GetElementByName( L"properties" ); if ( ! pProperties ) return FALSE; CXMLElement* pContents = pXML->GetElementByName( L"contents" ); if ( ! pContents ) return FALSE; for ( POSITION pos = pContents->GetElementIterator(); pos; ) { CXMLElement* pElement = pContents->GetNextElement( pos ); if ( pElement->IsNamed( L"file" ) ) { augment::auto_ptr< File > pNewFile( new File( this ) ); if ( pNewFile.get() && pNewFile->Parse( pElement ) ) m_pFiles.AddTail( pNewFile.release() ); } } if ( CXMLElement* pMetadata = pProperties->GetElementByName( L"metadata" ) ) { m_pMetadata = CloneMetadata( pMetadata ); if ( m_pMetadata ) m_sThisURI = m_pMetadata->GetAttributeValue( CXMLAttribute::schemaName ); } if ( CXMLElement* pTitle = pProperties->GetElementByName( L"title" ) ) m_sTitle = pTitle->GetValue(); if ( CXMLElement* pMounting = pProperties->GetElementByName( L"mounting" ) ) { if ( CXMLElement* pParent = pMounting->GetElementByName( L"parent" ) ) m_sParentURI = pParent->GetAttributeValue( L"uri" ); if ( CXMLElement* pThis = pMounting->GetElementByName( L"this" ) ) m_sThisURI = pThis->GetAttributeValue( L"uri" ); } if ( m_sThisURI.IsEmpty() ) { Close(); return FALSE; } return TRUE; }
BOOL CShareMonkeyData::ImportData(CXMLElement* pRoot) { if ( pRoot == NULL ) return FALSE; if ( m_nRequestType == stProductMatch ) { if ( m_pSchema == NULL ) // Get the schema from the product Category { CXMLElement* pCategory = pRoot->GetElementByName( L"CategoryID" ); int nCategory = 0; CString strCategory = pCategory->GetValue(); if ( pCategory && strCategory.GetLength() && _stscanf( strCategory, L"%i", &nCategory ) == 1 ) { switch ( nCategory ) { case 1: m_pSchema = SchemaCache.Get( CSchema::uriAudio ); break; case 2: m_pSchema = SchemaCache.Get( CSchema::uriBook ); // For documents break; case 3: m_pSchema = SchemaCache.Get( CSchema::uriArchive ); // For games break; case 4: m_pSchema = SchemaCache.Get( CSchema::uriApplication ); // For software break; case 5: m_pSchema = SchemaCache.Get( CSchema::uriVideo ); break; //default: // break; } } } if ( m_pSchema == NULL ) return FALSE; m_pRazaXML = m_pSchema->Instantiate( TRUE ); CXMLElement* pXML = m_pRazaXML->AddElement( m_pSchema->m_sSingular ); Setup( m_pSchema, TRUE ); for ( POSITION pos = pRoot->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pRoot->GetNextElement( pos ); if ( pElement->IsNamed( L"ProductName" ) ) m_sProductName = pElement->GetValue(); else if ( pElement->IsNamed( L"ProductID" ) ) m_sProductID = pElement->GetValue(); else if ( pElement->IsNamed( L"ProductDescription" ) ) m_sDescription = pElement->GetValue(); else if ( pElement->IsNamed( L"ProductURLs" ) ) { CXMLElement* pBuyURL = pElement->GetElementByName( L"ProductBuyURL" ); if ( pBuyURL ) m_sBuyURL = pBuyURL->GetValue(); } else if ( pElement->IsNamed( L"ProductImages" ) ) { CXMLElement* pImage = pElement->GetElementByName( L"LargeImage" ); if ( pImage == NULL ) pImage = pElement->GetElementByName( L"MediumImage" ); if ( pImage == NULL ) pImage = pElement->GetElementByName( L"SmallImage" ); if ( pImage ) { if ( CXMLElement* pImageURL = pImage->GetElementByName( L"ImageURL" ) ) m_sThumbnailURL = pImageURL->GetValue(); } } } CXMLAttribute* pAttribute = new CXMLAttribute( NULL, L"title" ); pAttribute->SetValue( m_sProductName ); pXML->AddAttribute( pAttribute ); pAttribute = new CXMLAttribute( NULL, L"description" ); pAttribute->SetValue( m_sDescription ); pXML->AddAttribute( pAttribute ); //if ( ! m_sBuyURL.IsEmpty() ) //{ // pAttribute = new CXMLAttribute( NULL, L"distributerLink" ); // pAttribute->SetValue( m_sBuyURL ); // pXML->AddAttribute( pAttribute ); //} Combine( pXML ); delete m_pRazaXML; m_pRazaXML = NULL; } else if ( m_nRequestType == stStoreMatch ) { CXMLElement* pStore = pRoot->GetElementByName( L"StoreName" ); if ( pStore == NULL ) return FALSE; CString strName = pStore->GetValue(); if ( strName.IsEmpty() ) return FALSE; CXMLElement* pPrice = pRoot->GetElementByName( L"Price" ); if ( pPrice == NULL ) return FALSE; CXMLElement* pValue = pPrice->GetElementByName( L"PriceFormatted" ); if ( pValue == NULL ) return FALSE; CString strValue = pValue->GetValue(); if ( strValue.IsEmpty() ) return FALSE; CXMLElement* pLink = pRoot->GetElementByName( L"StoreURL" ); if ( pLink ) { CString strLink; strLink.Format( L"%s|%s", (LPCTSTR)pLink->GetValue(), (LPCTSTR)strValue ); while ( Find( strName ) ) strName += '\x00A0'; CMetaItem* pItem = Add( strName, strLink ); pItem->m_bValueDefined = TRUE; } } return TRUE; }