add D_DoomPrefDir() instead of D_DoomExeDir() to iwad_dirs (#2115)

D_DoomPrefDir() returns the executable directory on Windows,
and a user-writable config directory everywhere else.
This commit is contained in:
Fabian Greffrath 2025-01-03 10:50:18 +01:00 committed by GitHub
parent 2ac2f646de
commit 5e04f8742e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 35 deletions

View File

@ -89,6 +89,38 @@ char *D_DoomExeDir(void)
return base; return base;
} }
// [FG] get the path to the default configuration dir to use
char *D_DoomPrefDir(void)
{
static char *dir;
if (dir == NULL)
{
#if !defined(_WIN32) || defined(_WIN32_WCE)
// Configuration settings are stored in an OS-appropriate path
// determined by SDL. On typical Unix systems, this might be
// ~/.local/share/chocolate-doom. On Windows, we behave like
// Vanilla Doom and save in the current directory.
char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
if (result != NULL)
{
dir = M_DirName(result);
SDL_free(result);
}
else
#endif /* #ifndef _WIN32 */
{
dir = D_DoomExeDir();
}
M_MakeDirectory(dir);
}
return dir;
}
// This is Windows-specific code that automatically finds the location // This is Windows-specific code that automatically finds the location
// of installed IWAD files. The registry is inspected to find special // of installed IWAD files. The registry is inspected to find special
// keys installed by the Windows installers for various CD versions // keys installed by the Windows installers for various CD versions
@ -547,7 +579,9 @@ void BuildIWADDirList(void)
// Next check the directory where the executable is located. This might // Next check the directory where the executable is located. This might
// be different from the current directory. // be different from the current directory.
array_push(iwad_dirs, D_DoomExeDir()); // D_DoomPrefDir() returns the executable directory on Windows,
// and a user-writable config directory everywhere else.
array_push(iwad_dirs, D_DoomPrefDir());
// Add DOOMWADDIR if it is in the environment // Add DOOMWADDIR if it is in the environment
env = M_getenv("DOOMWADDIR"); env = M_getenv("DOOMWADDIR");

View File

@ -30,6 +30,7 @@ typedef struct
} iwad_t; } iwad_t;
char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir
char *D_DoomPrefDir(void); // [FG] default configuration dir
char *D_FindWADByName(const char *filename); char *D_FindWADByName(const char *filename);
char *D_TryFindWADByName(const char *filename); char *D_TryFindWADByName(const char *filename);
char *D_FindLMPByName(const char *filename); char *D_FindLMPByName(const char *filename);

View File

@ -622,38 +622,6 @@ char *D_DoomExeName(void)
return name; return name;
} }
// [FG] get the path to the default configuration dir to use
char *D_DoomPrefDir(void)
{
static char *dir;
if (dir == NULL)
{
#if !defined(_WIN32) || defined(_WIN32_WCE)
// Configuration settings are stored in an OS-appropriate path
// determined by SDL. On typical Unix systems, this might be
// ~/.local/share/chocolate-doom. On Windows, we behave like
// Vanilla Doom and save in the current directory.
char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
if (result != NULL)
{
dir = M_DirName(result);
SDL_free(result);
}
else
#endif /* #ifndef _WIN32 */
{
dir = D_DoomExeDir();
}
M_MakeDirectory(dir);
}
return dir;
}
// Calculate the path to the directory for autoloaded WADs/DEHs. // Calculate the path to the directory for autoloaded WADs/DEHs.
// Creates the directory as necessary. // Creates the directory as necessary.

View File

@ -30,7 +30,6 @@ void D_AddFile(const char *file);
char *D_DoomExeName(void); // killough 10/98: executable's name char *D_DoomExeName(void); // killough 10/98: executable's name
extern char *basesavegame; // killough 2/16/98: savegame path extern char *basesavegame; // killough 2/16/98: savegame path
extern char *screenshotdir; // [FG] screenshot path extern char *screenshotdir; // [FG] screenshot path
char *D_DoomPrefDir(void); // [FG] default configuration dir
void D_SetSavegameDirectory(void); void D_SetSavegameDirectory(void);
extern const char *gamedescription; extern const char *gamedescription;

View File

@ -30,6 +30,7 @@
#include "am_map.h" #include "am_map.h"
#include "config.h" #include "config.h"
#include "d_main.h" #include "d_main.h"
#include "d_iwad.h"
#include "doomdef.h" #include "doomdef.h"
#include "doomstat.h" #include "doomstat.h"
#include "doomtype.h" #include "doomtype.h"

View File

@ -25,7 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "d_main.h" #include "d_iwad.h"
#include "d_think.h" #include "d_think.h"
#include "doomdef.h" #include "doomdef.h"
#include "doomstat.h" #include "doomstat.h"