| 729 | //----------------------------------------------------------------------------- |
| 730 | |
| 731 | Stream *ZipArchive::openFileForRead(const CentralDir *fileCD) |
| 732 | { |
| 733 | if(mMode != Read && mMode != ReadWrite) |
| 734 | return NULL; |
| 735 | |
| 736 | if((fileCD->mInternalFlags & (CDFileDeleted | CDFileOpen)) != 0) |
| 737 | return NULL; |
| 738 | |
| 739 | Stream *stream = mStream; |
| 740 | |
| 741 | if(fileCD->mInternalFlags & CDFileDirty) |
| 742 | { |
| 743 | // File is dirty, we need to read from the temporary file |
| 744 | for(S32 i = 0;i < mTempFiles.size();++i) |
| 745 | { |
| 746 | if(mTempFiles[i]->getCentralDir() == fileCD) |
| 747 | { |
| 748 | // Found the temporary file |
| 749 | if(! mTempFiles[i]->rewind()) |
| 750 | { |
| 751 | if(isVerbose()) |
| 752 | Con::errorf("ZipArchive::openFile - %s: %s is dirty, but could not rewind temporary file?", mFilename ? mFilename : "<no filename>", fileCD->mFilename.c_str()); |
| 753 | return NULL; |
| 754 | } |
| 755 | |
| 756 | stream = mTempFiles[i]; |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | if(stream == mStream) |
| 762 | { |
| 763 | if(isVerbose()) |
| 764 | Con::errorf("ZipArchive::openFile - %s: %s is dirty, but no temporary file found?", mFilename ? mFilename : "<no filename>", fileCD->mFilename.c_str()); |
| 765 | return NULL; |
| 766 | } |
| 767 | } |
| 768 | else |
| 769 | { |
| 770 | // Read from the zip file directly |
| 771 | if(! mStream->setPosition(fileCD->mLocalHeadOffset)) |
| 772 | { |
| 773 | if(isVerbose()) |
| 774 | Con::errorf("ZipArchive::openFile - %s: Could not locate local header for file %s", mFilename ? mFilename : "<no filename>", fileCD->mFilename.c_str()); |
| 775 | return NULL; |
| 776 | } |
| 777 | |
| 778 | FileHeader fh; |
| 779 | if(! fh.read(mStream)) |
| 780 | { |
| 781 | if(isVerbose()) |
| 782 | Con::errorf("ZipArchive::openFile - %s: Could not read local header for file %s", mFilename ? mFilename : "<no filename>", fileCD->mFilename.c_str()); |
| 783 | return NULL; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | Stream *attachTo = stream; |
| 788 | U16 compMethod = fileCD->mCompressMethod; |
nothing calls this directly
no test coverage detected