void z3ResEx::parseMsfMethod2( TMemoryStream &msf ) { unsigned short strLen( 0 ); unsigned short mrfIndexLen( 0 ); // Folders are now in a table at the top of the file msf.Read( &mrfIndexLen, sizeof( unsigned short ) ); if (mrfIndexLen == 0) { // There are no folders in the filesystem return; } // List of filenames vector<string> vecMsf(mrfIndexLen); vector<unsigned char> strBuffer(MAX_STRING_SIZE); // MRF filenames are now packed in a list for( unsigned short i( 0 ); i != mrfIndexLen; ++i ) { strLen = msf.ReadUShort(); unpackStringEx( msf, strBuffer, strLen ); // Required to rename files //vecMsf[i].first.assign( (char *)strBuffer ); // Cached file opening (and a pointer so we can call the constructor) //vecMsf[i].second = new TFileStream( strBuffer ); vecMsf[i] = string(strBuffer.begin(), strBuffer.end()); } // Files are now listed (similar to before) FILEINDEX_ENTRY2 fiItem; unsigned int items( 0 ), errors( 0 ); //msf.SaveToFile("debugFilesys.dat"); bool bMatchesCriteria = true; string tmpFilename; while( ( msf.Position() < msf.Size() ) && ( errors < MAX_ERRORS ) ) { msf.Read( &fiItem, sizeof( FILEINDEX_ENTRY2 ) ); strLen = msf.ReadUShort(); unpackStringEx( msf, strBuffer, strLen ); if( !m_folderCriteria.empty() ) { tmpFilename = string(strBuffer.begin(), strBuffer.end()); std::transform(tmpFilename.begin(), tmpFilename.end(), tmpFilename.begin(), ::toupper); bMatchesCriteria = !( tmpFilename.find( m_folderCriteria ) == string::npos ); } if( bMatchesCriteria ) { if( m_listContents ) { printf( "%s (%u bytes)\n", &strBuffer[0], fiItem.size ); } else { if( !( extractItem2( fiItem, vecMsf[ fiItem.mrfIndex ], reinterpret_cast<const char*>(&strBuffer[0]) ) ) ) ++errors; } } ++items; } vecMsf.clear(); printf( "Processed %u items (%u issues)\n\n", items, errors ); }
void z3ResEx::parseMsfMethod2( TMemoryStream &msf ) { unsigned short strLen( 0 ); unsigned char *strBuffer( nullptr ); unsigned short mrfIndexLen( 0 ); // Folders are now in a table at the top of the file msf.Read( &mrfIndexLen, sizeof( unsigned short ) ); // List of filenames //typedef std::pair<string, TFileStream* > mrfItem; typedef vector<string > mrfItemList; mrfItemList vecMsf; vecMsf.resize( mrfIndexLen ); // MRF filenames are now packed in a list for( unsigned short i( 0 ); i != mrfIndexLen; ++i ) { strLen = msf.ReadUShort(); unpackStringEx( msf, strBuffer, strLen ); // Required to rename files //vecMsf[i].first.assign( (char *)strBuffer ); // Cached file opening (and a pointer so we can call the constructor) //vecMsf[i].second = new TFileStream( strBuffer ); vecMsf[i].assign( (char *)strBuffer ); delete strBuffer; } // Files are now listed (similar to before) FILEINDEX_ENTRY2 fiItem; unsigned int items( 0 ), errors( 0 ); //msf.SaveToFile("debugFilesys.dat"); while( ( msf.Position() < msf.Size() ) && ( errors < MAX_ERRORS ) ) { msf.Read( &fiItem, sizeof( FILEINDEX_ENTRY2 ) ); strLen = msf.ReadUShort(); unpackStringEx( msf, strBuffer, strLen ); if( m_listContents ) { printf( "%s (%u bytes)\n", strBuffer, fiItem.size ); } else { if( !( extractItem2( fiItem, vecMsf[ fiItem.mrfIndex ], (char *)strBuffer ) ) ) ++errors; } delete strBuffer; ++items; } vecMsf.clear(); printf( "Processed %u items (%u issues)\n\n", items, errors ); }