示例#1
0
bool FOResourceStream::openArchived()
{
    FOResourceManager *manager = FOResourceManager::getSingleton();
    std::string archivePath = manager->getArchive(m_fileInfo->getArchive());
    if (archivePath.empty())
        return false;
    IFileStream *archiveStream = new IFileStream(archivePath.c_str());
    if (archiveStream->GetHandle() == NULL) {
        delete archiveStream;
        return false;
    }
    m_rawStream.Attach(archiveStream, m_fileInfo->getOffset(), m_fileInfo->getRawFileSize());
    if (m_fileInfo->isCompressed()) {
        // Create buffers
        ASSERT(m_inBuffer == NULL && m_outBuffer == NULL);
        m_inBuffer = new UInt8[CHUNK];
        m_outBuffer = new UInt8[CHUNK];

        // Create zlib state
        m_zstream = new z_stream;
        m_zstream->next_in = m_inBuffer;
        m_zstream->avail_in = 0;
        m_zstream->zalloc = Z_NULL;
        m_zstream->zfree = Z_NULL;
        m_zstream->opaque = Z_NULL;
        m_zstream->next_out = m_outBuffer;
        m_zstream->avail_out = CHUNK;

        // Fill the input buffers
        fillInBuffer();

        // Init zlib
        int result = inflateInit(m_zstream);
        if (result != Z_OK) {
            close();
            _ERROR("Could not init ZLIB inflate: %s(%d)", m_zstream->msg, result);
            return false;
        }


    }
    else {

    }
    streamLength = m_fileInfo->getFileSize();
    streamOffset = 0;
    m_open = true;
    return true;
}
示例#2
0
bool FOResourceStream::openNormal()
{
    if (m_fileInfo->getPath().empty())
        return false;
    IFileStream *fileStream = new IFileStream(m_fileInfo->getPath().c_str());
    if (fileStream->GetHandle() == NULL) {
        delete fileStream;
        return false;
    }
    m_rawStream.Attach(fileStream, 0, fileStream->GetLength());
    streamLength = fileStream->GetLength();
    streamOffset = 0;
    m_open = true;
    return true;
}