Fix Windows binreloc executable finding.

Taking into account the behavior of
g_win32_get_package_installation_directory_of_module when the last
directory element either is or isn't "bin".
This commit is contained in:
John Ralls 2018-09-16 12:36:04 -07:00
parent 06d836e66b
commit 162605f505
2 changed files with 38 additions and 19 deletions

View File

@ -70,23 +70,32 @@ _br_find_exe (Gnc_GbrInitError *error)
if (error) if (error)
*error = GNC_GBR_INIT_ERROR_DISABLED; *error = GNC_GBR_INIT_ERROR_DISABLED;
return NULL; return NULL;
#else #elif defined G_OS_WIN32
#ifdef G_OS_WIN32 /* N.B. g_win32_get_package_installation_directory_of_module returns the
/* I *thought* this program code already included the * parent if the last element of the directory is "bin" or "lib", but
relocation code for windows. Unfortunately this is not * otherwise the directory itself. We assume that gnucash.exe isn't in lib.
the case and we have to add this manually. This is only */
one possibility; other ways of looking up the full path gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
of gnucash.exe probably exist.*/ gchar *result = g_build_filename (prefix, "bin", "gnucash.exe", NULL);
gchar *prefix; if (prefix = NULL)
gchar *result; {
if (error)
/* From the glib docs: When passed NULL, this function looks *error = GNC_GBR_INIT_WIN32_NO_EXE;
up installation the directory of the main executable of return NULL;
the current process */ }
prefix = g_win32_get_package_installation_directory_of_module (NULL); if (!g_file_test (result, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE))
result = g_build_filename (prefix, {
BINDIR, "gnucash.exe", g_free (result);
(char*)NULL); result = g_build_filename (prefix, "gnucash.exe");
if (!g_file_test (result,
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE))
{
g_free (result);
result = NULL;
if (error)
*error = GNC_GBR_INIT_WIN32_NO_EXE;
}
}
g_free (prefix); g_free (prefix);
return result; return result;
#elif defined MAC_INTEGRATION #elif defined MAC_INTEGRATION
@ -228,7 +237,6 @@ _br_find_exe (Gnc_GbrInitError *error)
g_free (line); g_free (line);
fclose (f); fclose (f);
return path; return path;
#endif /* G_OS_WINDOWS */
#endif /* ENABLE_BINRELOC */ #endif /* ENABLE_BINRELOC */
} }
@ -309,6 +317,15 @@ set_gerror (GError **error, Gnc_GbrInitError errcode)
case GNC_GBR_INIT_ERROR_DISABLED: case GNC_GBR_INIT_ERROR_DISABLED:
error_message = "Binary relocation support is disabled."; error_message = "Binary relocation support is disabled.";
break; break;
case GNC_GBR_INIT_ERROR_MAC_NOT_BUNDLE:
error_message = "BinReloc determined that gnucash is not running from a bundle";
break;
case GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE:
error_message = "Binreloc determined that the bundle is not an app bundle";
break;
case GNC_GBR_INIT_WIN32_NO_EXE_DIR:
error_message = "Binreloc was unable to determine the location of gnucash.exe.";
break;
default: default:
error_message = "Unknown error."; error_message = "Unknown error.";
break; break;

View File

@ -54,7 +54,9 @@ typedef enum
/** Binreloc determined that the bundle is not an app bundle */ /** Binreloc determined that the bundle is not an app bundle */
GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE, GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE,
/** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */ /** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */
GNC_GBR_INIT_ERROR_DISABLED GNC_GBR_INIT_ERROR_DISABLED,
/** Binreloc was unable to determine the location of gnucash.exe. */
GNC_GBR_INIT_WIN32_NO_EXE_DIR
} Gnc_GbrInitError; } Gnc_GbrInitError;