Skip to content

Commit

Permalink
try to load soundfonts from a local user directory first (#1787)
Browse files Browse the repository at this point in the history
Fixes #1781
  • Loading branch information
fabiangreffrath authored Jul 13, 2024
1 parent c447781 commit 2782539
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/i_flmusic.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef fluid_long_long_t fluid_int_t;
#include "i_printf.h"
#include "i_sound.h"
#include "m_array.h"
#include "m_io.h"
#include "m_misc.h"
#include "memio.h"
#include "mus2mid.h"
Expand Down Expand Up @@ -100,9 +101,36 @@ static fluid_long_long_t FL_sftell(void *handle)

static void ScanDir(const char *dir)
{
const char usr_share[] = "/usr/share";
char *rel = NULL;
glob_t *glob;

// [FG] replace global "/usr/share" with user's "~/.local/share"
if (strncmp(dir, usr_share, strlen(usr_share)) == 0)
{
char *home_dir = M_getenv("XDG_DATA_HOME");

if (home_dir == NULL)
{
home_dir = M_getenv("HOME");
}

if (home_dir)
{
char *local_share = M_StringJoin(home_dir, "/.local/share");
char *local_dir = M_StringReplace(dir, usr_share, local_share);

// [FG] do not trigger this code path again
if (strncmp(local_dir, usr_share, strlen(usr_share)) != 0)
{
ScanDir(local_dir);
}

free(local_dir);
free(local_share);
}
}

// [FG] relative to the executable directory
if (dir[0] == '.')
{
Expand Down

0 comments on commit 2782539

Please sign in to comment.