Commit 0657b852 authored by Luca Bacci's avatar Luca Bacci Committed by Jehan
Browse files

Use GLib to convert between UTF-8 and UTF-16

parent 48c1d076
......@@ -625,29 +625,18 @@ main (int argc,
const gchar *install_dir;
gchar *bin_dir;
LPWSTR w_bin_dir;
int n;
w_bin_dir = NULL;
install_dir = gimp_installation_directory ();
bin_dir = g_build_filename (install_dir, "bin", NULL);
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
bin_dir, -1, NULL, 0);
if (n == 0)
goto out;
w_bin_dir = g_malloc_n (n + 1, sizeof (wchar_t));
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
bin_dir, -1,
w_bin_dir, (n + 1) * sizeof (wchar_t));
if (n == 0)
goto out;
SetDllDirectoryW (w_bin_dir);
out:
w_bin_dir = g_utf8_to_utf16 (bin_dir, -1, NULL, NULL, NULL);
if (w_bin_dir)
g_free (w_bin_dir);
{
SetDllDirectoryW (w_bin_dir);
g_free (w_bin_dir);
}
g_free (bin_dir);
}
......
......@@ -213,29 +213,18 @@ gimp_main (GType plug_in_type,
const gchar *install_dir;
gchar *bin_dir;
LPWSTR w_bin_dir;
int n;
w_bin_dir = NULL;
install_dir = gimp_installation_directory ();
bin_dir = g_build_filename (install_dir, "bin", NULL);
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
bin_dir, -1, NULL, 0);
if (n == 0)
goto out;
w_bin_dir = g_malloc_n (n + 1, sizeof (wchar_t));
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
bin_dir, -1,
w_bin_dir, (n + 1) * sizeof (wchar_t));
if (n == 0)
goto out;
SetDllDirectoryW (w_bin_dir);
out:
w_bin_dir = g_utf8_to_utf16 (bin_dir, -1, NULL, NULL, NULL);
if (w_bin_dir)
g_free (w_bin_dir);
{
SetDllDirectoryW (w_bin_dir);
g_free (w_bin_dir);
}
g_free (bin_dir);
}
......
......@@ -377,7 +377,6 @@ gimp_file_show_in_file_manager (GFile *file,
{
gboolean ret;
char *filename;
int n;
LPWSTR w_filename = NULL;
ITEMIDLIST *pidl = NULL;
......@@ -385,7 +384,8 @@ gimp_file_show_in_file_manager (GFile *file,
/* Calling this function multiple times should do no harm, but it is
easier to put this here as it needs linking against ole32. */
CoInitialize (NULL);
if (FAILED (CoInitialize (NULL)))
return ret;
filename = g_file_get_path (file);
if (!filename)
......@@ -395,20 +395,8 @@ gimp_file_show_in_file_manager (GFile *file,
goto out;
}
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
filename, -1, NULL, 0);
if (n == 0)
{
g_set_error_literal (error, G_FILE_ERROR, 0,
_("Error converting UTF-8 filename to wide char"));
goto out;
}
w_filename = g_malloc_n (n + 1, sizeof (wchar_t));
n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
filename, -1,
w_filename, (n + 1) * sizeof (wchar_t));
if (n == 0)
w_filename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
if (!w_filename)
{
g_set_error_literal (error, G_FILE_ERROR, 0,
_("Error converting UTF-8 filename to wide char"));
......@@ -432,6 +420,8 @@ gimp_file_show_in_file_manager (GFile *file,
g_free (w_filename);
g_free (filename);
CoUninitialize ();
return ret;
}
......
Supports Markdown
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