2007-08-21 [wwp] 2.10.0cvs140
authorTristan Chabredier <wwp@claws-mail.org>
Tue, 21 Aug 2007 09:04:16 +0000 (09:04 +0000)
committerTristan Chabredier <wwp@claws-mail.org>
Tue, 21 Aug 2007 09:04:16 +0000 (09:04 +0000)
* src/main.c
* src/common/utils.h
Route glib's stdout/stderr messages to a log file (Windows only),
instead of loosing them.

ChangeLog
PATCHSETS
configure.ac
src/common/utils.h
src/main.c

index 6f925625849cb0f4efbaa2513a1b671a7359e48b..32a3d780d71a4be6113d2c86ef10edab373840ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-08-21 [wwp]       2.10.0cvs140
+
+       * src/main.c
+       * src/common/utils.h
+               Route glib's stdout/stderr messages to a log file (Windows only),
+               instead of loosing them.
+
 2007-08-21 [paul]      2.10.0cvs139
 
        * src/mainwindow.c
index 6578ade83b5c08c8352ceb93cdd241bc0f745d93..774ede0bb7501195df40e658540c7b4d6ab553db 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.2.2.12 -r 1.2.2.13 src/ldapctrl.c;  ) > 2.10.0cvs137.patchset
 ( cvs diff -u -r 1.61.2.65 -r 1.61.2.66 src/account.c;  cvs diff -u -r 1.105.2.107 -r 1.105.2.108 src/prefs_account.c;  cvs diff -u -r 1.49.2.32 -r 1.49.2.33 src/prefs_account.h;  ) > 2.10.0cvs138.patchset
 ( cvs diff -u -r 1.274.2.205 -r 1.274.2.206 src/mainwindow.c;  cvs diff -u -r 1.94.2.145 -r 1.94.2.146 src/messageview.c;  ) > 2.10.0cvs139.patchset
+( cvs diff -u -r 1.115.2.162 -r 1.115.2.163 src/main.c;  cvs diff -u -r 1.20.2.48 -r 1.20.2.49 src/common/utils.h;  ) > 2.10.0cvs140.patchset
index 8c6c55e194551dcedfe4f8c1d7135519bc977d6b..a9506a2b22a2601d4e257157a0f4003def882f8d 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=10
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=139
+EXTRA_VERSION=140
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 29b8ca90f94ed6e64a5d6417065ede0b3f351940..0ddd4099019137d46d2ed0feef2a7e37c09c4981 100644 (file)
@@ -108,6 +108,14 @@ gint g_chmod       (const gchar    *path,
        if (change_dir(dir) < 0) return val; \
 }
 
+#define CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(dir, val, code) \
+{ \
+       if (change_dir(dir) < 0) { \
+               code \
+               return val; \
+       } \
+}
+
 #define Xalloca(ptr, size, iffail) \
 { \
        if ((ptr = alloca(size)) == NULL) { \
index f3458725dcfc9252150bd025d832e6114010cc44..ca78c5e6f2f96a6e65f35e4803114d6dbb34301f 100644 (file)
@@ -664,6 +664,97 @@ static void main_vol_unmount_cb(GnomeVFSVolumeMonitor *vfs, GnomeVFSVolume *vol,
 }
 #endif
 
+#ifdef G_OS_WIN32
+static FILE* win32_debug_fp=NULL;
+static guint win32_log_handler_app_id;
+static guint win32_log_handler_glib_id;
+static guint win32_log_handler_gtk_id;
+
+static void win32_print_stdout(const gchar *string)
+{
+       if (win32_debug_fp) {
+               fprintf(win32_debug_fp, string);
+               fflush(win32_debug_fp);
+       }
+}
+
+static void win32_print_stderr(const gchar *string)
+{
+       if (win32_debug_fp) {
+               fprintf(win32_debug_fp, string);
+               fflush(win32_debug_fp);
+       }
+}
+
+static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
+{
+       if (win32_debug_fp) {
+               const gchar* type;
+
+               switch(log_level & G_LOG_LEVEL_MASK)
+               {
+                       case G_LOG_LEVEL_ERROR:
+                               type="error";
+                               break;
+                       case G_LOG_LEVEL_CRITICAL:
+                               type="critical";
+                               break;
+                       case G_LOG_LEVEL_WARNING:
+                               type="warning";
+                               break;
+                       case G_LOG_LEVEL_MESSAGE:
+                               type="message";
+                               break;
+                       case G_LOG_LEVEL_INFO:
+                               type="info";
+                               break;
+                       case G_LOG_LEVEL_DEBUG:
+                               type="debug";
+                               break;
+                       default:
+                               type="N/A";
+               }
+               if (log_domain)
+                       fprintf(win32_debug_fp, "%s: %s: %s", log_domain, type, message);
+               else
+                       fprintf(win32_debug_fp, "%s: %s", type, message);
+               fflush(win32_debug_fp);
+       }
+}
+
+static void win32_open_log(void)
+{
+       if (is_file_exist("claws-win32.log")) {
+               if (rename_force("claws-win32.log", "claws-win32.log.bak") < 0)
+                       FILE_OP_ERROR("claws-win32.log", "rename");
+       }
+       win32_debug_fp = fopen("claws-win32.log", "w");
+       if (win32_debug_fp)
+       {
+               g_set_print_handler(win32_print_stdout);
+               g_set_printerr_handler(win32_print_stdout);
+               win32_log_handler_app_id = g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION, win32_log, NULL);
+               win32_log_handler_glib_id = g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION, win32_log, NULL);
+               win32_log_handler_gtk_id = g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION, win32_log, NULL);
+       }
+}
+
+static void win32_close_log(void)
+{
+       if (win32_debug_fp)
+       {
+               g_log_remove_handler("", win32_log_handler_app_id);
+               g_log_remove_handler("GLib", win32_log_handler_glib_id);
+               g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
+               fclose(win32_debug_fp);
+               win32_debug_fp=NULL;
+       }
+}              
+#endif
+
 int main(int argc, char *argv[])
 {
 #ifdef MAEMO
@@ -682,7 +773,13 @@ int main(int argc, char *argv[])
        
        sc_starting = TRUE;
 
+#ifdef G_OS_WIN32
+       win32_open_log();
+#endif
        if (!claws_init(&argc, &argv)) {
+#ifdef G_OS_WIN32
+               win32_close_log();
+#endif
                return 0;
        }
 
@@ -697,6 +794,9 @@ int main(int argc, char *argv[])
                gtk_set_locale();
                gtk_init(&argc, &argv);
                crash_main(cmd.crash_params);
+#ifdef G_OS_WIN32
+               win32_close_log();
+#endif
                return 0;
        }
        crash_install_handlers();
@@ -754,6 +854,9 @@ int main(int argc, char *argv[])
                                   "currently available. This will cause "
                                   "crashes. You need to upgrade GTK+ or "
                                   "recompile Claws Mail."));
+#ifdef G_OS_WIN32
+               win32_close_log();
+#endif
                exit(1);
        }
 #else
@@ -763,6 +866,9 @@ int main(int argc, char *argv[])
                                   "currently available. This will cause "
                                   "crashes. You need to recompile "
                                   "Claws Mail."));
+#ifdef G_OS_WIN32
+               win32_close_log();
+#endif
                exit(1);
        }
 #endif 
@@ -776,7 +882,11 @@ int main(int argc, char *argv[])
        gtk_rc_parse(userrc);
        g_free(userrc);
 
+#ifdef G_OS_WIN32
+       CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
+#else
        CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
+#endif
        
        /* no config dir exists. See if we can migrate an old config. */
        if (!is_dir_exist(RC_DIR)) {
@@ -804,9 +914,13 @@ int main(int argc, char *argv[])
                /* If migration failed or the user didn't want to do it,
                 * we create a new one (and we'll hit wizard later). 
                 */
-               if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0)
+               if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0) {
+#ifdef G_OS_WIN32
+                       win32_close_log();
+#endif
                        exit(1);
        }
+       }
        
 
        if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) &&
@@ -827,7 +941,11 @@ int main(int argc, char *argv[])
        gtk_accel_map_load (userrc);
        g_free(userrc);
 
+#ifdef G_OS_WIN32
+       CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_rc_dir(), 1, win32_close_log(););
+#else
        CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
+#endif
 
        MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir());
        MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
@@ -856,7 +974,11 @@ int main(int argc, char *argv[])
        }
        set_log_file(LOG_DEBUG_FILTERING, "filtering.log");
 
+#ifdef G_OS_WIN32
+       CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
+#else
        CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
+#endif
 
        folder_system_init();
        prefs_common_read_config();
@@ -956,6 +1078,9 @@ int main(int argc, char *argv[])
                if (!run_wizard(mainwin, TRUE)) {
                        if (asked_for_migration)
                                remove_dir_recursive(RC_DIR);
+#ifdef G_OS_WIN32
+                       win32_close_log();
+#endif
                        exit(1);
                }
                main_window_reflect_prefs_all_now();
@@ -967,11 +1092,17 @@ int main(int argc, char *argv[])
                if (!run_wizard(mainwin, FALSE)) {
                        if (asked_for_migration)
                                remove_dir_recursive(RC_DIR);
+#ifdef G_OS_WIN32
+                       win32_close_log();
+#endif
                        exit(1);
                }
                account_read_config_all();
                if(!account_get_list()) {
                        exit_claws(mainwin);
+#ifdef G_OS_WIN32
+                       win32_close_log();
+#endif
                        exit(1);
                }
        }
@@ -1079,6 +1210,9 @@ int main(int argc, char *argv[])
                                   "external plugin. Please reinstall the "
                                   "plugin and try again."));
                        exit_claws(mainwin);
+#ifdef G_OS_WIN32
+                       win32_close_log();
+#endif
                        exit(1);
                }
        }
@@ -1172,6 +1306,9 @@ int main(int argc, char *argv[])
 
 #ifdef MAEMO
        osso_deinitialize(osso_context);
+#endif
+#ifdef G_OS_WIN32
+       win32_close_log();
 #endif
        exit_claws(mainwin);