Exemple #1
0
void CDownloadTask::RunPreviewRequest()
{
	m_bSuccess = m_pRequest->Execute( false );	// Without threading

	if ( ! IsThreadEnabled() || m_pDownload->m_sPath.IsEmpty() ) return;

	// Save downloaded preview as png-file
	const CString strPath = m_pDownload->m_sPath + L".png";
	CImageFile pImage;
	CBuffer* pBuffer = IsPreviewAnswerValid( m_pDownload->m_oSHA1 );
	if ( pBuffer && pBuffer->m_pBuffer && pBuffer->m_nLength &&
		 pImage.LoadFromMemory( L".jpg", pBuffer->m_pBuffer, pBuffer->m_nLength, FALSE, TRUE ) &&
		 pImage.SaveToFile( (LPCTSTR)strPath, 100 ) )
	{
		// Make it hidden, so the files won't be shared
		SetFileAttributes( (LPCTSTR)strPath, FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM );
	}
	else
	{
		// Failed
		m_pDownload->m_bWaitingPreview = FALSE;
		theApp.Message( MSG_ERROR, IDS_SEARCH_DETAILS_PREVIEW_FAILED, (LPCTSTR)GetRequest() );
	}
}