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