Skip to content

Commit 5e04f87

Browse files
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.
1 parent 2ac2f64 commit 5e04f87

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

src/d_iwad.c

+35-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,38 @@ char *D_DoomExeDir(void)
8989
return base;
9090
}
9191

92+
// [FG] get the path to the default configuration dir to use
93+
94+
char *D_DoomPrefDir(void)
95+
{
96+
static char *dir;
97+
98+
if (dir == NULL)
99+
{
100+
#if !defined(_WIN32) || defined(_WIN32_WCE)
101+
// Configuration settings are stored in an OS-appropriate path
102+
// determined by SDL. On typical Unix systems, this might be
103+
// ~/.local/share/chocolate-doom. On Windows, we behave like
104+
// Vanilla Doom and save in the current directory.
105+
106+
char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
107+
if (result != NULL)
108+
{
109+
dir = M_DirName(result);
110+
SDL_free(result);
111+
}
112+
else
113+
#endif /* #ifndef _WIN32 */
114+
{
115+
dir = D_DoomExeDir();
116+
}
117+
118+
M_MakeDirectory(dir);
119+
}
120+
121+
return dir;
122+
}
123+
92124
// This is Windows-specific code that automatically finds the location
93125
// of installed IWAD files. The registry is inspected to find special
94126
// keys installed by the Windows installers for various CD versions
@@ -547,7 +579,9 @@ void BuildIWADDirList(void)
547579

548580
// Next check the directory where the executable is located. This might
549581
// be different from the current directory.
550-
array_push(iwad_dirs, D_DoomExeDir());
582+
// D_DoomPrefDir() returns the executable directory on Windows,
583+
// and a user-writable config directory everywhere else.
584+
array_push(iwad_dirs, D_DoomPrefDir());
551585

552586
// Add DOOMWADDIR if it is in the environment
553587
env = M_getenv("DOOMWADDIR");

src/d_iwad.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct
3030
} iwad_t;
3131

3232
char *D_DoomExeDir(void); // killough 2/16/98: path to executable's dir
33+
char *D_DoomPrefDir(void); // [FG] default configuration dir
3334
char *D_FindWADByName(const char *filename);
3435
char *D_TryFindWADByName(const char *filename);
3536
char *D_FindLMPByName(const char *filename);

src/d_main.c

-32
Original file line numberDiff line numberDiff line change
@@ -622,38 +622,6 @@ char *D_DoomExeName(void)
622622
return name;
623623
}
624624

625-
// [FG] get the path to the default configuration dir to use
626-
627-
char *D_DoomPrefDir(void)
628-
{
629-
static char *dir;
630-
631-
if (dir == NULL)
632-
{
633-
#if !defined(_WIN32) || defined(_WIN32_WCE)
634-
// Configuration settings are stored in an OS-appropriate path
635-
// determined by SDL. On typical Unix systems, this might be
636-
// ~/.local/share/chocolate-doom. On Windows, we behave like
637-
// Vanilla Doom and save in the current directory.
638-
639-
char *result = SDL_GetPrefPath("", PROJECT_SHORTNAME);
640-
if (result != NULL)
641-
{
642-
dir = M_DirName(result);
643-
SDL_free(result);
644-
}
645-
else
646-
#endif /* #ifndef _WIN32 */
647-
{
648-
dir = D_DoomExeDir();
649-
}
650-
651-
M_MakeDirectory(dir);
652-
}
653-
654-
return dir;
655-
}
656-
657625
// Calculate the path to the directory for autoloaded WADs/DEHs.
658626
// Creates the directory as necessary.
659627

src/d_main.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ void D_AddFile(const char *file);
3030
char *D_DoomExeName(void); // killough 10/98: executable's name
3131
extern char *basesavegame; // killough 2/16/98: savegame path
3232
extern char *screenshotdir; // [FG] screenshot path
33-
char *D_DoomPrefDir(void); // [FG] default configuration dir
3433
void D_SetSavegameDirectory(void);
3534

3635
extern const char *gamedescription;

src/m_config.c

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "am_map.h"
3131
#include "config.h"
3232
#include "d_main.h"
33+
#include "d_iwad.h"
3334
#include "doomdef.h"
3435
#include "doomstat.h"
3536
#include "doomtype.h"

src/r_data.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <stdlib.h>
2626
#include <string.h>
2727

28-
#include "d_main.h"
28+
#include "d_iwad.h"
2929
#include "d_think.h"
3030
#include "doomdef.h"
3131
#include "doomstat.h"

0 commit comments

Comments
 (0)