void ACEXML_ZipCharStream::rewind() { if (this->infile_ == 0) return; zzip_rewind (this->infile_); this->determine_encoding(); }
std::future<void*> ResourceManager::LoadSound(const char* filepath, void* _fSystem) { #ifdef _CACH_PARSED_DATA_ for (std::map<const char*, SoundData*>::iterator it = mSoundResource.begin(); it != mSoundResource.end(); it++) { if (it->first == filepath) return mThreadPool.AddTask<LoadSoundTask>(it->second->buffer, it->second->bufferSize, &mGlLock, _fSystem); } #endif unsigned int bufferSize; unsigned char* buffer; switch (mAssetPacketExtension) { case PACA: bufferSize = mPacaReader.GetResourceSize(filepath); buffer = new unsigned char[bufferSize]; if (mPacaReader.GetResource(filepath, buffer, bufferSize)) { #ifdef _CACH_PARSED_DATA_ SoundData* sd = new SoundData(); sd->buffer = buffer; sd->bufferSize = bufferSize; mSoundResource.insert(std::pair<const char*, SoundData*>(filepath, sd)); #endif return mThreadPool.AddTask<LoadSoundTask>(buffer, bufferSize, &mGlLock, _fSystem); } break; case ZIP: ZZIP_FILE* fp = zzip_file_open(mDir, filepath, 0); zzip_seek(fp, 0, SEEK_END); bufferSize = zzip_tell(fp); zzip_rewind(fp); buffer = new unsigned char[bufferSize]; bufferSize = zzip_file_read(fp, buffer, static_cast<int>(bufferSize)); zzip_file_close(fp); #ifdef _CACH_PARSED_DATA_ SoundData* sd = new SoundData(); sd->buffer = buffer; sd->bufferSize = bufferSize; mSoundResource.insert(std::pair<const char*, SoundData*>(filepath, sd)); #endif return mThreadPool.AddTask<LoadSoundTask>(buffer, bufferSize, &mGlLock, _fSystem); } }
TextureResource* ResourceManager::LoadTexture( const char* file) { #ifdef _CACH_PARSED_DATA_ for (std::map<const char*, TextureResource*>::iterator it = mTextureResource.begin(); it != mTextureResource.end(); it++) { if (it->first == file) return it->second; } #endif unsigned int bufferSize; unsigned char* buffer; switch ( mAssetPacketExtension ) { case PACA: bufferSize = mPacaReader.GetResourceSize(file); buffer = new unsigned char[bufferSize]; if ( mPacaReader.GetResource(file, buffer, bufferSize ) ) { TextureResource* textureResource = new TextureResource(); textureResource->future = mThreadPool.AddTask<LoadTextureTask>(buffer, bufferSize, &mGlLock); #ifdef _CACH_PARSED_DATA_ mTextureResource.insert(std::pair<const char*, TextureResource*>(file, textureResource)); #endif return textureResource; } break; case ZIP: ZZIP_FILE* fp = zzip_file_open( mDir, file, 0 ); zzip_seek( fp, 0, SEEK_END ); bufferSize = zzip_tell( fp ); zzip_rewind( fp ); buffer = new unsigned char[bufferSize]; bufferSize = zzip_file_read( fp, buffer, static_cast<int>( bufferSize ) ); zzip_file_close( fp ); TextureResource* textureResource = new TextureResource(); textureResource->future = mThreadPool.AddTask<LoadTextureTask>(buffer, bufferSize, &mGlLock); #ifdef _CACH_PARSED_DATA_ mTextureResource.insert(std::pair<const char*, TextureResource*>(file, textureResource)); #endif return textureResource; } }
PSAR_ENTRY *LPP_PsarDecoder_getEntry(const char *filename) { if(!initialized) return NULL; zzip_strings_t ext[] = {"", 0}; ZZIP_FILE *fd = zzip_open_ext_io(filename, O_RDONLY | (0x0), ZZIP_ONLYZIP, ext, &psar_handlers); if(fd == NULL) { #ifdef DEBUG dwrite_output("Function %s Line %d : Cannot open the file '%s' for read.\n", __FUNCTION__, __LINE__, filename); #endif return NULL; } PSAR_ENTRY *entry = (PSAR_ENTRY*)malloc(sizeof(PSAR_ENTRY)); if(!entry) { #ifdef DEBUG dwrite_output("Function %s Line %d : Cannot allocate 'entry' to memory.\n", __FUNCTION__, __LINE__); #endif zzip_close(fd); return NULL; } memset(entry, 0, sizeof(PSAR_ENTRY)); zzip_seek(fd, 0, SEEK_END); entry->len = zzip_tell(fd); zzip_rewind(fd); if(entry->len <= 0) { free(entry); zzip_fclose(fd); #ifdef DEBUG dwrite_output("Function %s Line %d : file len is lower than zero.\n", __FUNCTION__, __LINE__); #endif return NULL; } entry->data = (u8*)malloc(entry->len); zzip_fread(entry->data, 1, entry->len, fd); zzip_fclose(fd); return(entry); }
/** * This function will perform a => lseek(2) operation on a real/zipped file * * It will try to seek to the offset specified by offset, relative to whence, * which is one of SEEK_SET, SEEK_CUR or SEEK_END. * * If the file-handle is wrapping a stat'able file then it will actually just * perform a normal => lseek(2)-call. Otherwise the relative offset * is calculated, negative offsets are transformed into positive ones * by rewinding the file, and then data is read until the offset is * reached. This can make the function terribly slow, but this is * how gzio implements it, so I'm not sure there is a better way * without using the internals of the algorithm. */ zzip_off_t zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) { zzip_off_t cur_pos, rel_ofs, read_size, ofs; ZZIP_DIR *dir; if (! fp) return -1; if (! fp->dir) { /* stat fd */ return fp->io->fd.seeks(fp->fd, offset, whence); } cur_pos = zzip_tell(fp); /* calculate relative offset */ switch (whence) { case SEEK_SET: /* from beginning */ rel_ofs = offset - cur_pos; break; case SEEK_CUR: /* from current */ rel_ofs = offset; break; case SEEK_END: /* from end */ rel_ofs = fp->usize + offset - cur_pos; break; default: /* something wrong */ return -1; } if (rel_ofs == 0) return cur_pos; /* don't have to move */ if (rel_ofs < 0) { /* convert backward into forward */ if (zzip_rewind(fp) == -1) return -1; read_size = cur_pos + rel_ofs; cur_pos = 0; } else { /* amount to read is positive relative offset */ read_size = rel_ofs; } if (read_size < 0) /* bad offset, before beginning of file */ return -1; if (read_size + cur_pos > (zzip_off_t)fp->usize) /* bad offset, past EOF */ return -1; if (read_size == 0) /* nothing to read */ return cur_pos; dir = fp->dir; /* * If this is other handle than previous, save current seek pointer * and read the file position of `this' handle. */ if (dir->currentfp != fp) { if (zzip_file_saveoffset(dir->currentfp) < 0 || dir->currentfp->io->fd.seeks(dir->fd, fp->offset, SEEK_SET) < 0) { dir->errcode = ZZIP_DIR_SEEK; return -1; } else { dir->currentfp = fp; } } if (fp->method == 0) { /* unstore, just lseek relatively */ ofs = fp->io->fd.tells(dir->fd); ofs = fp->io->fd.seeks(dir->fd,read_size,SEEK_CUR); if (ofs > 0) { /* readjust from beginning of file */ ofs -= fp->dataoffset; fp->restlen = fp->usize - ofs; } return ofs; } else { /* method == 8, inflate */ char *buf; /*FIXME: use a static buffer! */ buf = (char *)malloc(ZZIP_32K); if (! buf) return -1; while (read_size > 0) { zzip_off_t size = ZZIP_32K; if (read_size < size/*32K*/) size = read_size; size = zzip_file_read(fp, buf, (zzip_size_t)size); if (size <= 0) { free(buf); return -1; } read_size -= size; } free (buf); } return zzip_tell(fp); }
ModelFileParser* ResourceManager::LoadModel(const char* file) { #ifdef _CACH_PARSED_DATA_ for (std::map<const char*, ModelFileParser*>::iterator it = mModelFileParsers.begin(); it != mModelFileParsers.end(); it++) { if (it->first == file) return it->second; } #endif unsigned int bufferSize; char* buffer; switch ( mAssetPacketExtension ) { case PACA: { bufferSize = mPacaReader.GetResourceSize( file ); buffer = new char[bufferSize]; if ( !mPacaReader.GetResource( file, buffer, bufferSize ) ) return nullptr; break; } break; case ZIP: { ZZIP_FILE* fp = zzip_file_open( mDir, file, 0 ); zzip_seek( fp, 0, SEEK_END ); bufferSize = zzip_tell( fp ); zzip_rewind( fp ); buffer = new char[bufferSize]; bufferSize = zzip_file_read( fp, buffer, bufferSize ); zzip_file_close( fp ); } break; } addToMemCount(bufferSize); ModelFileParser* mParser; std::string fileString; fileString = std::string(file); if (fileString.substr(fileString.find_last_of(".") + 1) == "mesh") { mParser = new MeshParser(); addToMemCount(sizeof(mParser)); } else if (fileString.substr(fileString.find_last_of(".") + 1) == "obj") { mParser = new ObjParser(); addToMemCount(sizeof(mParser)); } else { delete[] buffer; addToMemCount(-bufferSize); return NULL; } mParser->Load(buffer, bufferSize); addToMemCount(mParser->memory); delete[] buffer; addToMemCount(-bufferSize); #ifdef _CACH_PARSED_DATA_ mModelFileParsers.insert(std::pair<const char*, ModelFileParser*>(file, mParser)); #endif return mParser; }