void CUploadsWnd::OnUploadsDisconnect() { CList<CUploadFile*> pList; CSingleLock pLock( &Transfers.m_pSection, TRUE ); for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } while ( ! pList.IsEmpty() ) { CUploadFile* pFile = pList.RemoveHead(); if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL ) { CUploadTransfer* pUpload = pFile->GetActive(); if ( pUpload->m_nProtocol == PROTOCOL_ED2K && pUpload->m_nState != upsNull ) { CString strFormat, strMessage; LoadString( strFormat, IDS_UPLOAD_CANCEL_ED2K ); strMessage.Format( strFormat, (LPCTSTR)pUpload->m_sName ); pLock.Unlock(); INT_PTR nResp = MsgBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 ); pLock.Lock(); if ( nResp == IDCANCEL ) break; if ( nResp != IDYES || ! Uploads.Check( pUpload ) ) continue; } pUpload->Close( TRUE ); } } }
BOOL CUploads::EnforcePerHostLimit(CUploadTransfer* pHit, BOOL bRequest) { int nCount = 0; for ( POSITION pos = GetIterator() ; pos ; ) { CUploadTransfer* pUpload = GetNext( pos ); if ( pUpload->m_nState == upsUploading || pUpload->m_nState == upsQueued || pUpload->m_nState == upsPreQueue ) { if ( pUpload->m_pHost.sin_addr.S_un.S_addr == pHit->m_pHost.sin_addr.S_un.S_addr ) nCount++; } } if ( nCount <= Settings.Uploads.MaxPerHost ) return FALSE; while ( nCount > Settings.Uploads.MaxPerHost ) { CUploadTransfer* pNewest = NULL; for ( POSITION pos = GetIterator() ; pos ; ) { CUploadTransfer* pUpload = GetNext( pos ); if ( pUpload->m_nState == upsUploading || pUpload->m_nState == upsQueued || pUpload->m_nState == upsPreQueue ) { if ( pUpload != pHit && pUpload->m_pHost.sin_addr.S_un.S_addr == pHit->m_pHost.sin_addr.S_un.S_addr ) { if ( bRequest && pUpload->m_pBaseFile == pHit->m_pBaseFile ) { pNewest = pUpload; break; } if ( pNewest == NULL || pUpload->m_tConnected > pNewest->m_tConnected ) pNewest = pUpload; } } } if ( pNewest == NULL ) break; if ( bRequest ) { if ( pNewest->m_pBaseFile == pHit->m_pBaseFile && ! pNewest->m_bLive ) { UploadQueues.StealPosition( pHit, pNewest ); theApp.Message( MSG_ERROR, IDS_UPLOAD_DROPPED_OLDER, (LPCTSTR)pNewest->m_sAddress ); pNewest->Close( FALSE ); } else { return FALSE; } } else { theApp.Message( MSG_ERROR, IDS_UPLOAD_DROPPED_NEWER, (LPCTSTR)pNewest->m_sAddress ); pNewest->Close( FALSE ); } nCount--; } return FALSE; }