예제 #1
0
void CDownloadGroups::Unlink(CDownload* pDownload, BOOL bAndSuper)
{
	CSingleLock pLock( &m_pSection, TRUE );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CDownloadGroup* pGroup = GetNext( pos );
		if ( bAndSuper || pGroup != m_pSuper ) pGroup->Remove( pDownload );
	}
}
예제 #2
0
void CDownloadGroups::Unlink(CDownload* pDownload, BOOL bAndSuper)
{
	ASSUME_LOCK( Transfers.m_pSection );
	CQuickLock pLock( m_pSection );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CDownloadGroup* pGroup = GetNext( pos );
		if ( bAndSuper || pGroup != m_pSuper ) pGroup->Remove( pDownload );
	}
}
예제 #3
0
void CDownloadGroups::Link(CDownload* pDownload)
{
	CSingleLock pLock( &m_pSection, TRUE );

	GetSuperGroup()->Add( pDownload );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CDownloadGroup* pGroup = GetNext( pos );
		pGroup->Link( pDownload );
	}
}
예제 #4
0
void CDownloadGroups::Link(CDownload* pDownload)
{
	ASSUME_LOCK( Transfers.m_pSection );
	CQuickLock pLock( m_pSection );

	GetSuperGroup()->Add( pDownload );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CDownloadGroup* pGroup = GetNext( pos );
		pGroup->Link( pDownload );
	}
}
예제 #5
0
CString CDownloadGroups::GetCompletedPath(CDownload* pDownload)
{
	CSingleLock pLock( &m_pSection, TRUE );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		CDownloadGroup* pGroup = GetNext( pos );

		if ( pGroup != m_pSuper && pGroup->Contains( pDownload ) )
		{
			if ( pGroup->m_sFolder.GetLength() ) return pGroup->m_sFolder;
		}
	}

	return Settings.Downloads.CompletePath;
}
예제 #6
0
void CDownloadGroups::CleanTemporary()
{
	for ( POSITION pos = GetIterator() ; pos ; )
	{
		POSITION posCurrent = pos;
		CDownloadGroup* pGroup = GetNext( pos );
		if ( pGroup->IsTemporary() )
		{
			ASSERT( pGroup != m_pSuper );

			m_pList.RemoveAt( posCurrent );
			delete pGroup;
			
			m_nBaseCookie ++;
			m_nGroupCookie ++;

			pos = GetIterator();
		}
	}
}
예제 #7
0
파일: Remote.cpp 프로젝트: GetEnvy/Envy
void CRemote::PageDownloads()
{
	if ( CheckCookie() ) return;
	m_nTab = tabDownloads;

	CString str;
	str.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );

	CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );

	Prepare();		// Header
	Add( L"random", str );
	Output( L"downloadsHeader" );

	BOOL bExclusive = ! GetKey( L"group_exclusive" ).IsEmpty();
	BOOL bReveal = ! GetKey( L"group_reveal" ).IsEmpty();

	for ( POSITION posGroup = DownloadGroups.GetIterator(); posGroup != NULL; )
	{
		CDownloadGroup* pGroup = DownloadGroups.GetNext( posGroup );

		CString strGroupID;
		strGroupID.Format( L"%p", pGroup );
		Add( L"group_id", strGroupID );

		if ( bExclusive )
			pGroup->m_bRemoteSelected = ( GetKey( L"group_exclusive" ) == strGroupID );
		else if ( bReveal )
			pGroup->m_bRemoteSelected = TRUE;
		else if ( GetKey( L"group_select" ) == strGroupID )
			pGroup->m_bRemoteSelected = TRUE;
		else if ( GetKey( L"group_deselect" ) == strGroupID )
			pGroup->m_bRemoteSelected = FALSE;

		Add( L"group_caption", pGroup->m_sName );
		if ( pGroup->m_bRemoteSelected )
			Add( L"group_selected", L"true" );
		Output( L"downloadsTab" );
		Prepare( L"group_" );
	}

	if ( ! GetKey( L"filter_set" ).IsEmpty() )
	{
		Settings.Downloads.FilterMask &= ~( DLF_ACTIVE | DLF_PAUSED | DLF_QUEUED | DLF_SOURCES | DLF_SEED );
		if ( GetKey( L"filter_active" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_ACTIVE;
		if ( GetKey( L"filter_paused" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_PAUSED;
		if ( GetKey( L"filter_queued" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_QUEUED;
		if ( GetKey( L"filter_sources" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_SOURCES;
		if ( GetKey( L"filter_seeds" ) == L"1" )  Settings.Downloads.FilterMask |= DLF_SEED;
		Settings.Downloads.ShowSources = ( GetKey( L"filter_show_all" ) == L"1" );
	}

	Add( L"filter_active", ( Settings.Downloads.FilterMask & DLF_ACTIVE ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_paused", ( Settings.Downloads.FilterMask & DLF_PAUSED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_queued", ( Settings.Downloads.FilterMask & DLF_QUEUED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_sources", ( Settings.Downloads.FilterMask & DLF_SOURCES ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_seeds", ( Settings.Downloads.FilterMask & DLF_PAUSED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_show_all", Settings.Downloads.ShowSources ? L"checked=\"checked\"" : L"" );
	Output( L"downloadsTop" );

	for ( POSITION posDownload = Downloads.GetIterator(); posDownload != NULL; )
	{
		CDownload* pDownload = Downloads.GetNext( posDownload );

		CString strDownloadID;
		strDownloadID.Format( L"%p", pDownload );

		if ( GetKey( L"modify_id" ) == strDownloadID )
		{
			CString strAction = GetKey( L"modify_action" );
			strAction.MakeLower();

			if ( strAction == L"expand" )
			{
				if ( CDownloadsCtrl::IsExpandable( pDownload ) )
					pDownload->m_bExpanded = TRUE;
			}
			else if ( strAction == L"collapse" )
			{
				if ( CDownloadsCtrl::IsExpandable( pDownload ) )
					pDownload->m_bExpanded = FALSE;
			}
			else if ( strAction == L"resume" )
			{
				pDownload->Resume();
			}
			else if ( strAction == L"pause" )
			{
				if ( ! pDownload->IsPaused() && ! pDownload->IsTasking() )
					pDownload->Pause();
			}
			else if ( strAction == L"cancel" )
			{
				if ( ! pDownload->IsTasking() )
					pDownload->Remove();
				continue;
			}
			else if ( strAction == L"clear" )
			{
				if ( pDownload->IsCompleted() && ! pDownload->IsPreviewVisible() )
				{
					pDownload->Remove();
					continue;
				}
			}
			else if ( strAction == L"more_sources" )
			{
				// roo_koo_too improvement
				pDownload->FindMoreSources();
			}
		}

		if ( CDownloadsCtrl::IsFiltered( pDownload ) ) continue;

		CDownloadGroup* pGroup = NULL;

		for ( POSITION posGroup = DownloadGroups.GetIterator(); posGroup != NULL; )
		{
			pGroup = DownloadGroups.GetNext( posGroup );
			if ( pGroup->m_bRemoteSelected && pGroup->Contains( pDownload ) ) break;
			pGroup = NULL;
		}

		if ( pGroup == NULL ) continue;

		Add( L"download_id", strDownloadID );
		Add( L"download_filename", pDownload->GetDisplayName() );
		Add( L"download_size", ( pDownload->m_nSize == SIZE_UNKNOWN ) ?
			LoadString( IDS_STATUS_UNKNOWN ) : Settings.SmartVolume( pDownload->m_nSize ) );
		int nProgress = int( pDownload->GetProgress() );
		str.Format( L"%i", nProgress );
		Add( L"download_percent", str );
		str.Format( L"%i", 100 - nProgress );
		Add( L"download_percent_inverse", str );
		Add( L"download_speed", Settings.SmartSpeed( pDownload->GetMeasuredSpeed() ) );
		if ( CDownloadsCtrl::IsExpandable( pDownload ) )
		{
			if ( pDownload->m_bExpanded )
				Add( L"download_is_expanded", L"true" );
			else
				Add( L"download_is_collapsed", L"true" );
		}
		if ( pDownload->IsCompleted() )
			Add( L"download_is_complete", L"true" );
		else if ( pDownload->IsPaused() )
			Add( L"download_is_paused", L"true" );

		Add( L"download_status", pDownload->GetDownloadStatus() );
		Add( L"download_sources", pDownload->GetDownloadSources() );
		Output( L"downloadsDownload" );

		if ( pDownload->m_bExpanded && CDownloadsCtrl::IsExpandable( pDownload ) )
		{
			for ( POSITION posSource = pDownload->GetIterator(); posSource; )
			{
				CDownloadSource* pSource = pDownload->GetNext( posSource );

				ASSERT( pSource->m_pDownload == pDownload );

				CString strSourceID;
				strSourceID.Format( L"%p", pSource );

				if ( GetKey( L"modify_id" ) == strSourceID )
				{
					CString strModifyAction = GetKey( L"modify_action" );
					strModifyAction.MakeLower();

					if ( strModifyAction == L"access" )
					{
						// Only create a new Transfer if there isn't already one
						if ( pSource->IsIdle() && pSource->m_nProtocol != PROTOCOL_ED2K )
						{
							if ( pDownload->IsPaused() )
								pDownload->Resume();	// Workaround duplicate

							pDownload->Resume();

							if ( pSource->m_bPushOnly )
								pSource->PushRequest();
							else if ( CDownloadTransfer* pTransfer = pSource->CreateTransfer() )
								pTransfer->Initiate();
						}
					}
					else if ( strModifyAction == L"forget" )
					{
						pSource->Remove( TRUE, TRUE );
						continue;
					}
				}

				if ( Settings.Downloads.ShowSources || pSource->IsConnected() )
				{
					Add( L"source_id", strSourceID );
					Add( L"source_agent", pSource->m_sServer );
					Add( L"source_nick", pSource->m_sNick );

					if ( ! pSource->IsIdle() )
					{
						Add( L"source_status", pSource->GetState( FALSE ) );
						Add( L"source_volume", Settings.SmartVolume( pSource->GetDownloaded() ) );
						if ( DWORD nSpeed = pSource->GetMeasuredSpeed() )
							Add( L"source_speed", Settings.SmartSpeed( nSpeed ) );
						Add( L"source_address", pSource->GetAddress() );
						Add( L"source_caption", pSource->GetAddress() + L" - " + pSource->m_sNick );
					}
					else	// No transfer
					{
						Add( L"source_address", CString( inet_ntoa( pSource->m_pAddress ) ) );
						Add( L"source_caption", CString( inet_ntoa( pSource->m_pAddress ) ) + L" - " + pSource->m_sNick );

						if ( pSource->m_tAttempt > 0 )
						{
							DWORD tNow = GetTickCount();

							if ( pSource->m_tAttempt >= tNow )
							{
								tNow = ( pSource->m_tAttempt - tNow ) / 1000;
								CString strSourceStatus;
								strSourceStatus.Format( L"%.2u:%.2u", tNow / 60, tNow % 60 );
								Add( L"source_status", strSourceStatus );
							}
						}
					}

					Output( L"downloadsSource" );
					Prepare( L"source_" );
				}
			}
		}

		Prepare( L"download_" );
	} // for POSITION loop

	Output( L"downloadsBottom" );
	Output( L"downloadsFooter" );
}
예제 #8
0
void CDownloadGroups::Serialize(CArchive& ar)
{
	int nVersion = GROUPS_SER_VERSION;
	BYTE nState;

	if ( ar.IsStoring() )
	{
		ar << nVersion;

		ar.WriteCount( Downloads.GetCount() );

		for ( POSITION pos = Downloads.GetIterator() ; pos ; )
		{
			ar << Downloads.GetNext( pos )->m_nSerID;
		}

		ar.WriteCount( GetCount() );

		for ( POSITION pos = GetIterator() ; pos ; )
		{
			CDownloadGroup* pGroup = GetNext( pos );

			nState = ( pGroup == m_pSuper ) ? 1 : 0;
			ar << nState;

			pGroup->Serialize( ar, nVersion );
		}
	}
	else
	{
		ar >> nVersion;
		if ( nVersion <= 1 || nVersion > GROUPS_SER_VERSION ) AfxThrowUserException();

		int nCount = ar.ReadCount();

		for ( ; nCount > 0 ; nCount-- )
		{
			DWORD nDownload;
			ar >> nDownload;
			if ( CDownload* pDownload = Downloads.FindBySID( nDownload ) )
				Downloads.Reorder( pDownload, NULL );
		}

		if ( nCount = ar.ReadCount() ) Clear();

		for ( ; nCount > 0 ; nCount-- )
		{
			CDownloadGroup* pGroup = Add();

			ar >> nState;
			if ( nState == 1 ) m_pSuper = pGroup;

			pGroup->Serialize( ar, nVersion );
		}

		GetSuperGroup();

		for ( POSITION pos = Downloads.GetIterator() ; pos ; )
		{
			m_pSuper->Add( Downloads.GetNext( pos ) );
		}
	}
}
예제 #9
0
void CDownloadGroups::CreateDefault()
{
	CSingleLock pLock( &m_pSection, TRUE );

	CDownloadGroup* pGroup	= GetSuperGroup();

	pGroup = Add( _T("Audio") );
	pGroup->AddFilter( _T(".mp3") );
	pGroup->AddFilter( _T(".ogg") );
	pGroup->AddFilter( _T(".wav") );
	pGroup->AddFilter( _T(".wma") );
	pGroup->SetSchema( CSchema::uriMusicAlbum );

	pGroup = Add( _T("Video") );
	pGroup->AddFilter( _T(".asf") );
	pGroup->AddFilter( _T(".avi") );
	pGroup->AddFilter( _T(".mov") );
	pGroup->AddFilter( _T(".mpg") );
	pGroup->AddFilter( _T(".mpeg") );
	pGroup->AddFilter( _T(".ogm") );
	pGroup->AddFilter( _T(".wmv") );
	pGroup->SetSchema( CSchema::uriVideo );

	pGroup = Add( _T("BitTorrent") );
	pGroup->AddFilter( _T("torrent") );
	pGroup->SetSchema( CSchema::uriROM );
}
예제 #10
0
void CDownloadGroups::CreateDefault()
{
	CQuickLock pLock( m_pSection );

	CDownloadGroup* pGroup	= GetSuperGroup();

	pGroup = Add( _T("Audio") );
	pGroup->SetSchema( CSchema::uriAudio );
	pGroup->SetDefaultFilters();

	pGroup = Add( _T("Video") );
	pGroup->SetSchema( CSchema::uriVideo );
	pGroup->SetDefaultFilters();

	pGroup = Add( _T("Image") );
	pGroup->SetSchema( CSchema::uriImage );
	pGroup->SetDefaultFilters();

	pGroup = Add( _T("BitTorrent") );
	pGroup->SetSchema( CSchema::uriBitTorrent );
	pGroup->SetDefaultFilters();
	pGroup->SetFolder( Settings.Downloads.TorrentPath );

	pGroup = Add( _T("Collection") );
	pGroup->SetSchema( CSchema::uriCollection );
	pGroup->SetDefaultFilters();
	pGroup->SetFolder( Settings.Downloads.CollectionPath );
}