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

Function PartStream_Open

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

Source from the content-addressed store, hash-verified

1815}
1816
1817static TFileStream * PartStream_Open(LPCTSTR szFileName, DWORD dwStreamFlags)
1818{
1819 TBlockStream * pStream;
1820
1821 // Create new empty stream
1822 pStream = (TBlockStream *)AllocateFileStream(szFileName, sizeof(TBlockStream), dwStreamFlags);
1823 if(pStream == NULL)
1824 return NULL;
1825
1826 // Do we have a master stream?
1827 if(pStream->pMaster != NULL)
1828 {
1829 if(!PartStream_CreateMirror(pStream))
1830 {
1831 FileStream_Close(pStream);
1832 SetCascError(ERROR_FILE_NOT_FOUND);
1833 return NULL;
1834 }
1835 }
1836 else
1837 {
1838 // Attempt to open the base stream
1839 if(!pStream->BaseOpen(pStream, pStream->szFileName, dwStreamFlags))
1840 {
1841 FileStream_Close(pStream);
1842 return NULL;
1843 }
1844
1845 // Load the part stream block map
1846 if(!PartStream_LoadBitmap(pStream))
1847 {
1848 FileStream_Close(pStream);
1849 SetCascError(ERROR_BAD_FORMAT);
1850 return NULL;
1851 }
1852 }
1853
1854 // Set the stream position to zero. Stream size is already set
1855 assert(pStream->StreamSize != 0);
1856 pStream->StreamPos = 0;
1857 pStream->dwFlags |= STREAM_FLAG_READ_ONLY;
1858
1859 // Set new function pointers
1860 pStream->StreamRead = (STREAM_READ)BlockStream_Read;
1861 pStream->StreamGetPos = BlockStream_GetPos;
1862 pStream->StreamGetSize = BlockStream_GetSize;
1863 pStream->StreamClose = (STREAM_CLOSE)PartStream_Close;
1864
1865 // Supply the block functions
1866 pStream->BlockCheck = (BLOCK_CHECK)PartStream_BlockCheck;
1867 pStream->BlockRead = (BLOCK_READ)PartStream_BlockRead;
1868 return pStream;
1869}
1870
1871//-----------------------------------------------------------------------------
1872// Local functions - encrypted stream support

Callers 1

FileStream_OpenFileFunction · 0.85

Calls 5

AllocateFileStreamFunction · 0.85
PartStream_CreateMirrorFunction · 0.85
FileStream_CloseFunction · 0.85
SetCascErrorFunction · 0.85
PartStream_LoadBitmapFunction · 0.85

Tested by

no test coverage detected