Source/ThunderBeast/QuakeToon/qcommon/files.c
pack_t *FS_LoadPackFile (char *packfile)
{
	dpackheader_t	header;
	int				i;
	packfile_t		*newfiles;
	int				numpackfiles;
	pack_t			*pack;
	FILE			*packhandle;
	dpackfile_t		info[MAX_FILES_IN_PACK];
	unsigned		checksum;

	packhandle = fopen(packfile, "rb");
	if (!packhandle)
		return NULL;

	fread (&header, 1, sizeof(header), packhandle);
	if (LittleLong(header.ident) != IDPAKHEADER)
		Com_Error (ERR_FATAL, "%s is not a packfile", packfile);
	header.dirofs = LittleLong (header.dirofs);
	header.dirlen = LittleLong (header.dirlen);

	numpackfiles = header.dirlen / sizeof(dpackfile_t);

	if (numpackfiles > MAX_FILES_IN_PACK)
		Com_Error (ERR_FATAL, "%s has %i files", packfile, numpackfiles);

	newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t));

	fseek (packhandle, header.dirofs, SEEK_SET);
	fread (info, 1, header.dirlen, packhandle);

// crc the directory to check for modifications
	checksum = Com_BlockChecksum ((void *)info, header.dirlen);

#ifdef NO_ADDONS
	if (checksum != PAK0_CHECKSUM)
		return NULL;
#endif
// parse the directory
	for (i=0 ; i<numpackfiles ; i++)
	{
		strcpy (newfiles[i].name, info[i].name);
		newfiles[i].filepos = LittleLong(info[i].filepos);
		newfiles[i].filelen = LittleLong(info[i].filelen);
	}

	pack = Z_Malloc (sizeof (pack_t));
	strcpy (pack->filename, packfile);
	pack->handle = packhandle;
	pack->numfiles = numpackfiles;
	pack->files = newfiles;
	
	Com_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
	return pack;
}
/*
=================
FS_LoadPackFile

Takes an explicit (not game tree related) path to a pak file.

Loads the header and directory, adding the files at the beginning
of the list so they override previous pack files.
=================
*/
FS_LoadPackFile
Takes an explicit (not game tree related) path to a pak file.

Loads the header and directory, adding the files at the beginning
of the list so they override previous pack files.
FS_LoadPackFile Takes an explicit ( not game tree related ) path to a pak file . Loads the header and directory adding the files at the beginning of the list so they override previous pack files .
pack_t *FS_LoadPackFile (char *packfile)
{
	dpackheader_t	header;
	int				i;
	packfile_t		*newfiles;
	int				numpackfiles;
	pack_t			*pack;
	FILE			*packhandle;
	dpackfile_t		info[MAX_FILES_IN_PACK];
	unsigned		checksum;
	packhandle = fopen(packfile, "rb");
	if (!packhandle)
		return NULL;
	fread (&header, 1, sizeof(header), packhandle);
	if (LittleLong(header.ident) != IDPAKHEADER)
		Com_Error (ERR_FATAL, "%s is not a packfile", packfile);
	header.dirofs = LittleLong (header.dirofs);
	header.dirlen = LittleLong (header.dirlen);
	numpackfiles = header.dirlen / sizeof(dpackfile_t);
	if (numpackfiles > MAX_FILES_IN_PACK)
		Com_Error (ERR_FATAL, "%s has %i files", packfile, numpackfiles);
	newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t));
	fseek (packhandle, header.dirofs, SEEK_SET);
	fread (info, 1, header.dirlen, packhandle);
	checksum = Com_BlockChecksum ((void *)info, header.dirlen);
#ifdef NO_ADDONS
	if (checksum != PAK0_CHECKSUM)
		return NULL;
#endif
	for (i=0 ; i<numpackfiles ; i++)
	{
		strcpy (newfiles[i].name, info[i].name);
		newfiles[i].filepos = LittleLong(info[i].filepos);
		newfiles[i].filelen = LittleLong(info[i].filelen);
	}
	pack = Z_Malloc (sizeof (pack_t));
	strcpy (pack->filename, packfile);
	pack->handle = packhandle;
	pack->numfiles = numpackfiles;
	pack->files = newfiles;
	Com_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
	return pack;
}
pack_t * FS_LoadPackFile ( char * packfile ) { dpackheader_t header ; int i ; packfile_t * newfiles ; int numpackfiles ; pack_t * pack ; FILE * packhandle ; dpackfile_t info [ MAX_FILES_IN_PACK ] ; unsigned checksum ; packhandle = fopen ( packfile , " " ) ; if ( ! packhandle ) return NULL ; fread ( & header , 1 , sizeof ( header ) , packhandle ) ; if ( LittleLong ( header . ident ) != IDPAKHEADER ) Com_Error ( ERR_FATAL , " " , packfile ) ; header . dirofs = LittleLong ( header . dirofs ) ; header . dirlen = LittleLong ( header . dirlen ) ; numpackfiles = header . dirlen / sizeof ( dpackfile_t ) ; if ( numpackfiles > MAX_FILES_IN_PACK ) Com_Error ( ERR_FATAL , " " , packfile , numpackfiles ) ; newfiles = Z_Malloc ( numpackfiles * sizeof ( packfile_t ) ) ; fseek ( packhandle , header . dirofs , SEEK_SET ) ; fread ( info , 1 , header . dirlen , packhandle ) ; checksum = Com_BlockChecksum ( ( void * ) info , header . dirlen ) ; #ifdef NO_ADDONS if ( checksum != PAK0_CHECKSUM ) return NULL ; #endif for ( i = 0 ; i < numpackfiles ; i ++ ) { strcpy ( newfiles [ i ] . name , info [ i ] . name ) ; newfiles [ i ] . filepos = LittleLong ( info [ i ] . filepos ) ; newfiles [ i ] . filelen = LittleLong ( info [ i ] . filelen ) ; } pack = Z_Malloc ( sizeof ( pack_t ) ) ; strcpy ( pack -> filename , packfile ) ; pack -> handle = packhandle ; pack -> numfiles = numpackfiles ; pack -> files = newfiles ; Com_Printf ( " \n " , packfile , numpackfiles ) ; return pack ; }
FS_LoadPackFile
Takes an explicit (not game tree related) path to a pak file.
FS_LoadPackFile Takes an explicit ( not game tree related ) path to a pak file .
// crc the directory to check for modifications // parse the directory