Esempio n. 1
0
snd_stream_t *S_CodecOpenStreamExt (const char *filename)
{
	snd_codec_t *codec;
	snd_stream_t *stream;
	const char *ext;

	ext = COM_FileGetExtension(filename);
	if (! *ext)
	{
		Con_Printf("No extension for %s\n", filename);
		return NULL;
	}

	codec = codecs;
	while (codec)
	{
		if (!Q_strcasecmp(ext, codec->ext))
			break;
		codec = codec->next;
	}
	if (!codec)
	{
		Con_Printf("Unknown extension for %s\n", filename);
		return NULL;
	}
	stream = codec->codec_open(filename);
	if (stream)
		stream->status = STREAM_PLAY;
	return stream;
}
Esempio n. 2
0
void BGM_Play (const char *filename)
{
	char tmp[MAX_QPATH];
	const char *ext;
	music_handler_t *handler;

	BGM_Stop();

	if (music_handlers == NULL)
		return;

	if (!filename || !*filename)
	{
		Con_DPrintf("null music file name\n");
		return;
	}

	ext = COM_FileGetExtension(filename);
	if (! *ext)	/* try all things */
	{
		BGM_Play_noext(filename, ANY_CODECTYPE);
		return;
	}

	handler = music_handlers;
	while (handler)
	{
		if (handler->is_available &&
		    !q_strcasecmp(ext, handler->ext))
			break;
		handler = handler->next;
	}
	if (!handler)
	{
		Con_Printf("Unhandled extension for %s\n", filename);
		return;
	}
	q_snprintf(tmp, sizeof(tmp), "%s/%s", handler->dir, filename);
	switch (handler->player)
	{
	case BGM_MIDIDRV:
	/* not supported in quake */
		break;
	case BGM_STREAMER:
		bgmstream = S_CodecOpenStreamType(tmp, handler->type);
		if (bgmstream)
			return;		/* success */
		break;
	case BGM_NONE:
	default:
		break;
	}

	Con_Printf("Couldn't handle music file %s\n", filename);
}
Esempio n. 3
0
snd_stream_t *S_CodecOpenStreamAny (const char *filename)
{
	snd_codec_t *codec;
	snd_stream_t *stream;
	const char *ext;

	ext = COM_FileGetExtension(filename);
	if (! *ext)	/* try all available */
	{
		char tmp[MAX_QPATH];

		codec = codecs;
		while (codec)
		{
			q_snprintf(tmp, sizeof(tmp), "%s.%s", filename, codec->ext);
			stream = codec->codec_open(tmp);
			if (stream)
			{
				stream->status = STREAM_PLAY;
				return stream;
			}
			codec = codec->next;
		}

		return NULL;
	}
	else	/* use the name as is */
	{
		codec = codecs;
		while (codec)
		{
			if (!Q_strcasecmp(ext, codec->ext))
				break;
			codec = codec->next;
		}
		if (!codec)
		{
			Con_Printf("Unknown extension for %s\n", filename);
			return NULL;
		}
		stream = codec->codec_open(filename);
		if (stream)
			stream->status = STREAM_PLAY;
		return stream;
	}
}
Esempio n. 4
0
void Modlist_Init (void)
{
	DIR		*dir_p, *mod_dir_p;
	struct dirent	*dir_t, *mod_dir_t;
	char		dir_string[MAX_OSPATH], mod_string[MAX_OSPATH];

	q_snprintf (dir_string, sizeof(dir_string), "%s/", com_basedir);
	dir_p = opendir(dir_string);
	if (dir_p == NULL)
		return;

	while ((dir_t = readdir(dir_p)) != NULL)
	{
		if (!strcmp(dir_t->d_name, ".") || !strcmp(dir_t->d_name, ".."))
			continue;
		q_snprintf(mod_string, sizeof(mod_string), "%s%s/", dir_string, dir_t->d_name);
		mod_dir_p = opendir(mod_string);
		if (mod_dir_p == NULL)
			continue;
		// find progs.dat and pak file(s)
		while ((mod_dir_t = readdir(mod_dir_p)) != NULL)
		{
			if (!q_strcasecmp(mod_dir_t->d_name, "progs.dat")) {
				Modlist_Add(dir_t->d_name);
				break;
			}
			if (!q_strcasecmp(COM_FileGetExtension(mod_dir_t->d_name), "pak")) {
				Modlist_Add(dir_t->d_name);
				break;
			}
		}
		closedir(mod_dir_p);
	}

	closedir(dir_p);
}
Esempio n. 5
0
// TODO: Factor out to a general-purpose file searching function
void DemoList_Init (void)
{
#ifdef _WIN32
	WIN32_FIND_DATA	fdat;
	HANDLE		fhnd;
#else
	DIR		*dir_p;
	struct dirent	*dir_t;
#endif
	char		filestring[MAX_OSPATH];
	char		demname[32];
	char		ignorepakdir[32];
	searchpath_t	*search;
	pack_t		*pak;
	int		i;
	
	// we don't want to list the demos in id1 pakfiles,
	// because these are not "add-on" demos
	q_snprintf (ignorepakdir, sizeof(ignorepakdir), "/%s/", GAMENAME);
	
	for (search = com_searchpaths; search; search = search->next)
	{
		if (*search->filename) //directory
		{
#ifdef _WIN32
			q_snprintf (filestring, sizeof(filestring), "%s/*.dem", search->filename);
			fhnd = FindFirstFile(filestring, &fdat);
			if (fhnd == INVALID_HANDLE_VALUE)
				continue;
			do
			{
				COM_StripExtension(fdat.cFileName, demname, sizeof(demname));
				FileList_Add (demname, &demolist);
			} while (FindNextFile(fhnd, &fdat));
			FindClose(fhnd);
#else
			q_snprintf (filestring, sizeof(filestring), "%s/", search->filename);
			dir_p = opendir(filestring);
			if (dir_p == NULL)
				continue;
			while ((dir_t = readdir(dir_p)) != NULL)
			{
				if (q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "dem") != 0)
					continue;
				COM_StripExtension(dir_t->d_name, demname, sizeof(demname));
				FileList_Add (demname, &demolist);
			}
			closedir(dir_p);
#endif
		}
		else //pakfile
		{
			if (!strstr(search->pack->filename, ignorepakdir))
			{ //don't list standard id demos
				for (i = 0, pak = search->pack; i < pak->numfiles; i++)
				{
					if (!strcmp(COM_FileGetExtension(pak->files[i].name), "dem"))
					{
						COM_StripExtension(pak->files[i].name, demname, sizeof(demname));
						FileList_Add (demname, &demolist);
					}
				}
			}
		}
	}
}
Esempio n. 6
0
void BGM_PlayMIDIorMusic (const char *filename)
{
/* instead of searching by the order of music_handlers, do so by
 * the order of searchpath priority: the file from the searchpath
 * with the highest path_id is most likely from our own gamedir
 * itself.  this way, if a mod has egyp1 as a mp3 or a midi, which
 * is below *.ogg in the music_handler order, the mp3 or midi will
 * still have priority over egyp1.ogg from, say, data1.
 */
	char tmp[MAX_QPATH];
	const char *ext, *dir;
	unsigned int path_id, prev_id, type;
	qboolean try_midi_stream;
	music_handler_t *handler;

	if (music_handlers == NULL)
		return;

	BGM_Stop();

	if (!filename || !*filename)
	{
		Con_DPrintf("null music file name\n");
		return;
	}

	ext = COM_FileGetExtension(filename);
	if (*ext != '\0')
	{
		BGM_Play(filename);
		return;
	}

	prev_id = 0;
	type = 0;
	dir = ext = NULL;
	handler = music_handlers;
	try_midi_stream = false;
	while (handler)
	{
		if (! handler->is_available)
			goto _next;
		if (! MIDITYPE(handler->type) &&
		     (no_extmusic || !bgm_extmusic.value))
			goto _next;
		q_snprintf(tmp, sizeof(tmp), "%s/%s.%s",
			   handler->dir, filename, handler->ext);
		if (! FS_FileExists(tmp, &path_id))
		{
			if (handler->type == MIDIDRIVER_MID)
				break;
			goto _next;
		}
		if (path_id > prev_id)
		{
			prev_id = path_id;
			type = handler->type;
			ext = handler->ext;
			dir = handler->dir;
			if (handler->type == MIDIDRIVER_MID)
			{
				if (handler->next &&
				    handler->next->is_available)
					try_midi_stream = true;
				break;
			}
		}
	_next:
		handler = handler->next;
	}
	if (ext == NULL)
		Con_Printf("Couldn't handle music file %s\n", filename);
	else
	{
		q_snprintf(tmp, sizeof(tmp), "%s/%s.%s", dir, filename, ext);
		switch (type)
		{
		case MIDIDRIVER_MID:
			if (BGM_Play_mididrv(tmp) == 0)
				return;		/* success */
			/* BGM_MIDIDRV is followed by CODECTYPE_MID streamer.
			 * Even if the midi driver failed, we may still have
			 * a chance with the streamer if it's available... */
			if (!try_midi_stream)
				break;
			type = CODECTYPE_MID;
		default:
			bgmstream = S_CodecOpenStreamType(tmp, type);
			if (bgmstream)
				return;		/* success */
		}
		Con_Printf("Couldn't handle music file %s\n", tmp);
	}
}
Esempio n. 7
0
void BGM_Play (const char *filename)
{
	char tmp[MAX_QPATH];
	const char *ext;
	music_handler_t *handler;

	BGM_Stop();

	if (music_handlers == NULL)
		return;

	if (!filename || !*filename)
	{
		Con_DPrintf("null music file name\n");
		return;
	}

	ext = COM_FileGetExtension(filename);
	if (! *ext)	/* try all things */
	{
		BGM_Play_noext(filename, ANY_CODECTYPE);
		return;
	}

	/* use the filename as is */
	handler = music_handlers;
	while (handler)
	{
		if (handler->is_available &&
		    !q_strcasecmp(ext, handler->ext))
			break;
		handler = handler->next;
	}
	if (!handler)
	{
		Con_Printf("Unhandled extension for %s\n", filename);
		return;
	}
	q_snprintf(tmp, sizeof(tmp), "%s/%s", handler->dir, filename);
	switch (handler->player)
	{
	case BGM_MIDIDRV:
		if (BGM_Play_mididrv(tmp) == 0)
			return;		/* success */
		/* BGM_MIDIDRV is followed by CODECTYPE_MID streamer.
		 * Even if the midi driver failed, we may still have
		 * a chance with the streamer if it's available... */
		if (! (handler->next && handler->next->is_available))
			break;
		handler = handler->next;
	case BGM_STREAMER:
		bgmstream = S_CodecOpenStreamType(tmp, handler->type);
		if (bgmstream)
			return;		/* success */
		break;
	case BGM_NONE:
	default:
		break;
	}

	Con_Printf("Couldn't handle music file %s\n", filename);
}