shithub: choc

Download patch

ref: 78a0de9cb560d3b4066913119e9597c57d558484
parent: a21dacec42e2ec31d80942bae35fa19ae07277f9
author: Simon Howard <fraggle@soulsphere.org>
date: Thu Feb 28 16:21:33 EST 2019

musicpacks: Allow .mp3 files for music replacements.

--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -707,13 +707,15 @@
     return result;
 }
 
-// If filename ends with .{ext}, check if a .ogg or .flac file exists with that
-// name, returning it if found. If neither file exists, NULL exists. If the
+// If filename ends with .{ext}, check if a .ogg, .flac or .mp3 exists with
+// that name, returning it if found. If none exist, NULL is returned. If the
 // filename doesn't end with .{ext} then it just acts as a wrapper around
 // GetFullPath().
 static char *ExpandFileExtension(const char *musicdir, const char *filename)
 {
+    static const char *extns[] = {".flac", ".ogg", ".mp3"};
     char *replaced, *result;
+    int i;
 
     if (!M_StringEndsWith(filename, ".{ext}"))
     {
@@ -720,23 +722,17 @@
         return GetFullPath(musicdir, filename);
     }
 
-    replaced = M_StringReplace(filename, ".{ext}", ".flac");
-    result = GetFullPath(musicdir, replaced);
-    if (M_FileExists(result))
+    for (i = 0; i < arrlen(extns); ++i)
     {
-        return result;
+        replaced = M_StringReplace(filename, ".{ext}", extns[i]);
+        result = GetFullPath(musicdir, replaced);
+        free(replaced);
+        if (M_FileExists(result))
+        {
+            return result;
+        }
+        free(result);
     }
-    free(result);
-    free(replaced);
-
-    replaced = M_StringReplace(filename, ".{ext}", ".ogg");
-    result = GetFullPath(musicdir, replaced);
-    if (M_FileExists(result))
-    {
-        return result;
-    }
-    free(result);
-    free(replaced);
 
     return NULL;
 }