bool CRunTimeKeyValuesStringTable::ReadStringTable( int numStrings, CUtlBuffer& buf )
{
	Assert( m_Strings.Count() == 0 );

	CUtlVector< int > offsets;
	offsets.EnsureCapacity( numStrings );

	offsets.CopyArray( (int *)( buf.PeekGet() ), numStrings );

	// Skip over data
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, buf.TellGet() + numStrings * sizeof( int ) );

	int stringSize = buf.GetInt();
	
	// Read in the string table
	m_Strings.EnsureCapacity( numStrings );
	int i;
	for ( i = 0 ; i < numStrings; ++i )
	{
		m_Strings.AddToTail( (const char *)buf.PeekGet( offsets[ i ] ) );
	}

	buf.SeekGet( CUtlBuffer::SEEK_HEAD, buf.TellGet() + stringSize );

	return true;
}
static bool LoadFile( char const* pFileName, CUtlBuffer& buf )
{
	FileHandle_t fp;

	// load the model
	if( (fp = g_pFileSystem->Open(pFileName, "rb" )) == NULL)
		return false;

	// Get the file size
	int size = g_pFileSystem->Size( fp );
	if (size == 0)
	{
		g_pFileSystem->Close( fp );
		return false;
	}

	buf.EnsureCapacity( size );
	g_pFileSystem->Read( buf.PeekPut(), size, fp );
	g_pFileSystem->Close( fp );

	buf.SeekPut( CUtlBuffer::SEEK_HEAD, size );
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );

	return true;
}
Esempio n. 3
0
static int CountBinaryBytes( CUtlBuffer &buf, int *pEndGet )
{
	// This counts the number of bytes in the uuencoded text
	int nStartGet = buf.TellGet();
	buf.EatWhiteSpace();
	*pEndGet = buf.TellGet();
	int nByteCount = 0;
	while ( buf.IsValid() )
	{
		char c1 = buf.GetChar();
		char c2 = buf.GetChar();

		bool bIsNum1 = ( c1 >= '0' ) && ( c1 <= '9' );
		bool bIsNum2 = ( c2 >= '0' ) && ( c2 <= '9' );

		bool bIsAlpha1 = (( c1 >= 'A' ) && ( c1 <= 'F' )) || (( c1 >= 'a' ) && ( c1 <= 'f' ));
		bool bIsAlpha2 = (( c2 >= 'A' ) && ( c2 <= 'F' )) || (( c2 >= 'a' ) && ( c2 <= 'f' ));

		if ( !(bIsNum1 || bIsAlpha1) || !(bIsNum2 || bIsAlpha2) )
			break;

		buf.EatWhiteSpace();
		*pEndGet = buf.TellGet();
		++nByteCount;
	}
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nStartGet );
	return nByteCount;
}
//-----------------------------------------------------------------------------
// Sets the current TGA
//-----------------------------------------------------------------------------
void CTGAPreviewPanel::SetTGA( const char *pFullPath )
{
	int nWidth, nHeight;
	ImageFormat format;
	float flGamma;

	CUtlBuffer buf;
	if ( !g_pFullFileSystem->ReadFile( pFullPath, NULL, buf ) )
	{
		Warning( "Can't open TGA file: %s\n", pFullPath );
		return;
	}

	TGALoader::GetInfo( buf, &nWidth, &nHeight, &format, &flGamma );

	Shutdown();
	Init( nWidth, nHeight, true );
	m_TGAName = pFullPath;

	buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
	if ( !TGALoader::Load( (unsigned char*)GetImageBuffer(), buf, 
		  nWidth, nHeight, IMAGE_FORMAT_BGRA8888, flGamma, false ) )
	{
		Shutdown();
	}
	else
	{
		DownloadTexture();
	}
}
void CCompileCaptionsApp::DescribeCaptions( char const *file )
{
	CUtlBuffer buf;
	if ( !g_pFullFileSystem->ReadFile( file, NULL, buf ) )
	{
		Error( "Unable to read '%s' into buffer\n", file );
	}

	CompiledCaptionHeader_t header;
	buf.Get( &header, sizeof( header ) );
	if ( header.magic != COMPILED_CAPTION_FILEID )
		Error( "Invalid file id for %s\n", file );
	if ( header.version != COMPILED_CAPTION_VERSION )
		Error( "Invalid file version for %s\n", file );

	// Read the directory
	CUtlSortVector< CaptionLookup_t, CCaptionLookupLess > directory;
	directory.EnsureCapacity( header.directorysize );
	directory.CopyArray( (const CaptionLookup_t *)buf.PeekGet(), header.directorysize );
	directory.RedoSort( true );
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, header.dataoffset );

	int i;
	CUtlVector< CaptionBlock_t >	blocks;
	for ( i = 0; i < header.numblocks; ++i )
	{
		CaptionBlock_t& newBlock = blocks[ blocks.AddToTail() ];
		Q_memset( newBlock.data, 0, sizeof( newBlock.data ) );
		buf.Get( newBlock.data, header.blocksize );
	}

	CUtlMap< unsigned int, StringIndex_t > inverseMap( 0, 0, DefLessFunc( unsigned int ) );
	for ( StringIndex_t idx = g_pVGuiLocalize->GetFirstStringIndex(); idx != INVALID_LOCALIZE_STRING_INDEX; idx = g_pVGuiLocalize->GetNextStringIndex( idx ) )
	{
		const char *name = g_pVGuiLocalize->GetNameByIndex( idx );
		CaptionLookup_t dummy;
		dummy.SetHash( name );

		inverseMap.Insert( dummy.hash, idx );
	}

	// Now print everything out...
	for ( i = 0; i < header.directorysize; ++i )
	{
		const CaptionLookup_t& entry = directory[ i ];
		char const *name = g_pVGuiLocalize->GetNameByIndex( inverseMap.Element( inverseMap.Find( entry.hash ) ) );
		const CaptionBlock_t& block = blocks[ entry.blockNum ];
		const wchar_t *data = (const wchar_t *)&block.data[ entry.offset ];
		wchar_t *temp = ( wchar_t * )_alloca( entry.length * sizeof( short ) );
		wcsncpy( temp, data, ( entry.length / sizeof( short ) ) - 1 );

		vprint( 0, "%3.3d:  (%40.40s) hash(%15.15u), block(%4.4d), offset(%4.4d), len(%4.4d) %S\n",
			i, name, entry.hash, entry.blockNum, entry.offset, entry.length, temp );
	}
}
Esempio n. 6
0
//-----------------------------------------------------------------------------
// Get PSD file image resources
//-----------------------------------------------------------------------------
PSDImageResources PSDGetImageResources( CUtlBuffer &buf )
{
	int nGet = buf.TellGet();

	// Header
	PSDHeader_t header;
	buf.Get( &header, sizeof( header ) );

	// Then palette
	unsigned int numBytesPalette = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, numBytesPalette );

	// Then image resources
	unsigned int numBytesImgResources = BigLong( buf.GetUnsignedInt() );
	PSDImageResources imgres( numBytesImgResources, ( unsigned char * ) buf.PeekGet() );

	// Restore the seek
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nGet );

	return imgres;
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
// Is it a PSD file?
//-----------------------------------------------------------------------------
bool IsPSDFile( CUtlBuffer &buf )
{
	int nGet = buf.TellGet();
	PSDHeader_t header;
	buf.Get( &header, sizeof(header) );
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nGet );

	if ( BigLong( header.m_nSignature ) != PSD_SIGNATURE )
		return false;
	if ( BigShort( header.m_nVersion ) != 1 )
		return false;
	return ( BigShort( header.m_nDepth ) == 8 );
}
Esempio n. 8
0
bool Unserialize( CUtlBuffer &buf, CUtlBinaryBlock &dest )
{
	if ( !buf.IsText() )
	{
		int nLen = buf.GetInt( );
		dest.SetLength( nLen );
		if ( dest.Length() != 0 )
		{
			buf.Get( dest.Get(), dest.Length() );
		}

		if ( nLen != dest.Length() )
		{
			buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLen - dest.Length() );
			return false;
		}

		return buf.IsValid();
	}

	int nEndGet;
	int nByteCount = CountBinaryBytes( buf, &nEndGet );
	if ( nByteCount < 0 )
		return false;

	buf.EatWhiteSpace();
	int nDest = 0;
	dest.SetLength( nByteCount );
	while( buf.TellGet() < nEndGet )
	{
		char c1 = buf.GetChar();
		char c2 = buf.GetChar();

		unsigned char b1 = HexCharToInt( c1 );
		unsigned char b2 = HexCharToInt( c2 );
		if ( b1 == 0xFF || b2 == 0xFF )
			return false;

		dest[ nDest++ ] = b2 | ( b1 << 4 );
		buf.EatWhiteSpace();
	}

	return true;
}
Esempio n. 9
0
bool AStar::Load(IFileSystem *filesystem, const char *Filename)
{
	CUtlBuffer buf;

	if(!filesystem->ReadFile(Filename, "MOD", buf))
	{
		return false;
	}

	buf.SeekGet(CUtlBuffer::SEEK_HEAD, 0);

	int SrcID, DestID;

	//////////////////////////////////////////////
	// Nodes
	int NodeTotal = buf.GetInt();

	for(int i = 0; i < NodeTotal; i++)
	{
		Vector origin;
		origin.x = buf.GetFloat();
		origin.y = buf.GetFloat();
		origin.z = buf.GetFloat();
		AddNode(new AStarNode(origin));
	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// Links
	int TotalNumLinks = buf.GetInt();

	for(int i = 0; i < TotalNumLinks; i++)
	{
		SrcID = buf.GetInt();
		DestID = buf.GetInt();
		Nodes[SrcID]->AddLink(Nodes[DestID]);
	}

	//////////////////////////////////////////////

	return true;
}
Esempio n. 10
0
//-----------------------------------------------------------------------------
// Returns information about the PSD file
//-----------------------------------------------------------------------------
bool PSDGetInfo( CUtlBuffer &buf, int *pWidth, int *pHeight, ImageFormat *pImageFormat, float *pSourceGamma )
{
	int nGet = buf.TellGet();
	PSDHeader_t header;
	buf.Get( &header, sizeof(header) );
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nGet );

	if ( BigLong( header.m_nSignature ) != PSD_SIGNATURE )
		return false;
	if ( BigShort( header.m_nVersion ) != 1 )
		return false;
	if ( BigShort( header.m_nDepth ) != 8 )
		return false;

	*pWidth = BigLong( header.m_nColumns );
	*pHeight = BigLong( header.m_nRows );
	*pImageFormat = BigShort( header.m_nChannels ) == 3 ? IMAGE_FORMAT_RGB888 : IMAGE_FORMAT_RGBA8888;
	*pSourceGamma = ARTWORK_GAMMA;

	return true;
}
void CBugReporter::SubstituteBugId( int bugid, char *out, int outlen, CUtlBuffer& src )
{
	out[ 0 ] = 0;

	char *dest = out;

	src.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );

	char const *replace = "\\BugId\\";
	int replace_len = Q_strlen( replace );

	for ( int pos = 0; pos <= src.TellPut() && ( ( dest - out ) < outlen ); )
	{
		char const *str = ( char const * )src.PeekGet( pos );
		if ( !Q_strnicmp( str, replace, replace_len ) )
		{
			*dest++ = '\\';

			char num[ 32 ];
			Q_snprintf( num, sizeof( num ), "%i", bugid );
			char *pnum = num;
			while ( *pnum )
			{
				*dest++ = *pnum++;
			}

			*dest++ = '\\';
			pos += replace_len;
			continue;
		}

		*dest++ = *str;
		++pos;
	}
	*dest = 0;
}
Esempio n. 12
0
//-----------------------------------------------------------------------------
// Converts a buffer from a CRLF buffer to a CR buffer (and back)
// Returns false if no conversion was necessary (and outBuf is left untouched)
// If the conversion occurs, outBuf will be cleared.
//-----------------------------------------------------------------------------
bool CUtlBuffer::ConvertCRLF( CUtlBuffer &outBuf )
{
	if ( !IsText() || !outBuf.IsText() )
		return false;

	if ( ContainsCRLF() == outBuf.ContainsCRLF() )
		return false;

	int nInCount = TellMaxPut();

	outBuf.Purge();
	outBuf.EnsureCapacity( nInCount );

	bool bFromCRLF = ContainsCRLF();

	// Start reading from the beginning
	int nGet = TellGet();
	int nPut = TellPut();
	int nGetDelta = 0;
	int nPutDelta = 0;

	const char *pBase = (const char*)Base();
	int nCurrGet = 0;
	while ( nCurrGet < nInCount )
	{
		const char *pCurr = &pBase[nCurrGet];
		if ( bFromCRLF )
		{
			const char *pNext = Q_strnistr( pCurr, "\r\n", nInCount - nCurrGet );
			if ( !pNext )
			{
				outBuf.Put( pCurr, nInCount - nCurrGet );
				break;
			}

			int nBytes = (size_t)pNext - (size_t)pCurr;
			outBuf.Put( pCurr, nBytes );
			outBuf.PutChar( '\n' );
			nCurrGet += nBytes + 2;
			if ( nGet >= nCurrGet - 1 )
			{
				--nGetDelta;
			}
			if ( nPut >= nCurrGet - 1 )
			{
				--nPutDelta;
			}
		}
		else
		{
			const char *pNext = Q_strnchr( pCurr, '\n', nInCount - nCurrGet );
			if ( !pNext )
			{
				outBuf.Put( pCurr, nInCount - nCurrGet );
				break;
			}

			int nBytes = (size_t)pNext - (size_t)pCurr;
			outBuf.Put( pCurr, nBytes );
			outBuf.PutChar( '\r' );
			outBuf.PutChar( '\n' );
			nCurrGet += nBytes + 1;
			if ( nGet >= nCurrGet )
			{
				++nGetDelta;
			}
			if ( nPut >= nCurrGet )
			{
				++nPutDelta;
			}
		}
	}

	Assert(	nPut + nPutDelta <= outBuf.TellMaxPut() );

	outBuf.SeekGet( SEEK_HEAD, nGet + nGetDelta ); 
	outBuf.SeekPut( SEEK_HEAD, nPut + nPutDelta ); 

	return true;
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
// Reads the PSD file into the specified buffer
//-----------------------------------------------------------------------------
bool PSDReadFileRGBA8888( CUtlBuffer &buf, Bitmap_t &bitmap )
{
	PSDHeader_t header;
	buf.Get( &header, sizeof(header) );

	if ( BigLong( header.m_nSignature ) != PSD_SIGNATURE )
		return false;
	if ( BigShort( header.m_nVersion ) != 1 )
		return false;
	if ( BigShort( header.m_nDepth ) != 8 )
		return false;

	PSDMode_t mode = (PSDMode_t)BigShort( header.m_nMode );
	int nChannelsCount = BigShort( header.m_nChannels );

	if ( mode == MODE_MULTICHANNEL || mode == MODE_LAB )
		return false;

	switch ( mode )
	{
	case MODE_RGBA:
		if ( nChannelsCount < 3 )
			return false;
		break;

	case MODE_GREYSCALE:
	case MODE_PALETTIZED:
		if ( nChannelsCount != 1 && nChannelsCount != 2 )
			return false;
		break;

	case MODE_CMYK:
		if ( nChannelsCount < 4 )
			return false;
		break;

	default:
		Warning( "Unsupported PSD color mode!\n" );
		return false;
	}

	int nWidth = BigLong( header.m_nColumns );
	int nHeight = BigLong( header.m_nRows );

	// Skip parts of memory we don't care about
	int nColorModeSize = BigLong( buf.GetUnsignedInt() );
	Assert( nColorModeSize % 3 == 0 );
	unsigned char *pPaletteBits = (unsigned char*)_alloca( nColorModeSize );
	PSDPalette_t palette;
	palette.m_pRed = palette.m_pGreen = palette.m_pBlue = 0;
	if ( nColorModeSize )
	{
		int nPaletteSize = nColorModeSize / 3;
		buf.Get( pPaletteBits, nColorModeSize );
		palette.m_pRed = pPaletteBits;
		palette.m_pGreen = palette.m_pRed + nPaletteSize;
		palette.m_pBlue = palette.m_pGreen + nPaletteSize;
	}
 	int nImageResourcesSize = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nImageResourcesSize );
	int nLayersSize = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLayersSize );

	unsigned short nCompressionType = BigShort( buf.GetShort() );

	bitmap.Init( nWidth, nHeight, IMAGE_FORMAT_RGBA8888 );

	bool bSecondPassCMYKA = ( nChannelsCount > 4 && mode == MODE_CMYK );
	if ( nCompressionType == 0 )
	{
		PSDReadUncompressedChannels( buf, ( nChannelsCount > 4 ) ? 4 : nChannelsCount, mode, palette, bitmap );
	}
	else
	{
		// Skip the data that indicates the length of each compressed row in bytes
		// NOTE: There are two bytes per row per channel
		unsigned int nLineLengthData = sizeof(unsigned short) * bitmap.m_nHeight * nChannelsCount;
		buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLineLengthData );
		PSDReadCompressedChannels( buf, ( nChannelsCount > 4 ) ? 4 : nChannelsCount, mode, palette, bitmap );
	}

	// Read the alpha in a second pass for CMYKA
	if ( bSecondPassCMYKA )
	{
		if ( nCompressionType == 0 )
		{
			PSDReadUncompressedChannels( buf, 1, MODE_COUNT, palette, bitmap );
		}
		else
		{
			PSDReadCompressedChannels( buf, 1, MODE_COUNT, palette, bitmap );
		}
	}

	return true;
}
Esempio n. 14
0
void ProcessFiles( const char *pNormalFileNameWithoutExtension,
				   int startFrame, int endFrame,
				   float bumpScale )
{
	static char heightTGAFileName[1024];
	static char normalTGAFileName[1024];
	static char buf[1024];
	bool animated = !( startFrame == -1 || endFrame == -1 );
	int numFrames = endFrame - startFrame + 1;
	int frameID;

	for( frameID = 0; frameID < numFrames; frameID++ )
	{
		if( animated )
		{
			sprintf( normalTGAFileName, "%s%03d.tga", pNormalFileNameWithoutExtension, frameID + startFrame );
		}
		else
		{
			sprintf( normalTGAFileName, "%s.tga", pNormalFileNameWithoutExtension );
		}
		if( !Q_stristr( pNormalFileNameWithoutExtension, "_normal" ) )
		{
			fprintf( stderr, "ERROR: config file name must end in _normal.txt\n" );
			return;
		}

		strcpy( buf, pNormalFileNameWithoutExtension );

		// Strip '_normal' off the end because we're looking for '_height' 
		char *pcUnderscore = Q_stristr( buf, "_normal" );
		*pcUnderscore = NULL;

		if( animated )
		{
			sprintf( heightTGAFileName, "%s_height%03d.tga", buf, frameID + startFrame );
		}
		else
		{
			sprintf( heightTGAFileName, "%s_height.tga", buf );
		}
		
		enum ImageFormat imageFormat;
		int width, height;
		float sourceGamma;
		CUtlBuffer buf;
		if ( !g_pFullFileSystem->ReadFile( heightTGAFileName, NULL, buf ) )
		{
			fprintf( stderr, "%s not found\n", heightTGAFileName );
			return;
		}

		if ( !TGALoader::GetInfo( buf, &width, &height, &imageFormat, &sourceGamma ) )
		{
			fprintf( stderr, "error in %s\n", heightTGAFileName );
			return;
		}

		int memRequired = ImageLoader::GetMemRequired( width, height, 1, IMAGE_FORMAT_IA88, false );
		unsigned char *pImageIA88 = new unsigned char[memRequired];
		
		buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
		TGALoader::Load( pImageIA88, buf, width, height, IMAGE_FORMAT_IA88, sourceGamma, false );

		memRequired = ImageLoader::GetMemRequired( width, height, 1, IMAGE_FORMAT_RGBA8888, false );
		unsigned char *pImageRGBA8888 = new unsigned char[memRequired];
		ImageLoader::ConvertIA88ImageToNormalMapRGBA8888( pImageIA88, width, height, pImageRGBA8888, bumpScale );

		CUtlBuffer normalBuf;
		ImageLoader::NormalizeNormalMapRGBA8888( pImageRGBA8888, width * height );
		if( ImageRGBA8888HasAlpha( pImageRGBA8888, width * height ) )
		{
			TGAWriter::WriteToBuffer( pImageRGBA8888, normalBuf, width, height, IMAGE_FORMAT_RGBA8888, IMAGE_FORMAT_RGBA8888 );
		}
		else
		{
			memRequired = ImageLoader::GetMemRequired( width, height, 1, IMAGE_FORMAT_RGB888, false );
			unsigned char *pImageRGB888 = new unsigned char[memRequired];
			ImageLoader::ConvertImageFormat( pImageRGBA8888, IMAGE_FORMAT_RGBA8888, 
				pImageRGB888, IMAGE_FORMAT_RGB888, width, height, 0, 0 );
			TGAWriter::WriteToBuffer( pImageRGB888, normalBuf, width, height, IMAGE_FORMAT_RGB888, IMAGE_FORMAT_RGB888 );
			delete [] pImageRGB888;
		}
		if ( !g_pFullFileSystem->WriteFile( normalTGAFileName, NULL, normalBuf ) )
		{
			fprintf( stderr, "unable to write %s\n", normalTGAFileName );
			return;
		}
		delete [] pImageIA88;
		delete [] pImageRGBA8888;
	}
}
Esempio n. 15
0
bool xZipAddFile( const char* filename, CUtlBuffer &fileBuff, bool bPrecacheEntireFile, bool bProcessPrecacheHeader, bool bProcessPrecacheHeaderOnly )
{
    unsigned int fileSize = fileBuff.TellMaxPut();

    // Track total input bytes for stats reasons
    InputFileBytes += fileSize;

    unsigned customPreloadSize = 0;

    if( bPrecacheEntireFile  )
    {
        customPreloadSize = fileSize;
    }
    else if( bProcessPrecacheHeader )
    {
        customPreloadSize = xZipComputeCustomPreloads( filename );
    }
    else if( bProcessPrecacheHeaderOnly )
    {
        customPreloadSize = xZipComputeCustomPreloads( filename );
        fileSize = min( fileSize, customPreloadSize );
    }

    unsigned CRC = xZipCRCFilename( filename );

    // Does this file have a split header?
    if( customPreloadSize > 0  )
    {
        // Initialize the entry header:
        xZipDirectoryEntry_t entry;
        memset( &entry, 0, sizeof( entry ) );

        entry.FilenameCRC = CRC;
        entry.Length = customPreloadSize;
        entry.StoredOffset = ftell(hTempFilePreload);

        // Add the directory entry to the preload table:
        Header.PreloadDirectoryEntries++;
        pPreloadDirectoryEntries = (xZipDirectoryEntry_t*)realloc( pPreloadDirectoryEntries, sizeof( xZipDirectoryEntry_t ) * Header.PreloadDirectoryEntries );
        memcpy( pPreloadDirectoryEntries + Header.PreloadDirectoryEntries - 1, &entry, sizeof( entry ) );

        // Concatenate the data in the preload file:
        fileBuff.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
        WriteFileBytes( hTempFilePreload, fileBuff, entry.Length );
        fileBuff.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );


        // Add the filename entry:
        AddFilename( filename );

        // Spew it:
        printf("+Preload: \"%s\": Length:%u\n", filename, entry.Length );
    }

    // Copy the file to the regular data region:
    xZipDirectoryEntry_t entry;
    memset(&entry,0,sizeof(entry));
    entry.FilenameCRC = CRC;
    entry.Length = fileSize;
    entry.StoredOffset = ftell(hTempFileData);

    // Add the directory entry to the table:
    Header.DirectoryEntries++;
    pDirectoryEntries = (xZipDirectoryEntry_t*)realloc( pDirectoryEntries, sizeof( xZipDirectoryEntry_t ) * Header.DirectoryEntries );
    memcpy( pDirectoryEntries + Header.DirectoryEntries - 1, &entry, sizeof( entry ) );

    WriteFileBytes( hTempFileData, fileBuff, entry.Length );

    // Align the data region to a 512 byte boundry:  (has to be on last entry as well to ensure enough space to perform the final read,
    // and initial alignment is taken careof by assembexzip)
    int nPadding = ( XBOX_HDD_SECTORSIZE - ( ftell( hTempFileData ) % XBOX_HDD_SECTORSIZE) ) % XBOX_HDD_SECTORSIZE;

    PadFileBytes( hTempFileData, nPadding );

    // Add the file to the file string table:
    AddFilename( filename );

    // Print a summary
    printf("+File: \"%s\": Length:%u Padding:%i\n", filename,  entry.Length, nPadding );

    return true;
}