summary refs log tree commit diff stats
path: root/src/common
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2015-10-05 14:47:48 -0400
committerPatrick Griffis <tingping@tingping.se>2015-10-05 15:06:57 -0400
commit599f5c7b2991e09481ab84e5936f2a1d802a0fe8 (patch)
tree4dd3d4119fabbe2281135b13886dd64581b53232 /src/common
parentfad8f93ad8079a887bb3b13fb52aeef4ed473513 (diff)
win32: Don't rely on CWD for portable-mode check
Also cache the result...

Fixes #1500
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/common/util.c b/src/common/util.c
index be3dcac2..316ac9d4 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1462,14 +1462,24 @@ int
 portable_mode (void)
 {
 #ifdef WIN32
-	if ((_access( "portable-mode", 0 )) != -1)
-	{
-		return 1;
-	}
-	else
+	static int is_portable = -1;
+
+	if (G_UNLIKELY(is_portable == -1))
 	{
-		return 0;
+		char *path = g_win32_get_package_installation_directory_of_module (NULL);
+		char *filename;
+
+		if (path == NULL)
+			path = g_strdup (".");
+
+		filename = g_build_filename (path, "portable-mode", NULL);
+		is_portable = g_file_test (filename, G_FILE_TEST_EXISTS);
+
+		g_free (path);
+		g_free (filename);
 	}
+
+	return is_portable;
 #else
 	return 0;
 #endif