//------------------------------------------------------------------------------ void MpqHandler::clear() { for ( MpqArchiveList_t::iterator mpq_arc = _mpqArchiveList.begin(); mpq_arc != _mpqArchiveList.end(); ++mpq_arc ) { libmpq__archive_close( *mpq_arc ); } }
//------------------------------------------------------------------------------ libmpq__off_t MpqHandler::getListFile( const std::string &filename, mpq_archive_s **mpq_arc, uint8_t **buffer ) const { int32_t err = 0; std::string mpq_file = _dataDirectory + std::string( "/" ) + filename; try { // open mpq archive err = libmpq__archive_open( mpq_arc, mpq_file.c_str(), -1 ); if ( err != LIBMPQ_SUCCESS ) { throw( std::string( "libmpq__archive_open failed" ) ); } // get file number of the list file which contains all names in the archive uint32_t file_num = 0; err = libmpq__file_number( *mpq_arc, LIBMPQ_LISTFILE_NAME, &file_num ); if ( err != LIBMPQ_SUCCESS ) { throw( std::string( "libmpq__file_number failed" ) ); } // read file from archive...get file size and reserve space libmpq__off_t file_size; err = libmpq__file_unpacked_size( *mpq_arc, file_num, &file_size ); if ( err != LIBMPQ_SUCCESS ) { throw( std::string( "libmpq__file_unpacked_size failed" ) ); } // read file from archive to buffer *buffer = new uint8_t[file_size]; err = libmpq__file_read( *mpq_arc, file_num, *buffer, file_size, NULL ); if ( err != LIBMPQ_SUCCESS ) { throw( std::string( "libmpq__file_read failed" ) ); } return file_size; } catch( std::string err_msg ) { // if an archive has been opened close it if ( *mpq_arc ) { libmpq__archive_close( *mpq_arc ); } delete [] *buffer; // quit application std::stringstream ss; ss << "Cannot open " << mpq_file << " " << err_msg; quitApp( ss.str() ); } return -1; }
/* this function shows some archive information. */ int mpq_info__archive_info(char *program_name, char *mpq_filename, unsigned int number, unsigned int count) { /* some common variables. */ int result; off_t size_packed = 0; off_t size_unpacked = 0; off_t offset = 0; unsigned int version = 0; unsigned int files = 0; mpq_archive_s *mpq_archive; /* open the mpq-archive. */ if ((result = libmpq__archive_open(&mpq_archive, mpq_filename, -1)) < 0) { /* open archive failed. */ NOTICE("archive number: %i/%i\n", number, count); NOTICE("archive name: %s\n", mpq_filename); NOTICE("archive type: no mpq archive\n"); } else { /* fetch some required information. */ libmpq__archive_version(mpq_archive, &version); libmpq__archive_offset(mpq_archive, &offset); libmpq__archive_files(mpq_archive, &files); libmpq__archive_size_packed(mpq_archive, &size_packed); libmpq__archive_size_unpacked(mpq_archive, &size_unpacked); /* open archive was successful, show information. */ NOTICE("archive number: %i/%i\n", number, count); NOTICE("archive name: %s\n", mpq_filename); NOTICE("archive version: %i\n", version); NOTICE("archive offset: %" OFFTSTR "\n", offset); NOTICE("archive files: %i\n", files); NOTICE("archive packed size: %" OFFTSTR "\n", size_packed); NOTICE("archive unpacked size: %" OFFTSTR "\n", size_unpacked); NOTICE("archive compression ratio: %.2f\n", (100 - ((float)size_packed / (float)size_unpacked * 100))); libmpq__archive_close(mpq_archive); } /* if multiple archives were given, continue with next one. */ if (number < count) { NOTICE("\n-- next archive --\n\n"); } /* if no error was found, return zero. */ return 0; }
void MPQArchive::close() { //gOpenArchives.erase(erase(&mpq_a); libmpq__archive_close(mpq_a); }
void MPQArchive::close() { libmpq__archive_close(mpq_a); }
MPQArchiveImpl::~MPQArchiveImpl() { if ( archive_!=0 ) // sanity check, libmpq will crash if archive is null libmpq__archive_close( archive_ ); }