예제 #1
0
bool zip::ZipArchiveInput::ReadFile( String_t const& fileName, Byte_t*& pMemoryBlock, size_t& size )
{
	String_t fileNameKey = fileName;
	if( !m_caseSensitive )
		for (size_t i = 0; i < fileNameKey.size(); ++i )
			fileNameKey[i] = _ttolower( fileNameKey[i] );

	NameToEntry_t::const_iterator keyValue = m_nameToEntry.find( fileNameKey );
	if( keyValue == m_nameToEntry.end() )
	{
		m_errorMessage << "file " << fileNameKey << " not found in the zip index" << std::endl;
		return false;
	}

	ZipEntry const& zipEntry = keyValue->second;
	unz_file_pos pos;
	pos.pos_in_zip_directory = zipEntry.pos_in_zip_directory;
	pos.num_of_file = zipEntry.num_of_file;

	int err = unzGoToFilePos( uf, &pos );
	if( err != UNZ_OK )
	{
		m_errorMessage << "Can't go to file " << fileName << std::endl;
		return false;
	}

	return ReadCurrentFile( fileName, pMemoryBlock, size );
}
예제 #2
0
bool zip::ZipArchiveInput::LocateAndReadFile( String_t const& fileName, Byte_t*& pMemoryBlock, size_t& size )
{
	int err = UNZ_OK;
#ifdef SCARAB_WCHAR_MODE
	std::string fileNameInZip = utf_convert::as_utf8( fileName );
#else
	std::string fileNameInZip = fileName;
#endif
	if ( unzLocateFile( uf, fileNameInZip.c_str(), m_caseSensitive ) != UNZ_OK )
	{
		m_errorMessage << "file " << fileName << " not found in the zipfile" << std::endl;
		return false;
	}

	return ReadCurrentFile( fileName, pMemoryBlock, size );
}
예제 #3
0
bool vtUnzip::ExtractCurrentFile(FILE* file, void* buf, size_t size_buf)
{
	bool bOK = true;
	while (bOK)
	{
		int bytes = ReadCurrentFile(buf,size_buf);
		if (bytes < 0)
		{
			VTLOG("error with zipfile in ReadCurrentFile\n");
			bOK = false;
		}
		else if (bytes > 0)
		{
			if (fwrite(buf,bytes,1,file)!=1)
			{
				VTLOG("error in writing extracted file\n");
				bOK = false;
			}
		}
		else
			break;
	}
	return bOK;
}