コード例 #1
0
/*
==========
S_OGG_LoadFileList

Load list of Ogg Vorbis files in music/
Based on code by QuDos
==========
*/
void S_OGG_LoadFileList (void)
{
	char	*p, *path = NULL;
	char	**list;			// List of .ogg files
	char	findname[MAX_OSPATH];
	char	lastPath[MAX_OSPATH];	// Knightmare added
	int		i, numfiles = 0;

	ogg_filelist = malloc(sizeof(char *) * MAX_OGGLIST);
	memset( ogg_filelist, 0, sizeof( char * ) * MAX_OGGLIST );
	lastPath[0] = 0;	// Knightmare added

	// Set search path
	path = FS_NextPath(path);
	while (path) 
	{
		// Knightmare- catch repeated paths
		if ( strlen(lastPath) > 0 && !strcmp (path, lastPath) ) {
			path = FS_NextPath( path );
			continue;
		}

		// Get file list
		Com_sprintf( findname, sizeof(findname), "%s/music/*.ogg", path );
		list = FS_ListFiles(findname, &numfiles, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM);

		// Add valid Ogg Vorbis file to the list
		for (i=0; i<numfiles && ogg_numfiles<MAX_OGGLIST; i++)
		{
			if (!list || !list[i])
				continue;
			p = list[i];

			if (!strstr(p, ".ogg"))
				continue;
		//	if (!S_OGG_Check(p))
		//		continue;
			if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist)) // check if already in list
			{
				ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
				sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
				ogg_numfiles++;
			}
		}
		if (numfiles) // Free the file list
			FS_FreeFileList(list, numfiles);

		strncpy (lastPath, path, sizeof(lastPath));	// Knightmare- copy to lastPath
		path = FS_NextPath( path );
	}

#ifndef OGG_DIRECT_FILE
	// check pak after
	if (list = FS_ListPak("music/", &numfiles))
	{
		// Add valid Ogg Vorbis file to the list
		for (i=0; i<numfiles && ogg_numfiles<MAX_OGGLIST; i++)
		{
			if (!list || !list[i])
				continue;
			p = list[i];
			if (!strstr(p, ".ogg"))
				continue;
		//	if (!S_OGG_Check(p))
		//		continue;
			if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist)) // check if already in list
			{
				ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
				sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
				ogg_numfiles++;
			}
		}
	}

	if (numfiles)
		FS_FreeFileList(list, numfiles);
#endif // OGG_DIRECT_FILE
}
コード例 #2
0
ファイル: snd_stream.c プロジェクト: jacqueskrige/uqe-quake2
/*
==========
S_OGG_LoadFileList
Load list of Ogg Vorbis files in /music/
==========
*/
static void S_OGG_LoadFileList (void)
{
	char	*p, *path = NULL;
	char	**list;
	char	findname[MAX_OSPATH];
	char	lastPath[MAX_OSPATH];
	int		i, numfiles = 0;

	extern char **FS_ListFiles( char *, int *, unsigned, unsigned );
	extern qboolean	FS_ItemInList (char *check, int num, char **list);

	if (!sound_started)
		return;

	ogg_filelist = malloc(sizeof(char *) * MAX_OGGLIST);
	memset(ogg_filelist, 0, sizeof( char * ) * MAX_OGGLIST );
	lastPath[0] = 0;

	// set search path
	path = FS_NextPath(path);
	while (path) 
	{
		// catch repeated paths
		if ( strlen(lastPath) > 0 && !strcmp (path, lastPath) )
		{
			path = FS_NextPath( path );
			continue;
		}

		// get file list
		Com_sprintf( findname, sizeof(findname), "%s/music/*.ogg", path );
		list = FS_ListFiles(findname, &numfiles, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM);

		// add valid Ogg Vorbis files to the list
		for (i=0; i<numfiles && ogg_numfiles<MAX_OGGLIST; i++)
		{
			if (!list || !list[i])
				continue;

			p = list[i];

			if (!strstr(p, ".ogg"))
				continue;

			// check if already in list
			if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist))
			{
				ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
				sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
				ogg_numfiles++;
			}
		}

		// Free the file list
		if (numfiles)
			FS_FreeFileList(list, numfiles);

		// copy to lastPath
		strncpy (lastPath, path, sizeof(lastPath));

		path = FS_NextPath( path );
	}

	// check pak after
	if (list = FS_ListPak("music/", &numfiles))
	{
		// add valid Ogg Vorbis file to the list
		for (i=0; i<numfiles && ogg_numfiles<MAX_OGGLIST; i++)
		{
			if (!list || !list[i])
				continue;

			p = list[i];

			if (!strstr(p, ".ogg"))
				continue;

			// check if already in list
			if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist))
			{
				ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
				sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
				ogg_numfiles++;
			}
		}
	}

	if (numfiles)
		FS_FreeFileList(list, numfiles);
}