tStore log/score/config files in AppData - vaccinewars - be a doctor and try to… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit f6cbc8315299ce88c405cd826d990cdb19a0c09a | |
parent 1024456d3fa3d80248ae1f8d99392eec154c4545 | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 30 Nov 2020 23:11:30 -0800 | |
Store log/score/config files in AppData | |
Rather than trying to place them in the same directory | |
as the dopewars binary on Windows, place log files, high score | |
files, and per-user config files in the per-user application | |
data directory. Closes #52. | |
Diffstat: | |
M ChangeLog | 4 ++++ | |
M doc/configfile.html | 3 ++- | |
M doc/windows.html | 12 +++++++----- | |
M src/dopewars.c | 12 +++++++++++- | |
M src/winmain.c | 22 +++++++++++++++++++++- | |
5 files changed, 45 insertions(+), 8 deletions(-) | |
--- | |
diff --git a/ChangeLog b/ChangeLog | |
t@@ -16,6 +16,10 @@ SVN | |
https://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Environment) | |
- The default web browser on Linux has changed from 'mozilla' to | |
'firefox'; on Mac the system-configured default browser is used. | |
+ - On Windows the high score file and config file are now stored in the | |
+ user application data directory (e.g. | |
+ C:\Users\foo\AppData\Local\dopewars) rather than the same directory as | |
+ the dopewars binary. | |
- Add sound support on Mac. | |
- Add 64-bit Windows binaries. | |
- Fix for a DOS against the server using the REQUESTJET message type | |
diff --git a/doc/configfile.html b/doc/configfile.html | |
t@@ -31,7 +31,8 @@ location settings <i>Port</i> and <i>Server</i> are still us… | |
<li>The global configuration file (if present) <b>/etc/dopewars</b></li> | |
<li>The user-specific file (if present) <b>~/.dopewars</b></li> | |
<li><i>(Windows only)</i> The file <b>dopewars-config.txt</b> in the current | |
-directory</li> | |
+user's application data directory (e.g. | |
+<tt>C:\Users\foo\AppData\Local\dopewars\</tt>)</li> | |
<li>Options specified on the <a href="commandline.html">command line</a></li> | |
</ol> | |
diff --git a/doc/windows.html b/doc/windows.html | |
t@@ -37,17 +37,19 @@ details.</p> | |
identical. Both will accept the same command line parameters and configuration | |
options. However, since the standard Unix paths for the high score file and | |
configuration files do not translate well to Windows, by default the program | |
-will look for both the high score file <b>dopewars.sco</b> in the current | |
-directory, and will read a global configuration file <b>dopewars-config.txt</b> | |
-from the directory in which the dopewars binary was installed, followed by | |
-a per-user configuration file of the same name in the working directory.</p> | |
+will look for the high score file <b>dopewars.sco</b> in the current | |
+user's application data directory (e.g. | |
+<tt>C:\Users\foo\AppData\Local\dopewars\</tt>), and will read a global | |
+configuration file <b>dopewars-config.txt</b> from the directory in which the | |
+dopewars binary was installed, followed by a per-user configuration file of | |
+the same name in the AppData directory.</p> | |
<hr /> | |
<ul> | |
<li><a href="index.html">Main index</a></li> | |
</ul> | |
<p> | |
- Last update: <b>19-10-2002</b><br /> | |
+ Last update: <b>30-11-2020</b><br /> | |
Valid <a href="http://validator.w3.org/check/referer">XHTML 1.1</a> | |
</p> | |
</body> | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -2337,6 +2337,10 @@ gchar *GetDocIndex(void) | |
return file; | |
} | |
+#ifdef CYGWIN | |
+extern gchar *appdata_path; | |
+#endif | |
+ | |
/* | |
* Returns the pathname of the global (all users) configuration file, | |
* as a dynamically-allocated string that must be later freed. On | |
t@@ -2367,7 +2371,8 @@ gchar *GetGlobalConfigFile(void) | |
gchar *GetLocalConfigFile(void) | |
{ | |
#ifdef CYGWIN | |
- return g_strdup("dopewars-config.txt"); | |
+ return g_strdup_printf("%s/dopewars-config.txt", | |
+ appdata_path ? appdata_path : "."); | |
#else | |
gchar *home, *conf = NULL; | |
t@@ -2771,7 +2776,12 @@ struct CMDLINE *GeneralStartup(int argc, char *argv[]) | |
{ | |
/* First, open the hard-coded high score file with possibly | |
* elevated privileges */ | |
+#ifdef CYGWIN | |
+ priv_hiscore = g_strdup_printf("%s/dopewars.sco", | |
+ appdata_path ? appdata_path : DPSCOREDIR); | |
+#else | |
priv_hiscore = g_strdup_printf("%s/dopewars.sco", DPSCOREDIR); | |
+#endif | |
HiScoreFile = g_strdup(priv_hiscore); | |
OpenHighScoreFile(); | |
DropPrivileges(); | |
diff --git a/src/winmain.c b/src/winmain.c | |
t@@ -26,9 +26,11 @@ | |
#ifdef CYGWIN | |
+#include <direct.h> | |
#include <winsock2.h> | |
#include <windows.h> | |
#include <commctrl.h> | |
+#include <shlobj.h> | |
#include <glib.h> | |
#include <stdlib.h> | |
t@@ -104,9 +106,25 @@ static void WindowPrintEnd() | |
static FILE *LogFile = NULL; | |
+gchar *appdata_path = NULL; | |
+ | |
+static void GetAppDataPath() | |
+{ | |
+ char shfolder[MAX_PATH]; | |
+ | |
+ if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, | |
+ NULL, 0, shfolder))) { | |
+ appdata_path = g_strdup_printf("%s/dopewars", shfolder); | |
+ mkdir(appdata_path); | |
+ } | |
+} | |
+ | |
static void LogFileStart() | |
{ | |
- LogFile = fopen("dopewars-log.txt", "w"); | |
+ char *logfile = g_strdup_printf("%s/dopewars-log.txt", | |
+ appdata_path ? appdata_path : "."); | |
+ LogFile = fopen(logfile, "w"); | |
+ g_free(logfile); | |
} | |
static void LogFilePrintFunc(const gchar *string) | |
t@@ -266,6 +284,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevI… | |
g_free(modpath); | |
} | |
+ GetAppDataPath(); | |
+ | |
LogFileStart(); | |
g_set_print_handler(LogFilePrintFunc); | |