talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit e89ae048d98669ce0b04d99d4d179c10d3054d46
parent fc0fc25b23afe539958a8724ea91c21d8550d41b
Author: Oliver Lowe <o@olowe.co>
Date:   Wed, 13 Aug 2025 12:49:14 +1000

Keep once-called function where it's called only

Diffstat:
Msrc/Makefile.am | 2--
Dsrc/file_checker.c | 125-------------------------------------------------------------------------------
Dsrc/file_checker.h | 30------------------------------
Msrc/main.c | 80++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 77 insertions(+), 160 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -70,7 +70,6 @@ abook_headers = \ editvcard.h \ exphtmldlg.h \ exporthtml.h \ - file_checker.h \ vcard.h claws_mail_SOURCES = \ @@ -93,7 +92,6 @@ claws_mail_SOURCES = \ enriched.c \ entity.c \ export.c \ - file_checker.c \ filtering.c \ folder.c \ folder_item_prefs.c \ diff --git a/src/file_checker.c b/src/file_checker.c @@ -1,125 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2013-2022 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 <http://www.gnu.org/licenses/>. - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include "file-utils.h" -#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]; - gboolean fileexists, bakexists; - - filename = folder_get_list_path(); - - fileexists = is_file_exist(filename); - - bak = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, - FOLDER_LIST, ".bak", NULL); - bakexists = is_file_exist(bak); - - if (bakexists) { - date = get_file_mtime(bak); - ts = localtime(&date); - strftime(buf, sizeof(buf), "%a %d-%b-%Y %H:%M %Z", ts); - } - - if (!fileexists && bakexists) { - 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, NULL, _("_No"), NULL, _("_Yes"), - NULL, NULL, ALERTFOCUS_FIRST); - 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; - } - } - - if (fileexists) { - 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, NULL, _("_No"), NULL, _("_Yes"), - NULL, NULL, ALERTFOCUS_FIRST); - 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; - } - } - xml_free_tree(node); - } - - return TRUE; -} diff --git a/src/file_checker.h b/src/file_checker.h @@ -1,30 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2013-2021 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 <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __FILE_CHECKER_H__ -#define __FILE_CHECKER_H__ - -#include <glib.h> -#include <gdk/gdk.h> -#include <gtk/gtk.h> - -gboolean check_file_integrity(); - -#endif - diff --git a/src/main.c b/src/main.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include <string.h> #include <ctype.h> #include <unistd.h> @@ -45,7 +46,6 @@ #include <sys/file.h> #endif -#include "file_checker.h" #include "wizard.h" #ifdef HAVE_STARTUP_NOTIFICATION #ifdef GDK_WINDOWING_X11 @@ -566,6 +566,81 @@ static void win32_close_log(void) } #endif +bool verify_folderlist_xml() +{ + GNode *node; + static gchar *filename = NULL; + static gchar *bak = NULL; + time_t date; + struct tm *ts; + gchar buf[BUFFSIZE]; + gboolean fileexists, bakexists; + + filename = folder_get_list_path(); + + fileexists = is_file_exist(filename); + + bak = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, + FOLDER_LIST, ".bak", NULL); + bakexists = is_file_exist(bak); + + if (bakexists) { + date = get_file_mtime(bak); + ts = localtime(&date); + strftime(buf, sizeof(buf), "%a %d-%b-%Y %H:%M %Z", ts); + } + + if (!fileexists && bakexists) { + 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, NULL, _("_No"), NULL, _("_Yes"), + NULL, NULL, ALERTFOCUS_FIRST); + 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; + } + } + + if (fileexists) { + 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, NULL, _("_No"), NULL, _("_Yes"), + NULL, NULL, ALERTFOCUS_FIRST); + 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; + } + } + xml_free_tree(node); + } + + return true; +} + static void main_dump_features_list(gboolean show_debug_only) /* display compiled-in features list */ { @@ -857,7 +932,7 @@ int main(int argc, char *argv[]) mainwin = main_window_create(); - if (!check_file_integrity()) + if (!verify_folderlist_xml()) exit(1); manage_window_focus_in(mainwin->window, NULL, NULL); @@ -2294,4 +2369,3 @@ static void install_basic_sighandlers() sigprocmask(SIG_UNBLOCK, &mask, 0); #endif /* !G_OS_WIN32 */ } -