Common::SeekableReadStream *HERFFile::getResource(uint32 index) const { const IResource &res = getIResource(index); if (res.size == 0) return new Common::MemoryReadStream(0, 0); Common::SeekableReadStream *herf = ResMan.getResource(TypeMan.setFileType(_fileName, kFileTypeNone), kFileTypeHERF); if (!herf) throw Common::Exception(Common::kOpenError); if (!herf->seek(res.offset)) { delete herf; throw Common::Exception(Common::kSeekError); } Common::SeekableReadStream *resStream = herf->readStream(res.size); if (!resStream || (((uint32) resStream->size()) != res.size)) { delete herf; delete resStream; throw Common::Exception(Common::kReadError); } delete herf; return resStream; }
Common::SeekableReadStream *BIFFile::getResource(uint32 index, bool tryNoCopy) const { const IResource &res = getIResource(index); if (tryNoCopy) return new Common::SeekableSubReadStream(_bif.get(), res.offset, res.offset + res.size); _bif->seek(res.offset); return _bif->readStream(res.size); }
Common::SeekableReadStream *NDSFile::getResource(uint32 index) const { const IResource &res = getIResource(index); if (res.size == 0) return new Common::MemoryReadStream(0, 0); Common::File nds; open(nds); if (!nds.seek(res.offset)) throw Common::Exception(Common::kSeekError); Common::SeekableReadStream *resStream = nds.readStream(res.size); if (!resStream || (((uint32) resStream->size()) != res.size)) { delete resStream; throw Common::Exception(Common::kReadError); } return resStream; }
Common::SeekableReadStream *ERFFile::getResource(uint32 index) const { const IResource &res = getIResource(index); if (res.unpackedSize == 0) return new Common::MemoryReadStream(0, 0); if (_flags & 0xF0) throw Common::Exception("Unhandled ERF encryption"); Common::File erf; open(erf); if (!erf.seek(res.offset)) throw Common::Exception(Common::kSeekError); byte *compressedData = new byte[res.packedSize]; if (erf.read(compressedData, res.packedSize) != res.packedSize) { delete[] compressedData; throw Common::Exception(Common::kReadError); } return decompress(compressedData, res.packedSize, res.unpackedSize); }
uint32 BIFFile::getResourceSize(uint32 index) const { return getIResource(index).size; }
uint32 ERFFile::getResourceSize(uint32 index) const { return getIResource(index).unpackedSize; }