From 8036835628d66b3561668eb4872debed3075ca5d Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Sun, 1 Mar 2009 04:13:19 -0700 Subject: Fixed crash involving file picker and locales (patch by Alissa Sabre) --- ChangeLog.txt | 4 ++++ linden/indra/newview/llfilepicker.cpp | 39 ++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 34cc409..e187605 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -14,6 +14,10 @@ Ditto. + * linden/indra/newview/llfilepicker.cpp: + Applied patch for VWR-5575 (crash in the file picker dealing + with accented characters and bad locale) by Alissa Sabre. + =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =- 1.1.0 RC2 -= diff --git a/linden/indra/newview/llfilepicker.cpp b/linden/indra/newview/llfilepicker.cpp index bbcfba6..1edfbe6 100644 --- a/linden/indra/newview/llfilepicker.cpp +++ b/linden/indra/newview/llfilepicker.cpp @@ -899,12 +899,41 @@ BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename) // static void LLFilePicker::add_to_selectedfiles(gpointer data, gpointer user_data) { - LLFilePicker* picker = (LLFilePicker*) user_data; + // We need to run g_filename_to_utf8 in the user's locale + std::string old_locale(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, ""); + + LLFilePicker* picker = (LLFilePicker*) user_data; + GError *error = NULL; gchar* filename_utf8 = g_filename_to_utf8((gchar*)data, - -1, NULL, NULL, NULL); - picker->mFiles.push_back(std::string(filename_utf8)); - lldebugs << "ADDED FILE " << filename_utf8 << llendl; - g_free(filename_utf8); + -1, NULL, NULL, &error); + if (error) + { + // This condition should really be notified to the user, e.g., + // through a message box. Just logging it is inapropriate. + // FIXME. + + // Ghhhh. g_filename_display_name is new to glib 2.6, and it + // is too new for SL! (Note that the latest glib as of this + // writing is 2.22. *sigh*) LL supplied *makeASCII family are + // also unsuitable since they allow control characters... + + std::string display_name; + for (const gchar *str = (const gchar *)data; *str; str++) + { + display_name += (char)((*str >= 0x20 && *str <= 0x7E) ? *str : '?'); + } + llwarns << "g_filename_to_utf8 failed on \"" << display_name << "\": " << error->message << llendl; + } + + if (filename_utf8) + { + picker->mFiles.push_back(std::string(filename_utf8)); + lldebugs << "ADDED FILE " << filename_utf8 << llendl; + g_free(filename_utf8); + } + + setlocale(LC_ALL, old_locale.c_str()); } // static -- cgit v1.1