From 60030a8d4f5100fbc29c137c734830ee33e346d2 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Sun, 17 Sep 2023 22:20:33 +0200 Subject: [PATCH] Fluidsynth: support relative paths in soundfont_dir to enable the AppImage to find its own bundled soundfont file --- src/i_flmusic.c | 21 +++++++++++++++++++-- src/m_misc.c | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/i_flmusic.c b/src/i_flmusic.c index 2f04cb4e..e1949456 100644 --- a/src/i_flmusic.c +++ b/src/i_flmusic.c @@ -36,6 +36,7 @@ #include "w_wad.h" #include "z_zone.h" #include "i_glob.h" +#include "d_iwad.h" // [FG] D_DoomExeDir() char *soundfont_path = ""; char *soundfont_dir = ""; @@ -124,8 +125,19 @@ static void AddSoundFont(const char *path) static void ScanDir(const char *dir) { - glob_t *glob = I_StartMultiGlob(dir, GLOB_FLAG_NOCASE|GLOB_FLAG_SORTED, - "*.sf2", "*.sf3", NULL); + char *rel = NULL; + glob_t *glob; + + // [FG] relative to the executable directory + if (dir[0] == '.') + { + rel = M_StringJoin(D_DoomExeDir(), DIR_SEPARATOR_S, dir, NULL); + dir = rel; + } + + glob = I_StartMultiGlob(dir, GLOB_FLAG_NOCASE|GLOB_FLAG_SORTED, + "*.sf2", "*.sf3", NULL); + while(1) { const char *filename = I_NextGlob(glob); @@ -139,6 +151,11 @@ static void ScanDir(const char *dir) } I_EndGlob(glob); + + if (rel) + { + free(rel); + } } static void GetSoundFonts(void) diff --git a/src/m_misc.c b/src/m_misc.c index 44b12743..e9ed6e75 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -484,7 +484,9 @@ default_t defaults[] = { {.s = "/usr/share/soundfonts:" /* Debian/Ubuntu/OpenSUSE */ "/usr/share/sounds/sf2:" - "/usr/share/sounds/sf3"}, + "/usr/share/sounds/sf3:" + /* AppImage */ + "../share/" PROJECT_SHORTNAME "/soundfonts"}, #endif {0}, string, ss_none, wad_no, "FluidSynth soundfont directories"