diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | configure.in | 8 | ||||
-rw-r--r-- | libsylph/defs.h | 3 | ||||
-rw-r--r-- | libsylph/sylmain.c | 10 | ||||
-rw-r--r-- | plugin/test/test.c | 11 | ||||
-rw-r--r-- | src/libsylpheed-plugin-0.def | 14 | ||||
-rw-r--r-- | src/main.c | 70 | ||||
-rw-r--r-- | src/main.h | 1 | ||||
-rw-r--r-- | src/mainwindow.c | 56 | ||||
-rw-r--r-- | src/mainwindow.h | 1 | ||||
-rw-r--r-- | src/plugin.c | 48 | ||||
-rw-r--r-- | src/plugin.h | 6 | ||||
-rw-r--r-- | src/plugin_manager.c | 27 | ||||
-rw-r--r-- | src/update_check.c | 487 | ||||
-rw-r--r-- | src/update_check.h | 15 |
15 files changed, 720 insertions, 50 deletions
@@ -1,3 +1,16 @@ +2010-11-02 + + * libsylph/sylmain.c + libsylph/defs.h + src/update_check.[ch] + src/plugin_manager.c + src/plugin.[ch] + src/main.[ch] + src/libsylpheed-plugin-0.def + src/mainwindow.[ch] + plugin/test/test.c + configure.in: merged plug-in update check and automatic update patch. + 2010-10-25 * libsylph/procmime.[ch]: added procmime_get_part_fp_fp(). diff --git a/configure.in b/configure.in index 18eabd79..57b9dc3e 100644 --- a/configure.in +++ b/configure.in @@ -404,6 +404,14 @@ if test x"$ac_cv_enable_updatecheck" = xyes ; then AC_DEFINE(USE_UPDATE_CHECK, 1, Define if you want update check feature.) fi +dnl for update check feature +AC_ARG_ENABLE(updatecheckplugin, + [ --disable-updatecheckplugin Disable update check plugin feature], + [ac_cv_enable_updatecheckplugin=$enableval], [ac_cv_enable_updatecheckplugin=yes]) +if test x"$ac_cv_enable_updatecheckplugin" = xyes ; then + AC_DEFINE(USE_UPDATE_CHECK_PLUGIN, 1, Define if you want update check plugin feature.) +fi + dnl Check for d_type member in struct dirent AC_MSG_CHECKING([whether struct dirent has d_type member]) AC_CACHE_VAL(ac_cv_dirent_d_type,[ diff --git a/libsylph/defs.h b/libsylph/defs.h index c3790a18..8786fb27 100644 --- a/libsylph/defs.h +++ b/libsylph/defs.h @@ -72,7 +72,10 @@ #define MANUAL_HTML_INDEX "sylpheed.html" #define FAQ_HTML_INDEX "sylpheed-faq.html" #define HOMEPAGE_URI "http://sylpheed.sraoss.jp/" +#define DOWNLOAD_URI "http://sylpheed.sraoss.jp/download.php" #define VERSION_URI "http://sylpheed.sraoss.jp/version.txt" +#define PLUGIN_HOMEPAGE_URI "http://sylpheed.sraoss.jp/en/plugin.html" +#define PLUGIN_VERSION_URI "http://sylpheed.sraoss.jp/plugin_version.txt" #define FOLDER_LIST "folderlist.xml" #define CACHE_FILE ".sylpheed_cache" #define MARK_FILE ".sylpheed_mark" diff --git a/libsylph/sylmain.c b/libsylph/sylmain.c index bcd677b1..b753b3c4 100644 --- a/libsylph/sylmain.c +++ b/libsylph/sylmain.c @@ -57,6 +57,7 @@ G_DEFINE_TYPE(SylApp, syl_app, G_TYPE_OBJECT); enum { INIT_DONE, APP_EXIT, + APP_FORCE_EXIT, ADD_MSG, REMOVE_MSG, REMOVE_ALL_MSG, @@ -98,6 +99,15 @@ static void syl_app_class_init(SylAppClass *klass) syl_marshal_VOID__VOID, G_TYPE_NONE, 0); + app_signals[APP_FORCE_EXIT] = + g_signal_new("app-force-exit", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + syl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); app_signals[ADD_MSG] = g_signal_new("add-msg", G_TYPE_FROM_CLASS(gobject_class), diff --git a/plugin/test/test.c b/plugin/test/test.c index 9529d86e..b8bfa7a1 100644 --- a/plugin/test/test.c +++ b/plugin/test/test.c @@ -48,6 +48,8 @@ static void compose_destroy_cb(GObject *obj, gpointer compose); static void create_window(void); static void create_folderview_sub_widget(void); +gulong app_exit_handler_id = 0; + void plugin_load(void) { GList *list, *cur; @@ -76,8 +78,9 @@ void plugin_load(void) syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL); syl_plugin_add_menuitem("/Tools", "Plugin test", create_window, NULL); - g_signal_connect(syl_app_get(), "init-done", G_CALLBACK(init_done_cb), + g_signal_connect_after(syl_app_get(), "init-done", G_CALLBACK(init_done_cb), NULL); + app_exit_handler_id = g_signal_connect(syl_app_get(), "app-exit", G_CALLBACK(app_exit_cb), NULL); syl_plugin_signal_connect("folderview-menu-popup", @@ -99,6 +102,7 @@ void plugin_load(void) void plugin_unload(void) { g_print("test plug-in unloaded!\n"); + g_signal_handler_disconnect(syl_app_get(), app_exit_handler_id); } SylPluginInfo *plugin_info(void) @@ -113,6 +117,11 @@ gint plugin_interface_version(void) static void init_done_cb(GObject *obj, gpointer data) { + syl_plugin_update_check_set_check_url("http://localhost/version_pro.txt?"); + syl_plugin_update_check_set_download_url("http://localhost/download.php?sno=123&ver=VER&os=win"); + syl_plugin_update_check_set_jump_url("http://localhost/index.html"); + syl_plugin_update_check_set_check_plugin_url("http://localhost/plugin_version.txt"); + syl_plugin_update_check_set_jump_plugin_url("http://localhost/plugin.html"); g_print("test: %p: app init done\n", obj); } diff --git a/src/libsylpheed-plugin-0.def b/src/libsylpheed-plugin-0.def index b462ed3e..b7129663 100644 --- a/src/libsylpheed-plugin-0.def +++ b/src/libsylpheed-plugin-0.def @@ -88,7 +88,13 @@ EXPORTS syl_plugin_summary_write_unlock @ 86
syl_plugin_unload_all @ 87
syl_plugin_update_check @ 88
- syl_plugin_update_check_get_check_url @ 89
- syl_plugin_update_check_get_jump_url @ 90
- syl_plugin_update_check_set_check_url @ 91
- syl_plugin_update_check_set_jump_url @ 92
+ syl_plugin_update_check_get_check_plugin_url @ 89
+ syl_plugin_update_check_get_check_url @ 90
+ syl_plugin_update_check_get_download_url @ 91
+ syl_plugin_update_check_get_jump_plugin_url @ 92
+ syl_plugin_update_check_get_jump_url @ 93
+ syl_plugin_update_check_set_check_plugin_url @ 94
+ syl_plugin_update_check_set_check_url @ 95
+ syl_plugin_update_check_set_download_url @ 96
+ syl_plugin_update_check_set_jump_plugin_url @ 97
+ syl_plugin_update_check_set_jump_url @ 98
@@ -132,6 +132,8 @@ static struct RemoteCmd { gchar *open_msg; gboolean configdir; gboolean exit; + gboolean restart; + const gchar *argv0; #ifdef G_OS_WIN32 gushort ipcport; #endif @@ -615,6 +617,8 @@ static void parse_cmd_opt(int argc, char *argv[]) cmd.compose = TRUE; cmd.compose_mailto = NULL; } + + cmd.argv0 = argv[0]; } static gint get_queued_message_num(void) @@ -758,6 +762,50 @@ static void setup_rc_dir(void) syl_setup_rc_dir(); } +static void app_restart(void) +{ + gchar *cmdline; + GError *error = NULL; +#ifdef G_OS_WIN32 + if (cmd.configdir) { + cmdline = g_strdup_printf("\"%s\"%s --configdir \"%s\" --ipcport %d", + cmd.argv0, + get_debug_mode() ? " --debug" : "", + get_rc_dir(), + cmd.ipcport); + } else { + cmdline = g_strdup_printf("\"%s\"%s --ipcport %d", + cmd.argv0, + get_debug_mode() ? " --debug" : "", + cmd.ipcport); + } +#else + if (cmd.configdir) { + cmdline = g_strdup_printf("\"%s\"%s --configdir \"%s\"", + cmd.argv0, + get_debug_mode() ? " --debug" : "", + get_rc_dir()); + } else { + cmdline = g_strdup_printf("\"%s\"%s", + cmd.argv0, + get_debug_mode() ? " --debug" : ""); + } +#endif + if (!g_spawn_command_line_async(cmdline, &error)) { + alertpanel_error("restart failed\n'%s'\n%s", cmdline, error->message); + g_error_free(error); + } + g_free(cmdline); +} + +void app_will_restart(gboolean force) +{ + cmd.restart = TRUE; + app_will_exit(force); + /* canceled */ + cmd.restart = FALSE; +} + void app_will_exit(gboolean force) { MainWindow *mainwin; @@ -794,6 +842,8 @@ void app_will_exit(gboolean force) manage_window_focus_in(mainwin->window, NULL, NULL); } + if (force) + g_signal_emit_by_name(syl_app_get(), "app-force-exit"); g_signal_emit_by_name(syl_app_get(), "app-exit"); inc_autocheck_timer_remove(); @@ -831,11 +881,23 @@ void app_will_exit(gboolean force) syl_cleanup(); lock_socket_remove(); +#ifdef USE_UPDATE_CHECK_PLUGIN +#ifdef G_OS_WIN32 + cur = gtk_window_list_toplevels(); + g_list_foreach(cur, (GFunc)gtk_widget_hide, NULL); + g_list_free(cur); + update_check_spawn_plugin_updater(); +#endif +#endif + cleanup_console(); if (gtk_main_level() > 0) gtk_main_quit(); + if (cmd.restart) + app_restart(); + exit(0); } @@ -1223,8 +1285,16 @@ static void plugin_init(void) ADD_SYM(update_check); ADD_SYM(update_check_set_check_url); ADD_SYM(update_check_get_check_url); + ADD_SYM(update_check_set_download_url); + ADD_SYM(update_check_get_download_url); ADD_SYM(update_check_set_jump_url); ADD_SYM(update_check_get_jump_url); +#ifdef USE_UPDATE_CHECK_PLUGIN + ADD_SYM(update_check_set_check_plugin_url); + ADD_SYM(update_check_get_check_plugin_url); + ADD_SYM(update_check_set_jump_plugin_url); + ADD_SYM(update_check_get_jump_plugin_url); +#endif /* USE_UPDATE_CHECK_PLUGIN */ #endif ADD_SYM(alertpanel_full); @@ -25,5 +25,6 @@ extern gchar *prog_version; void app_will_exit (gboolean force); +void app_will_restart (gboolean force); #endif /* __MAIN_H__ */ diff --git a/src/mainwindow.c b/src/mainwindow.c index c1329202..fbfc1a5d 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -535,6 +535,10 @@ static void help_cmdline_cb (MainWindow *mainwin, static void update_check_cb (MainWindow *mainwin, guint action, GtkWidget *widget); +#ifdef USE_UPDATE_CHECK_PLUGIN +static void update_check_plugin_cb(MainWindow *mainwin, guint action, + GtkWidget *widget); +#endif #endif static void scan_tree_func (Folder *folder, @@ -899,6 +903,9 @@ static GtkItemFactoryEntry mainwin_entries[] = #if USE_UPDATE_CHECK {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"}, {N_("/_Help/_Update check..."), NULL, update_check_cb, 0, NULL}, +#ifdef USE_UPDATE_CHECK_PLUGIN + {N_("/_Help/Update check _plugin..."), NULL, update_check_plugin_cb, 0, NULL}, +#endif #endif {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"}, {N_("/_Help/_About"), NULL, about_show, 0, NULL} @@ -1450,29 +1457,15 @@ GtkWidget *main_window_get_message_window(MainWindow *mainwin) } } -void main_window_change_layout(MainWindow *mainwin, LayoutType layout, - SeparateType type) +void main_window_hide(MainWindow *mainwin) { GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview); GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview); GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); GtkWidget *qsearch_wid = GTK_WIDGET_PTR(mainwin->summaryview->qsearch); GtkWidget *vbox_summary = qsearch_wid->parent; - GtkWidget *focus_widget; - - debug_print("Changing window layout type (layout: %d -> %d, separation: %d -> %d)\n", prefs_common.layout_type, layout, mainwin->type, type); - - if (prefs_common.layout_type == layout && mainwin->type == type) - return; - - /* keep previous focus */ - focus_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window)); /* remove widgets from those containers */ - gtk_widget_ref(folder_wid); - gtk_widget_ref(summary_wid); - gtk_widget_ref(message_wid); - gtk_widget_ref(qsearch_wid); gtkut_container_remove (GTK_CONTAINER(folder_wid->parent), folder_wid); gtkut_container_remove @@ -1515,6 +1508,31 @@ void main_window_change_layout(MainWindow *mainwin, LayoutType layout, } gtk_widget_hide(mainwin->window); +} + +void main_window_change_layout(MainWindow *mainwin, LayoutType layout, + SeparateType type) +{ + GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview); + GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview); + GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); + GtkWidget *qsearch_wid = GTK_WIDGET_PTR(mainwin->summaryview->qsearch); + GtkWidget *focus_widget; + + debug_print("Changing window layout type (layout: %d -> %d, separation: %d -> %d)\n", prefs_common.layout_type, layout, mainwin->type, type); + + if (prefs_common.layout_type == layout && mainwin->type == type) + return; + + /* keep previous focus */ + focus_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window)); + + gtk_widget_ref(folder_wid); + gtk_widget_ref(summary_wid); + gtk_widget_ref(message_wid); + gtk_widget_ref(qsearch_wid); + + main_window_hide(mainwin); main_window_set_widgets(mainwin, layout, type); gtk_widget_show(mainwin->window); if (focus_widget) @@ -4137,6 +4155,14 @@ static void update_check_cb(MainWindow *mainwin, guint action, { update_check(TRUE); } + +#ifdef USE_UPDATE_CHECK_PLUGIN +static void update_check_plugin_cb(MainWindow *mainwin, guint action, + GtkWidget *widget) +{ + update_check_plugin(TRUE); +} +#endif #endif static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data) diff --git a/src/mainwindow.h b/src/mainwindow.h index 54686543..50550c26 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -154,6 +154,7 @@ MainWindow *main_window_get (void); GtkWidget *main_window_get_folder_window (MainWindow *mainwin); GtkWidget *main_window_get_message_window (MainWindow *mainwin); +void main_window_hide (MainWindow *mainwin); void main_window_change_layout (MainWindow *mainwin, LayoutType layout, SeparateType type); diff --git a/src/plugin.c b/src/plugin.c index baead872..6a656f06 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1080,6 +1080,22 @@ const gchar *syl_plugin_update_check_get_check_url(void) return SAFE_CALL_RET(func); } +void syl_plugin_update_check_set_download_url(const gchar *url) +{ + void (*func)(const gchar *); + + func = syl_plugin_lookup_symbol("update_check_set_download_url"); + SAFE_CALL_ARG1(func, url); +} + +const gchar *syl_plugin_update_check_get_download_url(void) +{ + const gchar * (*func)(void); + + func = syl_plugin_lookup_symbol("update_check_get_download_url"); + return SAFE_CALL_RET(func); +} + void syl_plugin_update_check_set_jump_url(const gchar *url) { void (*func)(const gchar *); @@ -1096,6 +1112,38 @@ const gchar *syl_plugin_update_check_get_jump_url(void) return SAFE_CALL_RET(func); } +void syl_plugin_update_check_set_check_plugin_url(const gchar *url) +{ + void (*func)(const gchar *); + + func = syl_plugin_lookup_symbol("update_check_set_check_plugin_url"); + SAFE_CALL_ARG1(func, url); +} + +const gchar *syl_plugin_update_check_get_check_plugin_url(void) +{ + const gchar * (*func)(void); + + func = syl_plugin_lookup_symbol("update_check_get_check_plugin_url"); + return SAFE_CALL_RET(func); +} + +void syl_plugin_update_check_set_jump_plugin_url(const gchar *url) +{ + void (*func)(const gchar *); + + func = syl_plugin_lookup_symbol("update_check_set_jump_plugin_url"); + SAFE_CALL_ARG1(func, url); +} + +const gchar *syl_plugin_update_check_get_jump_plugin_url(void) +{ + const gchar * (*func)(void); + + func = syl_plugin_lookup_symbol("update_check_get_jump_plugin_url"); + return SAFE_CALL_RET(func); +} + gint syl_plugin_alertpanel_full(const gchar *title, const gchar *message, gint type, gint default_value, gboolean can_disable, diff --git a/src/plugin.h b/src/plugin.h index 4d0ea5df..60a0d263 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -246,8 +246,14 @@ void syl_plugin_inc_unlock (void); void syl_plugin_update_check (gboolean show_dialog_always); void syl_plugin_update_check_set_check_url (const gchar *url); const gchar *syl_plugin_update_check_get_check_url (void); +void syl_plugin_update_check_set_download_url (const gchar *url); +const gchar *syl_plugin_update_check_get_download_url (void); void syl_plugin_update_check_set_jump_url (const gchar *url); const gchar *syl_plugin_update_check_get_jump_url (void); +void syl_plugin_update_check_set_check_plugin_url (const gchar *url); +const gchar *syl_plugin_update_check_get_check_plugin_url(void); +void syl_plugin_update_check_set_jump_plugin_url (const gchar *url); +const gchar *syl_plugin_update_check_get_jump_plugin_url(void); /* type corresponds to AlertType * default_value and return value corresponds to AlertValue */ diff --git a/src/plugin_manager.c b/src/plugin_manager.c index 53195fe9..60ab4137 100644 --- a/src/plugin_manager.c +++ b/src/plugin_manager.c @@ -31,7 +31,10 @@ #include "plugin.h" #include "plugin_manager.h" #include "manage_window.h" +#include "alertpanel.h" #include "gtkutils.h" +#include "update_check.h" +#include "utils.h" static struct PluginManagerWindow { GtkWidget *window; @@ -97,10 +100,21 @@ void plugin_manager_open(void) manage_window_focus_in(pm_window.window, NULL, NULL); } +#ifdef USE_UPDATE_CHECK_PLUGIN +static gint plugin_manager_update_check(void) +{ + update_check_plugin(TRUE); + return TRUE; +} +#endif /* USE_UPDATE_CHECK_PLUGIN */ + static void plugin_manager_create(void) { GtkWidget *window; GtkWidget *vbox; +#ifdef USE_UPDATE_CHECK_PLUGIN + GtkWidget *update_check_btn; +#endif GtkWidget *close_btn; GtkWidget *confirm_area; @@ -122,8 +136,15 @@ static void plugin_manager_create(void) gtk_container_add(GTK_CONTAINER(window), vbox); gtkut_stock_button_set_create(&confirm_area, +#ifdef USE_UPDATE_CHECK_PLUGIN + &update_check_btn, _("Check for _update"), + &close_btn, GTK_STOCK_CLOSE, + NULL, NULL); +#else &close_btn, GTK_STOCK_CLOSE, - NULL, NULL, NULL, NULL); + NULL, NULL, + NULL, NULL); +#endif gtk_widget_show(confirm_area); gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0); gtk_widget_grab_default(close_btn); @@ -132,6 +153,10 @@ static void plugin_manager_create(void) G_CALLBACK(plugin_manager_deleted), NULL); g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(key_pressed), NULL); +#ifdef USE_UPDATE_CHECK_PLUGIN + g_signal_connect(G_OBJECT(update_check_btn), "clicked", + G_CALLBACK(plugin_manager_update_check), NULL); +#endif g_signal_connect(G_OBJECT(close_btn), "clicked", G_CALLBACK(plugin_manager_deleted), NULL); diff --git a/src/update_check.c b/src/update_check.c index b5dffeb1..44f931ca 100644 --- a/src/update_check.c +++ b/src/update_check.c @@ -43,11 +43,40 @@ #include "socket.h" #include "utils.h" #include "version.h" +#include "plugin.h" static gchar *check_url = NULL; +static gchar *download_url = NULL; static gchar *jump_url = NULL; +#ifdef USE_UPDATE_CHECK_PLUGIN +static gchar *check_plugin_url = NULL; +static gchar *jump_plugin_url = NULL; +#endif /* USE_UPDATE_CHECK_PLUGIN */ -static gboolean compare_version(gint major, gint minor, gint micro, +static gint compare_version(gint lmajor, gint lminor, gint lmicro, + gint rmajor, gint rminor, gint rmicro) +{ + debug_print("comparing %d.%d.%d <> %d.%d.%d\n", + lmajor, lminor, lmicro, + rmajor, rminor, rmicro); + + if (lmajor > rmajor) + return 1; + if (lmajor < rmajor) + return -1; + if (lminor > rminor) + return 1; + if (lminor < rminor) + return -1; + if (lmicro > rmicro) + return 1; + if (lmicro < rmicro) + return -1; + + return 0; +} + +static gboolean compare_sylpheed_version(gint major, gint minor, gint micro, const gchar *extra, gboolean remote_is_release, gboolean cur_ver_is_release) { @@ -56,18 +85,15 @@ static gboolean compare_version(gint major, gint minor, gint micro, remote_is_release ? "release" : "devel", cur_ver_is_release ? "release" : "devel"); - if (major > MAJOR_VERSION) - return TRUE; - if (major < MAJOR_VERSION) - return FALSE; - if (minor > MINOR_VERSION) - return TRUE; - if (minor < MINOR_VERSION) - return FALSE; - if (micro > MICRO_VERSION) + switch (compare_version(major, minor, micro, + MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION)) { + case 1: return TRUE; - if (micro < MICRO_VERSION) + case -1: return FALSE; + default: + break; + } /* compare extra version 3.0.0.a (rel) > 3.0.0 (rel) @@ -99,7 +125,7 @@ static void parse_version_string(const gchar *ver, gint *major, gint *minor, *minor = atoi(vers[1]); if (vers[2]) { *micro = atoi(vers[2]); - if (vers[3]) { + if (vers[3] && extra) { *extra = g_strdup(vers[3]); } } @@ -108,6 +134,95 @@ static void parse_version_string(const gchar *ver, gint *major, gint *minor, g_strfreev(vers); } +#ifdef G_OS_WIN32 +static gboolean spawn_update_manager(void) +{ + gchar *src = NULL, *dest = NULL, *quoted_uri = NULL; + gchar *cmdline[] = {NULL, "/uri", NULL, NULL}; + GError *error = NULL; + gboolean ret = FALSE; + + src = g_strconcat(get_startup_dir(), G_DIR_SEPARATOR_S, "update-manager.exe", NULL); + if (!is_file_exist(src)) { + g_warning("Not found update-manager.exe"); + goto finish; + } + dest = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "sylpheed-update-manager.exe", NULL); + if (copy_file(src, dest, FALSE) < 0) { + g_warning("Couldn't copy update-manager.exe"); + goto finish; + } + quoted_uri = g_strdup_printf("'%s'", download_url); + cmdline[0] = dest; + cmdline[2] = quoted_uri; + if (g_spawn_async + (NULL, cmdline, NULL, + G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + NULL, NULL, NULL, &error) == FALSE) { + g_warning("Couldn't execute update-manager.exe"); + if (error) { + g_warning("g_spawn_async: %s", error->message); + g_error_free(error); + } + } else { + ret = TRUE; + } +finish: + g_free(src); + g_free(dest); + g_free(quoted_uri); + return ret; +} + +#ifdef USE_UPDATE_CHECK_PLUGIN +static gchar *plugin_updater_ini = NULL; + +void update_check_spawn_plugin_updater(void) +{ + gchar *exe = NULL, *quoted_ini = NULL; + gchar *cmdline[] = {NULL, "/ini", NULL, NULL}; + GError *error = NULL; + gboolean ret = FALSE; + + if (!plugin_updater_ini) + return ret; + if (!is_file_exist(plugin_updater_ini)) { + g_warning("Not found %s", plugin_updater_ini); + goto finish; + } + exe = g_strconcat(get_startup_dir(), G_DIR_SEPARATOR_S, "plugin-updater.exe", NULL); + if (!is_file_exist(exe)) { + g_warning("Not found plugin-updater.exe"); + goto finish; + } + + quoted_ini = g_strdup_printf("'%s'", plugin_updater_ini); + cmdline[0] = exe; + cmdline[2] = quoted_ini; + if (g_spawn_sync + (NULL, cmdline, NULL, + G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + NULL, NULL, NULL, NULL, NULL, &error) == FALSE) { + g_warning("Couldn't execute plugin-updater.exe"); + debug_print("Couldn't execute plugin-updater.exe\n"); + if (error) { + g_warning("g_spawn_async: %s", error->message); + debug_print("g_spawn_async: %s\n", error->message); + g_error_free(error); + } + } else { + ret = TRUE; + } +finish: + g_free(exe); + g_free(quoted_ini); + g_free(plugin_updater_ini); + plugin_updater_ini = NULL; + return ret; +} +#endif /* USE_UPDATE_CHECK_PLUGIN */ +#endif /* G_OS_WIN32 */ + static void update_dialog(const gchar *new_ver, const gchar *disp_ver, gboolean manual) { @@ -139,7 +254,14 @@ static void update_dialog(const gchar *new_ver, const gchar *disp_ver, manual ? FALSE : TRUE, GTK_STOCK_YES, GTK_STOCK_NO, NULL); if ((val & G_ALERT_VALUE_MASK) == G_ALERTDEFAULT) { +#ifdef G_OS_WIN32 + if (!download_url) + update_check_set_download_url(DOWNLOAD_URI); + if (!spawn_update_manager()) + open_uri(jump_url, prefs_common.uri_cmd); +#else open_uri(jump_url, prefs_common.uri_cmd); +#endif } if (val & G_ALERTDISABLE) { prefs_common.auto_update_check = FALSE; @@ -212,14 +334,14 @@ static void update_check_cb(GPid pid, gint status, gpointer data) if (!strcmp(key, "RELEASE")) { parse_version_string(val, &major, &minor, µ, &extra); - result = compare_version(major, minor, micro, extra, - TRUE, cur_ver_is_release); + result = compare_sylpheed_version(major, minor, micro, extra, + TRUE, cur_ver_is_release); rel_result = result; } else if (!cur_ver_is_release && !strcmp(key, "DEVEL")) { parse_version_string(val, &major, &minor, µ, &extra); - result = compare_version(major, minor, micro, extra, - FALSE, cur_ver_is_release); + result = compare_sylpheed_version(major, minor, micro, extra, + FALSE, cur_ver_is_release); dev_result = result; } @@ -265,16 +387,13 @@ static void update_check_cb(GPid pid, gint status, gpointer data) gdk_threads_leave(); } -void update_check(gboolean show_dialog_always) +static void spawn_curl(gchar *url, GChildWatchFunc func, gpointer data) { gchar *cmdline[8] = {"curl", "--silent", "--max-time", "10"}; + gint argc = 4; GPid pid; GError *error = NULL; - if (!check_url) - update_check_set_check_url - ("http://sylpheed.sraoss.jp/version.txt?"); - if (child_stdout > 0) { debug_print("update check is in progress\n"); return; @@ -282,16 +401,15 @@ void update_check(gboolean show_dialog_always) child_stdout = 0; - debug_print("update_check: getting latest version from %s\n", check_url); + debug_print("spawn_curl: getting from %s\n", url); - cmdline[4] = check_url; + cmdline[argc++] = url; if (prefs_common.use_http_proxy && prefs_common.http_proxy_host && prefs_common.http_proxy_host[0] != '\0') { - cmdline[5] = "--proxy"; - cmdline[6] = prefs_common.http_proxy_host; - cmdline[7] = NULL; - } else - cmdline[5] = NULL; + cmdline[argc++] = "--proxy"; + cmdline[argc++] = prefs_common.http_proxy_host; + } + cmdline[argc++] = NULL; if (g_spawn_async_with_pipes (NULL, cmdline, NULL, @@ -315,7 +433,280 @@ void update_check(gboolean show_dialog_always) return; } - g_child_watch_add(pid, update_check_cb, (gpointer)show_dialog_always); + g_child_watch_add(pid, func, data); +} + +#ifdef USE_UPDATE_CHECK_PLUGIN +struct download_plugin_info { + const gchar *filename; + const SylPluginInfo* info; + gchar *url; + gint major, minor, micro; +}; + +static void download_plugin_info_free(struct download_plugin_info *pinfo) +{ + if (!pinfo) + return; + g_free(pinfo->url); + g_free(pinfo); +} + +static GHashTable *get_plugin_version_table(void) +{ + GSList *list, *cur; + SylPluginInfo *info; + GModule *module; + struct download_plugin_info *pinfo; + GHashTable *plugin_version_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)download_plugin_info_free); + + list = syl_plugin_get_module_list(); + for (cur = list; cur != NULL; cur = cur->next) { + module = (GModule *)cur->data; + + info = syl_plugin_get_info(module); + if (info) { + pinfo = g_new0(struct download_plugin_info, 1); + pinfo->filename = g_module_name(module); + pinfo->info = info; + g_hash_table_insert(plugin_version_table, info->name, pinfo); + } else { + debug_print("info not found: %s\n", g_module_name(module)); + } + } + + return plugin_version_table; +} + +#ifdef G_OS_WIN32 +static gboolean write_plugin_updater_ini(GSList *list) +{ + guint num, h = 12; + struct download_plugin_info *pinfo; + GString *ini = g_string_new("[Settings]\n"); + GSList *cur; + gchar *basename, *p; + gboolean ret = TRUE; + + num = g_slist_length(list); + g_string_append_printf(ini, "NumFields=%d\n", num+1); + + num = 0; + g_string_append_printf(ini, "\n[Field %d]\n", ++num); + g_string_append_printf(ini, "Type=GroupBox\n"); + g_string_append_printf(ini, "Left=0\n"); + g_string_append_printf(ini, "Right=-1\n"); + g_string_append_printf(ini, "Top=0\n"); + g_string_append_printf(ini, "Bottom=-5\n"); + g_string_append_printf(ini, "Text=\" Select update plugins \"\n"); + + for (cur = list; cur != NULL; cur = cur->next) { + pinfo = cur->data; + g_string_append_printf(ini, "\n[Field %d]\n", ++num); + g_string_append_printf(ini, "Type=checkbox\n"); + g_string_append_printf(ini, "Text=%s %s -> %d.%d.%d\n", + pinfo->info->name, pinfo->info->version, + pinfo->major, pinfo->minor, pinfo->micro); + g_string_append_printf(ini, "Left=10\n"); + g_string_append_printf(ini, "Right=-10\n"); + g_string_append_printf(ini, "Top=%u\n", (h+=5)); + g_string_append_printf(ini, "Bottom=%u\n", (h+=8)); + g_string_append_printf(ini, "State=1\n"); + g_string_append_printf(ini, "URL=%s\n", pinfo->url); + g_string_append_printf(ini, "name=%s\n", pinfo->info->name); + + basename = g_path_get_basename(pinfo->filename); + p = strrchr(basename, '.'); + if (p) *p = '\0'; /* cut ".dll" */ + g_string_append_printf(ini, "basename=%s\n", basename); + g_free(basename); + } + + debug_print("write_plugin_updater_ini:\n%s\n", ini->str); + + plugin_updater_ini = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "sylpheed-plugin-updater.ini", NULL); + if (str_write_to_file(ini->str, plugin_updater_ini) < 0) { + g_free(plugin_updater_ini); + plugin_updater_ini = NULL; + ret = FALSE; + } + + g_string_free(ini, TRUE); + return ret; +} +#endif /* G_OS_WIN32 */ + +static void update_plugin_dialog(GString *text, GSList *list) +{ + AlertValue val; + + if (!jump_plugin_url) + update_check_set_jump_plugin_url(PLUGIN_HOMEPAGE_URI); + + val = alertpanel_full(_("New version found"), text->str, + ALERT_QUESTION, + G_ALERTDEFAULT, + FALSE, + GTK_STOCK_YES, GTK_STOCK_NO, NULL); + if ((val & G_ALERT_VALUE_MASK) == G_ALERTDEFAULT) { +#ifdef G_OS_WIN32 + if (write_plugin_updater_ini(list)) + app_will_restart(TRUE); +#else + open_uri(jump_plugin_url, prefs_common.uri_cmd); +#endif + } +} + +static void update_check_plugin_cb(GPid pid, gint status, gpointer data) +{ + gchar **lines; + gchar *key, *val, *p; + gchar *cur_ver; + gint i; + gboolean show_dialog_always = (gboolean)data; + gchar buf[BUFFSIZE]; + ssize_t size; + GHashTable *plugin_version_table = NULL; + struct download_plugin_info *pinfo = NULL; + gboolean result = FALSE; + gboolean got_version = FALSE; + GString *text = NULL; + GSList *list = NULL; + + debug_print("update_check_plugin_cb\n"); + + if (!child_stdout) { + g_spawn_close_pid(pid); + return; + } + + size = read(child_stdout, buf, sizeof(buf) - 1); + if (size < 0) { + fd_close(child_stdout); + child_stdout = 0; + g_spawn_close_pid(pid); + return; + } + buf[size] = '\0'; + + fd_close(child_stdout); + child_stdout = 0; + g_spawn_close_pid(pid); + + lines = g_strsplit(buf, "\n", -1); + plugin_version_table = get_plugin_version_table(); + text = g_string_new(_("A newer version of plugin has been found.\n" + "Upgrade now?\n")); + + for (i = 0; lines[i] != NULL; i++) { + gint new_major = 0, new_minor = 0, new_micro = 0; + gint cur_major = 0, cur_minor = 0, cur_micro = 0; + debug_print("update_check_plugin: %s\n", lines[i]); + p = strchr(lines[i], '='); + if (!p) continue; + key = g_strndup(lines[i], p - lines[i]); + val = p + 1; + + parse_version_string(val, &new_major, &new_minor, &new_micro, NULL); + if (new_major + new_minor + new_micro != 0) { + got_version = TRUE; + } + + pinfo = g_hash_table_lookup(plugin_version_table, key); + if (pinfo && (cur_ver = pinfo->info->version)) { + parse_version_string(cur_ver, &cur_major, &cur_minor, &cur_micro, NULL); + if (0 < compare_version(new_major, new_minor, new_micro, + cur_major, cur_minor, cur_micro)) { + g_string_append_printf(text, "\n %s %d.%d.%d -> %d.%d.%d", key, + cur_major, cur_minor, cur_micro, + new_major, new_minor, new_micro); + + result = TRUE; + + debug_print("val = %s\n", val); + p = strchr(val, ','); + if (p) { + struct download_plugin_info *pinfo2 = g_new0(struct download_plugin_info, 1); + pinfo2->filename = pinfo->filename; + pinfo2->info = pinfo->info; + pinfo2->url = g_strdup(p+1); /* skip ',' */ + pinfo2->major = new_major; + pinfo2->minor = new_minor; + pinfo2->micro = new_micro; + list = g_slist_append(list, pinfo2); + } + } + } + + g_free(key); + } + + g_strfreev(lines); + g_hash_table_destroy(plugin_version_table); + + debug_print("%s\n", text->str); + + gdk_threads_enter(); + + if (!gtkut_window_modal_exist() && !inc_is_active()) { + if (result) { + update_plugin_dialog(text, list); + list = NULL; + } else if (show_dialog_always) { + if (got_version) + alertpanel_message(_("Information"), + _("Sylpheed plugins are already the latest version."), + ALERT_NOTICE); + else + alertpanel_error(_("Couldn't get the version information of plugins.")); + } + } else { + debug_print("update_check_plugin_cb: modal dialog exists or incorporation is active. Disabling update dialog.\n"); + } + + g_string_free(text, TRUE); + g_slist_foreach(list, (GFunc)download_plugin_info_free, NULL); + g_slist_free(list); + + gdk_threads_leave(); +} + +void update_check_plugin(gboolean show_dialog_always) +{ + gchar buf[1024]; + + if (!check_plugin_url) { +#ifdef G_OS_WIN32 + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=win", PLUGIN_VERSION_URI, VERSION); +#else + if (strstr(TARGET_ALIAS, "linux")) + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=linux", PLUGIN_VERSION_URI, VERSION); + else + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=other", PLUGIN_VERSION_URI, VERSION); +#endif + update_check_set_check_plugin_url(buf); + } + spawn_curl(check_plugin_url, update_check_plugin_cb, (gpointer)show_dialog_always); +} +#endif /* USE_UPDATE_CHECK_PLUGIN */ + +void update_check(gboolean show_dialog_always) +{ + gchar buf[1024]; + + if (!check_url) { +#ifdef G_OS_WIN32 + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=win", VERSION_URI); +#else + if (strstr(TARGET_ALIAS, "linux")) + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=linux", VERSION_URI, VERSION); + else + g_snprintf(buf, sizeof(buf), "%s?ver=%s&os=other", VERSION_URI, VERSION); +#endif + update_check_set_check_url(buf); + } + spawn_curl(check_url, update_check_cb, (gpointer)show_dialog_always); } void update_check_set_check_url(const gchar *url) @@ -330,6 +721,18 @@ const gchar *update_check_get_check_url(void) return check_url; } +void update_check_set_download_url(const gchar *url) +{ + if (download_url) + g_free(download_url); + download_url = g_strdup(url); +} + +const gchar *update_check_get_download_url(void) +{ + return download_url; +} + void update_check_set_jump_url(const gchar *url) { if (jump_url) @@ -342,4 +745,30 @@ const gchar *update_check_get_jump_url(void) return jump_url; } +#ifdef USE_UPDATE_CHECK_PLUGIN +void update_check_set_check_plugin_url(const gchar *url) +{ + if (check_plugin_url) + g_free(check_plugin_url); + check_plugin_url = g_strdup(url); +} + +const gchar *update_check_get_check_plugin_url(void) +{ + return check_plugin_url; +} + +void update_check_set_jump_plugin_url(const gchar *url) +{ + if (jump_plugin_url) + g_free(jump_plugin_url); + jump_plugin_url = g_strdup(url); +} + +const gchar *update_check_get_jump_plugin_url(void) +{ + return jump_plugin_url; +} +#endif /* USE_UPDATE_CHECK_PLUGIN */ + #endif /* USE_UPDATE_CHECK */ diff --git a/src/update_check.h b/src/update_check.h index 86d6a7e9..ac4c4770 100644 --- a/src/update_check.h +++ b/src/update_check.h @@ -29,12 +29,27 @@ #include <glib.h> void update_check (gboolean show_dialog_always); +void update_check_plugin (gboolean show_dialog_always); +#ifdef G_OS_WIN32 +#ifdef USE_UPDATE_CHECK_PLUGIN +void update_check_spawn_plugin_updater(void); +#endif +#endif void update_check_set_check_url (const gchar *url); const gchar *update_check_get_check_url (void); +void update_check_set_download_url (const gchar *url); +const gchar *update_check_get_download_url(void); void update_check_set_jump_url (const gchar *url); const gchar *update_check_get_jump_url (void); +#ifdef USE_UPDATE_CHECK_PLUGIN +void update_check_set_check_plugin_url (const gchar *url); +const gchar *update_check_get_check_plugin_url(void); +void update_check_set_jump_plugin_url (const gchar *url); +const gchar *update_check_get_jump_plugin_url(void); +#endif /* USE_UPDATE_CHECK_PLUGIN */ + #endif /* USE_UPDATE_CHECK */ #endif /* __UPDATE_CHECK_H__ */ |