ref: 2afa4144dbb898e3e746a5aeb0af562958fbc27a
parent: 056bd10f6e6206fcb875e8601572e54ed216d4f1
author: Simon Howard <[email protected]>
date: Tue Oct 7 17:48:08 EDT 2014
Allow multiple substitute mappings for music tracks. For the Hexen substitute mapping configuration file, it's desirable to be able to include two mappings for each music lump: a straight high quality recording of that lump, and the recording that was included on the Hexen CD audio tracks. So allow multiple mappings so that we can fall back to try other filenames if the first choice file doesn't appear to exist.
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -414,6 +414,7 @@
{
sha1_context_t context;
sha1_digest_t hash;
+ char *filename;
int i;
// Don't bother doing a hash if we're never going to find anything.
@@ -427,16 +428,30 @@
SHA1_Final(hash, &context);
// Look for a hash that matches.
+ // The substitute mapping list can (intentionally) contain multiple
+ // filename mappings for the same hash. This allows us to try
+ // different files and fall back if our first choice isn't found.
+ filename = NULL;
+
for (i = 0; i < subst_music_len; ++i)
{
if (memcmp(hash, subst_music[i].hash, sizeof(hash)) == 0)
{
- return subst_music[i].filename;
+ filename = subst_music[i].filename;
+
+ // If the file exists, then use this file in preference to
+ // any fallbacks. But we always return a filename if it's
+ // in the list, even if it's just so we can print an error
+ // message to the user saying it doesn't exist.
+ if (M_FileExists(filename))
+ {
+ break;
+ }
}
}
- return NULL;
+ return filename;
}
// Add a substitute music file to the lookup list.