Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brotli cfile test #226

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
* ZIP Archive (.zip)
* ZIP Archived Comic Book (.cbz)
* ZOO Compressed Archive File (.zoo)
* Single files compressed with gzip, bzip, bzip2, compress, lrzip, lzip,
* Single files compressed with gzip, brotli (.br), bzip, bzip2, compress, lrzip, lzip,
lzop, rzip, xz.

* Home Page

http://www.mate-desktop.org/
https://mate-desktop.org/

* Licensing

Expand Down
1 change: 1 addition & 0 deletions caja/caja-engrampa.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static struct {
{ "application/x-alz", TRUE },
{ "application/x-ar", TRUE },
{ "application/x-arj", TRUE },
{ "application/x-brotli", TRUE },
{ "application/x-bzip", TRUE },
{ "application/x-bzip-compressed-tar", TRUE },
{ "application/x-bzip1", TRUE },
Expand Down
2 changes: 1 addition & 1 deletion data/engrampa.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<li>WinRAR Compressed Archive (.rar)</li>
<li>RAR Archived Comic Book (.cbr)</li>
<li>RPM Linux Package (.rpm) [Read-only mode]</li>
<li>Tape Archive File uncompressed (.tar) or compressed with: gzip (.tar.gz, .tgz), bzip (.tar.bz, .tbz), bzip2 (.tar.bz2, .tbz2),
<li>Tape Archive File uncompressed (.tar) or compressed with: gzip (.tar.gz, .tgz), brotli (.br), bzip (.tar.bz, .tbz), bzip2 (.tar.bz2, .tbz2),
compress (.tar.Z, .taz), lrzip (.tar.lrz, .tlrz), lzip (.tar.lz, .tlz), lzop (.tar.lzo, .tzo), 7zip (.tar.7z), xz (.tar.xz)
</li>
<li>Stuffit Archives (.bin, .sit)</li>
Expand Down
2 changes: 1 addition & 1 deletion data/engrampa.desktop.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Terminal=false
Type=Application
Icon=engrampa
Categories=GTK;Utility;Archiving;Compression;
MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-ar;application/x-arj;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lrzip;application/x-lrzip-compressed-tar;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-ms-wim;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;application/x-archive;application/vnd.ms-cab-compressed;
MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-ar;application/x-arj;application/x-brotli;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lrzip;application/x-lrzip-compressed-tar;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-ms-wim;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;application/x-archive;application/vnd.ms-cab-compressed;
Keywords=MATE;archive;manager;compression;
X-MATE-DocPath=engrampa/engrampa.xml
X-MATE-Bugzilla-Bugzilla=MATE
Expand Down
1 change: 1 addition & 0 deletions data/packages.match
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Package Matches]
arj=
binutils=
brotli=
bzip2=
cpio=
dpkg=
Expand Down
1 change: 1 addition & 0 deletions src/fr-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ get_mime_type_from_magic_numbers (GFile *file)
{ 0, 6, "7z\274\257\047\034", "application/x-7z-compressed" },
{ 7, 7, "**ACE**", "application/x-ace" },
{ 0, 2, "\x60\xea", "application/x-arj" },
{ 0, 4, "\xce\xb2\xcf\x81", "application/x-brotli" },
{ 0, 3, "BZh", "application/x-bzip2" },
{ 0, 2, "\037\213", "application/x-gzip" },
{ 0, 4, "LZIP", "application/x-lzip" },
Expand Down
93 changes: 76 additions & 17 deletions src/fr-command-cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".gz", NULL);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
r_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
fr_process_add_arg (comm->process, filename);
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".br", NULL);
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_set_working_dir (comm->process, temp_dir);
Expand Down Expand Up @@ -291,7 +299,7 @@ fr_command_cfile_add (FrCommand *comm,
compressed_filename = g_strconcat (filename, ".rz", NULL);
}

/* copy compressed file to the dest dir */
/* copy compressed file to the dest dir */

fr_process_begin_command (comm->process, "cp");
fr_process_set_working_dir (comm->process, temp_dir);
Expand Down Expand Up @@ -364,6 +372,13 @@ fr_command_cfile_extract (FrCommand *comm,
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
fr_process_begin_command (comm->process, "brotli");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_add_arg (comm->process, "-f");
Expand Down Expand Up @@ -454,8 +469,45 @@ fr_command_cfile_extract (FrCommand *comm,
g_free (temp_dir);
}

static void
fr_command_cfile_test (FrCommand *comm)
{
const char *compress_cmd;
if (is_mime_type (comm->mime_type, "application/x-gzip")) {
compress_cmd = "gzip";
}
else if (is_mime_type (comm->mime_type, "application/x-brotli")) {
compress_cmd = "brotli";
}
else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
compress_cmd = "bzip2";
}
else if (is_mime_type (comm->mime_type, "application/x-compress")) {
compress_cmd = is_program_in_path ("gzip") ? "gzip" : "uncompress";
}
else if (is_mime_type (comm->mime_type, "application/x-lzip")) {
compress_cmd = "lzip";
}
else if (is_mime_type (comm->mime_type, "application/x-lzma")) {
compress_cmd = "lzma";
}
else if (is_mime_type (comm->mime_type, "application/x-xz")) {
compress_cmd = "xz";
}
else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
compress_cmd = "lzop";
} else { // i.e. if (is_mime_type (comm->mime_type, "application/x-rzip"))
g_warning ("Test integrity in unsupported for %s\n", comm->mime_type);
return;
}
fr_process_begin_command (comm->process, compress_cmd);
fr_process_add_arg (comm->process, "-vt"); // verbose and test
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
}

const char *cfile_mime_type[] = { "application/x-gzip",
"application/x-brotli",
"application/x-bzip",
"application/x-compress",
"application/x-lzip",
Expand All @@ -475,7 +527,7 @@ fr_command_cfile_get_mime_types (FrCommand *comm)

static FrCommandCap
fr_command_cfile_get_capabilities (FrCommand *comm,
const char *mime_type,
const char *mime_type,
gboolean check_command)
{
FrCommandCap capabilities;
Expand All @@ -485,6 +537,10 @@ fr_command_cfile_get_capabilities (FrCommand *comm,
if (is_program_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-brotli")) {
if (is_program_available ("brotli", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-bzip")) {
if (is_program_available ("bzip2", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
Expand Down Expand Up @@ -523,12 +579,12 @@ fr_command_cfile_get_capabilities (FrCommand *comm,
static void
fr_command_cfile_finalize (GObject *object)
{
g_return_if_fail (object != NULL);
g_return_if_fail (FR_IS_COMMAND_CFILE (object));
g_return_if_fail (object != NULL);
g_return_if_fail (FR_IS_COMMAND_CFILE (object));

/* Chain up */
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (object);
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (object);
}


Expand All @@ -538,6 +594,8 @@ fr_command_cfile_get_packages (FrCommand *comm,
{
if (is_mime_type (mime_type, "application/x-gzip"))
return PACKAGES ("gzip");
else if (is_mime_type (mime_type, "application/x-brotli"))
return PACKAGES ("brotli");
else if (is_mime_type (mime_type, "application/x-bzip"))
return PACKAGES ("bzip2");
else if (is_mime_type (mime_type, "application/x-compress"))
Expand All @@ -560,18 +618,19 @@ fr_command_cfile_get_packages (FrCommand *comm,
static void
fr_command_cfile_class_init (FrCommandCFileClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
FrCommandClass *afc;
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
FrCommandClass *afc;

parent_class = g_type_class_peek_parent (class);
parent_class = g_type_class_peek_parent (class);
afc = (FrCommandClass*) class;

gobject_class->finalize = fr_command_cfile_finalize;
gobject_class->finalize = fr_command_cfile_finalize;

afc->list = fr_command_cfile_list;
afc->list = fr_command_cfile_list;
afc->add = fr_command_cfile_add;
afc->delete = fr_command_cfile_delete;
afc->extract = fr_command_cfile_extract;
afc->test = fr_command_cfile_test;
afc->get_mime_types = fr_command_cfile_get_mime_types;
afc->get_capabilities = fr_command_cfile_get_capabilities;
afc->get_packages = fr_command_cfile_get_packages;
Expand All @@ -587,17 +646,17 @@ fr_command_cfile_init (FrCommand *comm)
comm->propExtractCanSkipOlder = FALSE;
comm->propExtractCanJunkPaths = FALSE;
comm->propPassword = FALSE;
comm->propTest = FALSE;
comm->propTest = TRUE;
}


GType
fr_command_cfile_get_type ()
{
static GType type = 0;
static GType type = 0;

if (! type) {
GTypeInfo type_info = {
if (! type) {
GTypeInfo type_info = {
sizeof (FrCommandCFileClass),
NULL,
NULL,
Expand All @@ -613,7 +672,7 @@ fr_command_cfile_get_type ()
"FRCommandCFile",
&type_info,
0);
}
}

return type;
return type;
}
2 changes: 2 additions & 0 deletions src/fr-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ FrMimeTypeDescription mime_type_desc[] = {
{ "application/x-ar", ".a", N_("Ar (.a)"), 0 },
{ "application/x-ar", ".ar", N_("Ar (.ar)"), 0 },
{ "application/x-arj", ".arj", N_("Arj (.arj)"), 0 },
{ "application/x-brotli", ".br", N_("brotli (.br)"), 0 },
{ "application/x-bzip", ".bz2", NULL, 0 },
{ "application/x-bzip-compressed-tar", ".tar.bz2", N_("Tar compressed with bzip2 (.tar.bz2)"), 0 },
{ "application/x-bzip1", ".bz", NULL, 0 },
Expand Down Expand Up @@ -119,6 +120,7 @@ FrExtensionType file_ext_type[] = {
{ ".ar", "application/x-ar" },
{ ".arj", "application/x-arj" },
{ ".bin", "application/x-stuffit" },
{ ".br", "application/x-brotli" },
{ ".bz", "application/x-bzip" },
{ ".bz2", "application/x-bzip" },
{ ".cab", "application/vnd.ms-cab-compressed" },
Expand Down
43 changes: 25 additions & 18 deletions src/fr-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -7324,6 +7324,27 @@ last_output_window__unrealize_cb (GtkWidget *widget,
}


static void
fr_window_view_last_output_print(GtkTextBuffer *text_buffer,
GtkTextIter *iter,
GList *scan)
{
for (; scan; scan = scan->next) {
char *line = scan->data;
char *utf8_line;
gsize bytes_written;

utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
iter,
utf8_line,
bytes_written,
"monospace", NULL);
g_free (utf8_line);
gtk_text_buffer_insert (text_buffer, iter, "\n", 1);
}
}

void
fr_window_view_last_output (FrWindow *window,
const char *title)
Expand All @@ -7334,7 +7355,6 @@ fr_window_view_last_output (FrWindow *window,
GtkWidget *scrolled;
GtkTextBuffer *text_buffer;
GtkTextIter iter;
GList *scan;

if (title == NULL)
title = _("Last Output");
Expand Down Expand Up @@ -7392,24 +7412,11 @@ fr_window_view_last_output (FrWindow *window,
G_CALLBACK (last_output_window__unrealize_cb),
NULL);

/**/

gtk_text_buffer_get_iter_at_offset (text_buffer, &iter, 0);
scan = window->archive->process->out.raw;
for (; scan; scan = scan->next) {
char *line = scan->data;
char *utf8_line;
gsize bytes_written;

utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL);
gtk_text_buffer_insert_with_tags_by_name (text_buffer,
&iter,
utf8_line,
bytes_written,
"monospace", NULL);
g_free (utf8_line);
gtk_text_buffer_insert (text_buffer, &iter, "\n", 1);
}
/* Show STDOUT of process */
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->out.raw);
/* Show STDERR of process */
fr_window_view_last_output_print(text_buffer, &iter, window->archive->process->err.raw);

/**/

Expand Down