Beispiel #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 );
}
Beispiel #2
0
bool zip::ZipArchiveInput::Index()
{
	static const int UNZ_MAXFILENAMEINZIP = 256;

	int err = unzGoToFirstFile(uf);
	if( err != UNZ_OK )
	{
		m_errorMessage << "Can't go to first file" << std::endl;
		return false;
	}

	while (err == UNZ_OK)
	{
		char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
		err = unzGetCurrentFileInfo64(uf, NULL,	szCurrentFileName, sizeof(szCurrentFileName)-1,NULL,0,NULL,0);
		if(err == UNZ_OK)
		{
#ifdef SCARAB_WCHAR_MODE
			String_t fileNameKey = utf_convert::as_wide( szCurrentFileName );
#else
			String_t fileNameKey = szCurrentFileName;
#endif
			if( !m_caseSensitive )
				for (size_t i = 0; i < fileNameKey.size(); ++i )
					fileNameKey[i] = _ttolower( fileNameKey[i] );

			unz_file_pos pos;
			err = unzGetFilePos( uf, &pos );
			if( err != UNZ_OK )
			{
				m_errorMessage << "Can't get file position for " << fileNameKey << std::endl;
				return false;
			}

			ZipEntry zipEntry;
			zipEntry.pos_in_zip_directory = pos.pos_in_zip_directory;
			zipEntry.num_of_file = pos.num_of_file;
			m_nameToEntry.insert( std::make_pair( fileNameKey, zipEntry ) );

			err = unzGoToNextFile(uf);
			if( err != UNZ_OK && err != UNZ_END_OF_LIST_OF_FILE )
			{
				m_errorMessage << "Can't go to next file" << std::endl;
				return false;
			}
		}
		else
		{
			m_errorMessage << "Can't get file info" << std::endl;
			return false;
		}
	}

	return err == UNZ_END_OF_LIST_OF_FILE;
}