[evolution-data-server] Miscellaneous Win32 related changes



commit 53ed55394eadfd04edeeddfb5292ebfe6954b773
Author: Milan Crha <mcrha redhat com>
Date:   Fri Sep 5 19:00:02 2014 +0200

    Miscellaneous Win32 related changes
    
     * register maildir provider - it was built, but not registered, though
       it is required for evolution; there will be needed more changer, but
       let's have this as a     starter
     * write Windows full path in .service files - D-Bus requires a Windows
       full path there, not a Unix-like, thus depends on WIN32_SERVICELIBEXECDIR,
       which should provide this path with forward slashes
     * introduce e_util_win32_initialize(), which should be called at
       the beginning of the main(); it makes also sure that D-Bus daemon is running

 camel/providers/local/camel-local-provider.c       |    6 +-
 configure.ac                                       |   11 ++-
 libedataserver/e-data-server-util.c                |   92 ++++++++++++++++++++
 libedataserver/e-data-server-util.h                |    1 +
 .../evolution-addressbook-factory.c                |   40 +--------
 .../evolution-calendar-factory.c                   |   40 +--------
 .../evolution-source-registry.c                    |    5 +
 .../evolution-user-prompter.c                      |    6 ++
 8 files changed, 121 insertions(+), 80 deletions(-)
---
diff --git a/camel/providers/local/camel-local-provider.c b/camel/providers/local/camel-local-provider.c
index 0f73c6c..de41646 100644
--- a/camel/providers/local/camel-local-provider.c
+++ b/camel/providers/local/camel-local-provider.c
@@ -73,8 +73,6 @@ static CamelProvider mbox_provider = {
        /* ... */
 };
 
-#ifndef G_OS_WIN32
-
 static CamelProviderConfEntry maildir_conf_entries[] = {
        { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
        { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
@@ -95,6 +93,8 @@ static CamelProvider maildir_provider = {
        /* ... */
 };
 
+#ifndef G_OS_WIN32
+
 static CamelProviderConfEntry spool_conf_entries[] = {
        { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
        { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
@@ -250,11 +250,11 @@ camel_provider_module_init (void)
        spool_directory_provider.url_equal = local_url_equal;
        spool_directory_provider.translation_domain = GETTEXT_PACKAGE;
        camel_provider_register (&spool_directory_provider);
+#endif
 
        maildir_provider.object_types[CAMEL_PROVIDER_STORE] = camel_maildir_store_get_type ();
        maildir_provider.url_hash = local_url_hash;
        maildir_provider.url_equal = local_url_equal;
        maildir_provider.translation_domain = GETTEXT_PACKAGE;
        camel_provider_register (&maildir_provider);
-#endif
 }
diff --git a/configure.ac b/configure.ac
index 4cd6009..13c7f48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1669,8 +1669,17 @@ AC_SUBST(camel_providerdir)
 dnl *******************
 dnl D-BUS service stuff
 dnl *******************
+servicelibexecdir=${libexecdir}
+if test x$os_win32 = xyes -a "x$WIN32_SERVICELIBEXECDIR" != "x" ; then
+       dnl
+       dnl D-Bus requires Windows full path, not Unix-like, like the one provided by MSYS
+       dnl
+       AC_SUBST(WIN32_SERVICELIBEXECDIR)
+       servicelibexecdir="$WIN32_SERVICELIBEXECDIR"
+fi
+AC_SUBST(servicelibexecdir)
 m4_pattern_allow([AM_V_GEN])
-EVO_SUBST_SERVICE_RULE='%.service: %.service.in Makefile ; $(AM_V_GEN) sed -e "s|\ 
libexecdir\@|$(libexecdir)|" -e s"|\ ADDRESS_BOOK_DBUS_SERVICE_NAME\@|$(ADDRESS_BOOK_DBUS_SERVICE_NAME)|" -e 
"s|\ CALENDAR_DBUS_SERVICE_NAME\@|$(CALENDAR_DBUS_SERVICE_NAME)|" -e "s|\ 
SOURCES_DBUS_SERVICE_NAME\@|$(SOURCES_DBUS_SERVICE_NAME)|" -e "s|\ 
USER_PROMPTER_DBUS_SERVICE_NAME\@|$(USER_PROMPTER_DBUS_SERVICE_NAME)|" $< > $@'
+EVO_SUBST_SERVICE_RULE='%.service: %.service.in Makefile ; $(AM_V_GEN) sed -e "s|\ 
libexecdir\@|$(servicelibexecdir)|" -e s"|\ 
ADDRESS_BOOK_DBUS_SERVICE_NAME\@|$(ADDRESS_BOOK_DBUS_SERVICE_NAME)|" -e "s|\ 
CALENDAR_DBUS_SERVICE_NAME\@|$(CALENDAR_DBUS_SERVICE_NAME)|" -e "s|\ 
SOURCES_DBUS_SERVICE_NAME\@|$(SOURCES_DBUS_SERVICE_NAME)|" -e "s|\ 
USER_PROMPTER_DBUS_SERVICE_NAME\@|$(USER_PROMPTER_DBUS_SERVICE_NAME)|" $< > $@'
 AC_SUBST(EVO_SUBST_SERVICE_RULE)
 
 dnl ******************************
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index dcd1a63..76495be 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -1632,6 +1632,16 @@ e_async_closure_callback (GObject *object,
 #ifdef G_OS_WIN32
 
 #include <windows.h>
+#include <stdio.h>
+#include <conio.h>
+#include <io.h>
+
+#ifndef PROCESS_DEP_ENABLE
+#define PROCESS_DEP_ENABLE 0x00000001
+#endif
+#ifndef PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION
+#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002
+#endif
 
 static const gchar *prefix = NULL;
 static const gchar *cp_prefix;
@@ -1751,6 +1761,88 @@ PUBLIC_GETTER (prefix)
 PUBLIC_GETTER (cp_prefix)
 PUBLIC_GETTER (localedir)
 
+/**
+ * e_util_win32_initialize:
+ *
+ * Initializes win32 environment. This might be called in main().
+ **/
+void
+e_util_win32_initialize (void)
+{
+       gchar module_filename[2048 + 1];
+       DWORD chars;
+
+       /* Reduce risks */
+       {
+               typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName);
+               t_SetDllDirectoryA p_SetDllDirectoryA;
+
+               p_SetDllDirectoryA = GetProcAddress (
+                       GetModuleHandle ("kernel32.dll"),
+                       "SetDllDirectoryA");
+
+               if (p_SetDllDirectoryA != NULL)
+                       p_SetDllDirectoryA ("");
+       }
+#ifndef _WIN64
+       {
+               typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
+               t_SetProcessDEPPolicy p_SetProcessDEPPolicy;
+
+               p_SetProcessDEPPolicy = GetProcAddress (
+                       GetModuleHandle ("kernel32.dll"),
+                       "SetProcessDEPPolicy");
+
+               if (p_SetProcessDEPPolicy != NULL)
+                       p_SetProcessDEPPolicy (
+                               PROCESS_DEP_ENABLE |
+                               PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
+       }
+#endif
+
+       if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) {
+               /* stdout is fine, presumably redirected to a file or pipe */
+       } else {
+               typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
+
+               AttachConsole_t p_AttachConsole =
+                       (AttachConsole_t) GetProcAddress (
+                       GetModuleHandle ("kernel32.dll"), "AttachConsole");
+
+               if (p_AttachConsole && p_AttachConsole (ATTACH_PARENT_PROCESS)) {
+                       freopen ("CONOUT$", "w", stdout);
+                       dup2 (fileno (stdout), 1);
+                       freopen ("CONOUT$", "w", stderr);
+                       dup2 (fileno (stderr), 2);
+               }
+       }
+
+       chars = GetModuleFileNameA (hmodule, module_filename, 2048);
+       if (chars > 0) {
+               gchar *path;
+
+               module_filename[chars] = '\0';
+
+               path = strrchr (module_filename, '\\');
+               if (path)
+                       path[1] = '\0';
+
+               path = g_build_path (";", module_filename, g_getenv ("PATH"), NULL);
+
+               if (!g_setenv ("PATH", path, TRUE))
+                       g_warning ("Could not set PATH for Evolution and its child processes");
+
+               g_free (path);
+       }
+
+       /* Make sure D-Bus is running. The executable makes sure the daemon
+          is not restarted, thus it's safe to be called witn D-Bus already
+          running. */
+       if (system ("dbus-launch.exe") != 0) {
+               /* Ignore, just to mute compiler warning */;
+       }
+}
+
 #endif /* G_OS_WIN32 */
 
 static gint default_dbus_timeout = -1;
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index f1a571f..bee242c 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -128,6 +128,7 @@ const gchar *       e_util_get_localedir            (void) G_GNUC_CONST;
 gchar *                e_util_replace_prefix           (const gchar *configure_time_prefix,
                                                 const gchar *runtime_prefix,
                                                 const gchar *configure_time_path);
+void           e_util_win32_initialize         (void);
 #endif
 
 /* utility functions for easier processing of named parameters */
diff --git a/services/evolution-addressbook-factory/evolution-addressbook-factory.c 
b/services/evolution-addressbook-factory/evolution-addressbook-factory.c
index ab649c6..057804c 100644
--- a/services/evolution-addressbook-factory/evolution-addressbook-factory.c
+++ b/services/evolution-addressbook-factory/evolution-addressbook-factory.c
@@ -24,17 +24,7 @@
 #include <gtk/gtk.h>
 #endif
 
-#ifdef G_OS_WIN32
-#include <windows.h>
-#include <conio.h>
-#ifndef PROCESS_DEP_ENABLE
-#define PROCESS_DEP_ENABLE 0x00000001
-#endif
-#ifndef PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION
-#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002
-#endif
-#endif
-
+#include <libedataserver/libedataserver.h>
 #include <libedata-book/libedata-book.h>
 
 static gboolean opt_keep_running = FALSE;
@@ -58,33 +48,7 @@ main (gint argc,
        GError *error = NULL;
 
 #ifdef G_OS_WIN32
-       /* Reduce risks */
-       {
-               typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName);
-               t_SetDllDirectoryA p_SetDllDirectoryA;
-
-               p_SetDllDirectoryA = GetProcAddress (
-                       GetModuleHandle ("kernel32.dll"),
-                       "SetDllDirectoryA");
-
-               if (p_SetDllDirectoryA != NULL)
-                       p_SetDllDirectoryA ("");
-       }
-#ifndef _WIN64
-       {
-               typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
-               t_SetProcessDEPPolicy p_SetProcessDEPPolicy;
-
-               p_SetProcessDEPPolicy = GetProcAddress (
-                       GetModuleHandle ("kernel32.dll"),
-                       "SetProcessDEPPolicy");
-
-               if (p_SetProcessDEPPolicy != NULL)
-                       p_SetProcessDEPPolicy (
-                               PROCESS_DEP_ENABLE |
-                               PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
-       }
-#endif
+       e_util_win32_initialize ();
 #endif
 
        setlocale (LC_ALL, "");
diff --git a/services/evolution-calendar-factory/evolution-calendar-factory.c 
b/services/evolution-calendar-factory/evolution-calendar-factory.c
index ba4e5c8..f565baf 100644
--- a/services/evolution-calendar-factory/evolution-calendar-factory.c
+++ b/services/evolution-calendar-factory/evolution-calendar-factory.c
@@ -28,17 +28,7 @@
 #include <libical/ical.h>
 #endif
 
-#ifdef G_OS_WIN32
-#include <windows.h>
-#include <conio.h>
-#ifndef PROCESS_DEP_ENABLE
-#define PROCESS_DEP_ENABLE 0x00000001
-#endif
-#ifndef PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION
-#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002
-#endif
-#endif
-
+#include <libedataserver/libedataserver.h>
 #include <libedata-cal/libedata-cal.h>
 
 static gboolean opt_keep_running = FALSE;
@@ -62,33 +52,7 @@ main (gint argc,
        GError *error = NULL;
 
 #ifdef G_OS_WIN32
-       /* Reduce risks */
-       {
-               typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName);
-               t_SetDllDirectoryA p_SetDllDirectoryA;
-
-               p_SetDllDirectoryA = GetProcAddress (
-                       GetModuleHandle ("kernel32.dll"),
-                       "SetDllDirectoryA");
-
-               if (p_SetDllDirectoryA != NULL)
-                       p_SetDllDirectoryA ("");
-       }
-#ifndef _WIN64
-       {
-               typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
-               t_SetProcessDEPPolicy p_SetProcessDEPPolicy;
-
-               p_SetProcessDEPPolicy = GetProcAddress (
-                       GetModuleHandle ("kernel32.dll"),
-                       "SetProcessDEPPolicy");
-
-               if (p_SetProcessDEPPolicy != NULL)
-                       p_SetProcessDEPPolicy (
-                               PROCESS_DEP_ENABLE |
-                               PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
-       }
-#endif
+       e_util_win32_initialize ();
 #endif
 
        setlocale (LC_ALL, "");
diff --git a/services/evolution-source-registry/evolution-source-registry.c 
b/services/evolution-source-registry/evolution-source-registry.c
index 5319fff..1c2bf9e 100644
--- a/services/evolution-source-registry/evolution-source-registry.c
+++ b/services/evolution-source-registry/evolution-source-registry.c
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 #endif
 
+#include <libedataserver/libedataserver.h>
 #include <libebackend/libebackend.h>
 
 #include "evolution-source-registry-resource.h"
@@ -146,6 +147,10 @@ main (gint argc,
        EDBusServerExitCode exit_code;
        GError *error = NULL;
 
+#ifdef G_OS_WIN32
+       e_util_win32_initialize ();
+#endif
+
        setlocale (LC_ALL, "");
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
diff --git a/services/evolution-user-prompter/evolution-user-prompter.c 
b/services/evolution-user-prompter/evolution-user-prompter.c
index a0ebf91..0f1c96d 100644
--- a/services/evolution-user-prompter/evolution-user-prompter.c
+++ b/services/evolution-user-prompter/evolution-user-prompter.c
@@ -20,6 +20,8 @@
 #include <libintl.h>
 #include <glib/gi18n.h>
 
+#include <libedataserver/libedataserver.h>
+
 #include "prompt-user.h"
 
 static gboolean opt_keep_running = FALSE;
@@ -39,6 +41,10 @@ main (gint argc,
        EDBusServer *server;
        GError *error = NULL;
 
+#ifdef G_OS_WIN32
+       e_util_win32_initialize ();
+#endif
+
        setlocale (LC_ALL, "");
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");


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