Example #1
0
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 );
}
Example #2
0
BOOL CDDEServer::Execute(LPCTSTR pszTopic, LPCTSTR pszMessage)
{
	CWnd* pWnd = AfxGetMainWnd();

	if ( _tcscmp( pszTopic, _T("URL") ) == 0 )
	{
		theApp.Message( MSG_SYSTEM, IDS_URL_RECEIVED, pszMessage );

		CShareazaURL* pURL = new CShareazaURL();

		if ( pURL->Parse( pszMessage ) )
		{
			if ( ! pWnd->PostMessage( WM_URL, (WPARAM)pURL ) ) delete pURL;
			return TRUE;
		}

		delete pURL;
		theApp.Message( MSG_ERROR, IDS_URL_PARSE_ERROR );
	}
	else if ( _tcscmp( pszTopic, _T("TORRENT") ) == 0 )
	{
		theApp.Message( MSG_SYSTEM, IDS_BT_PREFETCH_FILE, pszMessage );

		CBTInfo* pTorrent = new CBTInfo();

		if ( pTorrent->LoadTorrentFile( pszMessage ) )
		{
			if ( pTorrent->HasEncodingError() ) theApp.Message( MSG_SYSTEM, _T("Possible encoding error detected while parsing torrent") );
			CShareazaURL* pURL = new CShareazaURL( pTorrent );
			if ( ! pWnd->PostMessage( WM_URL, (WPARAM)pURL ) ) delete pURL;
			return TRUE;
		}

		delete pTorrent;
		theApp.Message( MSG_ERROR, IDS_BT_PREFETCH_ERROR, pszMessage );
	}
	else if ( _tcscmp( pszTopic, _T("COLLECTION") ) == 0 )
	{
		LPTSTR pszPath = new TCHAR[ _tcslen(pszMessage) + 1 ];
		CopyMemory( pszPath, pszMessage, sizeof(TCHAR) * ( _tcslen(pszMessage) + 1 ) );

		if ( pWnd->PostMessage( WM_COLLECTION, (WPARAM)pszPath ) )
		{
			return TRUE;
		}
		else
		{
			delete [] pszPath;
		}
	}

	return FALSE;
}