From 9ed22a2e63369ca915cf9f4926dab9e11d729018 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Thu, 2 Jan 2025 12:10:55 +0100 Subject: [PATCH] add D_DoomPrefDir() instead of D_DoomExeDir() to iwad_dirs D_DoomPrefDir() returns the executable directory on Windows, and a user-writable config directory everywhere else. --- src/d_iwad.c | 36 +++++++++++++++++++++++++++++++++++- src/d_iwad.h | 1 + src/d_main.c | 32 -------------------------------- src/d_main.h | 1 - src/m_config.c | 1 + src/r_data.c | 2 +- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/d_iwad.c b/src/d_iwad.c index 92e2730d2..d570cafee 100644 --- a/src/d_iwad.c +++ b/src/d_iwad.c @@ -89,6 +89,38 @@ char *D_DoomExeDir(void) 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 // of installed IWAD files. The registry is inspected to find special // 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 // 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 env = M_getenv("DOOMWADDIR"); diff --git a/src/d_iwad.h b/src/d_iwad.h index c527df866..28ecef55b 100644 --- a/src/d_iwad.h +++ b/src/d_iwad.h @@ -30,6 +30,7 @@ typedef struct } iwad_t; 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_TryFindWADByName(const char *filename); char *D_FindLMPByName(const char *filename); diff --git a/src/d_main.c b/src/d_main.c index 298561c23..d63d096d9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -622,38 +622,6 @@ char *D_DoomExeName(void) 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. // Creates the directory as necessary. diff --git a/src/d_main.h b/src/d_main.h index c5ee4913c..7b65db2f3 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -30,7 +30,6 @@ void D_AddFile(const char *file); 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 -char *D_DoomPrefDir(void); // [FG] default configuration dir void D_SetSavegameDirectory(void); extern const char *gamedescription; diff --git a/src/m_config.c b/src/m_config.c index 7764059ad..41af21746 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -30,6 +30,7 @@ #include "am_map.h" #include "config.h" #include "d_main.h" +#include "d_iwad.h" #include "doomdef.h" #include "doomstat.h" #include "doomtype.h" diff --git a/src/r_data.c b/src/r_data.c index 432baa573..183c91051 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -25,7 +25,7 @@ #include #include -#include "d_main.h" +#include "d_iwad.h" #include "d_think.h" #include "doomdef.h" #include "doomstat.h"