Commit 1e295cb0 authored by Tor Lillqvist's avatar Tor Lillqvist Committed by Tor Lillqvist

Make GIMP work on Win32 even if installed in a path containing random

2005-08-24  Tor Lillqvist  <tml@novell.com>

	Make GIMP work on Win32 even if installed in a path containing
	random non-ASCII characters.

	* libgimpbase/gimpenv.c (gimp_toplevel_directory): [Win32] Use
	wide-char API on NT-based Windowses. Keep the toplevel directory
	name in UTF-8. The rest of GIMP assumes it is UTF-8 anyway, and
	for instance passes file names constructed from it to g_open().

	* app/plug-in/plug-in.c (plug_in_open): On Win32, if compiled
	against GLib < 2.8.2, convert the pathname arguments passed to
	g_spawn_async() to locale charset (system codepage). The
	g_spawn*() functions in GLib < 2.8.2 take system codepage
	arguments and not UTF-8.
parent 4ba616a3
2005-08-24 Tor Lillqvist <tml@novell.com>
Make GIMP work on Win32 even if installed in a path containing
random non-ASCII characters.
* libgimpbase/gimpenv.c (gimp_toplevel_directory): [Win32] Use
wide-char API on NT-based Windowses. Keep the toplevel directory
name in UTF-8. The rest of GIMP assumes it is UTF-8 anyway, and
for instance passes file names constructed from it to g_open().
* app/plug-in/plug-in.c (plug_in_open): On Win32, if compiled
against GLib < 2.8.2, convert the pathname arguments passed to
g_spawn_async() to locale charset (system codepage). The
g_spawn*() functions in GLib < 2.8.2 take system codepage
arguments and not UTF-8.
2005-08-24 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/paint-funcs/paint-funcs-generic.h (blend_pixels):
......
......@@ -425,12 +425,38 @@ plug_in_open (PlugIn *plug_in)
argc = 0;
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
/* In GLib < 2.8.2 on Win32 the argument vector passed to g_spawn*()
* should be in system codepage.
*
* Checking compile-time GLib version is the right thing to do.
* Even if running against GLib >= 2.8.2, code compiled against
* headers from GLib < 2.8.2 use backward-compatible functions that
* still take system codepage. Only code compiled against headers
* from GLib >= 2.8.2 use the g_spawn versions (that actually are
* called g_spawn*_utf8()) that take UTF-8.
*/
if (interp)
{
args[argc++] = g_locale_from_utf8 (interp, -1, NULL, NULL, NULL);
if (args[argc-1] == NULL)
g_error ("Interpreter %s is a file name with characters not in the system codepage. That doesn't work when GIMP is built against GLib 2.8.1 or earlier.", interp);
}
#else
if (interp)
args[argc++] = interp;
#endif
if (interp_arg)
args[argc++] = interp_arg;
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
args[argc++] = g_locale_from_utf8 (plug_in->prog, -1, NULL, NULL, NULL);
if (args[argc-1] == NULL)
g_error ("Plug-in %s is a file name with characters not in the system codepage. That doesn't work when GIMP is built against GLib 2.8.1 or earlier.", plug_in->prog);
#else
args[argc++] = plug_in->prog;
#endif
args[argc++] = "-gimp";
args[argc++] = read_fd;
args[argc++] = write_fd;
......@@ -510,6 +536,17 @@ cleanup:
g_free (write_fd);
g_free (stm);
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
argc = 0;
if (interp)
g_free (args[argc++]);
if (interp_arg)
argc++;
g_free (args[argc++]);
#endif
g_free (interp);
g_free (interp_arg);
......
......@@ -425,12 +425,38 @@ plug_in_open (PlugIn *plug_in)
argc = 0;
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
/* In GLib < 2.8.2 on Win32 the argument vector passed to g_spawn*()
* should be in system codepage.
*
* Checking compile-time GLib version is the right thing to do.
* Even if running against GLib >= 2.8.2, code compiled against
* headers from GLib < 2.8.2 use backward-compatible functions that
* still take system codepage. Only code compiled against headers
* from GLib >= 2.8.2 use the g_spawn versions (that actually are
* called g_spawn*_utf8()) that take UTF-8.
*/
if (interp)
{
args[argc++] = g_locale_from_utf8 (interp, -1, NULL, NULL, NULL);
if (args[argc-1] == NULL)
g_error ("Interpreter %s is a file name with characters not in the system codepage. That doesn't work when GIMP is built against GLib 2.8.1 or earlier.", interp);
}
#else
if (interp)
args[argc++] = interp;
#endif
if (interp_arg)
args[argc++] = interp_arg;
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
args[argc++] = g_locale_from_utf8 (plug_in->prog, -1, NULL, NULL, NULL);
if (args[argc-1] == NULL)
g_error ("Plug-in %s is a file name with characters not in the system codepage. That doesn't work when GIMP is built against GLib 2.8.1 or earlier.", plug_in->prog);
#else
args[argc++] = plug_in->prog;
#endif
args[argc++] = "-gimp";
args[argc++] = read_fd;
args[argc++] = write_fd;
......@@ -510,6 +536,17 @@ cleanup:
g_free (write_fd);
g_free (stm);
#if defined (G_OS_WIN32) && !GLIB_CHECK_VERSION (2, 8, 2)
argc = 0;
if (interp)
g_free (args[argc++]);
if (interp_arg)
argc++;
g_free (args[argc++]);
#endif
g_free (interp);
g_free (interp_arg);
......
......@@ -189,15 +189,35 @@ gimp_toplevel_directory (void)
/* Figure it out from the executable name */
static gchar *toplevel = NULL;
gchar filename[MAX_PATH];
gchar *filename;
gchar *sep1, *sep2;
if (toplevel)
return toplevel;
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
g_error ("GetModuleFilename failed");
if (G_WIN32_HAVE_WIDECHAR_API ())
{
wchar_t w_filename[MAX_PATH];
if (GetModuleFileNameW (NULL, 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");
}
else
{
gchar cp_filename[MAX_PATH];
if (GetModuleFileNameA (NULL, cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
g_error ("GetModuleFilenameA failed");
filename = g_locale_to_utf8 (cp_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>.
......@@ -230,7 +250,7 @@ gimp_toplevel_directory (void)
}
}
toplevel = g_strdup (filename);
toplevel = filename;
return toplevel;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment