ref: 04ecd397e8a7d7e22e41b282cd0c28d4795a904f
parent: d5b1a695090eb49da3a4277686a30920cd5de046
author: Fabian Greffrath <[email protected]>
date: Thu Mar 18 11:03:29 EDT 2021
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
--- a/src/i_main.c
+++ b/src/i_main.c
@@ -57,6 +57,7 @@
#endif
M_FindResponseFile();
+ M_SetExeDir();
#ifdef SDL_HINT_NO_SIGNAL_HANDLERS
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -933,7 +933,7 @@
{
musicdir = M_StringJoin(music_pack_path, DIR_SEPARATOR_S, NULL);
}
- else if (!strcmp(configdir, ""))
+ else if (!strcmp(configdir, exedir))
{
musicdir = M_StringDuplicate("");
}
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -417,3 +417,13 @@
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);
+}
--- 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);
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2273,9 +2273,6 @@
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 @@
// ~/.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 @@
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 @@
configdir = GetDefaultConfigDir();
}
- if (strcmp(configdir, "") != 0)
+ if (strcmp(configdir, exedir) != 0)
{
printf("Using %s for configuration and saves\n", configdir);
}
@@ -2410,7 +2406,7 @@
#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("");
}