void SortAliases (CAliasMap & AliasMap, CAliasArray & AliasArray) { int iCount = AliasMap.GetCount (); int i; CString strAliasName; CAlias * pAlias; POSITION pos; AliasArray.SetSize (iCount); // extract pointers into a simple array for (i = 0, pos = AliasMap.GetStartPosition(); pos; i++) { AliasMap.GetNextAssoc (pos, strAliasName, pAlias); AliasArray.SetAt (i, pAlias); } // sort the array qsort (AliasArray.GetData (), iCount, sizeof (CAlias *), CompareAlias); } // end of SortAliases
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; }