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

Function FlatStream_Open

src/External/CascLib/src/common/FileStream.cpp:1396–1471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1394}
1395
1396static TFileStream * FlatStream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
1397{
1398 TBlockStream * pStream;
1399 ULONGLONG ByteOffset = 0;
1400
1401 // Create new empty stream
1402 pStream = (TBlockStream *)AllocateFileStream(szFileName, sizeof(TBlockStream), dwStreamFlags);
1403 if(pStream == NULL)
1404 {
1405 SetCascError(ERROR_NOT_ENOUGH_MEMORY);
1406 return NULL;
1407 }
1408
1409 // Do we have a master stream?
1410 if(pStream->pMaster != NULL)
1411 {
1412 if(!FlatStream_CreateMirror(pStream))
1413 {
1414 FileStream_Close(pStream);
1415 SetCascError(ERROR_FILE_NOT_FOUND);
1416 return NULL;
1417 }
1418 }
1419 else
1420 {
1421 // Attempt to open the base stream
1422 if(!pStream->BaseOpen(pStream, pStream->szFileName, dwStreamFlags))
1423 {
1424 FileStream_Close(pStream);
1425 return NULL;
1426 }
1427
1428 // Load the bitmap, if required to
1429 if(dwStreamFlags & STREAM_FLAG_USE_BITMAP)
1430 FlatStream_LoadBitmap(pStream);
1431 }
1432
1433 // If we have a stream bitmap, set the reading functions
1434 // which check presence of each file block
1435 if(pStream->FileBitmap != NULL)
1436 {
1437 // Set the stream position to zero. Stream size is already set
1438 assert(pStream->StreamSize != 0);
1439 pStream->StreamPos = 0;
1440 pStream->dwFlags |= STREAM_FLAG_READ_ONLY;
1441
1442 // Supply the stream functions
1443 pStream->StreamRead = (STREAM_READ)BlockStream_Read;
1444 pStream->StreamGetSize = BlockStream_GetSize;
1445 pStream->StreamGetPos = BlockStream_GetPos;
1446 pStream->StreamClose = (STREAM_CLOSE)FlatStream_Close;
1447
1448 // Supply the block functions
1449 pStream->BlockCheck = (BLOCK_CHECK)FlatStream_BlockCheck;
1450 pStream->BlockRead = (BLOCK_READ)FlatStream_BlockRead;
1451 }
1452 else
1453 {

Callers 1

FileStream_OpenFileFunction · 0.85

Calls 5

AllocateFileStreamFunction · 0.85
SetCascErrorFunction · 0.85
FlatStream_CreateMirrorFunction · 0.85
FileStream_CloseFunction · 0.85
FlatStream_LoadBitmapFunction · 0.85

Tested by

no test coverage detected