Added support for local image attachments to the Litehtml plugin
[claws.git] / src / file_checker.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2013 Paul Mangan <paul@claws-mail.org> 
4  * and the Claws Mail team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  * 
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #include "claws-features.h"
24 #endif
25
26 #include "defs.h"
27
28 #include <glib.h>
29 #include <glib/gi18n.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <gtk/gtk.h>
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <ctype.h>
37
38 #include "file-utils.h"
39 #include "utils.h"
40 #include "alertpanel.h"
41 #include "folder.h"
42
43 static gboolean verify_folderlist_xml();
44
45 gboolean check_file_integrity()
46 {
47         if (verify_folderlist_xml() != TRUE)
48                 return FALSE;
49
50         return TRUE;
51 }
52
53 static gboolean verify_folderlist_xml()
54 {
55         GNode *node;
56         static gchar *filename = NULL;
57         static gchar *bak = NULL;
58         time_t date;
59         struct tm *ts;
60         gchar buf[BUFFSIZE];
61
62         filename = folder_get_list_path();
63         bak = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
64                           FOLDER_LIST, ".bak", NULL);
65         
66         if (is_file_exist(bak)) {
67                 date = get_file_mtime(bak);
68                 ts = localtime(&date);
69                 strftime(buf, sizeof(buf), "%a %d-%b-%Y %H:%M %Z", ts);
70         }
71         
72         if (!is_file_exist(filename) && is_file_exist(bak)) {
73                 AlertValue aval;
74                 gchar *msg;
75
76                 msg = g_strdup_printf
77                         (_("The file %s is missing! "
78                            "Do you want to use the backup file from %s?"), FOLDER_LIST,buf);
79                 aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL,
80                                 ALERTFOCUS_FIRST);
81                 g_free(msg);
82                 if (aval != G_ALERTALTERNATE)
83                         return FALSE;
84                 else {
85                         if (copy_file(bak,filename,FALSE) < 0) {
86                                 alertpanel_warning(_("Could not copy %s to %s"),bak,filename);
87                                 return FALSE;
88                         }
89                         g_free(bak);
90                         return TRUE;
91                 }
92         }
93
94         node = xml_parse_file(filename);
95         if (!node && is_file_exist(bak)) {
96                 AlertValue aval;
97                 gchar *msg;
98
99                 msg = g_strdup_printf
100                         (_("The file %s is empty or corrupted! "
101                            "Do you want to use the backup file from %s?"), FOLDER_LIST,buf);
102                 aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL,
103                                 ALERTFOCUS_FIRST);
104                 g_free(msg);
105                 if (aval != G_ALERTALTERNATE)
106                         return FALSE;
107                 else {
108                         if (copy_file(bak,filename,FALSE) < 0) {
109                                 alertpanel_warning(_("Could not copy %s to %s"),bak,filename);
110                                 return FALSE;
111                         }
112                         g_free(bak);
113                 }
114         }
115         xml_free_tree(node);
116
117         return TRUE;
118 }