changeset 1058:266dc3f31f35

Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
author Michael Pavone <pavone@retrodev.com>
date Sat, 30 Jul 2016 23:36:02 -0700
parents ff46d8fc2de8
children 8da967779710
files util.c
diffstat 1 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/util.c	Sat Jul 30 16:01:57 2016 -0700
+++ b/util.c	Sat Jul 30 23:36:02 2016 -0700
@@ -593,13 +593,35 @@
 	return ret;
 }
 
+
+#ifdef _WIN32
+char const *get_save_base_dir()
+{
+	static char path[MAX_PATH];
+	if (S_OK == SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))
+	{
+		return path;
+	}
+	return NULL;
+}
+#define CONFIG_PREFIX ""
+#define SAVE_PREFIX ""
+
+#else
+
+#define get_save_base_dir get_home_dir
+#define CONFIG_PREFIX "/.config"
+#define SAVE_PREFIX "/.local/share"
+
+#endif
+
 char const *get_config_dir()
 {
 	static char* confdir;
 	if (!confdir) {
-		char *homedir = get_home_dir();
-		if (homedir) {
-			confdir = alloc_concat(homedir, "/.config/blastem");
+		char const *base = get_save_base_dir();
+		if (base) {
+			confdir = alloc_concat(base, CONFIG_PREFIX PATH_SEP "blastem");
 		}
 	}
 	return confdir;
@@ -609,9 +631,9 @@
 {
 	static char* savedir;
 	if (!savedir) {
-		char *homedir = get_home_dir();
-		if (homedir) {
-			savedir = alloc_concat(homedir, "/.local/share/blastem");
+		char const *base = get_save_base_dir();
+		if (base) {
+			savedir = alloc_concat(base, SAVE_PREFIX PATH_SEP "blastem");
 		}
 	}
 	return savedir;