void CDownloadWithSources::Serialize(CArchive& ar, int nVersion) { CDownloadBase::Serialize( ar, nVersion ); if ( ar.IsStoring() ) { ar.WriteCount( GetSourceCount() ); for ( CDownloadSource* pSource = GetFirstSource() ; pSource ; pSource = pSource->m_pNext ) { pSource->Serialize( ar, nVersion ); } ar.WriteCount( m_pXML != NULL ? 1 : 0 ); if ( m_pXML ) m_pXML->Serialize( ar ); } else { for ( int nSources = ar.ReadCount() ; nSources ; nSources-- ) { // Create new source CDownloadSource* pSource = new CDownloadSource( (CDownload*)this ); // Add to the list m_nSourceCount ++; pSource->m_pPrev = m_pSourceLast; pSource->m_pNext = NULL; if ( m_pSourceLast != NULL ) { m_pSourceLast->m_pNext = pSource; m_pSourceLast = pSource; } else { m_pSourceFirst = m_pSourceLast = pSource; } // Load details from disk pSource->Serialize( ar, nVersion ); // Extract ed2k client ID from url (m_pAddress) because it wasn't saved if ( ( !pSource->m_nPort ) && ( _tcsnicmp( pSource->m_sURL, _T("ed2kftp://"), 10 ) == 0 ) ) { CString strURL = pSource->m_sURL.Mid(10); if ( strURL.GetLength()) _stscanf( strURL, _T("%lu"), &pSource->m_pAddress.S_un.S_addr ); } } if ( ar.ReadCount() ) { m_pXML = new CXMLElement(); m_pXML->Serialize( ar ); } } }
void CDownloadWithSources::Serialize(CArchive& ar, int nVersion) // DOWNLOAD_SER_VERSION { CDownloadBase::Serialize( ar, nVersion ); CQuickLock pLock( Transfers.m_pSection ); if ( ar.IsStoring() ) { DWORD_PTR nSources = GetCount(); if ( nSources > Settings.Downloads.SourcesWanted ) nSources = Settings.Downloads.SourcesWanted; ar.WriteCount( nSources ); for ( POSITION posSource = GetIterator() ; posSource && nSources ; nSources-- ) { CDownloadSource* pSource = GetNext( posSource ); pSource->Serialize( ar, nVersion ); } ar.WriteCount( m_pXML != NULL ? 1 : 0 ); if ( m_pXML ) m_pXML->Serialize( ar ); } else // Loading { for ( DWORD_PTR nSources = ar.ReadCount() ; nSources ; nSources-- ) { // Create new source //CDownloadSource* pSource = new CDownloadSource( (CDownload*)this ); CAutoPtr< CDownloadSource > pSource( new CDownloadSource( static_cast< CDownload* >( this ) ) ); if ( ! pSource ) AfxThrowMemoryException(); // Load details from disk pSource->Serialize( ar, nVersion ); // Extract ed2k client ID from url (m_pAddress) because it wasn't saved if ( ! pSource->m_nPort && _tcsnicmp( pSource->m_sURL, _T("ed2kftp://"), 10 ) == 0 ) { CString strURL = pSource->m_sURL.Mid(10); if ( ! strURL.IsEmpty() ) _stscanf( strURL, _T("%lu"), &pSource->m_pAddress.S_un.S_addr ); } InternalAdd( pSource.Detach() ); } if ( ar.ReadCount() ) { m_pXML = new CXMLElement(); if ( ! m_pXML ) AfxThrowMemoryException(); m_pXML->Serialize( ar ); } } }
void CXMLElement::Serialize(CArchive& ar) { CXMLNode::Serialize( ar ); if ( ar.IsStoring() ) { ar.WriteCount( GetAttributeCount() ); for ( POSITION pos = GetAttributeIterator() ; pos ; ) { GetNextAttribute( pos )->Serialize( ar ); } ar.WriteCount( GetElementCount() ); for ( POSITION pos = GetElementIterator() ; pos ; ) { GetNextElement( pos )->Serialize( ar ); } } else // Loading { for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- ) { CXMLAttribute* pAttribute = new CXMLAttribute( this ); pAttribute->Serialize( ar ); // Skip attribute if name is missing if ( pAttribute->m_sName.IsEmpty() ) { delete pAttribute; continue; } CString strNameLower( pAttribute->m_sName ); strNameLower.MakeLower(); // Delete the old attribute if one exists CXMLAttribute* pExisting; if ( m_pAttributes.Lookup( strNameLower, pExisting ) ) delete pExisting; m_pAttributes.SetAt( strNameLower, pAttribute ); if ( ! m_pAttributesInsertion.Find( strNameLower ) ) m_pAttributesInsertion.AddTail( strNameLower ); // Track output order workaround } for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- ) { CXMLElement* pElement = new CXMLElement( this ); pElement->Serialize( ar ); m_pElements.AddTail( pElement ); } } }
void CLibraryMaps::Serialize2(CArchive& ar, int nVersion) { if ( nVersion < 18 ) return; if ( ar.IsStoring() ) { ar.WriteCount( m_pDeleted.GetCount() ); for ( POSITION pos = m_pDeleted.GetHeadPosition() ; pos ; ) { m_pDeleted.GetNext( pos )->Serialize( ar, nVersion ); } } else // Loading { for ( DWORD_PTR nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { //CLibraryFile* pFile = new CLibraryFile( NULL ); CAutoPtr< CLibraryFile > pFile( new CLibraryFile( NULL ) ); if ( ! pFile ) AfxThrowMemoryException(); pFile->Serialize( ar, nVersion ); if ( ! LibraryMaps.LookupFileByHash( pFile ) ) Library.AddFile( pFile.Detach() ); } } }
void CLineGraph::Serialize(CArchive& ar) { if ( ar.IsStoring() ) { ar << m_bShowAxis; ar << m_bShowGrid; ar << m_bShowLegend; ar << m_nSpeed; ar << max( m_nScale, MIN_GRID_SIZE_HORZ ); ar.WriteCount( GetItemCount() ); for ( POSITION pos = GetItemIterator() ; pos ; ) { GetNextItem( pos )->Serialize( ar ); } } else // Loading { ar >> m_bShowAxis; ar >> m_bShowGrid; ar >> m_bShowLegend; ar >> m_nSpeed; ar >> m_nScale; m_nScale = max( m_nScale, MIN_GRID_SIZE_HORZ ); for ( DWORD_PTR nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { CGraphItem* pItem = new CGraphItem(); pItem->Serialize( ar ); m_pItems.AddTail( pItem ); } } }
void CObList::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nCount); for (CNode* pNode = m_pNodeHead; pNode != NULL; pNode = pNode->pNext) { ASSERT(AfxIsValidAddress(pNode, sizeof(CNode))); ar << pNode->data; } } else { DWORD_PTR nNewCount = ar.ReadCount(); CObject* newData; while (nNewCount--) { ar >> newData; AddTail(newData); } } }
void CLineGraph::Serialize(CArchive& ar) { if ( ar.IsStoring() ) { ar << m_bShowAxis; ar << m_bShowGrid; ar << m_bShowLegend; ar << m_nSpeed; ar << m_nScale; ar.WriteCount( GetItemCount() ); for ( POSITION pos = GetItemIterator() ; pos ; ) { GetNextItem( pos )->Serialize( ar ); } } else { ar >> m_bShowAxis; ar >> m_bShowGrid; ar >> m_bShowLegend; ar >> m_nSpeed; ar >> m_nScale; for ( int nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { CGraphItem* pItem = new CGraphItem(); pItem->Serialize( ar ); m_pItems.AddTail( pItem ); } } }
void CLibraryHistory::Serialize(CArchive& ar, int nVersion) { if ( nVersion < 7 ) return; int nCount = 0; POSITION pos; if ( ar.IsStoring() ) { for ( pos = GetIterator() ; pos ; ) { if ( GetNext( pos )->m_pFile != NULL ) nCount ++; } ar.WriteCount( nCount ); for ( pos = GetIterator() ; pos ; ) { CLibraryRecent* pRecent = GetNext( pos ); if ( pRecent->m_pFile != NULL ) pRecent->Serialize( ar, nVersion ); } ar << LastSeededTorrent.m_sPath; if ( LastSeededTorrent.m_sPath.GetLength() ) { ar << LastSeededTorrent.m_sName; ar << LastSeededTorrent.m_tLastSeeded; ar.Write( &LastSeededTorrent.m_pBTH, sizeof(SHA1) ); } } else { Clear(); for ( nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { CLibraryRecent* pRecent = new CLibraryRecent(); pRecent->Serialize( ar, nVersion ); if ( pRecent->m_pFile != NULL ) { m_pList.AddTail( pRecent ); } else { delete pRecent; } } if ( nVersion > 22 ) { ar >> LastSeededTorrent.m_sPath; if ( LastSeededTorrent.m_sPath.GetLength() ) { ar >> LastSeededTorrent.m_sName; ar >> LastSeededTorrent.m_tLastSeeded; ar.Read( &LastSeededTorrent.m_pBTH, sizeof(SHA1) ); } }
void CAlbumFolder::Serialize(CArchive& ar, int nVersion) { POSITION pos; if ( ar.IsStoring() ) { ar << m_sSchemaURI; ar.WriteCount( m_pXML != NULL ? 1 : 0 ); if ( m_pXML ) m_pXML->Serialize( ar ); ar << m_bCollSHA1; if ( m_bCollSHA1 ) ar.Write( &m_pCollSHA1, sizeof(SHA1) ); ar << m_sName; ar << m_bExpanded; ar << m_bAutoDelete; ar << m_sBestView; ar.WriteCount( GetFolderCount() ); for ( pos = GetFolderIterator() ; pos ; ) { CAlbumFolder* pFolder = GetNextFolder( pos ); pFolder->Serialize( ar, nVersion ); } ar.WriteCount( GetFileCount() ); for ( pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); ar << pFile->m_nIndex; } } else { CLibraryFile* pCollection = NULL; if ( m_pParent != NULL ) { ar >> m_sSchemaURI; m_pSchema = SchemaCache.Get( m_sSchemaURI ); } else {
void CObArray::Serialize( CArchive &ar ) /**************************************/ { CObject::Serialize( ar ); if( ar.IsStoring() ) { ar.WriteCount( m_nSize ); for( int i = 0; i < m_nSize; i++ ) { ar << m_pData[i]; } } else { int nSize = ar.ReadCount(); SetSize( nSize ); for( int i = 0; i < nSize; i++ ) { ar >> m_pData[i]; } } }
void CSearchWnd::Serialize(CArchive& ar) { CQuickLock pLock( m_pMatches->m_pSection ); int nVersion = 1; if ( ar.IsStoring() ) { ar << nVersion; ar.WriteCount( size() ); for ( iterator pManaged = begin() ; pManaged != end() ; ++pManaged ) { (*pManaged)->Serialize( ar ); } } else // Loading { ar >> nVersion; if ( nVersion != 1 ) AfxThrowUserException(); for ( DWORD_PTR nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { CSearchPtr pManaged( new CManagedSearch() ); pManaged->Serialize( ar ); m_oSearches.push_back( pManaged ); } } CBaseMatchWnd::Serialize( ar ); if ( ar.IsLoading() ) { if ( ! empty() ) m_wndPanel.ShowSearch( m_oSearches.back() ); PostMessage( WM_TIMER, 1 ); SendMessage( WM_TIMER, 2 ); SetAlert( FALSE ); } }
void CStringArray::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nSize); for (INT_PTR i = 0; i < m_nSize; i++) ar << m_pData[i]; } else { DWORD_PTR nOldSize = ar.ReadCount(); SetSize(nOldSize); for (INT_PTR i = 0; i < m_nSize; i++) ar >> m_pData[i]; } }
void CObBinTree::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nCount); WalkTree( SerialStore, (LPVOID)&ar, TV_PREORDER ); } else { DWORD nNewCount = (DWORD)ar.ReadCount(); CObject* newData; while (nNewCount--) { ar >> newData; Insert(newData); } } }
void CWordArray::Serialize(CArchive& ar) { UINT_PTR nWORDsLeft; UINT nWORDsToWrite; UINT nWORDsToRead; LPWORD pwData; ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nSize); nWORDsLeft = m_nSize; pwData = m_pData; while(nWORDsLeft > 0) { nWORDsToWrite = UINT(min(nWORDsLeft, INT_MAX/sizeof(WORD))); ar.Write(pwData, nWORDsToWrite*sizeof(WORD)); nWORDsLeft -= nWORDsToWrite; pwData += nWORDsToWrite; } } else { DWORD_PTR nOldSize = ar.ReadCount(); SetSize(nOldSize); nWORDsLeft = m_nSize; pwData = m_pData; while(nWORDsLeft > 0) { nWORDsToRead = UINT(min( nWORDsLeft, INT_MAX/sizeof(WORD))); ar.EnsureRead(pwData, nWORDsToRead*sizeof(WORD)); nWORDsLeft -= nWORDsToRead; pwData += nWORDsToRead; } } }
void CMapWordToOb::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nCount); if (m_nCount == 0) return; // nothing more to do ASSERT(m_pHashTable != NULL); for (UINT nHash = 0; nHash < m_nHashTableSize; nHash++) { CAssoc* pAssoc; for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; pAssoc = pAssoc->pNext) { ar << pAssoc->key; ar << pAssoc->value; } } } else { DWORD nNewCount = ar.ReadCount(); WORD newKey; CObject* newValue; while (nNewCount--) { ar >> newKey; ar >> newValue; SetAt(newKey, newValue); } } }
void CMapStringToOb::Serialize( CArchive &ar ) /********************************************/ { CObject::Serialize( ar ); CString key; CObject *value; if( ar.IsStoring() ) { ar.WriteCount( m_nCount ); POSITION position = GetStartPosition(); while( position != NULL ) { GetNextAssoc( position, key, value ); ar << key; ar << value; } } else { UINT nCount = ar.ReadCount(); for( int i = 0; i < nCount; i++ ) { ar >> key; ar >> value; SetAt( key, value ); } } }
void CWordArray::Serialize(CArchive& ar) { ASSERT_VALID(this); CObject::Serialize(ar); if (ar.IsStoring()) { ar.WriteCount(m_nSize); #ifdef _MAC if (!ar.IsByteSwapping()) #endif ar.Write(m_pData, m_nSize * sizeof(WORD)); #ifdef _MAC else { // write each item individually so that it will be byte-swapped for (int i = 0; i < m_nSize; i++) ar << m_pData[i]; } #endif } else { DWORD nOldSize = ar.ReadCount(); SetSize(nOldSize); ar.Read(m_pData, m_nSize * sizeof(WORD)); #ifdef _MAC if (ar.IsByteSwapping()) { for (int i = 0; i < m_nSize; i++) _AfxByteSwap(m_pData[i], (BYTE*)&m_pData[i]); } #endif } }
void CSecurity::Serialize(CArchive& ar) { int nVersion = SECURITY_SER_VERSION; if ( ar.IsStoring() ) { ar << nVersion; ar << m_bDenyPolicy; ar.WriteCount( GetCount() ); for ( POSITION pos = GetIterator() ; pos ; ) { GetNext( pos )->Serialize( ar, nVersion ); } // Unimplemented //for ( CAddressRuleMap::const_iterator i = m_pIPRules.begin() ; i != m_pIPRules.end() ; ++i ) //{ // (*i).second->Serialize( ar, nVersion ); //} } else // Loading { Clear(); ar >> nVersion; ar >> m_bDenyPolicy; const DWORD tNow = static_cast< DWORD >( time( NULL ) ); for ( DWORD_PTR nCount = ar.ReadCount() ; nCount > 0 ; nCount-- ) { CSecureRule* pRule = new CSecureRule( FALSE ); pRule->Serialize( ar, nVersion ); if ( pRule->IsExpired( tNow, TRUE ) ) { delete pRule; continue; } // Special handling for single-IP security rules if ( pRule->m_nType == CSecureRule::srAddress && pRule->m_nAction == CSecureRule::srDeny && *(DWORD*)pRule->m_nMask == 0xffffffff ) { SetAddressMap( *(DWORD*)pRule->m_nIP, SetRuleIndex( pRule ) ); continue; } if ( pRule->m_nType == CSecureRule::srContentHash && pRule->m_nAction == CSecureRule::srDeny ) { SetHashMap( pRule->GetContentWords(), SetRuleIndex( pRule ) ); continue; } if ( pRule->m_nType == CSecureRule::srExternal ) ListLoader.AddList( pRule ); m_pRules.AddTail( pRule ); } } }
void CDownloadGroups::Serialize(CArchive& ar) { int nVersion = GROUPS_SER_VERSION; BYTE nState; if ( ar.IsStoring() ) { ar << nVersion; ar.WriteCount( Downloads.GetCount() ); for ( POSITION pos = Downloads.GetIterator() ; pos ; ) { ar << Downloads.GetNext( pos )->m_nSerID; } ar.WriteCount( GetCount() ); for ( POSITION pos = GetIterator() ; pos ; ) { CDownloadGroup* pGroup = GetNext( pos ); nState = ( pGroup == m_pSuper ) ? 1 : 0; ar << nState; pGroup->Serialize( ar, nVersion ); } } else { ar >> nVersion; if ( nVersion <= 1 || nVersion > GROUPS_SER_VERSION ) AfxThrowUserException(); int nCount = ar.ReadCount(); for ( ; nCount > 0 ; nCount-- ) { DWORD nDownload; ar >> nDownload; if ( CDownload* pDownload = Downloads.FindBySID( nDownload ) ) Downloads.Reorder( pDownload, NULL ); } if ( nCount = ar.ReadCount() ) Clear(); for ( ; nCount > 0 ; nCount-- ) { CDownloadGroup* pGroup = Add(); ar >> nState; if ( nState == 1 ) m_pSuper = pGroup; pGroup->Serialize( ar, nVersion ); } GetSuperGroup(); for ( POSITION pos = Downloads.GetIterator() ; pos ; ) { m_pSuper->Add( Downloads.GetNext( pos ) ); } } }