rev1112 contd: Killed juggling around with adding Jukebox paths - must always be removed correctly if Jukebox loading fails

This commit is contained in:
zicodxx 2010-06-14 15:32:55 +00:00
parent 8cb8b6e653
commit 63966cab5c
2 changed files with 10 additions and 7 deletions

View file

@ -7,6 +7,7 @@ arch/include/window.h: Added missing newline at EOF
arch/sdl/jukebox.c: Small fix and improvement for Jukebox path detection arch/sdl/jukebox.c: Small fix and improvement for Jukebox path detection
arch/sdl/digi_mixer_music.c, main/songs.c: Use strrchr instead of strchr for music filename extension in case there are dots in the filename arch/sdl/digi_mixer_music.c, main/songs.c: Use strrchr instead of strchr for music filename extension in case there are dots in the filename
main/collide.c: Made reactor damage with persistent weapons FPS-independent but still a bit stronger than normal main/collide.c: Made reactor damage with persistent weapons FPS-independent but still a bit stronger than normal
arch/sdl/jukebox.c: rev1112 contd: Killed juggling around with adding Jukebox paths - must always be removed correctly if Jukebox loading fails
20100503 20100503
-------- --------

View file

@ -40,7 +40,8 @@ void jukebox_unload()
} }
/* Loads music file names from a given directory */ /* Loads music file names from a given directory */
void jukebox_load() { void jukebox_load()
{
int count; int count;
char *music_exts[] = { ".mp3", ".ogg", ".wav", ".aif", ".mid", NULL }; char *music_exts[] = { ".mp3", ".ogg", ".wav", ".aif", ".mid", NULL };
static char curpath[PATH_MAX+1]; static char curpath[PATH_MAX+1];
@ -58,7 +59,6 @@ void jukebox_load() {
{ {
char *p; char *p;
const char *sep = PHYSFS_getDirSeparator(); const char *sep = PHYSFS_getDirSeparator();
char absolute_path[PATH_MAX];
// make sure there's a proper path separator. // make sure there's a proper path separator.
if (strlen(GameCfg.CMLevelMusicPath) >= strlen(sep)) if (strlen(GameCfg.CMLevelMusicPath) >= strlen(sep))
@ -78,21 +78,22 @@ void jukebox_load() {
for (count = 0; JukeboxSongs[count]!=NULL; count++) {} for (count = 0; JukeboxSongs[count]!=NULL; count++) {}
if (!count) if (!count)
{ {
char absolute_path[PATH_MAX + 1];
PHYSFS_removeFromSearchPath(GameCfg.CMLevelMusicPath);
PHYSFSX_getRealPath(GameCfg.CMLevelMusicPath,absolute_path); PHYSFSX_getRealPath(GameCfg.CMLevelMusicPath,absolute_path);
PHYSFS_addToSearchPath(absolute_path, 0); memcpy(GameCfg.CMLevelMusicPath,absolute_path,sizeof(char)*PATH_MAX);
JukeboxSongs = PHYSFSX_findabsoluteFiles("", absolute_path, music_exts); PHYSFS_addToSearchPath(GameCfg.CMLevelMusicPath, 0);
JukeboxSongs = PHYSFSX_findabsoluteFiles("", GameCfg.CMLevelMusicPath, music_exts);
} }
} }
count = 0;
if (JukeboxSongs != NULL) if (JukeboxSongs != NULL)
{ {
for (count = 0; JukeboxSongs[count]!=NULL; count++) {} for (count = 0; JukeboxSongs[count]!=NULL; count++) {}
if (count) if (count)
{ {
con_printf(CON_DEBUG,"Jukebox: %d music file(s) found in %s\n", count, GameCfg.CMLevelMusicPath); con_printf(CON_DEBUG,"Jukebox: %d music file(s) found in %s\n", count, GameCfg.CMLevelMusicPath);
memcpy(curpath,GameCfg.CMLevelMusicPath,PATH_MAX); memcpy(curpath,GameCfg.CMLevelMusicPath,sizeof(char)*PATH_MAX);
if (GameCfg.CMLevelMusicTrack[1] != count) if (GameCfg.CMLevelMusicTrack[1] != count)
{ {
GameCfg.CMLevelMusicTrack[1] = count; GameCfg.CMLevelMusicTrack[1] = count;
@ -103,6 +104,7 @@ void jukebox_load() {
{ {
GameCfg.CMLevelMusicTrack[0] = -1; GameCfg.CMLevelMusicTrack[0] = -1;
GameCfg.CMLevelMusicTrack[1] = -1; GameCfg.CMLevelMusicTrack[1] = -1;
PHYSFS_removeFromSearchPath(GameCfg.CMLevelMusicPath);
con_printf(CON_DEBUG,"Jukebox music could not be found!\n"); con_printf(CON_DEBUG,"Jukebox music could not be found!\n");
} }
} }