//-------------------------------------------------------------------------------------------------------------- // Starts a new download if there are queued requests void DownloadManager::StartNewDownload() { if ( m_activeRequest || !m_queuedRequests.Count() ) return; while ( !m_activeRequest && m_queuedRequests.Count() ) { // Remove one request from the queue and make it active m_activeRequest = m_queuedRequests[0]; m_queuedRequests.Remove( 0 ); if ( g_pFileSystem->FileExists( m_activeRequest->gamePath ) ) { ConDColorMsg( DownloadColor, "Skipping existing file %s%s.\n", m_activeRequest->baseURL, m_activeRequest->gamePath ); m_activeRequest->shouldStop = true; m_activeRequest->threadDone = true; m_completedRequests.AddToTail( m_activeRequest ); m_activeRequest = NULL; } } if ( !m_activeRequest ) return; if ( g_pFileSystem->FileExists( m_activeRequest->gamePath ) ) { m_activeRequest->shouldStop = true; m_activeRequest->threadDone = true; m_completedRequests.AddToTail( m_activeRequest ); m_activeRequest = NULL; return; // don't download existing files } if ( m_activeRequest->bAsHTTP ) { // Check cache for partial match TheDownloadCache->GetCachedData( m_activeRequest ); //TODO: ContinueLoadingProgressBar( "Http", m_totalRequests - m_queuedRequests.Count(), 0.0f ); //TODO: SetLoadingProgressBarStatusText( "#GameUI_VerifyingAndDownloading" ); //TODO: SetSecondaryProgressBarText( m_activeRequest->gamePath ); //TODO: SetSecondaryProgressBar( 0.0f ); UpdateProgressBar(); ConDColorMsg( DownloadColor, "Downloading %s%s.\n", m_activeRequest->baseURL, m_activeRequest->gamePath ); m_lastPercent = 0; // Start the thread DWORD threadID; VCRHook_CreateThread(NULL, 0, DownloadThread, m_activeRequest, 0, &threadID ); } else { UpdateProgressBar(); ConDColorMsg( DownloadColor, "Downloading %s.\n", m_activeRequest->gamePath ); m_lastPercent = 0; m_activeRequest->nRequestID = cl.m_NetChannel->RequestFile( m_activeRequest->gamePath ); } }
//-------------------------------------------------------------------------------------------------------------- // Check download requests that have been completed to see if their threads have exited void DownloadManager::PruneCompletedRequests() { for ( int i=m_completedRequests.Count()-1; i>=0; --i ) { if ( m_completedRequests[i]->threadDone || !m_completedRequests[i]->bAsHTTP ) { if ( m_completedRequests[i]->cacheData ) { delete[] m_completedRequests[i]->cacheData; } delete m_completedRequests[i]; m_completedRequests.Remove( i ); } } }