From dafff23764ac6051a5e29a6dae55dd89ea27d6ec Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Wed, 12 Jul 2023 15:55:29 +0200 Subject: [PATCH] rewrite D_DoomExeDir() to use SDL_GetBasePath() (#1145) * rewrite D_DoomExeDir() to use SDL_GetBasePath() * move D_DoomExeDir() to src/d_iwad.c --- src/d_iwad.c | 30 +++++++++++++++++++++++++++++- src/d_iwad.h | 1 + src/d_main.c | 13 ------------- src/d_main.h | 1 - 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/d_iwad.c b/src/d_iwad.c index e4090ecb..62faaae0 100644 --- a/src/d_iwad.c +++ b/src/d_iwad.c @@ -18,6 +18,8 @@ #include +#include "SDL_filesystem.h" // [FG] SDL_GetBasePath() + #include "i_system.h" #include "m_io.h" #include "d_iwad.h" @@ -61,6 +63,32 @@ static void AddIWADDir(char *dir) } } +// Return the path where the executable lies -- Lee Killough + +char *D_DoomExeDir(void) +{ + static char *base; + + if (base == NULL) // cache multiple requests + { + char *result; + + result = SDL_GetBasePath(); + if (result != NULL) + { + base = M_StringDuplicate(result); + SDL_free(result); + } + else + { + result = M_DirName(myargv[0]); + base = M_StringDuplicate(result); + } + } + + return base; +} + // This is Windows-specific code that automatically finds the location // of installed IWAD files. The registry is inspected to find special // keys installed by the Windows installers for various CD versions @@ -538,7 +566,7 @@ void BuildIWADDirList(void) // Next check the directory where the executable is located. This might // be different from the current directory. - AddIWADDir(M_DirName(myargv[0])); + AddIWADDir(D_DoomExeDir()); // Add DOOMWADDIR if it is in the environment env = M_getenv("DOOMWADDIR"); diff --git a/src/d_iwad.h b/src/d_iwad.h index 49e4477e..fed24305 100644 --- a/src/d_iwad.h +++ b/src/d_iwad.h @@ -29,6 +29,7 @@ typedef struct const char *description; } iwad_t; +char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir char *D_FindWADByName(const char *filename); char *D_TryFindWADByName(const char *filename); char *D_FindIWADFile(GameMode_t *mode, GameMission_t *mission); diff --git a/src/d_main.c b/src/d_main.c index 733b5ac0..b082a17b 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -658,19 +658,6 @@ void D_AddFile(const char *file) wadfiles[numwadfiles] = NULL; } -// Return the path where the executable lies -- Lee Killough -char *D_DoomExeDir(void) -{ - static char *base; - - if (!base) // cache multiple requests - { - base = M_DirName(myargv[0]); - } - - return base; -} - // killough 10/98: return the name of the program the exe was invoked as char *D_DoomExeName(void) { diff --git a/src/d_main.h b/src/d_main.h index daf52a44..40a4a38a 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -28,7 +28,6 @@ extern char **wadfiles; // killough 11/98 void D_AddFile(const char *file); -char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir char *D_DoomExeName(void); // killough 10/98: executable's name extern char *basesavegame; // killough 2/16/98: savegame path extern char *screenshotdir; // [FG] screenshot path