Exemple #1
0
CCollectionFile::File* CCollectionFile::FindByURN(LPCTSTR pszURN)
{
	Hashes::Sha1Hash oSHA1;
	Hashes::TigerHash oTiger;
	Hashes::Md5Hash oMD5;
	Hashes::Ed2kHash oED2K;
	Hashes::BtHash oBTH;

	oSHA1.fromUrn( pszURN );
	oMD5.fromUrn( pszURN );
	oTiger.fromUrn( pszURN );
	oED2K.fromUrn( pszURN );
	oBTH.fromUrn( pszURN ) || oBTH.fromUrn< Hashes::base16Encoding >( pszURN );

	for ( POSITION pos = GetFileIterator(); pos; )
	{
		File* pFile = GetNextFile( pos );

		if ( validAndEqual( oSHA1, pFile->m_oSHA1 ) ) return pFile;
		if ( validAndEqual( oMD5, pFile->m_oMD5 ) ) return pFile;
		if ( validAndEqual( oTiger, pFile->m_oTiger ) ) return pFile;
		if ( validAndEqual( oED2K, pFile->m_oED2K ) ) return pFile;
		if ( validAndEqual( oBTH, pFile->m_oBTH ) ) return pFile;
	}

	return NULL;
}
Exemple #2
0
void CSearchInputBox::OnSearchPrefixBTH()
{
	CString sSearch;
	m_wndSearch.GetWindowText( sSearch );
	Hashes::BtHash oBTH;
	if ( oBTH.fromUrn( sSearch ) ||
		 oBTH.fromString( sSearch ) ||
		 oBTH.fromUrn< Hashes::base16Encoding >( sSearch ) ||
		 oBTH.fromString< Hashes::base16Encoding >( sSearch ) )
		sSearch = oBTH.toUrn();
	else
		sSearch = _T("urn:btih:[BTIH]");

	m_wndSearch.SetWindowText( sSearch );
	m_wndSearch.SetFocus();
	m_wndSearch.SetSel( 9, -1 );
}
CLibraryFile* CLibraryMaps::LookupFileByURN(LPCTSTR pszURN, BOOL bSharedOnly, BOOL bAvailableOnly) const
{
	ASSERT_VALID( this );
	ASSERT( pszURN && *pszURN );

	CLibraryFile* pFile = NULL;
	Hashes::TigerHash oTiger;
	Hashes::Sha1Hash oSHA1;
	Hashes::Ed2kHash oED2K;
	Hashes::BtHash oBTH;
	Hashes::Md5Hash oMD5;

	if ( oSHA1.fromUrn( pszURN ) )
	{
		if ( ( pFile = LookupFileBySHA1( oSHA1, bSharedOnly, bAvailableOnly ) ) != NULL )
			return pFile;
	}

	if ( oTiger.fromUrn( pszURN ) )
	{
		if ( ( pFile = LookupFileByTiger( oTiger, bSharedOnly, bAvailableOnly ) ) != NULL )
			return pFile;
	}

	if ( oED2K.fromUrn( pszURN ) )
	{
		if ( ( pFile = LookupFileByED2K( oED2K, bSharedOnly, bAvailableOnly ) ) != NULL )
			return pFile;
	}

	if ( oBTH.fromUrn( pszURN ) || oBTH.fromUrn< Hashes::base16Encoding >( pszURN ) )
	{
		if ( ( pFile = LookupFileByBTH( oBTH, bSharedOnly, bAvailableOnly ) ) != NULL )
			return pFile;
	}

	if ( oMD5.fromUrn( pszURN ) )
	{
		if ( ( pFile = LookupFileByMD5( oMD5, bSharedOnly, bAvailableOnly ) ) != NULL )
			return pFile;
	}

	return NULL;
}
void CNewSearchDlg::OnChangeSearch()
{
	CString strSearch;
	m_wndSearch.GetWindowText( strSearch );

	BOOL bHash = FALSE;
	Hashes::TigerHash oTiger;
	Hashes::Sha1Hash oSHA1;
	Hashes::Ed2kHash oED2K;
	Hashes::Md5Hash oMD5;
	Hashes::BtHash oBTH;

	bHash |= static_cast< BOOL >( oSHA1.fromUrn( strSearch ) );
	bHash |= static_cast< BOOL >( oTiger.fromUrn( strSearch ) );
	bHash |= static_cast< BOOL >( oED2K.fromUrn( strSearch ) );
	bHash |= static_cast< BOOL >( oMD5.fromUrn( strSearch ) );
	bHash |= static_cast< BOOL >( oBTH.fromUrn( strSearch ) ||
		oBTH.fromUrn< Hashes::base16Encoding >( strSearch ) );

	if ( m_wndSchema.IsWindowVisible() == bHash )
		m_wndSchema.ShowWindow( bHash ? SW_HIDE : SW_SHOW );
}