コード例 #1
0
ファイル: DlgDownload.cpp プロジェクト: ivan386/Shareaza
void CDownloadDlg::OnTorrentFile()
{
	UpdateData();

	CFileDialog dlg( TRUE, _T("torrent"), ( Settings.Downloads.TorrentPath + _T("\\.") ) , OFN_HIDEREADONLY,
		_T("Torrent Files|*.torrent|") +
		SchemaCache.GetFilter( CSchema::uriAllFiles ) +
		_T("|"), this );

	if ( dlg.DoModal() != IDOK ) return;

	if ( m_pDownload )
	{
		CBTInfo pInfo;
		if ( ! pInfo.LoadTorrentFile( dlg.GetPathName() ) )
			return;

		CSingleLock pTransfersLock( &Transfers.m_pSection );
		if ( ! pTransfersLock.Lock( 2000 ) )
			return;

		if ( Downloads.Check( m_pDownload ) )
		{
			m_pDownload->SetTorrent( &pInfo );
		}
	}
	else
	{
		// New torrent
		theApp.OpenTorrent( dlg.GetPathName(), TRUE );
	}

	EndDialog( IDCANCEL );
}
コード例 #2
0
void CLibraryFileView::OnLibraryDelete()
{
	CSingleLock pTransfersLock( &Transfers.m_pSection, TRUE );	// Can clear uploads and downloads
	CSingleLock pLibraryLock( &Library.m_pSection, TRUE );

	CLibraryListPtr pList( new CLibraryList() );

	POSITION posSel = StartSelectedFileLoop();
	while ( CLibraryFile* pFile = GetNextSelectedFile( posSel, FALSE, ! m_bGhostFolder ) )
	{
		pList->AddTail( pFile );
	}

	while ( ! pList->IsEmpty() )
	{
		CLibraryFile* pFile = Library.LookupFile( pList->GetHead(), FALSE, ! m_bGhostFolder );
		if ( pFile == NULL )
		{
			pList->RemoveHead();	// Remove item from list to avoid endless loop
			continue;
		}

		if ( m_bGhostFolder )
		{
			for ( INT_PTR nProcess = pList->GetCount() ; nProcess > 0 && pList->GetCount() > 0 ; nProcess-- )
			{
				if ( ( pFile = Library.LookupFile( pList->RemoveHead() ) ) != NULL )
					pFile->Delete( TRUE );
			}
		}
		else
		{
			CDeleteFileDlg dlg( this );
			dlg.m_sName	= pFile->m_sName;
			dlg.m_sComments = pFile->m_sComments;
			dlg.m_nRateValue = pFile->m_nRating;
			dlg.m_bAll	= pList->GetCount() > 1;

			pLibraryLock.Unlock();
			pTransfersLock.Unlock();

			if ( dlg.DoModal() != IDOK ) break;

			pTransfersLock.Lock();
			pLibraryLock.Lock();

			for ( INT_PTR nProcess = dlg.m_bAll ? pList->GetCount() : 1 ; nProcess > 0 && pList->GetCount() > 0 ; nProcess-- )
			{
				if ( ( pFile = Library.LookupFile( pList->RemoveHead(), FALSE, TRUE ) ) != NULL )
				{
					dlg.Apply( pFile );
					pFile->Delete();
				}
			}
		}

		Library.Update( true );
	}
}
コード例 #3
0
ファイル: DownloadGroups.cpp プロジェクト: ivan386/Shareaza
BOOL CDownloadGroups::Save(BOOL bForce)
{
	if ( ! bForce && m_nBaseCookie == m_nSaveCookie )
		return FALSE;

	CString strTemp = Settings.General.UserPath + _T("\\Data\\DownloadGroups.tmp");
	CString strFile = Settings.General.UserPath + _T("\\Data\\DownloadGroups.dat");

	CFile pFile;
	if ( ! pFile.Open( strTemp, CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive | CFile::osSequentialScan ) )
	{
		DeleteFile( strTemp );
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
		return FALSE;
	}

	try
	{
		CArchive ar( &pFile, CArchive::store );	// 4 KB buffer
		try
		{
			CQuickLock pTransfersLock( Transfers.m_pSection );
			CQuickLock pLock( m_pSection );

			Serialize( ar );

			m_nSaveCookie = m_nBaseCookie;

			ar.Close();
		}
		catch ( CException* pException )
		{
			ar.Abort();
			pFile.Abort();
			pException->Delete();
			theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
			return FALSE;
		}
		pFile.Close();
	}
	catch ( CException* pException )
	{
		pFile.Abort();
		pException->Delete();
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
		return FALSE;
	}

	if ( ! MoveFileEx( strTemp, strFile, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ) )
	{
		DeleteFile( strTemp );
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strFile );
		return FALSE;
	}

	return TRUE;
}
コード例 #4
0
ファイル: WndUploads.cpp プロジェクト: lemonxiao0/peerproject
void CUploadsWnd::OnUploadsLaunch()
{
	CSingleLock pTransfersLock( &Transfers.m_pSection );
	if ( ! pTransfersLock.Lock( 500 ) ) return;

	const BOOL bShift = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 );

	CList<CUploadFile*> pList;

	for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
	{
		CUploadFile* pFile = UploadFiles.GetNext( pos );
		if ( IsSelected( pFile ) )
			pList.AddTail( pFile );
	}

	pTransfersLock.Unlock();

	while ( ! pList.IsEmpty() )
	{
		pTransfersLock.Lock();
		CUploadFile* pFile = pList.RemoveHead();

		if ( pFile->m_sPath.IsEmpty() )		// Multifile torrent always opens folder?  (ToDo: Update this path assumption when fixed elsewhere)
		{
			const CString strPath = Settings.Downloads.TorrentPath + _T("\\") + pFile->m_sName;		// Try default multifile torrent folder  (Need better detection)
			pTransfersLock.Unlock();
			if ( PathIsDirectory( strPath ) )
				ShellExecute( GetSafeHwnd(), _T("open"), strPath, NULL, NULL, SW_SHOWNORMAL );
		}
		else if ( ! bShift )				// Show in Library by default
		{
			CPeerProjectFile oFile = *pFile;
			pTransfersLock.Unlock();

			CSingleLock pLibraryLock( &Library.m_pSection, TRUE );
			if ( CLibraryFile* pLibFile = LibraryMaps.LookupFileByHash( &oFile ) )
			{
				if ( CLibraryWnd* pLibrary = CLibraryWnd::GetLibraryWindow() )		// (CLibraryWnd*)( pMainWnd->m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd) ) ) )
				{
					pLibrary->Display( pLibFile );
				}
			}
		}
		else if ( UploadFiles.Check( pFile ) )	// Launch directly with Shift key
		{
			pTransfersLock.Unlock();
			CFileExecutor::Execute( pFile->m_sPath );
		}
	}
}
コード例 #5
0
ファイル: Download.cpp プロジェクト: GetEnvy/Envy
void CDownload::OnMoved()
{
	CSingleLock pTransfersLock( &Transfers.m_pSection, TRUE );

	// Just completed torrent
	if ( IsTorrent() && IsFullyVerified() )
	{
		// Set FALSE to prevent sending 'stop' announce to tracker
		m_bTorrentRequested = FALSE;
		StopTrying();

		// Send 'completed' announce to tracker
		SendCompleted();

		// This torrent is now seeding
		m_bSeeding = TRUE;
		m_bVerify = TRI_TRUE;
		m_bTorrentStarted = TRUE;
		m_bTorrentRequested = TRUE;
	}
	else
	{
		if ( IsTorrent() )
			m_bTorrentRequested = TRUE;		// Explicitly set flag to send stop announce to tracker
		StopTrying();
		ClearSources();
	}

	ASSERT( ! m_sPath.IsEmpty() );
	const CString strPath = m_sPath;
	m_sPath.Empty();

	pTransfersLock.Unlock();

	DeleteFileEx( strPath + L".png", FALSE, FALSE, TRUE );
	DeleteFileEx( strPath + L".sav", FALSE, FALSE, TRUE );
	DeleteFileEx( strPath, FALSE, FALSE, TRUE );

	pTransfersLock.Lock();

	// Download finalized, tracker notified, set flags that we completed
	m_bComplete  = true;
	m_tCompleted = GetTickCount();
	//LibraryBuilder.m_bBusy = false;
}
コード例 #6
0
ファイル: DownloadGroups.cpp プロジェクト: ivan386/Shareaza
BOOL CDownloadGroups::Load()
{
	CString strFile = Settings.General.UserPath + _T("\\Data\\DownloadGroups.dat");

	CFile pFile;
	if ( pFile.Open( strFile, CFile::modeRead | CFile::shareDenyWrite | CFile::osSequentialScan ) )
	{
		try
		{
			CArchive ar( &pFile, CArchive::load );	// 4 KB buffer
			try
			{
				CQuickLock pTransfersLock( Transfers.m_pSection );
				CQuickLock pLock( m_pSection );

				Serialize( ar );

				ar.Close();
			}
			catch ( CException* pException )
			{
				ar.Abort();
				pFile.Abort();
				pException->Delete();
				theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );
			}
			pFile.Close();
		}
		catch ( CException* pException )
		{
			pFile.Abort();
			pException->Delete();
			theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );
		}
	}
	else
		theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );

	m_nSaveCookie = m_nBaseCookie;

	return TRUE;
}
コード例 #7
0
ファイル: CtrlUploads.cpp プロジェクト: ivan386/Shareaza
void CUploadsCtrl::OnPaint()
{
	CRect rcClient, rcItem;
	CPaintDC dc( this );

	CSingleLock pTransfersLock( &Transfers.m_pSection, FALSE );
	if ( ! pTransfersLock.Lock( 250 ) )
		return;

	CSingleLock pUploadQueuesLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pUploadQueuesLock.Lock( 250 ) )
		return;

	if ( Settings.General.LanguageRTL ) dc.SetTextAlign( TA_RTLREADING );

	GetClientRect( &rcClient );
	rcClient.top += HEADER_HEIGHT;
	
	rcItem.CopyRect( &rcClient );
	rcItem.left -= GetScrollPos( SB_HORZ );
	rcItem.bottom = rcItem.top + ITEM_HEIGHT;
	
	int nScroll = GetScrollPos( SB_VERT );
	int nIndex = 0;
	
	CFont* pfOld = (CFont*)dc.SelectObject( &CoolInterface.m_fntNormal );
	BOOL bFocus = ( GetFocus() == this );

	for ( POSITION posQueue = GetQueueIterator() ; posQueue && rcItem.top < rcClient.bottom ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;
		
		if ( nScroll > 0 )
		{
			nScroll --;
		}
		else
		{
			if ( rcItem.bottom > rcClient.top )
				PaintQueue( dc, rcItem, pQueue, bFocus && ( m_nFocus == nIndex ) );
			rcItem.OffsetRect( 0, ITEM_HEIGHT );
		}
		
		nIndex ++;
		
		if ( ! pQueue->m_bExpanded ) continue;
		
		while ( posFile && rcItem.top < rcClient.bottom )
		{
			int nPosition;
			CUploadFile* pFile = GetNextFile( pQueue, posFile, &nPosition );
			if ( pFile == NULL ) continue;
			
			if ( nScroll > 0 )
			{
				nScroll --;
			}
			else
			{
				if ( rcItem.bottom > rcClient.top )
					PaintFile( dc, rcItem, pQueue, pFile, nPosition, bFocus && ( m_nFocus == nIndex ) );
				rcItem.OffsetRect( 0, ITEM_HEIGHT );
			}
			
			nIndex ++;
		}
	}

	pUploadQueuesLock.Unlock();
	pTransfersLock.Unlock();
	
	dc.SelectObject( pfOld );
	
	rcClient.top = rcItem.top;
	if ( rcClient.top < rcClient.bottom )
		dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
}
コード例 #8
0
ファイル: CtrlUploads.cpp プロジェクト: ivan386/Shareaza
void CUploadsCtrl::OnSize(UINT nType, int cx, int cy)
{
	int nWidth = 0, nHeight = 0;
	CRect rcClient;
	
	if ( nType != 1982 ) CWnd::OnSize( nType, cx, cy );
	
	GetClientRect( &rcClient );
	
	HDITEM pColumn ={};
	pColumn.mask = HDI_WIDTH;
	
	for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn ++ )
		nWidth += pColumn.cxy;
	
	SCROLLINFO pScroll = {};
	pScroll.cbSize	= sizeof(pScroll);
	pScroll.fMask	= SIF_RANGE|SIF_PAGE;
	pScroll.nMin	= 0;
	pScroll.nMax	= nWidth;
	pScroll.nPage	= rcClient.right;
	SetScrollInfo( SB_HORZ, &pScroll, TRUE );
	
	int nScroll = GetScrollPos( SB_HORZ );
	m_wndHeader.SetWindowPos( NULL, -nScroll, 0, rcClient.right + nScroll, HEADER_HEIGHT, SWP_SHOWWINDOW );
	
	CSingleLock pTransfersLock( &Transfers.m_pSection, FALSE );
	if ( ! pTransfersLock.Lock( 250 ) )
		return;

	CSingleLock pUploadQueuesLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pUploadQueuesLock.Lock( 250 ) )
		return;
	
	for ( POSITION posQueue = GetQueueIterator() ; posQueue ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		
		if ( posFile == NULL )
		{
			pQueue->m_bSelected = FALSE;
			continue;
		}
		
		nHeight ++;
		
		if ( ! pQueue->m_bExpanded ) continue;

		while ( posFile )
		{
			if ( GetNextFile( pQueue, posFile ) ) nHeight ++;
		}
	}
	
	pUploadQueuesLock.Unlock();
	pTransfersLock.Unlock();
	
	ZeroMemory( &pScroll, sizeof(pScroll) );
	pScroll.cbSize	= sizeof(pScroll);
	pScroll.fMask	= SIF_RANGE|SIF_PAGE;
	pScroll.nMin	= 0;
	pScroll.nMax	= nHeight;
	pScroll.nPage	= ( rcClient.bottom - HEADER_HEIGHT ) / ITEM_HEIGHT + 1;
	SetScrollInfo( SB_VERT, &pScroll, TRUE );
	
	m_nFocus = min( m_nFocus, max( 0, nHeight - 1 ) );
	
	Invalidate();
}
コード例 #9
0
ファイル: DlgExistingFile.cpp プロジェクト: GetEnvy/Envy
CExistingFileDlg::Action CExistingFileDlg::CheckExisting(const CEnvyFile* pFile)
{
	CSingleLock pLibraryLock( &Library.m_pSection );
	if ( ! SafeLock( pLibraryLock ) )
		return Cancel;

	if ( pFile->m_sPath.GetLength() )
	{
		const BOOL bIsFolder = ( pFile->m_sPath.GetAt( pFile->m_sPath.GetLength() - 1 ) == L'\\' );
		if ( bIsFolder )
		{
			const CLibraryFolder* pFolder = LibraryFolders.GetFolder( pFile->m_sPath.Left( pFile->m_sPath.GetLength() - 1 ) );
			return pFolder ? ShowInLibrary : Download;
		}
	}

	CLibraryFile* pLibFile = LibraryMaps.LookupFileByHash( pFile );
	if ( pLibFile == NULL )
		return Download;

	const DWORD nIndex = pLibFile->m_nIndex;

	CExistingFileDlg dlg( pLibFile );

	pLibraryLock.Unlock();

	dlg.DoModal();

	if ( dlg.m_nAction == 0 )
	{
		// Handle mutifile torrents
		if ( pFile->m_oBTH )
		{
			CSingleLock pTransfersLock( &Transfers.m_pSection );
			if ( SafeLock( pTransfersLock ) )
			{
				if ( CDownload* pDownload = Downloads.FindByBTH( pFile->m_oBTH ) )
				{
					if ( CMainWnd* pMainWnd = (CMainWnd*)AfxGetMainWnd() )
					{
						if ( CDownloadsWnd* pDownWnd = (CDownloadsWnd*)pMainWnd->m_pWindows.Find( RUNTIME_CLASS(CDownloadsWnd) ) )
						{
							pDownWnd->Select( pDownload );
							pTransfersLock.Unlock();

							pMainWnd->PostMessage( WM_COMMAND, ID_VIEW_DOWNLOADS );
							pMainWnd->PostMessage( WM_SYSCOMMAND, SC_RESTORE );

							return dlg.GetResult();
						}
					}
				}
			}
		}

		if ( CLibraryWnd* pLibrary = CLibraryWnd::GetLibraryWindow() )
		{
			if ( SafeLock( pLibraryLock ) )
			{
				if ( CLibraryFile* pLibFileLookup = Library.LookupFile( nIndex ) )
					pLibrary->Display( pLibFileLookup );
				pLibraryLock.Unlock();
			}
		}
	}

	return dlg.GetResult();
}