void SerializeAlias( CArchive & ar, CAliasArray & aAliases ) { char szFileMagic[] = "NETTSALIAS"; DWORD dwFileVersion = 0x20040825; if( ar.IsStoring() ) { ar.WriteString( szFileMagic ); ar << dwFileVersion; ar << (int)aAliases.GetSize(); for( int i=0; i<aAliases.GetSize(); i++ ) { CAlias & a = aAliases.ElementAt(i); ar << a.m_strName; ar << a.m_strValue; } } else { TCHAR buffer[64]; memset( buffer, 0, sizeof(buffer) ); ar.ReadString( buffer, strlen(szFileMagic) ); if( 0 != strncmp( szFileMagic, buffer, strlen(szFileMagic) ) ) return; DWORD dwVer; ar >> dwVer; if( dwVer > dwFileVersion ) return; int size; ar >> size; if( size < 0 || size > 10000 ) // too big return; aAliases.SetSize( 0, size+2 ); for( int i=0; i<size; i++ ) { CAlias a; ar >> a.m_strName; ar >> a.m_strValue; aAliases.Add( a ); } } }
BOOL CQSProfile::StoreAliases( CAliasArray & aNew ) { m_aAliases.SetSize( 0, aNew.GetSize() + 2 ); for( int i=0; i<aNew.GetSize(); i++ ) { CAlias & alias = aNew.ElementAt(i); m_aAliases.Add( alias ); } CFile file; if( file.Open( GetNetTSAliasFileName(), CFile::modeWrite | CFile::modeCreate ) ) { CArchive ar( &file, CArchive::store ); SerializeAlias( ar, m_aAliases ); ar.Close(); file.Close(); return TRUE; } return FALSE; }