| 1776 | |
| 1777 | |
| 1778 | static TFileStream * PartStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags) |
| 1779 | { |
| 1780 | TBlockStream * pStream; |
| 1781 | |
| 1782 | // Create new empty stream |
| 1783 | pStream = (TBlockStream *)AllocateFileStream(szFileName, sizeof(TBlockStream), dwStreamFlags); |
| 1784 | if(pStream == NULL) |
| 1785 | return NULL; |
| 1786 | |
| 1787 | // Do we have a master stream? |
| 1788 | if(pStream->pMaster != NULL) |
| 1789 | { |
| 1790 | if(!PartStream_CreateMirror(pStream)) |
| 1791 | { |
| 1792 | FileStream_Close(pStream); |
| 1793 | SetLastError(ERROR_FILE_NOT_FOUND); |
| 1794 | return NULL; |
| 1795 | } |
| 1796 | } |
| 1797 | else |
| 1798 | { |
| 1799 | // Attempt to open the base stream |
| 1800 | if(!pStream->BaseOpen(pStream, pStream->szFileName, dwStreamFlags)) |
| 1801 | { |
| 1802 | FileStream_Close(pStream); |
| 1803 | return NULL; |
| 1804 | } |
| 1805 | |
| 1806 | // Load the part stream block map |
| 1807 | if(!PartStream_LoadBitmap(pStream)) |
| 1808 | { |
| 1809 | FileStream_Close(pStream); |
| 1810 | SetLastError(ERROR_BAD_FORMAT); |
| 1811 | return NULL; |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | // Set the stream position to zero. Stream size is already set |
| 1816 | assert(pStream->StreamSize != 0); |
| 1817 | pStream->StreamPos = 0; |
| 1818 | pStream->dwFlags |= STREAM_FLAG_READ_ONLY; |
| 1819 | |
| 1820 | // Set new function pointers |
| 1821 | pStream->StreamRead = (STREAM_READ)BlockStream_Read; |
| 1822 | pStream->StreamGetPos = BlockStream_GetPos; |
| 1823 | pStream->StreamGetSize = BlockStream_GetSize; |
| 1824 | pStream->StreamClose = (STREAM_CLOSE)PartStream_Close; |
| 1825 | |
| 1826 | // Supply the block functions |
| 1827 | pStream->BlockCheck = (BLOCK_CHECK)PartStream_BlockCheck; |
| 1828 | pStream->BlockRead = (BLOCK_READ)PartStream_BlockRead; |
| 1829 | return pStream; |
| 1830 | } |
| 1831 | |
| 1832 | //----------------------------------------------------------------------------- |
| 1833 | // Local functions - MPQE stream support |
no test coverage detected