[file-roller] Added lrzip archives support
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] Added lrzip archives support
- Date: Mon, 3 May 2010 11:45:21 +0000 (UTC)
commit 79198a51c0359546ddb31f8418ec2f2605640f85
Author: Alexander Saprykin <xelfium gmail com>
Date: Mon May 3 13:08:58 2010 +0200
Added lrzip archives support
src/Makefile.am | 2 +
src/fr-archive.c | 1 +
src/fr-command-lrzip.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++
src/fr-command-lrzip.h | 37 +++++++
src/main.c | 4 +
5 files changed, 307 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 97e0f8e..523fde8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -119,6 +119,8 @@ file_roller_SOURCES = \
fr-command-unstuff.h \
fr-command-zip.c \
fr-command-zip.h \
+ fr-command-lrzip.c \
+ fr-command-lrzip.h \
fr-command-zoo.c \
fr-command-zoo.h \
fr-command-7z.c \
diff --git a/src/fr-archive.c b/src/fr-archive.c
index ff71e92..e4a1259 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -452,6 +452,7 @@ get_mime_type_from_magic_numbers (GFile *file)
{ "application/x-zoo", "\xdc\xa7\xc4\xfd", 20, 4 },
{ "application/zip", "PK\003\004", 0, 4 },
{ "application/zip", "PK00PK\003\004", 0, 8 },
+ { "application/x-lrzip", "LRZI", 0, 4 },
{ NULL, NULL, 0 }
};
char buffer[32];
diff --git a/src/fr-command-lrzip.c b/src/fr-command-lrzip.c
new file mode 100644
index 0000000..018802e
--- /dev/null
+++ b/src/fr-command-lrzip.c
@@ -0,0 +1,263 @@
+/*
+ * fr-command-lrzip.c
+ *
+ * Created on: 10.04.2010
+ * Author: Alexander Saprykin
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <glib.h>
+
+#include "file-data.h"
+#include "file-utils.h"
+#include "glib-utils.h"
+#include "fr-command.h"
+#include "fr-command-lrzip.h"
+
+static void fr_command_lrzip_class_init (FrCommandLrzipClass *class);
+static void fr_command_lrzip_init (FrCommand *afile);
+static void fr_command_lrzip_finalize (GObject *object);
+
+/* Parent Class */
+
+static FrCommandClass *parent_class = NULL;
+
+
+/* -- list -- */
+
+static void
+list__process_line (char *line,
+ gpointer data)
+{
+ FileData *fdata;
+ FrCommand *comm = FR_COMMAND (data);
+
+ g_return_if_fail (line != NULL);
+
+ if (strlen (line) == 0)
+ return;
+
+ if (!g_str_has_prefix (line, "Decompressed file size:"))
+ return;
+
+ fdata = file_data_new ();
+ fdata->size = g_ascii_strtoull (get_last_field (line, 4), NULL, 10);
+
+ struct stat st;
+ time_t tt;
+ if (stat(comm->filename, &st) == 0)
+ fdata->modified = st.st_mtim.tv_sec;
+ else
+ time(&(fdata->modified));
+ fdata->modified;
+ fdata->encrypted = FALSE;
+
+ char *new_fname = g_strdup (file_name_from_path (comm->filename));
+ if (g_str_has_suffix (new_fname, ".lrz"))
+ new_fname[strlen (new_fname) - 4] = '\0';
+
+ if (*new_fname == '/') {
+ fdata->full_path = g_strdup (new_fname);
+ fdata->original_path = fdata->full_path;
+ } else {
+ fdata->full_path = g_strconcat ("/", new_fname, NULL);
+ fdata->original_path = fdata->full_path + 1;
+ }
+ fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = new_fname;
+ fdata->dir = FALSE;
+ fdata->link = NULL;
+
+ if (fdata->name == 0)
+ file_data_free (fdata);
+ else
+ fr_command_add_file (comm, fdata);
+}
+
+
+static void
+fr_command_lrzip_list (FrCommand *comm)
+{
+ fr_process_set_err_line_func (comm->process, list__process_line, comm);
+
+ fr_process_begin_command (comm->process, "lrzip");
+ fr_process_add_arg (comm->process, "-i");
+ fr_process_add_arg (comm->process, comm->filename);
+ fr_process_end_command (comm->process);
+ fr_process_start (comm->process);
+}
+
+
+static void
+fr_command_lrzip_add (FrCommand *comm,
+ const char *from_file,
+ GList *file_list,
+ const char *base_dir,
+ gboolean update,
+ gboolean recursive)
+{
+ fr_process_begin_command (comm->process, "lrzip");
+
+ if (base_dir != NULL)
+ fr_process_set_working_dir (comm->process, base_dir);
+
+ /* preserve links. */
+
+ switch (comm->compression) {
+ case FR_COMPRESSION_VERY_FAST:
+ fr_process_add_arg (comm->process, "-l"); break;
+ case FR_COMPRESSION_FAST:
+ fr_process_add_arg (comm->process, "-g"); break;
+ case FR_COMPRESSION_NORMAL:
+ fr_process_add_arg (comm->process, "-b"); break;
+ case FR_COMPRESSION_MAXIMUM:
+ fr_process_add_arg (comm->process, "-z"); break;
+ }
+
+ fr_process_add_arg (comm->process, "-o");
+ fr_process_add_arg (comm->process, comm->filename);
+ fr_process_add_arg (comm->process, (char*)g_list_first (file_list));
+
+ fr_process_end_command (comm->process);
+}
+
+static void
+fr_command_lrzip_extract (FrCommand *comm,
+ const char *from_file,
+ GList *file_list,
+ const char *dest_dir,
+ gboolean overwrite,
+ gboolean skip_older,
+ gboolean junk_paths)
+{
+ fr_process_begin_command (comm->process, "lrzip");
+ fr_process_add_arg (comm->process, "-d");
+
+ if (dest_dir != NULL) {
+ fr_process_add_arg (comm->process, "-O");
+ fr_process_add_arg (comm->process, dest_dir);
+ }
+ if (overwrite)
+ fr_process_add_arg (comm->process, "-f");
+
+ fr_process_add_arg (comm->process, comm->filename);
+ fr_process_end_command (comm->process);
+}
+
+
+//static void
+//fr_command_lrzip_test (FrCommand *comm)
+//{
+// fr_process_begin_command (comm->process, "lrzip");
+// fr_process_add_arg (comm->process, "-t");
+// fr_process_add_arg (comm->process, comm->filename);
+// fr_process_end_command (comm->process);
+//}
+
+
+const char *lrzip_mime_type[] = { "application/x-lrzip", NULL };
+
+const char **
+fr_command_lrzip_get_mime_types (FrCommand *comm)
+{
+ return lrzip_mime_type;
+}
+
+FrCommandCap
+fr_command_lrzip_get_capabilities (FrCommand *comm,
+ const char *mime_type,
+ gboolean check_command)
+{
+ FrCommandCap capabilities = FR_COMMAND_CAN_DO_NOTHING;
+
+ if (is_program_available ("lrzip", check_command)) {
+ capabilities |= FR_COMMAND_CAN_READ_WRITE;
+ }
+
+ return capabilities;
+}
+
+static const char *
+fr_command_lrzip_get_packages (FrCommand *comm,
+ const char *mime_type)
+{
+ return PACKAGES ("lrzip");
+}
+
+static void
+fr_command_lrzip_class_init (FrCommandLrzipClass *class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ FrCommandClass *afc;
+
+ parent_class = g_type_class_peek_parent (class);
+ afc = (FrCommandClass*) class;
+
+ gobject_class->finalize = fr_command_lrzip_finalize;
+
+ afc->list = fr_command_lrzip_list;
+ afc->extract = fr_command_lrzip_extract;
+ afc->get_mime_types = fr_command_lrzip_get_mime_types;
+ afc->get_capabilities = fr_command_lrzip_get_capabilities;
+ afc->get_packages = fr_command_lrzip_get_packages;
+}
+
+
+static void
+fr_command_lrzip_init (FrCommand *comm)
+{
+ comm->propAddCanUpdate = FALSE;
+ comm->propAddCanReplace = FALSE;
+ comm->propAddCanStoreFolders = FALSE;
+ comm->propExtractCanAvoidOverwrite = TRUE;
+ comm->propExtractCanSkipOlder = FALSE;
+ comm->propExtractCanJunkPaths = FALSE;
+ comm->propPassword = FALSE;
+ comm->propTest = FALSE;
+}
+
+
+static void
+fr_command_lrzip_finalize (GObject *object)
+{
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (FR_IS_COMMAND_LRZIP (object));
+
+ /* Chain up */
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+GType
+fr_command_lrzip_get_type ()
+{
+ static GType type = 0;
+
+ if (! type) {
+ GTypeInfo type_info = {
+ sizeof (FrCommandLrzipClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) fr_command_lrzip_class_init,
+ NULL,
+ NULL,
+ sizeof (FrCommandLrzip),
+ 0,
+ (GInstanceInitFunc) fr_command_lrzip_init
+ };
+
+ type = g_type_register_static (FR_TYPE_COMMAND,
+ "FRCommandLrzip",
+ &type_info,
+ 0);
+ }
+
+ return type;
+}
diff --git a/src/fr-command-lrzip.h b/src/fr-command-lrzip.h
new file mode 100644
index 0000000..910a696
--- /dev/null
+++ b/src/fr-command-lrzip.h
@@ -0,0 +1,37 @@
+/*
+ * fr-command-lrzip.h
+ *
+ * Created on: 10.04.2010
+ * Author: Alexander Saprykin
+ */
+
+#ifndef FRCOMMANDLRZIP_H_
+#define FRCOMMANDLRZIP_H_
+
+#include <glib.h>
+#include "fr-command.h"
+#include "fr-process.h"
+
+#define FR_TYPE_COMMAND_LRZIP (fr_command_lrzip_get_type ())
+#define FR_COMMAND_LRZIP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FR_TYPE_COMMAND_LRZIP, FrCommandLrzip))
+#define FR_COMMAND_LRZIP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FR_TYPE_COMMAND_LRZIP, FrCommandLrzipClass))
+#define FR_IS_COMMAND_LRZIP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FR_TYPE_COMMAND_LRZIP))
+#define FR_IS_COMMAND_LRZIP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FR_TYPE_COMMAND_LRZIP))
+#define FR_COMMAND_LRZIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), FR_TYPE_COMMAND_LRZIP, FrCommandLrzipClass))
+
+typedef struct _FrCommandLrzip FrCommandLrzip;
+typedef struct _FrCommandLrzipClass FrCommandLrzipClass;
+
+struct _FrCommandLrzip
+{
+ FrCommand __parent;
+};
+
+struct _FrCommandLrzipClass
+{
+ FrCommandClass __parent_class;
+};
+
+GType fr_command_lrzip_get_type (void);
+
+#endif /* FRCOMMANDLRZIP_H_ */
diff --git a/src/main.c b/src/main.c
index 6d54ae7..c631992 100644
--- a/src/main.c
+++ b/src/main.c
@@ -45,6 +45,7 @@
#include "fr-command-zip.h"
#include "fr-command-zoo.h"
#include "fr-command-7z.h"
+#include "fr-command-lrzip.h"
#include "fr-process.h"
#include "fr-stock.h"
#include "gconf-utils.h"
@@ -118,6 +119,7 @@ FrMimeTypeDescription mime_type_desc[] = {
{ "application/x-xz-compressed-tar", ".tar.xz", N_("Tar compressed with xz (.tar.xz)"), 0 },
{ "application/x-zoo", ".zoo", N_("Zoo (.zoo)"), 0 },
{ "application/zip", ".zip", N_("Zip (.zip)"), 0 },
+ { "application/x-lrzip", ".lrz", N_("Lrzip (.lrz)"), 0},
{ NULL, NULL, NULL, 0 }
};
@@ -173,6 +175,7 @@ FrExtensionType file_ext_type[] = {
{ ".Z", "application/x-compress" },
{ ".zip", "application/zip" },
{ ".zoo", "application/x-zoo" },
+ { ".lrz", "application/x-lrzip" },
{ NULL, NULL }
};
@@ -616,6 +619,7 @@ register_commands (void)
register_command (FR_TYPE_COMMAND_RPM);
register_command (FR_TYPE_COMMAND_UNSTUFF);
register_command (FR_TYPE_COMMAND_ZIP);
+ register_command (FR_TYPE_COMMAND_LRZIP);
register_command (FR_TYPE_COMMAND_ZOO);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]