Skip to content

Commit ab9e18f

Browse files
stokitoraveit65
authored andcommitted
Added test integrity for the cfile compressors: gzip, bzip2, etc. But since most of them shows the message with file status to STDERR instead of STDOUT whe should show both in Test result window.
1 parent a699fa2 commit ab9e18f

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

‎src/fr-command-cfile.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,39 @@ fr_command_cfile_extract (FrCommand *comm,
469469
g_free (temp_dir);
470470
}
471471

472+
static void
473+
fr_command_cfile_test (FrCommand *comm)
474+
{
475+
const char *compress_cmd;
476+
if (is_mime_type (comm->mime_type, "application/x-gzip")) {
477+
compress_cmd = "gzip";
478+
}
479+
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
480+
compress_cmd = "bzip2";
481+
}
482+
else if (is_mime_type (comm->mime_type, "application/x-compress")) {
483+
compress_cmd = is_program_in_path ("gzip") ? "gzip" : "uncompress";
484+
}
485+
else if (is_mime_type (comm->mime_type, "application/x-lzip")) {
486+
compress_cmd = "lzip";
487+
}
488+
else if (is_mime_type (comm->mime_type, "application/x-lzma")) {
489+
compress_cmd = "lzma";
490+
}
491+
else if (is_mime_type (comm->mime_type, "application/x-xz")) {
492+
compress_cmd = "xz";
493+
}
494+
else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
495+
compress_cmd = "lzop";
496+
} else { // i.e. if (is_mime_type (comm->mime_type, "application/x-rzip"))
497+
g_warning ("Test integrity in unsupported for %s\n", comm->mime_type);
498+
return;
499+
}
500+
fr_process_begin_command (comm->process, compress_cmd);
501+
fr_process_add_arg (comm->process, "-vt"); // verbose and test
502+
fr_process_add_arg (comm->process, comm->filename);
503+
fr_process_end_command (comm->process);
504+
}
472505

473506
const char *cfile_mime_type[] = { "application/x-gzip",
474507
"application/x-brotli",
@@ -594,6 +627,7 @@ fr_command_cfile_class_init (FrCommandCFileClass *class)
594627
afc->add = fr_command_cfile_add;
595628
afc->delete = fr_command_cfile_delete;
596629
afc->extract = fr_command_cfile_extract;
630+
afc->test = fr_command_cfile_test;
597631
afc->get_mime_types = fr_command_cfile_get_mime_types;
598632
afc->get_capabilities = fr_command_cfile_get_capabilities;
599633
afc->get_packages = fr_command_cfile_get_packages;
@@ -609,7 +643,7 @@ fr_command_cfile_init (FrCommand *comm)
609643
comm->propExtractCanSkipOlder = FALSE;
610644
comm->propExtractCanJunkPaths = FALSE;
611645
comm->propPassword = FALSE;
612-
comm->propTest = FALSE;
646+
comm->propTest = TRUE;
613647
}
614648

615649

‎src/fr-window.c‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7400,6 +7400,27 @@ last_output_window__unrealize_cb (GtkWidget *widget,
74007400
}
74017401

74027402

7403+
static void
7404+
fr_window_view_last_output_print(GtkTextBuffer *text_buffer,
7405+
GtkTextIter *iter,
7406+
GList *scan)
7407+
{
7408+
for (; scan; scan = scan->next) {
7409+
char *line = scan->data;
7410+
char *utf8_line;
7411+
gsize bytes_written;
7412+
7413+
utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
7414+
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
7415+
iter,
7416+
utf8_line,
7417+
bytes_written,
7418+
"monospace", NULL);
7419+
g_free (utf8_line);
7420+
gtk_text_buffer_insert (text_buffer, iter, "\n", 1);
7421+
}
7422+
}
7423+
74037424
void
74047425
fr_window_view_last_output (FrWindow *window,
74057426
const char *title)
@@ -7410,7 +7431,6 @@ fr_window_view_last_output (FrWindow *window,
74107431
GtkWidget *scrolled;
74117432
GtkTextBuffer *text_buffer;
74127433
GtkTextIter iter;
7413-
GList *scan;
74147434

74157435
if (title == NULL)
74167436
title = _("Last Output");
@@ -7468,24 +7488,11 @@ fr_window_view_last_output (FrWindow *window,
74687488
G_CALLBACK (last_output_window__unrealize_cb),
74697489
NULL);
74707490

7471-
/**/
7472-
74737491
gtk_text_buffer_get_iter_at_offset (text_buffer, &iter, 0);
7474-
scan = window->archive->process->out.raw;
7475-
for (; scan; scan = scan->next) {
7476-
char *line = scan->data;
7477-
char *utf8_line;
7478-
gsize bytes_written;
7479-
7480-
utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
7481-
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
7482-
&iter,
7483-
utf8_line,
7484-
bytes_written,
7485-
"monospace", NULL);
7486-
g_free (utf8_line);
7487-
gtk_text_buffer_insert (text_buffer, &iter, "\n", 1);
7488-
}
7492+
/* Show STDOUT of process */
7493+
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->out.raw);
7494+
/* Show STDERR of process */
7495+
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->err.raw);
74897496

74907497
/**/
74917498

0 commit comments

Comments
 (0)