예제 #1
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 );
}
예제 #2
0
BOOL CDownloadEditPage::OnApply()
{
	if ( ! UpdateData() )
		return FALSE;

	CString strMessage;

	Hashes::Sha1Hash oSHA1;
	Hashes::TigerHash oTiger;
	Hashes::Ed2kHash oED2K;
	Hashes::Md5Hash oMD5;
	Hashes::BtHash oBTH;

	oSHA1.fromString( m_sSHA1 );
	oTiger.fromString( m_sTiger );
	oED2K.fromString( m_sED2K );
	oMD5.fromString( m_sMD5 );
	oBTH.fromString( m_sBTH );

	if ( ! m_sSHA1.IsEmpty() && ! oSHA1 )
	{
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("SHA1") );
		MsgBox( strMessage, MB_ICONEXCLAMATION );
		GetDlgItem( IDC_URN_SHA1 )->SetFocus();
		return FALSE;
	}
	if ( ! m_sTiger.IsEmpty() && ! oTiger )
	{
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("Tiger-Root") );
		MsgBox( strMessage, MB_ICONEXCLAMATION );
		GetDlgItem( IDC_URN_TIGER )->SetFocus();
		return FALSE;
	}
	if ( ! m_sED2K.IsEmpty() && ! oED2K )
	{
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("ED2K") );
		MsgBox( strMessage, MB_ICONEXCLAMATION );
		GetDlgItem( IDC_URN_ED2K )->SetFocus();
		return FALSE;
	}
	if ( ! m_sMD5.IsEmpty() && ! oMD5 )
	{
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("MD5") );
		MsgBox( strMessage, MB_ICONEXCLAMATION );
		GetDlgItem( IDC_URN_MD5 )->SetFocus();
		return FALSE;
	}
	if ( ! m_sBTH.IsEmpty() && ! oBTH )
	{
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("BitTorrent") );
		MsgBox( strMessage, MB_ICONEXCLAMATION );
		GetDlgItem( IDC_URN_BTH )->SetFocus();
		return FALSE;
	}

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

	CDownloadSheet* pSheet = (CDownloadSheet*)GetParent();
	CDownload* pDownload = pSheet->GetDownload();
	if ( ! pDownload )
		return CPropertyPageAdv::OnApply();		// Invalid download

	bool bNeedUpdate = false;
	bool bCriticalChange = false;

	bNeedUpdate	= pDownload->m_bSHA1Trusted ^ ( m_bSHA1Trusted == TRUE );
	bNeedUpdate	|= pDownload->m_bTigerTrusted ^ ( m_bTigerTrusted == TRUE );
	bNeedUpdate	|= pDownload->m_bED2KTrusted ^ ( m_bED2KTrusted == TRUE );
	bNeedUpdate	|= pDownload->m_bMD5Trusted ^ ( m_bMD5Trusted == TRUE );
	bNeedUpdate	|= pDownload->m_bBTHTrusted ^ ( m_bBTHTrusted == TRUE );

	if ( pDownload->m_sName != m_sName )
	{
		pLock.Unlock();
		if ( MsgBox( IDS_DOWNLOAD_EDIT_CHANGE_NAME, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;		// Was IDS_DOWNLOAD_EDIT_RENAME
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->Rename( m_sName );
		bNeedUpdate = true;
	}

	QWORD nNewSize = 0;
	if ( _stscanf( m_sFileSize, _T("%I64u"), &nNewSize ) == 1 && nNewSize != pDownload->m_nSize )
	{
		pLock.Unlock();
		if ( MsgBox( IDS_DOWNLOAD_EDIT_CHANGE_SIZE, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_nSize = nNewSize;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	SYSTEMTIME tDate;
	m_wndDate.GetTime( &tDate );
	if ( pDownload->m_tDate != tDate )
		pDownload->m_tDate = tDate;

	if ( pDownload->m_oSHA1.isValid() != oSHA1.isValid()
		|| validAndUnequal( pDownload->m_oSHA1, oSHA1 ) )
	{
		pLock.Unlock();
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("SHA1"), _T("SHA1") );
		if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_oSHA1 = oSHA1;
		if ( oSHA1 ) pDownload->m_bSHA1Trusted = true;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	if ( pDownload->m_oTiger.isValid() != oTiger.isValid()
		|| validAndUnequal( pDownload->m_oTiger, oTiger ) )
	{
		pLock.Unlock();
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("Tiger-Root"), _T("Tiger-Root") );
		if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_oTiger = oTiger;
		if ( oTiger ) pDownload->m_bTigerTrusted = true;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	if ( pDownload->m_oED2K.isValid() != oED2K.isValid()
		|| validAndUnequal( pDownload->m_oED2K, oED2K ) )
	{
		pLock.Unlock();
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("ED2K"), _T("ED2K") );
		if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_oED2K = oED2K;
		if ( oED2K ) pDownload->m_bED2KTrusted = true;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	if ( pDownload->m_oMD5.isValid() != oMD5.isValid()
		|| validAndUnequal( pDownload->m_oMD5, oMD5 ) )
	{
		pLock.Unlock();
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("MD5"), _T("MD5") );
		if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_oMD5 = oMD5;
		if ( oMD5 ) pDownload->m_bMD5Trusted = true;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	if ( pDownload->m_oBTH.isValid() != oBTH.isValid()
		|| validAndUnequal( pDownload->m_oBTH, oBTH ) )
	{
		pLock.Unlock();
		strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("BitTorrent"), _T("BitTorrent") );
		if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
		pLock.Lock();
		pDownload = pSheet->GetDownload();
		if ( ! pDownload ) return CPropertyPageAdv::OnApply();
		pDownload->m_oBTH = oBTH;
		if ( oBTH ) pDownload->m_bBTHTrusted = true;
		pDownload->CloseTransfers();
		pDownload->ClearVerification();
		bCriticalChange = true;
	}

	pDownload->m_bSHA1Trusted = m_bSHA1Trusted != FALSE;
	pDownload->m_bTigerTrusted = m_bTigerTrusted != FALSE;
	pDownload->m_bED2KTrusted = m_bED2KTrusted != FALSE;
	pDownload->m_bMD5Trusted = m_bMD5Trusted != FALSE;
	pDownload->m_bBTHTrusted = m_bBTHTrusted != FALSE;

	if ( bCriticalChange )
	{
		pDownload->CloseTransfers();
		pDownload->ClearSources();
		pDownload->ClearFailedSources();
		pDownload->ClearVerification();
		bNeedUpdate = true;
	}

	if ( bNeedUpdate )
		pDownload->SetModified();

	return CPropertyPageAdv::OnApply();
}