Use the location of the libgimpbase DLL and not that of the main

2007-12-12  Tor Lillqvist  <tml@novell.com>

	* libgimpbase/gimpenv.c (gimp_toplevel_directory) [Win32]: Use the
	location of the libgimpbase DLL and not that of the main
	executable (which will be the Python interpreter in the case of
	python-fu) to determine the top-level GIMP installation
	folder. (#502506)

	(gimp_locale_directory) [Win32]: Guard against the possibility
	that we can't get the system codepage form of the locale
	directory, in case the installation folder contains characters not
	in the system codepage. In that case use the short name instead.


svn path=/trunk/; revision=24333
This commit is contained in:
Tor Lillqvist
2007-12-12 09:41:13 +00:00
committed by Tor Lillqvist
parent 89545b9204
commit e698ec936d
2 changed files with 63 additions and 20 deletions

View File

@ -227,6 +227,34 @@ gimp_directory (void)
return gimp_dir;
}
#ifdef G_OS_WIN32
static HMODULE libgimpbase_dll = NULL;
/* Minimal DllMain that just stores the handle to this DLL */
BOOL WINAPI /* Avoid silly "no previous prototype" gcc warning */
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved);
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
libgimpbase_dll = hinstDLL;
break;
}
return TRUE;
}
#endif
static const gchar *
gimp_toplevel_directory (void)
{
@ -237,23 +265,22 @@ gimp_toplevel_directory (void)
#ifdef G_OS_WIN32
{
/* Figure it out from the executable name */
/* Figure it out from the location of this DLL */
gchar *filename;
gchar *sep1, *sep2;
wchar_t w_filename[MAX_PATH];
if (GetModuleFileNameW (NULL, w_filename, G_N_ELEMENTS (w_filename)) == 0)
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 executable file name is of the format
* <foobar>\bin\*.exe or
* <foobar>\lib\gimp\GIMP_API_VERSION\plug-ins\*.exe, use <foobar>.
* Otherwise, use the directory where the executable is.
/* 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, '\\');
@ -266,20 +293,6 @@ gimp_toplevel_directory (void)
{
*sep2 = '\0';
}
else
{
gchar test[MAX_PATH];
g_snprintf (test, sizeof (test) - 1,
"\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
if (strlen (filename) > strlen (test) &&
g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
test) == 0)
{
filename[strlen (filename) - strlen (test)] = '\0';
}
}
}
toplevel = filename;
@ -355,6 +368,23 @@ gimp_locale_directory (void)
g_free (tmp);
#ifdef G_OS_WIN32
tmp = g_locale_from_utf8 (gimp_locale_dir, -1, NULL, NULL, NULL);
/* g_locale_from_utf8() can fail in pathological cases, namely
* when the folder contains characters not in the system codepage,
* like Hebrew on a Western European machine.
*/
if (tmp == NULL)
{
/* Try to get the short name instead */
wchar_t *w_name = g_utf8_to_utf16 (gimp_locale_dir, -1, NULL, NULL, NULL);
wchar_t short_name[MAX_PATH];
DWORD rc = GetShortPathNameW (w_name, short_name, G_N_ELEMENTS (short_name));
if (rc > G_N_ELEMENTS (short_name) || rc == 0)
tmp = "."; /* eek */
else
tmp = g_utf16_to_utf8 (short_name, -1, NULL, NULL, NULL);
g_free (w_name);
}
g_free (gimp_locale_dir);
gimp_locale_dir = tmp;
#endif