[libsoup] libsoup/soup-session.c: Don't Hardcode Paths on Windows



commit f58c9879c1986d4b77c68bd81879f692a0c62d07
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Aug 6 00:30:52 2015 +0800

    libsoup/soup-session.c: Don't Hardcode Paths on Windows
    
    On Windows, use g_win32_get_package_installation_directory_of_module()
    and g_build_filename() to acquire the localedir to find the translations
    on Windows, instead of relying on the LOCALEDIR which is hardcoded at
    compile time, so that the libsoup DLL can be relocated on Windows with its
    translations.  Therefore, we define a simple DllMain() which is used to
    acquire the proper HMODULE for the purpose.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752952

 libsoup/soup-session.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 6420183..ca8d80c 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -77,10 +77,43 @@
  * subtypes) have a #SoupContentDecoder by default.
  **/
 
+#if defined (G_OS_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+HMODULE soup_dll;
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+         DWORD     fdwReason,
+         LPVOID    lpvReserved)
+{
+       switch (fdwReason) {
+       case DLL_PROCESS_ATTACH:
+               soup_dll = hinstDLL;
+               break;
+
+       case DLL_THREAD_DETACH:
+
+       default:
+               /* do nothing */
+               ;
+       }
+}
+#endif
+
 static void
 soup_init (void)
 {
+#ifdef G_OS_WIN32
+       char *basedir = g_win32_get_package_installation_directory_of_module (soup_dll);
+       char *localedir = g_build_filename (basedir, "share", "locale", NULL);
+       bindtextdomain (GETTEXT_PACKAGE, localedir);
+       g_free (localedir);
+       g_free (basedir);
+#else
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+#endif
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]