示例#1
0
文件: Download.cpp 项目: GetEnvy/Envy
bool CDownload::IsShared() const
{
	return m_bShared ||
		( Settings.Gnutella1.Enabled && m_oSHA1 ) ||
		( Settings.Gnutella2.Enabled && HasHash() ) ||
		( Settings.eDonkey.Enabled && m_oED2K ) ||
		( Settings.DC.Enabled && m_oTiger ) ||
		( Settings.BitTorrent.Enabled && IsTorrent() && ( IsSeeding() || IsStarted() ) );
}
示例#2
0
BOOL CCollectionFile::File::Parse(CXMLElement* pRoot)
{
	//if ( ! pRoot->IsNamed( L"file" ) ) return FALSE;	// Discards DC++

	for ( POSITION pos = pRoot->GetElementIterator(); pos; )
	{
		CXMLElement* pXML = pRoot->GetNextElement( pos );

		if ( pXML->IsNamed( L"id" ) )
		{
			if ( ! m_oSHA1 )  m_oSHA1.fromUrn( pXML->GetValue() );
			if ( ! m_oTiger ) m_oTiger.fromUrn( pXML->GetValue() );
			if ( ! m_oED2K )  m_oED2K.fromUrn( pXML->GetValue() );
			if ( ! m_oMD5 )   m_oMD5.fromUrn( pXML->GetValue() );
			if ( ! m_oBTH )   m_oBTH.fromUrn( pXML->GetValue() );
			if ( ! m_oBTH )   m_oBTH.fromUrn< Hashes::base16Encoding >( pXML->GetValue() );
		}
		else if ( pXML->IsNamed( L"description" ) )
		{
			if ( CXMLElement* pName = pXML->GetElementByName( L"name" ) )
				m_sName = pName->GetValue();

			if ( CXMLElement* pSize = pXML->GetElementByName( L"size" ) )
			{
				if ( _stscanf( pSize->GetValue(), L"%I64i", &m_nSize ) != 1 )
					return FALSE;
			}
		}
		else if ( pXML->IsNamed( L"metadata" ) )
		{
			if ( m_pMetadata ) delete m_pMetadata;
			m_pMetadata = CCollectionFile::CloneMetadata( pXML );
		}
		//else if ( pXML->IsNamed( L"packaged" ) )
		//{
		//	if ( CXMLElement* pSource = pXML->GetElementByName( L"source" ) )
		//		/*m_sSource =*/ pSource->GetValue();	// ToDo: Use Sources?
		//}
	}

	// DC++ format
	if ( m_sName.IsEmpty() && ! m_oTiger && m_nSize == SIZE_UNKNOWN )
	{
		m_sName = pRoot->GetAttributeValue( L"Name" );
		_stscanf( pRoot->GetAttributeValue( L"Size" ), L"%I64i", &m_nSize );
		m_oTiger.fromString( pRoot->GetAttributeValue( L"TTH" ) );
	}

	return HasHash();
}
示例#3
0
BOOL CRelatedSearch::CanSearchForThis()
{
	return HasHash();
}
示例#4
0
STRPTR HasWord(const STRPTR Word, struct WordList *WL)
{
    return(HasHash(Word, &WL->Hash));
}
示例#5
0
文件: Download.cpp 项目: GetEnvy/Envy
bool CDownload::HasStableName() const
{
	return ! m_sName.IsEmpty() && ( m_bStableName || HasHash() );
}
示例#6
0
文件: Download.cpp 项目: GetEnvy/Envy
void CDownload::OnRun()
{
	// Set the currently downloading state
	// (Used to optimize display in Ctrl/Wnd functions)
	m_bDownloading = false;

	const DWORD tNow = GetTickCount();

	if ( ! IsPaused() )
	{
		if ( GetFileError() != ERROR_SUCCESS )
		{
			// File or disk errors
			Pause( FALSE );
		}
		else if ( IsMoving() )
		{
			if ( ! IsCompleted() && ! IsTasking() )
				OnDownloaded();
		}
		else if ( IsTrying() || IsSeeding() )
		{
			// This download is trying to download
			if ( HasHash() )		// Workaround for direct downloads stuck "verifying"
				OpenDownload();

			// Dead Download Check: if download appears dead, give up and allow another to start.
			// Incomplete, and trying for at least 3 hours:
			if ( ! IsCompleted() && tNow > GetStartTimer() + ( 3 * 60 * 60 * 1000 ) )
			{
				const DWORD tHoursToTry = min( ( GetEffectiveSourceCount() + 49u ) / 50u, 9lu ) + Settings.Downloads.StarveGiveUp;

				// No new data for 5-14 hours
				if ( tNow > m_tReceived + ( tHoursToTry * 60 * 60 * 1000 ) )
				{
					if ( IsTorrent() )
					{
						// Are there other torrents that should start?
						if ( Downloads.GetTryingCount( TRUE ) >= Settings.BitTorrent.DownloadTorrents )
						{
							StopTrying();		// Give up for now, try again later
							return;
						}
					}
					else	// Regular download
					{
						// Are there other downloads that should try?
						if ( Downloads.GetTryingCount() >= ( Settings.Downloads.MaxFiles + Settings.Downloads.MaxFileSearches ) )
						{
							StopTrying();		// Give up for now, try again later
							return;
						}
					}
				}
			}
			// End Dead Download Check

			// Run the download
			RunTorrent( tNow );
			RunSearch( tNow );
			RunValidation();

			if ( IsSeeding() )
			{
				// Mark as collapsed to get correct heights when dragging files
				if ( ! Settings.General.DebugBTSources && m_bExpanded )
					m_bExpanded = FALSE;
			}
			else // if ( ! IsMoving() )
			{
				if ( IsComplete() && IsFileOpen() )
				{
					if ( IsFullyVerified() )
						OnDownloaded();
				}
				else if ( CheckTorrentRatio() )
				{
					if ( ! Network.IsConnected() )
					{
						StopTrying();
						return;
					}

					StartTransfersIfNeeded( tNow );
				}
			}

			// Calculate current downloading state
			if ( HasActiveTransfers() )
				m_bDownloading = true;

			// Mutate regular download to torrent download
			if ( Settings.BitTorrent.EnablePromote && m_oBTH && ! IsTorrent() )
			{
				m_pTorrent.Clear();
				m_pTorrent.m_oMD5	= m_oMD5;
				m_pTorrent.m_oBTH	= m_oBTH;
				m_pTorrent.m_oSHA1	= m_oSHA1;
				m_pTorrent.m_oED2K	= m_oED2K;
				m_pTorrent.m_oTiger	= m_oTiger;
				m_pTorrent.m_sName	= m_sName;
				m_pTorrent.m_nSize	= m_nSize;
				SetTorrent();
			}
		}
		else if ( ! IsCompleted() && m_bVerify != TRI_TRUE )
		{
			// This is pending download
		//	// If this download isn't trying to download, see if it can try
		//	if ( IsDownloading() )
		//		SetStartTimer();	// This download was probably started by a push/etc

			if ( Network.IsConnected() )
			{
				// Have extra regular downloads 'trying' so when a new slot is ready,
				// a download has sources and is ready to go.
				if ( Downloads.GetTryingCount() < ( Settings.Downloads.MaxFiles + Settings.Downloads.MaxFileSearches ) )
				{
					if ( ! IsTorrent() ||
						Downloads.GetTryingCount( true ) < Settings.BitTorrent.DownloadTorrents )
					{
						// Torrents only try when 'ready to go'. (Reduce tracker load)
						Resume();
					}
				}
			}
		//	else
		//		ASSERT( ! IsTrying() );
		}
	}

	// Don't save Downloads with many sources too often, since it's slow
	if ( tNow >= m_tSaved + ( GetCount() > 20 ? 5 * Settings.Downloads.SaveInterval : Settings.Downloads.SaveInterval ) )
	{
		if ( IsModified() )
		{
			FlushFile();
			if ( Save() )
				m_tSaved = tNow;
		}
	}
}
示例#7
0
char *HasWord(const char *Word, struct WordList *WL)
{
    return HasHash(Word, &WL->Hash);
}