//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int ReadQuakeFile(quakefile_t *qf, void *buffer, int length) { FILE *fp; unzFile zf; if (qf->zipfile) { //open the zip file zf = unzOpen(qf->pakfile); //set the file position in the zip file (also sets the current file info) unzSetOffset(zf, qf->pos); //open the Quake file in the zip file unzOpenCurrentFile(zf); //read the Quake file from the zip file length = unzReadCurrentFile(zf, buffer, length); //close the Quake file in the zip file unzCloseCurrentFile(zf); //close the zip file unzClose(zf); return length; } //end if else { fp = SafeOpenRead(qf->filename); SafeRead(fp, buffer, length); fclose(fp); return length; } //end else } //end of the function ReadQuakeFile
bool KAppRes::GetRawDataFromRes( const std::string& strId, void** ppBuffer, unsigned long& dwSize ) { bool retval = false; KResStore::iterator store; KResOffset::iterator offset; unsigned long dwOffset; int nRetCode; if (!ppBuffer) goto clean0; offset = m_mapResOffset.find(strId); if (offset == m_mapResOffset.end()) goto clean0; dwOffset = offset->second.first; dwSize = offset->second.second; *ppBuffer = new unsigned char[dwSize+1]; if (!*ppBuffer) goto clean0; nRetCode = unzSetOffset(m_pResPackData, dwOffset); if (nRetCode != UNZ_OK) goto clean0; nRetCode = unzOpenCurrentFile(m_pResPackData); if (nRetCode != UNZ_OK) goto clean0; nRetCode = unzReadCurrentFile(m_pResPackData, *ppBuffer, dwSize); if (0 == nRetCode) goto clean0; retval = true; clean0: if (!retval) { if (ppBuffer) { if (*ppBuffer) { delete[] (*ppBuffer); *ppBuffer = NULL; } } } return retval; }
//-----------------------------------------------------------------// bool unzip::get_file(uint32_t index, char* buff) { if(index < static_cast<uint32_t>(files_.size())) { unzSetOffset(hnd_, files_[index].ofs_); if(unzOpenCurrentFile(hnd_) != UNZ_OK) return false; size_t sz = get_filesize(index); unzReadCurrentFile(hnd_, buff, sz); unzCloseCurrentFile(hnd_); return true; } return false; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int LoadQuakeFile(quakefile_t *qf, void **bufferptr) { FILE *fp; void *buffer; int length; unzFile zf; if (qf->zipfile) { //open the zip file zf = unzOpen(qf->pakfile); //set the file position in the zip file (also sets the current file info) unzSetOffset(zf, qf->pos); //open the Quake file in the zip file unzOpenCurrentFile(zf); //allocate memory for the buffer length = qf->length; buffer = GetMemory(length+1); //read the Quake file from the zip file length = unzReadCurrentFile(zf, buffer, length); //close the Quake file in the zip file unzCloseCurrentFile(zf); //close the zip file unzClose(zf); *bufferptr = buffer; return length; } //end if else { fp = SafeOpenRead(qf->filename); length = qf->length; if (!length) length = Q_filelength(fp); buffer = GetMemory(length+1); ((char *)buffer)[length] = 0; SafeRead(fp, buffer, length); fclose(fp); *bufferptr = buffer; return length; } //end else } //end of the function LoadQuakeFile
//-----------------------------------------------------------------// bool unzip::create_file(uint32_t index, const std::string& filename) { if(index < static_cast<uint32_t>(files_.size())) { unzSetOffset(hnd_, files_[index].ofs_); if(unzOpenCurrentFile(hnd_) != UNZ_OK) return false; utils::file_io fout; fout.open(filename, "wb"); char buff[4096]; uLong sz; while((sz = unzReadCurrentFile(hnd_, buff, sizeof(buff))) > 0) { fout.write(buff, 1, sz); } unzCloseCurrentFile(hnd_); fout.close(); return true; } return false; }