void CUploadsWnd::OnSecurityBan() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; 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(); IN_ADDR pAddress = pUpload->m_pHost.sin_addr; pUpload->Remove( FALSE ); pLock.Unlock(); Security.Ban( &pAddress, banSession ); pLock.Lock(); } } }
void CUploadsWnd::OnBrowseLaunch() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; 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* pTransfer = pFile->GetActive(); PROTOCOLID nProtocol = pTransfer->m_nProtocol; SOCKADDR_IN pAddress = pTransfer->m_pHost; pLock.Unlock(); new CBrowseHostWnd( nProtocol, &pAddress ); pLock.Lock(); } } }
void CUploadsWnd::OnUpdateUploadsPriority(CCmdUI* pCmdUI) { Prepare(); // Default skin visible="false" if ( CCoolBarItem* pItem = CCoolBarItem::FromCmdUI( pCmdUI ) ) pItem->Show( m_bSelActive && ! m_bSelQueued ); BOOL bPriority = FALSE; if ( m_bSelActive && ! m_bSelQueued ) { for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) && pFile->GetActive()->m_bPriority && pFile->GetActive()->m_nState != upsNull ) { bPriority = TRUE; break; } } } pCmdUI->Enable( ( m_bSelActive && m_nSelected == 1 ) || bPriority ); pCmdUI->SetCheck( bPriority ); }
void CUploadsWnd::OnUploadsClear() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; 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 ) ) { CUploadTransfer* pUpload = pFile->GetActive(); if ( pUpload != NULL && pUpload->m_nProtocol == PROTOCOL_ED2K && pUpload->m_nState != upsNull ) { CString strFormat, strMessage; LoadString( strFormat, IDS_UPLOAD_CANCEL_ED2K ); strMessage.Format( strFormat, (LPCTSTR)pUpload->m_sFileName ); pLock.Unlock(); UINT nResp = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 ); pLock.Lock(); if ( nResp == IDCANCEL ) break; if ( nResp != IDYES || ! UploadFiles.Check( pFile ) ) continue; } pFile->Remove(); } } }
UINT __stdcall CUploadFile::TD_UpgradeRoute( LPVOID pV ) { CUploadFile* dvrCfg = (CUploadFile*)pV; if( dvrCfg == NULL ) return 0; dvrCfg->UpgradeRoute( ); return 0; }
void CUploadsCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CUploadFile* pFile; CUploadQueue* pQueue; m_wndTip.Hide(); switch ( nChar ) { case VK_HOME: SelectTo( 0 ); return; case VK_END: { INT nMin, nMax; GetScrollRange( SB_VERT, &nMin, &nMax ); SelectTo( max( 0, nMax - 1 ) ); } return; case VK_UP: SelectTo( m_nFocus - 1 ); return; case VK_DOWN: SelectTo( m_nFocus + 1 ); return; case VK_PRIOR: SelectTo( m_nFocus - 10 ); return; case VK_NEXT: SelectTo( m_nFocus + 10 ); return; case VK_LEFT: case '-': if ( GetAt( m_nFocus, &pQueue, &pFile ) ) { if ( pFile != NULL && pFile->GetActive() != NULL ) pQueue = pFile->GetActive()->m_pQueue; if ( pQueue != NULL && pQueue->m_bExpanded == TRUE ) { pQueue->m_bExpanded = FALSE; Update(); } } return; case VK_RIGHT: case '+': if ( GetAt( m_nFocus, &pQueue, NULL ) && pQueue != NULL && pQueue->m_bExpanded == FALSE ) { pQueue->m_bExpanded = TRUE; Update(); } return; } CWnd::OnKeyDown( nChar, nRepCnt, nFlags ); }
POSITION CUploadsCtrl::GetFileIterator(CUploadQueue* pQueue) { ASSUME_LOCK( Transfers.m_pSection ); if ( pQueue == UploadQueues.m_pTorrentQueue ) { for ( POSITION posNext = UploadFiles.GetIterator() ; posNext ; ) { POSITION posThis = posNext; CUploadFile* pFile = UploadFiles.GetNext( posNext ); CUploadTransfer* pTransfer = pFile->GetActive(); if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) continue; if ( pTransfer->m_nProtocol != PROTOCOL_BT ) continue; return posThis; } return NULL; } else if ( pQueue == UploadQueues.m_pHistoryQueue ) { for ( POSITION posNext = UploadFiles.GetIterator() ; posNext ; ) { POSITION posThis = posNext; CUploadFile* pFile = UploadFiles.GetNext( posNext ); CUploadTransfer* pTransfer = pFile->GetActive(); if ( pTransfer != NULL ) { if ( pTransfer->m_nProtocol == PROTOCOL_BT && pTransfer->m_nState != upsNull ) continue; if ( pTransfer->m_pQueue != NULL ) continue; } return posThis; } return NULL; } else { if ( Settings.Uploads.FilterMask & ULF_ACTIVE ) { if ( pQueue->GetActiveCount() > 0 ) { return pQueue->GetActiveIterator(); } } if ( Settings.Uploads.FilterMask & ULF_QUEUED ) { if ( pQueue->GetQueuedCount() > 0 ) { return (POSITION)1; } } return NULL; } }
void CUploadsWnd::OnUploadsStart() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) && pFile->GetActive() != NULL ) pFile->GetActive()->Promote(); } }
void CUploadFiles::Remove(CUploadTransfer* pTransfer) { for ( POSITION pos = GetIterator() ; pos ; ) { POSITION posRemove = pos; CUploadFile* pFile = GetNext( pos ); if ( pFile->Remove( pTransfer ) ) { delete pFile; m_pList.RemoveAt( posRemove ); } } }
void CUploadFiles::MoveToTail(CUploadTransfer* pTransfer) { for ( POSITION pos = GetIterator() ; pos ; ) { POSITION posThis = pos; CUploadFile* pFile = GetNext( pos ); if ( pFile->GetActive() == pTransfer ) { m_pList.RemoveAt( posThis ); m_pList.AddTail( pFile ); return; } } }
void CUploadsWnd::Prepare() { DWORD tNow = GetTickCount(); if ( tNow - m_tSel < 250 ) return; m_tSel = tNow; m_bSelFile = m_bSelUpload = FALSE; m_bSelActive = m_bSelQueued = FALSE; m_bSelHttp = m_bSelDonkey = FALSE; m_bSelSourceAcceptConnections = m_bSelSourceExtended = FALSE; CSingleLock pLock( &Transfers.m_pSection, TRUE ); for ( POSITION posFile = UploadFiles.GetIterator() ; posFile ; ) { CUploadFile* pFile = UploadFiles.GetNext( posFile ); if ( pFile->m_bSelected && IsSelected( pFile ) ) { m_bSelFile = TRUE; if ( CUploadTransfer* pTransfer = pFile->GetActive() ) { m_bSelUpload = TRUE; if ( pTransfer->m_nProtocol == PROTOCOL_HTTP ) m_bSelHttp = TRUE; if ( pTransfer->m_nProtocol == PROTOCOL_ED2K ) m_bSelDonkey = TRUE; if ( pTransfer->m_pQueue != NULL ) { if ( pTransfer->m_pQueue->m_pActive.Find( pTransfer ) != NULL ) m_bSelActive = TRUE; else m_bSelQueued = TRUE; } else if ( pTransfer->m_nState != upsNull ) { m_bSelActive = TRUE; } if ( pTransfer->m_bClientExtended ) m_bSelSourceExtended = TRUE; //m_bSelSourceAcceptConnections = pTransfer-> } } } }
CUploadFile* CUploadFiles::GetFile(CUploadTransfer* pUpload, const Hashes::Sha1Hash& oSHA1, LPCTSTR pszName, LPCTSTR pszPath, QWORD nSize) { for ( POSITION pos = GetIterator() ; pos ; ) { CUploadFile* pFile = GetNext( pos ); if ( pFile->m_pAddress.S_un.S_addr == pUpload->m_pHost.sin_addr.S_un.S_addr ) { if ( pFile->m_sPath == pszPath ) { pFile->Add( pUpload ); return pFile; } } } CUploadFile* pFile = new CUploadFile( pUpload, oSHA1, pszName, pszPath, nSize ); m_pList.AddTail( pFile ); return pFile; }
void CUploadsWnd::OnUploadsChat() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) && pFile->GetActive() != NULL ) { if ( pFile->GetActive()->m_nProtocol == PROTOCOL_HTTP ) // HTTP chat. (G2, G1) ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_HTTP ); else if ( pFile->GetActive()->m_bClientExtended ) // Client accepts G2 chat ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_G2 ); else if ( pFile->GetActive()->m_nProtocol == PROTOCOL_ED2K )// ED2K chat. ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_ED2K ); else // Should never be called theApp.Message( MSG_ERROR, _T("Error while initiating chat- Unable to select protocol") ); } } }
void CUploadsWnd::OnUploadsPriority() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( pFile->GetActive() != NULL ) { if ( m_nSelected == 1 && IsSelected( pFile ) && ! pFile->GetActive()->m_bPriority ) pFile->GetActive()->Promote( TRUE ); else if ( pFile->GetActive()->m_nState != upsNull ) pFile->GetActive()->m_bPriority = FALSE; } } }
void CUploadsWnd::Prepare() { if ( GetTickCount() < m_tSel + Settings.Interface.RefreshRateUI ) return; CSingleLock pLock( &Transfers.m_pSection, FALSE ); if ( ! pLock.Lock( Settings.Interface.RefreshRateUI ) ) return; m_tSel = GetTickCount(); m_nSelected = 0; m_bSelFile = m_bSelUpload = FALSE; m_bSelActive = m_bSelQueued = FALSE; m_bSelChat = m_bSelBrowse = FALSE; m_bSelSourceAcceptConnections = FALSE; m_bSelPartial = TRUE; for ( POSITION posFile = UploadFiles.GetIterator() ; posFile ; ) { CUploadFile* pFile = UploadFiles.GetNext( posFile ); if ( ! pFile->m_bSelected || ! IsSelected( pFile ) ) continue; m_bSelFile = TRUE; if ( CUploadTransfer* pTransfer = pFile->GetActive() ) { m_nSelected++; m_bSelUpload = TRUE; if ( pTransfer->m_bClientExtended ) { m_bSelChat = TRUE; m_bSelBrowse = TRUE; } else if ( pTransfer->m_nProtocol == PROTOCOL_ED2K ) { m_bSelChat = TRUE; CUploadTransferED2K* pTransferED2K = static_cast< CUploadTransferED2K* >( pTransfer ); if ( pTransferED2K->m_pClient && pTransferED2K->m_pClient->m_bEmBrowse ) m_bSelBrowse = TRUE; } if ( pTransfer->m_pQueue != NULL ) { if ( pTransfer->m_pQueue->IsActive( pTransfer ) ) m_bSelActive = TRUE; else m_bSelQueued = TRUE; } else if ( pTransfer->m_nState != upsNull ) { m_bSelActive = TRUE; } if ( m_bSelPartial == TRUE ) { if ( StartsWith( pFile->m_sPath, Settings.Downloads.IncompletePath ) ) continue; if ( ! pFile->m_sPath.IsEmpty() ) // Not multifile torrent m_bSelPartial = FALSE; else if ( PathIsDirectory( Settings.Downloads.TorrentPath + _T("\\") + pFile->m_sName ) ) // Try multifile torrent default, ToDo: Need better detection m_bSelPartial = FALSE; //CPeerProjectFile oFile = *pFile; //CSingleLock pLibraryLock( &Library.m_pSection ); //if ( pLibraryLock.Lock( 100 ) ) //{ // if ( CLibraryFile* pLibFile = LibraryMaps.LookupFileByHash( &oFile, FALSE, TRUE ) ) // m_bSelPartial = FALSE; // else if ( pFile->m_sPath.Find( pFile->m_sName ) > 3 ) // Not multifile torrent (Not in library, but shared seed from untracked download group) // m_bSelPartial = FALSE; // else if ( PathIsDirectory( Settings.Downloads.TorrentPath + _T("\\") + pFile->m_sName ) ) // Try multifile torrent default, need better detection // m_bSelPartial = FALSE; //} } } } }
CUploadFile* CUploadsCtrl::GetNextFile(CUploadQueue* pQueue, POSITION& pos, int* pnPosition) { ASSUME_LOCK( Transfers.m_pSection ); ASSERT( pos != NULL ); if ( pnPosition != NULL ) *pnPosition = -1; if ( pQueue == UploadQueues.m_pTorrentQueue ) { CUploadFile* pReturn = UploadFiles.GetNext( pos ); for ( ; pos ; ) { POSITION posThis = pos; CUploadFile* pFile = UploadFiles.GetNext( pos ); CUploadTransfer* pTransfer = pFile->GetActive(); if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) continue; if ( pTransfer->m_nProtocol != PROTOCOL_BT ) continue; pos = posThis; break; } return pReturn; } else if ( pQueue == UploadQueues.m_pHistoryQueue ) { CUploadFile* pReturn = UploadFiles.GetNext( pos ); for ( ; pos ; ) { POSITION posThis = pos; CUploadFile* pFile = UploadFiles.GetNext( pos ); CUploadTransfer* pTransfer = pFile->GetActive(); if ( pTransfer != NULL ) { //if ( pTransfer->m_nProtocol == PROTOCOL_BT && pTransfer->m_nState != upsNull ) continue; if ( pTransfer->m_nState != upsNull ) continue; if ( pTransfer->m_pQueue != NULL ) continue; } pos = posThis; break; } return pReturn; } else if ( (UINT_PTR)pos > pQueue->GetQueuedCount() ) { CUploadTransfer* pTransfer = pQueue->GetNextActive( pos ); if ( pos == NULL ) { if ( Settings.Uploads.FilterMask & ULF_QUEUED ) { if ( pQueue->GetQueuedCount() > 0 ) { pos = (POSITION)1; } } } if ( pnPosition != NULL ) *pnPosition = 0; return pTransfer->m_pBaseFile; } else { UINT_PTR nPos = (UINT_PTR)pos; CUploadTransfer* pTransfer = pQueue->GetQueuedAt( nPos - 1 ); if ( pnPosition != NULL ) *pnPosition = static_cast< int >( nPos ); ++nPos; if ( nPos > pQueue->GetQueuedCount() ) nPos = 0; pos = (POSITION)nPos; return pTransfer->m_pBaseFile; } }
void CRemote::PageUploads() { if ( CheckCookie() ) return; m_nTab = tabUploads; CSingleLock pLock( &UploadQueues.m_pSection, FALSE ); if ( ! SafeLock( pLock ) ) return; Prepare(); // Header CString strRandom; strRandom.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) ); Add( L"random", strRandom ); Output( L"uploadsHeader" ); for ( POSITION posQueue = CUploadsCtrl::GetQueueIterator(); posQueue != NULL; ) { CUploadQueue* pQueue = CUploadsCtrl::GetNextQueue( posQueue ); CString strQueueID; strQueueID.Format( L"%p", pQueue ); if ( GetKey( L"queue_expand" ) == strQueueID ) pQueue->m_bExpanded = TRUE; else if ( GetKey( L"queue_collapse" ) == strQueueID ) pQueue->m_bExpanded = FALSE; POSITION posFile = CUploadsCtrl::GetFileIterator( pQueue ); if ( posFile == NULL ) continue; Prepare(); Add( L"queue_id", strQueueID ); Add( L"queue_caption", pQueue->m_sName ); if ( pQueue->m_bExpanded ) Add( L"queue_expanded", L"true" ); if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue ) { CString str; str.Format( L"%u", pQueue->GetTransferCount() ); Add( L"queue_transfers", str ); str.Format( L"%u", pQueue->GetQueuedCount() ); Add( L"queue_queued", str ); Add( L"queue_bandwidth", Settings.SmartSpeed( pQueue->GetMeasuredSpeed() ) ); } Output( L"uploadsQueueStart" ); if ( pQueue->m_bExpanded ) { while ( posFile != NULL ) { int nPosition; CUploadFile* pFile = CUploadsCtrl::GetNextFile( pQueue, posFile, &nPosition ); if ( pFile == NULL ) continue; CUploadTransfer* pTransfer = pFile->GetActive(); CString strFileID; strFileID.Format( L"%p", pFile ); if ( GetKey( L"drop" ) == strFileID ) { pFile->Remove(); continue; } Add( L"file_id", strFileID ); Add( L"file_filename", pFile->m_sName ); Add( L"file_size", Settings.SmartVolume( pFile->m_nSize ) ); if ( pTransfer != NULL ) { Add( L"file_address", pTransfer->m_sAddress ); Add( L"file_nick", pTransfer->m_sRemoteNick ); Add( L"file_user", pTransfer->m_sAddress + L" - " + pTransfer->m_sRemoteNick ); Add( L"file_agent", pTransfer->m_sUserAgent ); } CString str; if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) { LoadString( str, IDS_STATUS_COMPLETED ); } else if ( pTransfer->m_nProtocol == PROTOCOL_BT ) { CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer; if ( ! pBT->m_bInterested ) LoadString( str, IDS_STATUS_UNINTERESTED ); else if ( pBT->m_bChoked ) LoadString( str, IDS_STATUS_CHOKED ); else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() ) str = Settings.SmartSpeed( nSpeed ); } else if ( nPosition > 0 ) { LoadString( str, IDS_STATUS_Q ); str.Format( L"%s %i", (LPCTSTR)str, nPosition ); } else { if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() ) str = Settings.SmartSpeed( nSpeed ); else LoadString( str, IDS_STATUS_NEXT ); } Add( L"file_speed", str ); Add( L"file_status", str ); Output( L"uploadsFile" ); Prepare( L"file_" ); } } Output( L"uploadsQueueEnd" ); Prepare( L"queue_" ); } Prepare(); Output( L"uploadsFooter" ); }