From c279d858e62bb7d6dbca8e3686e22a5bf88c79f8 Mon Sep 17 00:00:00 2001 From: jishengjie Date: Wed, 14 Dec 2022 15:38:30 +0800 Subject: fix: Encrypted documents in. 7z format cannot delete locked files and folders --- src/fr-command-7z.c | 17 +++++++++++++++++ src/fr-window.c | 28 +++++++++++++++++++++++++++- src/fr-window.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c index c3c66ab..4c5b03a 100644 --- a/src/fr-command-7z.c +++ b/src/fr-command-7z.c @@ -393,6 +393,19 @@ fr_command_7z_add (FrCommand *comm, fr_process_end_command (comm->process); } +static void +process_line__delete (char *line, + gpointer data) +{ + FrCommand *comm = FR_COMMAND (data); + + if ((strstr (line, "Wrong password?") != NULL) + || (strstr (line, "Enter password") != NULL)) + { + password_required = TRUE; + } +} + static void fr_command_7z_delete (FrCommand *comm, const char *from_file, @@ -400,6 +413,10 @@ fr_command_7z_delete (FrCommand *comm, { GList *scan; + fr_process_set_out_line_func (comm->process, + process_line__delete, + comm); + fr_command_7z_begin_command (comm); fr_process_add_arg (comm->process, "d"); if (spd_support) fr_process_add_arg (comm->process, "-spd"); diff --git a/src/fr-window.c b/src/fr-window.c index 3c71431..8061a39 100644 --- a/src/fr-window.c +++ b/src/fr-window.c @@ -6317,14 +6317,34 @@ fr_window_archive_add_dropped_items (FrWindow *window, window->priv->volume_size); } +static void +remove_data_free (GList *rdata) +{ + g_list_free_full(rdata, g_free); +} + void fr_window_archive_remove (FrWindow *window, GList *file_list) { + char *password; + GList *remove_list; + fr_window_clipboard_remove_file_list (window, file_list); fr_process_clear (window->archive->process); - fr_archive_remove (window->archive, file_list, window->priv->compression); + + remove_list = g_list_copy_deep (file_list, (GCopyFunc) g_strdup, NULL); + fr_window_set_current_batch_action (window, + FR_BATCH_ACTION_DELETE, + remove_list, + (GFreeFunc) remove_data_free); + + password = window->priv->password; + if (password != NULL && password[0] != '\0') + g_object_set (window->archive->command, "password", password, NULL); + + fr_archive_remove (window->archive, remove_list, window->priv->compression); fr_process_start (window->archive->process); } @@ -8529,6 +8549,12 @@ fr_window_exec_batch_action (FrWindow *window, fr_window_archive_add_dropped_items (window, (GList*) action->data, FALSE); break; + case FR_BATCH_ACTION_DELETE: + debug (DEBUG_INFO, "[BATCH] DELETE\n"); + + fr_window_archive_remove (window, (GList*) action->data); + break; + case FR_BATCH_ACTION_OPEN: debug (DEBUG_INFO, "[BATCH] OPEN\n"); diff --git a/src/fr-window.h b/src/fr-window.h index 23ecaa0..5606dfe 100644 --- a/src/fr-window.h +++ b/src/fr-window.h @@ -53,6 +53,7 @@ typedef enum { FR_BATCH_ACTION_LOAD, FR_BATCH_ACTION_OPEN, FR_BATCH_ACTION_ADD, + FR_BATCH_ACTION_DELETE, FR_BATCH_ACTION_EXTRACT, FR_BATCH_ACTION_EXTRACT_HERE, FR_BATCH_ACTION_EXTRACT_INTERACT, -- cgit v1.2.1