Beispiel #1
0
void DownloadBase::FileDownloadSharing(BOOL& transfer_failed)
{
	transfer_failed = FALSE;

	OpTransferItem* item = GetTransferItem();
	if(item != 0)
	{
		TransferItem* transfer_item = (TransferItem *)(item);
		OP_ASSERT(transfer_item != 0);

		transfer_item->SetCalculateKbps(TRUE);
		transfer_item->Get_P2P_URL()->ForceStatus(P2P_URL::P2P_SHARING_FILES);

		transfer_item->SetCurrentSize(GetVolumeComplete());
		transfer_item->SetCompleteSize(m_torrent.GetImpl()->GetTotalSize());
		transfer_item->SetUploaded(GetVolumeUploaded());

		if(GetVolumeComplete() == m_torrent.GetImpl()->GetTotalSize())
		{
			transfer_item->SetCompleted(TRUE);
		}
		g_Transfers->UpdateTransferSpeed((UINTPTR)this, transfer_item->GetKbps(), transfer_item->GetKbpsUpload());

//		OpVector<UploadTransferBT> *uploads = ((BTDownload *)this)->GetUploads();
//		UINT32 idx;
		UINT32 activeuploads = 0;

		if(m_lastProgressUpdate != 0)
		{
			time_t now = op_time(NULL);

			if(now < m_lastProgressUpdate + BT_PROGRESS_DELAY)
			{
				return;
			}
			m_lastProgressUpdate = now;

			activeuploads = m_Uploads.GetTransferCount(upsRequestAndUpload);

			UINT32 seeds = GetTransferCount(dtsCountAllWithCompleteFile);
			UINT32 all_peers = GetTransferCount(dtsCountAll);
			UINT32 downloading = GetTransferCount(dtsDownloading);

			all_peers -= seeds;
			transfer_item->SetConnectionsWithCompleteFile(seeds);
			transfer_item->SetConnectionsWithIncompleteFile(all_peers);
			transfer_item->SetDownloadConnections(downloading);
			transfer_item->SetUploadConnections(activeuploads);
			transfer_item->SetTotalWithCompleteFile(max(((BTDownload *)this)->m_totalSeeders, seeds));
			transfer_item->SetTotalDownloaders(max(((BTDownload *)this)->m_totalPeers, all_peers));
		}
	}
	else
		transfer_failed = TRUE;
}
Beispiel #2
0
void DownloadBase::FileDownloadStopped()
{
	OpTransferItem* item = GetTransferItem();
	if(item != 0)
	{
		TransferItem* transfer_item = (TransferItem *)(item);
		OP_ASSERT(transfer_item != 0);

		if(GetVolumeComplete() == m_torrent.GetImpl()->GetTotalSize())
		{
			((TransferItem *)transfer_item)->SetCompleted(TRUE);
			transfer_item->Get_P2P_URL()->ForceStatus(URL_LOADED);
		}
		else
		{
			transfer_item->Get_P2P_URL()->ForceStatus(URL_LOADING_ABORTED);
		}

		g_Transfers->UpdateTransferSpeed((UINTPTR)this, 0, 0);
		((TransferItem *)transfer_item)->SetCalculateKbps(FALSE);
		transfer_item->SetConnectionsWithCompleteFile(0);
		transfer_item->SetConnectionsWithIncompleteFile(0);
		transfer_item->SetDownloadConnections(0);
		transfer_item->SetUploadConnections(0);
		transfer_item->SetTotalWithCompleteFile(0);
		transfer_item->SetTotalDownloaders(0);

		m_last_downloaded = 0;
		m_last_uploaded = 0;
	}
}
Beispiel #3
0
void DownloadBase::FileDownloadBegin(BOOL& transfer_failed)
{
	transfer_failed = FALSE;

	OpTransferItem* item = GetTransferItem();
	if(item != 0)
	{
		TransferItem* transfer_item = (TransferItem *)(item);
		OP_ASSERT(transfer_item != 0);

		// Update the status to loading.
//		transfer_item->SetCalculateKbps(FALSE);
		transfer_item->Get_P2P_URL()->ForceStatus(URL_LOADING);
		transfer_item->SetCurrentSize(GetVolumeComplete());
		transfer_item->SetCompleteSize(m_torrent.GetImpl()->GetTotalSize());

//		OpVector<UploadTransferBT> *uploads = ((BTDownload *)this)->GetUploads();
//		UINT32 idx;
		UINT32 activeuploads = 0;


		activeuploads += m_Uploads.GetTransferCount(upsRequestAndUpload);

		UINT32 seeds = GetTransferCount(dtsCountAllWithCompleteFile);
		UINT32 all_peers = GetTransferCount(dtsCountAll);
		UINT32 downloading = GetTransferCount(dtsDownloading);

		all_peers -= seeds;
		transfer_item->SetConnectionsWithCompleteFile(seeds);
		transfer_item->SetConnectionsWithIncompleteFile(all_peers);
		transfer_item->SetDownloadConnections(downloading);
		transfer_item->SetUploadConnections(activeuploads);
		transfer_item->SetTotalWithCompleteFile(max(((BTDownload *)this)->m_totalSeeders, seeds));
		transfer_item->SetTotalDownloaders(max(((BTDownload *)this)->m_totalPeers, all_peers));
	}
	else
		transfer_failed = TRUE;
}
Beispiel #4
0
void DownloadBase::FileProgress(BOOL& transfer_failed)
{
	transfer_failed = FALSE;

	OpTransferItem* item = GetTransferItem();
	if(item != 0)
	{
		UINT64 downloaded = GetVolumeComplete();
		TransferItem* transfer_item = (TransferItem *)(item);
		OP_ASSERT(transfer_item != 0);

		transfer_item->SetCalculateKbps(TRUE);
		// If the user have pressed stop, the status won't be loading anymore.
//		if(transfer_item->Get_P2P_URL()->Status() == URL_LOADING)
		if(downloaded != m_torrent.GetImpl()->GetTotalSize())
		{
			transfer_item->Get_P2P_URL()->ForceStatus(URL_LOADING);
			if(downloaded >= m_last_downloaded)
			{
				transfer_item->SetCurrentSize(downloaded);
			}
			transfer_item->SetCompleteSize(m_torrent.GetImpl()->GetTotalSize());
			transfer_item->SetCompleted(FALSE);
		}
		UINT64 uploaded = GetVolumeUploaded();

		if(uploaded > m_last_uploaded)
		{
			transfer_item->SetUploaded(uploaded);

//			g_Transfers->SetUploaded(uploaded - m_last_uploaded);
		}
		m_last_uploaded = uploaded;


		UINT32 activeuploads = 0;

		if(m_lastProgressUpdate != 0)
		{
			time_t now = op_time(NULL);

			if(now < m_lastProgressUpdate + BT_PROGRESS_DELAY)
			{
				return;
			}
			m_lastProgressUpdate = now;

			activeuploads = m_Uploads.GetTransferCount(upsRequestAndUpload);

			UINT32 seeds = GetTransferCount(dtsCountAllWithCompleteFile);
			UINT32 all_peers = GetTransferCount(dtsCountAll);
			UINT32 downloading = GetTransferCount(dtsDownloading);

			all_peers -= seeds;
			transfer_item->SetConnectionsWithCompleteFile(seeds);
			transfer_item->SetConnectionsWithIncompleteFile(all_peers);
			transfer_item->SetDownloadConnections(downloading);
			transfer_item->SetUploadConnections(activeuploads);
			transfer_item->SetTotalWithCompleteFile(max(((BTDownload *)this)->m_totalSeeders, seeds));
			transfer_item->SetTotalDownloaders(max(((BTDownload *)this)->m_totalPeers, all_peers));
		}
		if(downloaded > m_last_downloaded)
		{
			m_last_downloaded = downloaded;
		}
	}
	else
		transfer_failed = TRUE;
}
Beispiel #5
0
bool CDownload::IsStarted() const
{
	return GetVolumeComplete() > 0;
}