From 7f46eb72bc824d528a63d7729128e8ce7963f9ef Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Fri, 27 May 2022 20:07:37 -0500 Subject: [PATCH 1/2] Fail loudly when config isn't writable --- src/d_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 2c02565d..8a63f61f 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -999,6 +999,7 @@ void D_SRB2Main(void) lumpinfo_t *lumpinfo; UINT16 wadnum; char *name; + FILE *tmpfile; INT32 pstartmap = 1; boolean autostart = false; @@ -1126,6 +1127,19 @@ void D_SRB2Main(void) configfile[sizeof configfile - 1] = '\0'; + // If config isn't writable, tons of behavior will be broken. + // Fail loudly before things get confusing! + tmpfile = fopen(configfile, "w"); + if (!tmpfile) + { +#if defined (_WIN32) + I_Error("Couldn't write game config.\nMake sure the game is installed somewhere it has write permissions.\n\n(Don't use the Downloads folder, Program Files, or your desktop!\nIf unsure, we recommend making a subfolder in your Documents folder.)"); +#else + I_Error("Couldn't write game config.\nMake sure you've installed the game somewhere it has write permissions."); +#endif + } + fclose(tmpfile); + #ifdef _arch_dreamcast strcpy(downloaddir, "/ram"); // the dreamcast's TMP #endif From 73aed4643ba1fa4e6b3effdd669b4b1ee4e2c382 Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Sat, 28 May 2022 14:57:16 -0500 Subject: [PATCH 2/2] Use a temporary file instead of checking against config (from JugadorXEI) --- src/d_main.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 8a63f61f..2fc0a4c5 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -999,7 +999,6 @@ void D_SRB2Main(void) lumpinfo_t *lumpinfo; UINT16 wadnum; char *name; - FILE *tmpfile; INT32 pstartmap = 1; boolean autostart = false; @@ -1129,8 +1128,14 @@ void D_SRB2Main(void) // If config isn't writable, tons of behavior will be broken. // Fail loudly before things get confusing! - tmpfile = fopen(configfile, "w"); - if (!tmpfile) + FILE *tmpfile; + char testfile[MAX_WADPATH]; + + snprintf(testfile, sizeof testfile, "%s" PATHSEP "file.tmp", srb2home); + testfile[sizeof testfile - 1] = '\0'; + + tmpfile = fopen(testfile, "w"); + if (tmpfile == NULL) { #if defined (_WIN32) I_Error("Couldn't write game config.\nMake sure the game is installed somewhere it has write permissions.\n\n(Don't use the Downloads folder, Program Files, or your desktop!\nIf unsure, we recommend making a subfolder in your Documents folder.)"); @@ -1138,7 +1143,11 @@ void D_SRB2Main(void) I_Error("Couldn't write game config.\nMake sure you've installed the game somewhere it has write permissions."); #endif } - fclose(tmpfile); + else + { + fclose(tmpfile); + remove(testfile); + } #ifdef _arch_dreamcast strcpy(downloaddir, "/ram"); // the dreamcast's TMP