win32: Don't rely on CWD for portable-mode check

Also cache the result...

Fixes #1500
This commit is contained in:
Patrick Griffis 2015-10-05 14:47:48 -04:00
parent fad8f93ad8
commit 599f5c7b29

View File

@ -1462,14 +1462,24 @@ int
portable_mode (void)
{
#ifdef WIN32
if ((_access( "portable-mode", 0 )) != -1)
static int is_portable = -1;
if (G_UNLIKELY(is_portable == -1))
{
return 1;
}
else
{
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