rewrite D_DoomExeDir() to use SDL_GetBasePath() (#1145)

* rewrite D_DoomExeDir() to use SDL_GetBasePath()

* move D_DoomExeDir() to src/d_iwad.c
This commit is contained in:
Fabian Greffrath 2023-07-12 15:55:29 +02:00 committed by GitHub
parent e0601f00fd
commit dafff23764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 15 deletions

View File

@ -18,6 +18,8 @@
#include <stdlib.h>
#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");

View File

@ -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);

View File

@ -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)
{

View File

@ -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