static const gchar * gimp_toplevel_directory (void) { static gchar *toplevel = NULL; if (toplevel) return toplevel; #ifdef G_OS_WIN32 { /* Figure it out from the location of this DLL */ gchar *filename; gchar *sep1, *sep2; wchar_t w_filename[MAX_PATH]; if (GetModuleFileNameW (libgimpbase_dll, w_filename, G_N_ELEMENTS (w_filename)) == 0) g_error ("GetModuleFilenameW failed"); filename = g_utf16_to_utf8 (w_filename, -1, NULL, NULL, NULL); if (filename == NULL) g_error ("Converting module filename to UTF-8 failed"); /* If the DLL file name is of the format * <foobar>\bin\*.dll, use <foobar>. * Otherwise, use the directory where the DLL is. */ sep1 = strrchr (filename, '\\'); *sep1 = '\0'; sep2 = strrchr (filename, '\\'); if (sep2 != NULL) { if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0) { *sep2 = '\0'; } } toplevel = filename; } #else toplevel = _gimp_reloc_find_prefix (PREFIX); #endif return toplevel; }
/* Locate the application's libexec folder. * * The path is generated by the following pseudo-code evaluation: * \code * prefix + "/libexec" * \endcode * * @param default_libexec_dir A default path which will used as fallback. * @return A string containing the libexec folder's path, which must be freed when * no longer necessary. If BinReloc is not initialized, or if the initialization * function failed, then a copy of default_libexec_dir will be returned. * If default_libexec_dir is NULL, then NULL will be returned. */ gchar * _gimp_reloc_find_libexec_dir (const gchar *default_libexec_dir) { gchar *prefix, *dir; prefix = _gimp_reloc_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ if (default_libexec_dir != NULL) return g_strdup (default_libexec_dir); else return NULL; } dir = g_build_filename (prefix, "libexec", NULL); g_free (prefix); return dir; }
/* Locate the application's configuration files folder. * * The path is generated by the following pseudo-code evaluation: * \code * prefix + "/etc/" + GIMP_PACKAGE + "/" + GIMP_SYSCONF_VERSION * \endcode * * @param default_etc_dir A default path which will used as fallback. * @return A string containing the etc folder's path, which must be freed when * no longer necessary. If BinReloc is not initialized, or if the * initialization function failed, then a copy of default_etc_dir * will be returned. If default_etc_dir is NULL, then NULL will be * returned. */ gchar * _gimp_reloc_find_etc_dir (const gchar *default_etc_dir) { gchar *prefix, *dir; prefix = _gimp_reloc_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ if (default_etc_dir != NULL) return g_strdup (default_etc_dir); else return NULL; } dir = g_build_filename (prefix, "etc", GIMP_PACKAGE, GIMP_SYSCONF_VERSION, NULL); g_free (prefix); return dir; }