lfnetwork.com mark read register faq members calendar

Thread: ui demo display code mod
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 05-11-2007, 12:06 AM   #1
dumbledore
Rookie
 
Join Date: Nov 2005
Posts: 85
ui demo display code mod

this isn't really a bug fix, but i thought it would be nice to post here.
i modified the ui so that demo display will show demos in subfolders as well as the root demos folders. this can help a lot for people who have a lot of demos and need to organize them better.

this replaces ui_loaddemos in ui_main.c

Code:
// share a temp buffer to reduce memory load
char sharedBuffer[4096*20];

static int UI_RecurseGetDemos( char *folder, char *demolist, int demolistSize, char *demoExt )
{
	char realFolders[1024], *folders = realFolders, *shBuf = sharedBuffer;
	char fold2copy[1024] = "";
	int numFolders, num;
	int ret = trap_FS_GetFileList( folder, demoExt, sharedBuffer, sizeof( sharedBuffer ) );
	// copy demos from shared buffer to demo list, adding appropriate folder name
	if( strchr( folder, '/' ) )
		Q_strncpyz( fold2copy, va( "%s/" , strchr( folder, '/' ) + 1 ), sizeof( fold2copy ) );
	for( num = 0; num < ret && demolistSize > 0; num++ )
	{
		Q_strncpyz( demolist, va( "%s%s", fold2copy, shBuf ), demolistSize );
		demolistSize -= strlen( demolist ) + 1;
		demolist += strlen( demolist ) + 1;
		shBuf += strlen( shBuf ) + 1;
	}
	
	// now go through folders
	numFolders = trap_FS_GetFileList( folder, "/", folders, sizeof( realFolders ) );
	for( num = 0; num < numFolders; num++, folders++ )
	{
		int temp;
		char fold[MAX_QPATH];
		if( *folders && Q_stricmp( folders, "." ) && Q_stricmp( folders, ".." ) )
		{
			int num2;
			Q_strncpyz( fold, va( "%s/%s", folder, folders ), sizeof( fold ) );
			temp = UI_RecurseGetDemos( fold, demolist, demolistSize, demoExt );
			ret += temp;
			for( num2 = 0; num2 < temp; demolist++ )
			{
				if( *demolist == 0 ) num2++;
				demolistSize--;
			}
		}
		for( ; *folders != 0; folders++ );
	}
	
	return ret;
}

/*
===============
UI_LoadDemos
===============
*/
static void UI_LoadDemos() {
	char	demolist[4096*20];
	char demoExt[32];
	char	*demoname;
	int		i, len;

	Com_sprintf(demoExt, sizeof(demoExt), "dm_%d", (int)trap_Cvar_VariableValue("protocol"));

	uiInfo.demoCount = UI_RecurseGetDemos( "demos", demolist, sizeof( demolist ), demoExt );

	Com_sprintf(demoExt, sizeof(demoExt), ".dm_%d", (int)trap_Cvar_VariableValue("protocol"));

	if (uiInfo.demoCount) {
		if (uiInfo.demoCount > MAX_DEMOS) {
			uiInfo.demoCount = MAX_DEMOS;
		}
		demoname = demolist;
		for ( i = uiInfo.demoCount - 1; i >= 0 ; i-- ) {
			len = strlen( demoname );
			if (!Q_stricmp(demoname +  len - strlen(demoExt), demoExt)) {
				demoname[len-strlen(demoExt)] = '\0';
			}
			//Q_strupr(demoname);
			uiInfo.demoList[i] = String_Alloc(demoname);
			demoname += len + 1;
		}
	}
}
[edit] this may need better buffer checking on demolist if someone had an enormous amount of demos...
dumbledore is offline   you may: quote & reply,
Old 05-14-2007, 12:56 AM   #2
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
Hey looks nice, I don't see though a check to keep it from recursing too far just in case it might go too far and crash.


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 05-14-2007, 07:55 PM   #3
dumbledore
Rookie
 
Join Date: Nov 2005
Posts: 85
um, it basically can't go too far, at least not on windows... the only time i can think of that being a problem is on linux with circular symlinks (not a problem on jka/windows). it's very unlikely that someone will have more nested folders than the code's call stack size, lol.
dumbledore is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > ui demo display code mod

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:20 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.