diff options
Diffstat (limited to 'src/fr-command-7z.c')
-rw-r--r-- | src/fr-command-7z.c | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c index 796e03a..8bb474e 100644 --- a/src/fr-command-7z.c +++ b/src/fr-command-7z.c @@ -49,10 +49,8 @@ static gboolean password_handled = FALSE; static FrCommandClass *parent_class = NULL; - /* -- list -- */ - static time_t mktime_from_string (char *date_s, char *time_s) @@ -88,7 +86,6 @@ mktime_from_string (char *date_s, return mktime (&tm); } - static void list__process_line (char *line, gpointer data) @@ -204,11 +201,18 @@ list__process_line (char *line, g_strfreev (fields); } - static void fr_command_7z_begin_command (FrCommand *comm) { - if (is_program_in_path ("7z")) + // Modern 7-Zip by the original author. + // Statically linked from a binary distribution, almost guaranteed to work. + if (is_program_in_path ("7zzs")) + fr_process_begin_command (comm->process, "7zzs"); + // Dynamically linked from either binary or source distribution. + else if (is_program_in_path ("7zz")) + fr_process_begin_command (comm->process, "7zz"); + // Legacy p7zip project. + else if (is_program_in_path ("7z")) fr_process_begin_command (comm->process, "7z"); else if (is_program_in_path ("7za")) fr_process_begin_command (comm->process, "7za"); @@ -216,7 +220,6 @@ fr_command_7z_begin_command (FrCommand *comm) fr_process_begin_command (comm->process, "7zr"); } - static void add_password_arg (FrCommand *comm, const char *password, @@ -232,7 +235,6 @@ add_password_arg (FrCommand *comm, } } - static void list__begin (gpointer data) { @@ -245,7 +247,6 @@ list__begin (gpointer data) p7z_comm->list_started = FALSE; } - static void fr_command_7z_list (FrCommand *comm) { @@ -267,7 +268,6 @@ fr_command_7z_list (FrCommand *comm) fr_process_start (comm->process); } - static void parse_progress_line (FrCommand *comm, const char *prefix, @@ -281,7 +281,6 @@ parse_progress_line (FrCommand *comm, fr_command_progress (comm, (double) ++comm->n_file / (comm->n_files + 1)); } - static void process_line__add (char *line, gpointer data) @@ -307,7 +306,6 @@ process_line__add (char *line, parse_progress_line (comm, "Compressing ", _("Adding file: "), line); } - static void fr_command_7z_add (FrCommand *comm, const char *from_file, @@ -343,8 +341,10 @@ fr_command_7z_add (FrCommand *comm, if (spd_support) fr_process_add_arg (comm->process, "-spd"); fr_process_add_arg (comm->process, "-bd"); + fr_process_add_arg (comm->process, "-bb1"); fr_process_add_arg (comm->process, "-y"); - fr_process_add_arg (comm->process, "-l"); + if (recursive) + fr_process_add_arg (comm->process, "-l"); add_password_arg (comm, comm->password, FALSE); if ((comm->password != NULL) && (*comm->password != 0) @@ -403,6 +403,16 @@ fr_command_7z_add (FrCommand *comm, fr_process_end_command (comm->process); } +static void +process_line__delete (char *line, + gpointer data) +{ + if ((strstr (line, "Wrong password?") != NULL) + || (strstr (line, "Enter password") != NULL)) + { + password_required = TRUE; + } +} static void fr_command_7z_delete (FrCommand *comm, @@ -411,6 +421,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"); @@ -442,7 +456,6 @@ fr_command_7z_delete (FrCommand *comm, fr_process_end_command (comm->process); } - static void process_line__extract (char *line, gpointer data) @@ -453,7 +466,6 @@ process_line__extract (char *line, parse_progress_line (comm, "Extracting ", _("Extracting file: "), line); } - static void fr_command_7z_extract (FrCommand *comm, const char *from_file, @@ -478,6 +490,7 @@ fr_command_7z_extract (FrCommand *comm, if (spd_support) fr_process_add_arg (comm->process, "-spd"); fr_process_add_arg (comm->process, "-bd"); + fr_process_add_arg (comm->process, "-bb1"); fr_process_add_arg (comm->process, "-y"); add_password_arg (comm, comm->password, FALSE); @@ -507,7 +520,6 @@ fr_command_7z_extract (FrCommand *comm, fr_process_end_command (comm->process); } - static void fr_command_7z_test (FrCommand *comm) { @@ -521,7 +533,6 @@ fr_command_7z_test (FrCommand *comm) fr_process_end_command (comm->process); } - static void fr_command_7z_handle_error (FrCommand *comm, FrProcError *error) @@ -577,7 +588,6 @@ fr_command_7z_handle_error (FrCommand *comm, } } - const char *sevenz_mime_types[] = { "application/epub+zip", "application/x-7z-compressed", "application/x-arj", @@ -591,7 +601,6 @@ const char *sevenz_mime_types[] = { "application/epub+zip", "application/zip", /* zip always at the end and the number of */ NULL }; /* place in fr_command_7z_get_mime_types */ - static const char ** fr_command_7z_get_mime_types (FrCommand *comm) { @@ -600,7 +609,7 @@ fr_command_7z_get_mime_types (FrCommand *comm) if (g_settings_get_boolean (settings, "unar-open-zip") && is_program_in_path ("unar") && is_program_in_path ("lsar")) - sevenz_mime_types [8] = NULL; + sevenz_mime_types [9] = NULL; else g_settings_set_boolean (settings, "unar-open-zip", FALSE); @@ -609,33 +618,36 @@ fr_command_7z_get_mime_types (FrCommand *comm) return sevenz_mime_types; } - -static FrCommandCap +static FrCommandCaps fr_command_7z_get_capabilities (FrCommand *comm, const char *mime_type, gboolean check_command) { - FrCommandCap capabilities; + FrCommandCaps capabilities; capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES; - if (! is_program_available ("7za", check_command) && ! is_program_available ("7zr", check_command) && ! is_program_available ("7z", check_command)) + gboolean available_7zip = is_program_available ("7zz", check_command) || is_program_available ("7zzs", check_command); + if (! available_7zip\ + && ! is_program_available ("7za", check_command) \ + && ! is_program_available ("7zr", check_command) \ + && ! is_program_available ("7z", check_command)) return capabilities; if (is_mime_type (mime_type, "application/x-7z-compressed")) { capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_CREATE_VOLUMES; - if (is_program_available ("7z", check_command)) + if (is_program_available ("7z", check_command) || available_7zip) capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER; } else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) { capabilities |= FR_COMMAND_CAN_READ_WRITE; - if (is_program_available ("7z", check_command)) + if (is_program_available ("7z", check_command) || available_7zip) capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER; } - else if (is_program_available ("7z", check_command)) { + else if (is_program_available ("7z", check_command) || available_7zip) { if (is_mime_type (mime_type, "application/x-rar") || is_mime_type (mime_type, "application/x-cbr")) { - if (! check_command || g_file_test ("/usr/lib/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/lib/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS) + if (! check_command || available_7zip || g_file_test ("/usr/lib/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/lib/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/libexec/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/libexec/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS)) capabilities |= FR_COMMAND_CAN_READ; } @@ -668,20 +680,18 @@ fr_command_7z_get_capabilities (FrCommand *comm, return capabilities; } - static const char * fr_command_7z_get_packages (FrCommand *comm, const char *mime_type) { if (is_mime_type (mime_type, "application/x-rar")) - return PACKAGES ("p7zip,p7zip-rar"); + return PACKAGES ("7zip,7zip-rar"); else if (is_mime_type (mime_type, "application/zip") || is_mime_type (mime_type, "application/vnd.ms-cab-compressed")) - return PACKAGES ("p7zip,p7zip-full"); + return PACKAGES ("7zip,7zip-full"); else - return PACKAGES ("p7zip"); + return PACKAGES ("7zip"); } - static void fr_command_7z_class_init (FrCommand7zClass *class) { @@ -704,7 +714,6 @@ fr_command_7z_class_init (FrCommand7zClass *class) afc->get_packages = fr_command_7z_get_packages; } - static void fr_command_7z_init (FrCommand *comm) { @@ -719,7 +728,6 @@ fr_command_7z_init (FrCommand *comm) comm->propListFromFile = TRUE; } - static void fr_command_7z_finalize (GObject *object) { @@ -731,7 +739,6 @@ fr_command_7z_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } - GType fr_command_7z_get_type () { |