MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / HttpDownloadFile

Function HttpDownloadFile

src/External/CascLib/src/CascFiles.cpp:1199–1259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1197}
1198
1199static DWORD HttpDownloadFile(
1200 LPCTSTR szRemoteName,
1201 LPCTSTR szLocalName,
1202 PULONGLONG PtrByteOffset,
1203 DWORD cbReadSize,
1204 DWORD dwPortFlags)
1205{
1206 TFileStream * pRemStream;
1207 LPBYTE pbFileData;
1208 DWORD dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
1209
1210 // Open the remote stream
1211 pRemStream = FileStream_OpenFile(szRemoteName, BASE_PROVIDER_HTTP | STREAM_PROVIDER_FLAT | dwPortFlags);
1212 if(pRemStream != NULL)
1213 {
1214 // Will we download the entire file or just a part of it?
1215 if(PtrByteOffset == NULL)
1216 {
1217 ULONGLONG FileSize = 0;
1218
1219 // Retrieve the file size, but not longer than 1 GB
1220 if(FileStream_GetSize(pRemStream, &FileSize))
1221 {
1222 // Verify valid size
1223 if(0 < FileSize && FileSize < CASC_MAX_ONLINE_FILE_SIZE)
1224 {
1225 cbReadSize = (DWORD)FileSize;
1226 dwErrCode = ERROR_SUCCESS;
1227 }
1228 else
1229 {
1230 dwErrCode = ERROR_BAD_FORMAT;
1231 }
1232 }
1233 else
1234 {
1235 dwErrCode = GetCascError();
1236 }
1237 }
1238
1239 // Shall we read something?
1240 if((dwErrCode == ERROR_SUCCESS) && (cbReadSize != 0) && (pbFileData = CASC_ALLOC<BYTE>(cbReadSize)) != NULL)
1241 {
1242 // Read all required data from the remote file
1243 if(FileStream_Read(pRemStream, PtrByteOffset, pbFileData, cbReadSize))
1244 dwErrCode = SaveLocalFile(szLocalName, pbFileData, cbReadSize);
1245
1246 // Free the data buffer
1247 CASC_FREE(pbFileData);
1248 }
1249
1250 // Close the remote stream
1251 FileStream_Close(pRemStream);
1252 }
1253 else
1254 {
1255 dwErrCode = GetCascError();
1256 }

Callers 1

FetchCascFileFunction · 0.85

Calls 7

FileStream_OpenFileFunction · 0.85
FileStream_GetSizeFunction · 0.85
GetCascErrorFunction · 0.85
FileStream_ReadFunction · 0.85
SaveLocalFileFunction · 0.85
CASC_FREEFunction · 0.85
FileStream_CloseFunction · 0.85

Tested by

no test coverage detected