예제 #1
0
파일: barchive.cpp 프로젝트: 33d/scummvm
void BArchive::openDFW(const Common::String &path) {
	byte *table;
	uint16 tableSize;
	byte buf[2];

	_f.open(path);
	if (!_f.isOpen()) {
		debugC(2, kDraciArchiverDebugLevel, "Error opening file");
		return;
	}

	_fileCount = _f.readUint16LE();
	tableSize = _f.readUint16LE();

	_f.read(buf, 2);
	if (memcmp(buf, _dfwMagicNumber, 2) == 0) {
		debugC(2, kDraciArchiverDebugLevel, "Success");
		_isDFW = true;
	} else {
		debugC(2, kDraciArchiverDebugLevel, "Not a DFW archive");
		_f.close();
		return;
	}

	debugC(2, kDraciArchiverDebugLevel, "Archive info (DFW): %d files", _fileCount);

	// Read in index table
	table = new byte[tableSize];
	_f.read(table, tableSize);

	// Read in file headers, but do not read the actual data yet
	// The data will be read on demand to save memory
	_files = new BAFile[_fileCount];
	Common::MemoryReadStream tableReader(table, tableSize);
	for (uint i = 0; i < _fileCount; ++i) {
		_files[i]._compLength = tableReader.readUint16LE();
		_files[i]._offset = tableReader.readUint32LE();

		// Seek to the current file
		_f.seek(_files[i]._offset);

		_files[i]._length = _f.readUint16LE(); // Read in uncompressed length
		_f.readUint16LE(); // Compressed length again (already read from the index table)
		_files[i]._stopper = _f.readByte();

		_files[i]._data = NULL; // File data will be read in on demand
		_files[i]._crc = 0; // Dummy value; not used in DFW archives
	}

	// Indicate that the archive was successfully opened
	_opened = true;

	// Cleanup
	delete[] table;
}
예제 #2
0
	/// Parses the streams to retrieve a StyleSheet.
	StyleSheet::StyleSheet (FileInformationBlock* fib, POLE::Stream* tableStream, POLE::Stream* dataStream) : stshi(NULL), Styles(NULL)
	{
		VirtualStreamReader tableReader( tableStream, fib->m_FibWord97.fcStshf, fib->m_bOlderVersion);

		//read size of the STSHI
		int stshiLengthBytesSize = 2;
		unsigned char* stshiLengthBytes = tableReader.ReadBytes( stshiLengthBytesSize, true );
		short cbStshi = FormatUtils::BytesToInt16( stshiLengthBytes, 0, stshiLengthBytesSize );
		RELEASEARRAYOBJECTS( stshiLengthBytes );

		//read the bytes of the STSHI
        tableReader.Seek( ( fib->m_FibWord97.fcStshf + 2 ), 0/*STREAM_SEEK_SET*/ );
		unsigned char* stshi = tableReader.ReadBytes( cbStshi, true );

		//parses STSHI
		this->stshi = new StyleSheetInformation( stshi, cbStshi );
		RELEASEARRAYOBJECTS( stshi );

		//create list of STDs
		Styles = new std::vector<StyleSheetDescription*>();

		for ( int i = 0; i < this->stshi->cstd; i++ )
		{
			//get the cbStd
			unsigned short cbStd = tableReader.ReadUInt16();

			if ( cbStd != 0 )
			{
				//read the STD bytes
				unsigned char* std = tableReader.ReadBytes( cbStd, true );

				//parse the STD bytes
				Styles->push_back( new StyleSheetDescription( std, cbStd, (int)this->stshi->cbSTDBaseInFile, dataStream, fib->m_bOlderVersion) );

				RELEASEARRAYOBJECTS( std );
			}
			else
			{
				Styles->push_back( NULL );
			}
		}
	}