From 599f5c7b2991e09481ab84e5936f2a1d802a0fe8 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 5 Oct 2015 14:47:48 -0400 Subject: win32: Don't rely on CWD for portable-mode check Also cache the result... Fixes #1500 --- src/common/util.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/common') 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 -- cgit 1.4.1