Fail loudly when config isn't writable
No write permissions = tons of broken game behavior: settings won't save, addons won't download, screenshots don't work. Let's nudge people in the right direction.
(The list of discouraged directories in the Windows-specific error message is taken from the installer recommendations: I don't actually know a specific reason you'd avoid installing to Downloads or Desktop besides mess.)
Merge request reports
Activity
It works, but it seems to behave quite strangely on Linux. If the file already exists, even if it can't write to it, it will not throw out an error.
Also, the way you're doing this is dangerous to the configuration file itself. If the game closes ungracefully (someone fatfingers their restart button, crashes unexpectedly) then kartconfig.cfg ends up becoming a 0 B file because the game didn't write to it at the end - the configuration file is gone. You should instead write a
.temp
file tosrb2home
instead then remove it at the end. Something like...// If config isn't writable, tons of behavior will be broken. // Fail loudly before things get confusing! 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.)"); #else I_Error("Couldn't write game config.\nMake sure you've installed the game somewhere it has write permissions."); #endif } else { fclose(tmpfile); remove(testfile); }
I tested this and it doesn't cause the problems that this current implementation causes, so please feel free to implement it.
Edit Note:
char testfile[MAX_WADPATH];
should be at the start alongside other declarations to avoid the C90 "mixed declarations and code" warning. Tested on Windows and Linux. I'll rescind my when this gets properly implemented.Edit 2:
Edited by JugadorXEIadded 1 commit
- 73aed464 - Use a temporary file instead of checking against config (from JugadorXEI)
mentioned in commit a95a8d5c