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 );
	}
}
Beispiel #2
0
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 );
		}
	}
}
Beispiel #3
0
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();
}