コード例 #1
0
//----------------------------------------------------------------------------------
// SendReport: Send report on what happened with this patch. 
//		(for automatic pruning of poor patch locations) 
//----------------------------------------------------------------------------------
void DownloadCtrl::SendReport(void)
{
	CustomInfo* pCustInfo = GetCustomInfo();
	CPatchData* pPatch = pCustInfo->GetSelectedPatch();
	PatchCore* pCore = GetMainControl()->GetPatchCore();

	ServerContext* pGamePatchServers = pCore->GetGamePatchServers();
	if (pGamePatchServers == NULL)
		return;

	AsyncSocketPtr aSocketP = new AsyncSocket(AsyncSocket::UDP);
	aSocketP->Bind(0);

	AddrList GamePatchServerAddrList;
	pGamePatchServers->CopyAddresses(GamePatchServerAddrList);
	for (AddrList::iterator anItr = GamePatchServerAddrList.begin(); anItr != GamePatchServerAddrList.end(); ++anItr)
	{
		ReportPatchStatusOpPtr pOp = new ReportPatchStatusOp(*anItr);
		pOp->SetProductName(pCustInfo->GetProductName());
		pOp->SetConfigName(pCustInfo->GetExtraConfig());
		pOp->SetFromVersion(pPatch->GetFromVersion());
		pOp->SetToVersion(pCustInfo->GetNewVersion()); 
		pOp->SetNetAddress(pPatch->GetPatchUrl());
		pOp->SetUDPSocket(aSocketP);

		if (m_bAborted)
			pOp->SetPatchStatus(1); // cancel type
		else if (m_bPatchIsValid && m_bPatchDownloadSucceeded)
			pOp->SetPatchStatus(0); // success type
		else
			pOp->SetPatchStatus(2); // failed type

		pOp->RunBlock(0);
	}
}
コード例 #2
0
//----------------------------------------------------------------------------------
// StartDownloads: Start the threads that will download the files.
//----------------------------------------------------------------------------------
void DownloadCtrl::StartDownloads(void)
{
	CustomInfo* pCustInfo = GetCustomInfo();

	CPatchData* pPatch = pCustInfo->GetSelectedPatch();
	if (pPatch)
	{
		#ifdef _DEBUG
			if (GetKeyState(VK_MENU) & GetKeyState(VK_CONTROL) & GetKeyState(VK_SHIFT) & 0x8000)
				pPatch->DebugBox(GetWindow());
		#endif

		GUIString sPatchFile = pPatch->GetPatchUrl();
		int nPos = sPatchFile.rFind('/');
		if (nPos == -1)
			nPos = sPatchFile.rFind('\\');
		if (nPos != -1)
			sPatchFile.erase(0, nPos + 1);
		else
			sPatchFile = TEXT("Update.exe");

		std::string aHostGraphic = pPatch->GetHostBmp();
		int aPos = aHostGraphic.find_last_of('.');
		std::string aHostGraphicExtension;
		if(aPos != std::string::npos && aHostGraphic.length() > aPos + 1)
			aHostGraphicExtension = aHostGraphic.substr(aPos+1);
		else
			aHostGraphicExtension = "bmp";

		m_sHostBitmapFile = GenerateTempFileName("FS", aHostGraphicExtension);

		CreateDirectoryRecursive(pCustInfo->GetPatchFolder());
		GUIString sPatchExe = pCustInfo->GetPatchFolder();
		sPatchExe.append(sPatchFile);

		pCustInfo->SetPatchFile(sPatchExe);

		mStartTime = time(NULL);
		mNumberCallbacks = 0;
		if (IsFtpAddress(pPatch->GetHostBmp()))
		{
			// Don't attempt to handle resumed downloads of bitmaps - not worth it.
			DeleteFile(std::string(m_sHostBitmapFile).c_str());
			m_pFtpGetBitmap = new FTPGetOp(pPatch->GetHostBmp(), true);
			m_pFtpGetBitmap->SetLocalPath(m_sHostBitmapFile);
			m_pFtpGetBitmap->SetCompletion(new DownloadCompletion(FtpBitmapDoneCallback));
			m_pFtpGetBitmap->RunAsync(static_cast<ULONG>(OP_TIMEOUT_INFINITE));
		}
		else
		{
			m_pHttpGetBitmap = new HTTPGetOp(pPatch->GetHostBmp());
			m_pHttpGetBitmap->SetLocalPath(m_sHostBitmapFile);
			m_pHttpGetBitmap->SetCompletion(new DownloadCompletion(HttpBitmapDoneCallback));
			m_pHttpGetBitmap->RunAsync(static_cast<ULONG>(OP_TIMEOUT_INFINITE));
		}

//		m_tDownloadStarted = GetTickCount();

		m_nPrevDownloadedFtpBytes = 0;
		if (IsFtpAddress(pPatch->GetPatchUrl()))
		{
			// If the previous patch profile does not match this patch profile, nuke the file.
			if (! pCustInfo->MatchFtpDownloadTag(sPatchExe, pCustInfo->GetNewVersion(), pPatch->GetPatchSize(), pPatch->GetChecksum()))
				DeleteFile(std::string(sPatchExe).c_str());
			else
				m_nPrevDownloadedFtpBytes = GetFileSize(sPatchExe);

			// Tag the patch's profile (so we can 'resume or not as appropriate later).
			pCustInfo->TagFtpDownload(sPatchExe, pCustInfo->GetNewVersion(), pPatch->GetPatchSize(), pPatch->GetChecksum());

			m_pFtpGetPatch = new FTPGetOp(pPatch->GetPatchUrl(), true);
			m_pFtpGetPatch->SetDoResume(true); // Allow resuming of downloads.
			m_pFtpGetPatch->SetLocalPath(sPatchExe);
			m_pFtpGetPatch->SetRecvChunkCompletion(new DownloadCompletion(PatchProgressCallback), CHUNCK_SIZE);
			m_pFtpGetPatch->SetCompletion(new DownloadCompletion(FtpPatchDoneCallback));
			m_pFtpGetPatch->RunAsync(static_cast<ULONG>(OP_TIMEOUT_INFINITE));
		}
		else
		{
			m_pHttpGetPatch = new HTTPGetOp(pPatch->GetPatchUrl());
			m_pHttpGetPatch->SetLocalPath(sPatchExe);
			m_pHttpGetPatch->SetRecvChunkCompletion(new DownloadCompletion(PatchProgressCallback), CHUNCK_SIZE);
			m_pHttpGetPatch->SetCompletion(new DownloadCompletion(HttpPatchDoneCallback));
			m_pHttpGetPatch->RunAsync(static_cast<ULONG>(OP_TIMEOUT_INFINITE));
		}

		m_bDownloadStarted = true;
	}
}