반응형
BOOL DownloadHttpFile(LPCSTR szDomainAddr, LPCSTR szInetFileAddr, LPCSTR szDownloadPath) { if (!szDomainAddr || !szInetFileAddr || !szDownloadPath) return FALSE; // 1. Create Session CInternetSession session; CHttpConnection* pHttpConn = session.GetHttpConnection(szDomainAddr); if (NULL == pHttpConn) return FALSE; // 2. Open Internet File CHttpFile* pHttpFile = (CHttpFile*)session.OpenURL(szInetFileAddr, 1, INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD); if (pHttpFile) { // 3. Create Download File to Local CFile downloadFile; if (downloadFile.Open(szDownloadPath, CFile::modeCreate | CFile::modeWrite)) { DWORD dwInetFileSize = 0; pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, dwInetFileSize); // 4. Download // Check Total File Size : do - while // Check Trans Size : while (TRUE) do { downloadFile.SeekToBegin(); pHttpFile->SeekToBegin(); while (TRUE) { ULONGLONG lnChunkSize = pHttpFile->GetLength(); if (lnChunkSize == 0) break; BYTE* pBuffer = new BYTE[(UINT)lnChunkSize + 1]; DWORD dwReadSize = pHttpFile->Read(pBuffer, (UINT)lnChunkSize); if (dwReadSize > 0) downloadFile.Write(pBuffer, dwReadSize); delete pBuffer; } } while (dwInetFileSize != downloadFile.GetLength()); downloadFile.Close(); } pHttpFile->Close(); delete pHttpFile; } pHttpConn->Close(); delete pHttpConn; return TRUE; }
* Session 및 File의 Close 주의
반응형
'Game Dev > Article' 카테고리의 다른 글
중첩을 피하는 코딩 스타일 (1) | 2009.04.12 |
---|---|
편리한 STL Container Macro (0) | 2009.03.26 |
배열과 Loop를 다루는 3가지 방법 (0) | 2009.01.12 |
Render to Texture (0) | 2008.12.17 |