Source/ThunderBeast/QuakeToonProto1/client/cl_parse.c
void CL_ParseDownload (void)
{
	int		size, percent;
	char	name[MAX_OSPATH];
	int		r;

	// read the data
	size = MSG_ReadShort (&net_message);
	percent = MSG_ReadByte (&net_message);
	if (size == -1)
	{
		Com_Printf ("Server does not have this file.\n");
		if (cls.download)
		{
			// if here, we tried to resume a file but the server said no
			fclose (cls.download);
			cls.download = NULL;
		}
		CL_RequestNextDownload ();
		return;
	}

	// open the file if not opened yet
	if (!cls.download)
	{
		CL_DownloadFileName(name, sizeof(name), cls.downloadtempname);

		FS_CreatePath (name);

		cls.download = fopen (name, "wb");
		if (!cls.download)
		{
			net_message.readcount += size;
			Com_Printf ("Failed to open %s\n", cls.downloadtempname);
			CL_RequestNextDownload ();
			return;
		}
	}

	fwrite (net_message.data + net_message.readcount, 1, size, cls.download);
	net_message.readcount += size;

	if (percent != 100)
	{
		// request next block
// change display routines by zoid
#if 0
		Com_Printf (".");
		if (10*(percent/10) != cls.downloadpercent)
		{
			cls.downloadpercent = 10*(percent/10);
			Com_Printf ("%i%%", cls.downloadpercent);
		}
#endif
		cls.downloadpercent = percent;

		MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
		SZ_Print (&cls.netchan.message, "nextdl");
	}
	else
	{
		char	oldn[MAX_OSPATH];
		char	newn[MAX_OSPATH];

//		Com_Printf ("100%%\n");

		fclose (cls.download);

		// rename the temp file to it's final name
		CL_DownloadFileName(oldn, sizeof(oldn), cls.downloadtempname);
		CL_DownloadFileName(newn, sizeof(newn), cls.downloadname);
		r = rename (oldn, newn);
		if (r)
			Com_Printf ("failed to rename.\n");

		cls.download = NULL;
		cls.downloadpercent = 0;

		// get another file if needed

		CL_RequestNextDownload ();
	}
}
/*
=====================
CL_ParseDownload

A download message has been received from the server
=====================
*/
CL_ParseDownload
A download message has been received from the server
CL_ParseDownload A download message has been received from the server
void CL_ParseDownload (void)
{
	int		size, percent;
	char	name[MAX_OSPATH];
	int		r;
	size = MSG_ReadShort (&net_message);
	percent = MSG_ReadByte (&net_message);
	if (size == -1)
	{
		Com_Printf ("Server does not have this file.\n");
		if (cls.download)
		{
			fclose (cls.download);
			cls.download = NULL;
		}
		CL_RequestNextDownload ();
		return;
	}
	if (!cls.download)
	{
		CL_DownloadFileName(name, sizeof(name), cls.downloadtempname);
		FS_CreatePath (name);
		cls.download = fopen (name, "wb");
		if (!cls.download)
		{
			net_message.readcount += size;
			Com_Printf ("Failed to open %s\n", cls.downloadtempname);
			CL_RequestNextDownload ();
			return;
		}
	}
	fwrite (net_message.data + net_message.readcount, 1, size, cls.download);
	net_message.readcount += size;
	if (percent != 100)
	{
#if 0
		Com_Printf (".");
		if (10*(percent/10) != cls.downloadpercent)
		{
			cls.downloadpercent = 10*(percent/10);
			Com_Printf ("%i%%", cls.downloadpercent);
		}
#endif
		cls.downloadpercent = percent;
		MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
		SZ_Print (&cls.netchan.message, "nextdl");
	}
	else
	{
		char	oldn[MAX_OSPATH];
		char	newn[MAX_OSPATH];
		fclose (cls.download);
		CL_DownloadFileName(oldn, sizeof(oldn), cls.downloadtempname);
		CL_DownloadFileName(newn, sizeof(newn), cls.downloadname);
		r = rename (oldn, newn);
		if (r)
			Com_Printf ("failed to rename.\n");
		cls.download = NULL;
		cls.downloadpercent = 0;
		CL_RequestNextDownload ();
	}
}
void CL_ParseDownload ( void ) { int size , percent ; char name [ MAX_OSPATH ] ; int r ; size = MSG_ReadShort ( & net_message ) ; percent = MSG_ReadByte ( & net_message ) ; if ( size == -1 ) { Com_Printf ( " \n " ) ; if ( cls . download ) { fclose ( cls . download ) ; cls . download = NULL ; } CL_RequestNextDownload ( ) ; return ; } if ( ! cls . download ) { CL_DownloadFileName ( name , sizeof ( name ) , cls . downloadtempname ) ; FS_CreatePath ( name ) ; cls . download = fopen ( name , " " ) ; if ( ! cls . download ) { net_message . readcount += size ; Com_Printf ( " \n " , cls . downloadtempname ) ; CL_RequestNextDownload ( ) ; return ; } } fwrite ( net_message . data + net_message . readcount , 1 , size , cls . download ) ; net_message . readcount += size ; if ( percent != 100 ) { #if 0 Com_Printf ( " " ) ; if ( 10 * ( percent / 10 ) != cls . downloadpercent ) { cls . downloadpercent = 10 * ( percent / 10 ) ; Com_Printf ( " " , cls . downloadpercent ) ; } #endif cls . downloadpercent = percent ; MSG_WriteByte ( & cls . netchan . message , clc_stringcmd ) ; SZ_Print ( & cls . netchan . message , " " ) ; } else { char oldn [ MAX_OSPATH ] ; char newn [ MAX_OSPATH ] ; fclose ( cls . download ) ; CL_DownloadFileName ( oldn , sizeof ( oldn ) , cls . downloadtempname ) ; CL_DownloadFileName ( newn , sizeof ( newn ) , cls . downloadname ) ; r = rename ( oldn , newn ) ; if ( r ) Com_Printf ( " \n " ) ; cls . download = NULL ; cls . downloadpercent = 0 ; CL_RequestNextDownload ( ) ; } }
CL_ParseDownload
A download message has been received from the server
CL_ParseDownload A download message has been received from the server
// read the data // if here, we tried to resume a file but the server said no // open the file if not opened yet // request next block // change display routines by zoid //		Com_Printf ("100%%\n"); // rename the temp file to it's final name // get another file if needed