commit 04ecd397e8a7d7e22e41b282cd0c28d4795a904f
Author: Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Thu Mar 18 15:03:29 2021 +0100
Commit: GitHub <noreply@github.com>
CommitDate: Thu Mar 18 15:03:29 2021 +0100
fix savegame directory on Windows (#1360)
* fix savegame directory on Windows
On Windows, we are supposed to put savegames into the current
directory instead of a "savegames" subdirectory unless the
-savedir parameter was given.
Hopefully fixes #1359 for good.
* turn exedir into a global static variable
* move M_SetExeDir() to m_argv.c and call it from main()
* initialize exedir
* remove redundant check, un-const char *exedir
---
src/i_main.c | 1 +
src/i_musicpack.c | 2 +-
src/m_argv.c | 10 ++++++++++
src/m_argv.h | 3 +++
src/m_config.c | 16 ++++++----------
5 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/i_main.c b/src/i_main.c
index b6699a48..176538df 100644
--- a/src/i_main.c
+++ b/src/i_main.c
@@ -57,6 +57,7 @@ int main(int argc, char **argv)
#endif
M_FindResponseFile();
+ M_SetExeDir();
#ifdef SDL_HINT_NO_SIGNAL_HANDLERS
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
diff --git a/src/i_musicpack.c b/src/i_musicpack.c
index 1c3ed6f5..dada1b39 100644
--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -933,7 +933,7 @@ static void LoadSubstituteConfigs(void)
{
musicdir = M_StringJoin(music_pack_path, DIR_SEPARATOR_S, NULL);
}
- else if (!strcmp(configdir, ""))
+ else if (!strcmp(configdir, exedir))
{
musicdir = M_StringDuplicate("");
}
diff --git a/src/m_argv.c b/src/m_argv.c
index 992d5cfb..921008aa 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -417,3 +417,13 @@ const char *M_GetExecutableName(void)
return M_BaseName(myargv[0]);
}
+char *exedir = NULL;
+
+void M_SetExeDir(void)
+{
+ char *dirname;
+
+ dirname = M_DirName(myargv[0]);
+ exedir = M_StringJoin(dirname, DIR_SEPARATOR_S, NULL);
+ free(dirname);
+}
diff --git a/src/m_argv.h b/src/m_argv.h
index 482f29a2..b42f11cd 100644
--- a/src/m_argv.h
+++ b/src/m_argv.h
@@ -28,6 +28,9 @@
extern int myargc;
extern char** myargv;
+extern char *exedir;
+void M_SetExeDir(void);
+
// Returns the position of the given parameter
// in the arg list (0 if not found).
int M_CheckParm (const char* check);
diff --git a/src/m_config.c b/src/m_config.c
index c8971595..d98cdecc 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2273,9 +2273,6 @@ float M_GetFloatVariable(const char *name)
static char *GetDefaultConfigDir(void)
{
- char *result;
- char *copy;
-
#if !defined(_WIN32) || defined(_WIN32_WCE)
// Configuration settings are stored in an OS-appropriate path
@@ -2283,6 +2280,9 @@ static char *GetDefaultConfigDir(void)
// ~/.local/share/chocolate-doom. On Windows, we behave like
// Vanilla Doom and save in the current directory.
+ char *result;
+ char *copy;
+
result = SDL_GetPrefPath("", PACKAGE_TARNAME);
if (result != NULL)
{
@@ -2291,11 +2291,7 @@ static char *GetDefaultConfigDir(void)
return copy;
}
#endif /* #ifndef _WIN32 */
-
- result = M_DirName(myargv[0]);
- copy = M_StringJoin(result, DIR_SEPARATOR_S, NULL);
- free(result);
- return copy;
+ return M_StringDuplicate(exedir);
}
//
@@ -2318,7 +2314,7 @@ void M_SetConfigDir(const char *dir)
configdir = GetDefaultConfigDir();
}
- if (strcmp(configdir, "") != 0)
+ if (strcmp(configdir, exedir) != 0)
{
printf("Using %s for configuration and saves\n", configdir);
}
@@ -2410,7 +2406,7 @@ char *M_GetSaveGameDir(const char *iwadname)
#endif
// If not "doing" a configuration directory (Windows), don't "do"
// a savegame directory, either.
- else if (!strcmp(configdir, ""))
+ else if (!strcmp(configdir, exedir))
{
savegamedir = M_StringDuplicate("");
}