From: Paul Date: Tue, 27 Aug 2013 08:45:42 +0000 (+0100) Subject: fix bug 2979, 'claws fails to load (empty) folderlist.xml and shows account wizard' X-Git-Tag: 3.9.3~52 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=76c91d8cceb7bdcdf8ede508fc1e1b349dcf930a fix bug 2979, 'claws fails to load (empty) folderlist.xml and shows account wizard' --- diff --git a/po/POTFILES.in b/po/POTFILES.in index 2599a2711..9d7a8a314 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -36,6 +36,7 @@ src/expldifdlg.c src/export.c src/exporthtml.c src/exportldif.c +src/file_checker.c src/folder.c src/foldersel.c src/folderview.c diff --git a/src/Makefile.am b/src/Makefile.am index 1a173ee9e..08bc2b381 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,6 +54,7 @@ old_abook_source = \ expldifdlg.c \ exporthtml.c \ exportldif.c \ + file_checker.c \ importldif.c \ importmutt.c \ importpine.c \ @@ -102,6 +103,7 @@ abook_headers = \ expldifdlg.h \ exporthtml.h \ exportldif.h \ + file_checker.h \ importldif.h \ importmutt.h \ importpine.h \ diff --git a/src/file_checker.c b/src/file_checker.c new file mode 100644 index 000000000..5205070bf --- /dev/null +++ b/src/file_checker.c @@ -0,0 +1,112 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2013 Paul Mangan + * and the Claws Mail team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#include "claws-features.h" +#endif + +#include "defs.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "utils.h" +#include "alertpanel.h" +#include "folder.h" + +static gboolean verify_folderlist_xml(); + +gboolean check_file_integrity() { + if (verify_folderlist_xml() != TRUE) + return FALSE; + + return TRUE; +} + +static gboolean verify_folderlist_xml() { + GNode *node; + static gchar *filename = NULL; + static gchar *bak = NULL; + time_t date; + struct tm *ts; + gchar buf[BUFFSIZE]; + + filename = folder_get_list_path(); + bak = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, + FOLDER_LIST, ".bak", NULL); + + if (is_file_exist(bak)) { + date = get_file_mtime(bak); + ts = localtime(&date); + strftime(buf, sizeof(buf), "%a %d-%b-%Y %H:%M %Z", ts); + } + + if (!is_file_exist(filename) && is_file_exist(bak)) { + AlertValue aval; + gchar *msg; + + msg = g_strdup_printf + (_("The file %s is missing! " + "Do you want to use the backup file from %s?"), FOLDER_LIST,buf); + aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL); + g_free(msg); + if (aval != G_ALERTALTERNATE) + return FALSE; + else { + if (copy_file(bak,filename,FALSE) < 0) { + alertpanel_warning(_("Could not copy %s to %s"),bak,filename); + return FALSE; + } + g_free(bak); + return TRUE; + } + + } + node = xml_parse_file(filename); + if (!node && is_file_exist(bak)) { + AlertValue aval; + gchar *msg; + + msg = g_strdup_printf + (_("The file %s is empty or corrupted! " + "Do you want to use the backup file from %s?"), FOLDER_LIST,buf); + aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL); + g_free(msg); + if (aval != G_ALERTALTERNATE) + return FALSE; + else { + if (copy_file(bak,filename,FALSE) < 0) { + alertpanel_warning(_("Could not copy %s to %s"),bak,filename); + return FALSE; + } + g_free(bak); + } + } + + return TRUE; +} diff --git a/src/file_checker.h b/src/file_checker.h new file mode 100644 index 000000000..e08ffe192 --- /dev/null +++ b/src/file_checker.h @@ -0,0 +1,31 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2013 Paul Mangan + * and the Claws Mail team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __FILE_CHECKER_H__ +#define __FILE_CHECKER_H__ + +#include +#include +#include + +gboolean check_file_integrity(); + +#endif + diff --git a/src/folder.c b/src/folder.c index 39ba0e4a7..1b4ec0390 100644 --- a/src/folder.c +++ b/src/folder.c @@ -88,7 +88,6 @@ void folder_init (Folder *folder, static gchar *folder_item_get_cache_file (FolderItem *item); static gchar *folder_item_get_mark_file (FolderItem *item); static gchar *folder_item_get_tags_file (FolderItem *item); -static gchar *folder_get_list_path (void); static GNode *folder_get_xml_node (Folder *folder); static Folder *folder_get_from_xml (GNode *node); static void folder_update_op_count_rec (GNode *node); @@ -4122,7 +4121,7 @@ static Folder *folder_get_from_xml(GNode *node) return folder; } -static gchar *folder_get_list_path(void) +gchar *folder_get_list_path(void) { static gchar *filename = NULL; diff --git a/src/folder.h b/src/folder.h index d87eb0cf7..44f69bb2c 100644 --- a/src/folder.h +++ b/src/folder.h @@ -998,4 +998,5 @@ gint folder_item_search_msgs_local (Folder *folder, SearchProgressNotify progress_cb, gpointer progress_data); +gchar *folder_get_list_path (void); #endif /* __FOLDER_H__ */ diff --git a/src/main.c b/src/main.c index f7a2eaad2..c7d3eac98 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,7 @@ #include #endif +#include "file_checker.h" #include "wizard.h" #ifdef HAVE_STARTUP_NOTIFICATION # define SN_API_NOT_YET_FROZEN @@ -1277,6 +1278,9 @@ int main(int argc, char *argv[]) mainwin = main_window_create(); + if (!check_file_integrity()) + exit(1); + #ifdef HAVE_NETWORKMANAGER_SUPPORT networkmanager_state_change_cb(nm_proxy,NULL,mainwin); #endif