| 261 | } |
| 262 | |
| 263 | static DWORD LoadSpanFrames(PCASC_FILE_SPAN pFileSpan, PCASC_CKEY_ENTRY pCKeyEntry, ULONGLONG DataFileOffset, LPBYTE pbFramePtr, LPBYTE pbFrameEnd, size_t cbHeaderSize) |
| 264 | { |
| 265 | PCASC_FILE_FRAME pFrames = NULL; |
| 266 | DWORD ContentSize = 0; |
| 267 | DWORD dwErrCode = ERROR_SUCCESS; |
| 268 | |
| 269 | assert(pFileSpan != NULL); |
| 270 | assert(pFileSpan->pStream != NULL); |
| 271 | assert(pFileSpan->pFrames == NULL); |
| 272 | |
| 273 | if(pFileSpan->FrameCount != 0) |
| 274 | { |
| 275 | // Move the raw archive offset |
| 276 | DataFileOffset += ((ULONGLONG)pFileSpan->FrameCount * sizeof(BLTE_FRAME)); |
| 277 | |
| 278 | // Allocate array of file frames |
| 279 | pFrames = CASC_ALLOC<CASC_FILE_FRAME>(pFileSpan->FrameCount); |
| 280 | if(pFrames != NULL) |
| 281 | { |
| 282 | // Copy the frames to the file structure |
| 283 | for(DWORD i = 0; i < pFileSpan->FrameCount; i++) |
| 284 | { |
| 285 | CASC_FILE_FRAME & Frame = pFrames[i]; |
| 286 | |
| 287 | // Capture the single BLTE frame |
| 288 | pbFramePtr = CaptureBlteFileFrame(Frame, pbFramePtr, pbFrameEnd); |
| 289 | if(pbFramePtr == NULL) |
| 290 | { |
| 291 | dwErrCode = ERROR_BAD_FORMAT; |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | // Fill-in the file range of the frame |
| 296 | Frame.StartOffset = pFileSpan->StartOffset + ContentSize; |
| 297 | Frame.EndOffset = Frame.StartOffset + Frame.ContentSize; |
| 298 | ContentSize += Frame.ContentSize; |
| 299 | |
| 300 | // Fill-in the archive range of the frame |
| 301 | assert((DataFileOffset + Frame.EncodedSize) > DataFileOffset); |
| 302 | Frame.DataFileOffset = DataFileOffset; |
| 303 | DataFileOffset += Frame.EncodedSize; |
| 304 | } |
| 305 | |
| 306 | // Save the content size of the file |
| 307 | if(pCKeyEntry->ContentSize == CASC_INVALID_SIZE) |
| 308 | { |
| 309 | pCKeyEntry->ContentSize = ContentSize; |
| 310 | } |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | dwErrCode = ERROR_NOT_ENOUGH_MEMORY; |
| 315 | } |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | // Allocate single "dummy" frame |
| 320 | pFrames = CASC_ALLOC<CASC_FILE_FRAME>(1); |
no test coverage detected