dumbledore Posted May 11, 2007 Share Posted May 11, 2007 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 // 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... Link to comment Share on other sites More sharing options...
Tinny Posted May 14, 2007 Share Posted May 14, 2007 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. Link to comment Share on other sites More sharing options...
dumbledore Posted May 14, 2007 Author Share Posted May 14, 2007 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.