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

View File

@ -54,7 +54,9 @@ typedef enum
/** Binreloc determined that the bundle is not an app bundle */
GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE,
/** 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;