From 659fff975b2e251248f8e46cc67513b7f24ffec8 Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Wed, 31 Jul 2013 02:15:44 +0800 Subject: Remove all things related to autoarchive, which becomes a shared library --- Makefile.am | 2 +- autoarchive/Makefile.am | 91 -- autoarchive/autoar-common.c | 163 --- autoarchive/autoar-common.h | 41 - autoarchive/autoar-create.c | 507 -------- autoarchive/autoar-create.h | 95 -- autoarchive/autoar-enum-types.c.template | 36 - autoarchive/autoar-enum-types.h.template | 26 - autoarchive/autoar-extract.c | 1373 -------------------- autoarchive/autoar-extract.h | 97 -- autoarchive/autoar-pref.c | 567 -------- autoarchive/autoar-pref.h | 134 -- autoarchive/autoarchive.h | 34 - autoarchive/org.gnome.desktop.archives.gschema.xml | 35 - autoarchive/test-extract.c | 97 -- autoarchive/test-pref.c | 26 - configure.ac | 6 +- embed/ephy-download.h | 2 +- src/Makefile.am | 1 - tests/Makefile.am | 1 - 20 files changed, 4 insertions(+), 3330 deletions(-) delete mode 100644 autoarchive/Makefile.am delete mode 100644 autoarchive/autoar-common.c delete mode 100644 autoarchive/autoar-common.h delete mode 100644 autoarchive/autoar-create.c delete mode 100644 autoarchive/autoar-create.h delete mode 100644 autoarchive/autoar-enum-types.c.template delete mode 100644 autoarchive/autoar-enum-types.h.template delete mode 100644 autoarchive/autoar-extract.c delete mode 100644 autoarchive/autoar-extract.h delete mode 100644 autoarchive/autoar-pref.c delete mode 100644 autoarchive/autoar-pref.h delete mode 100644 autoarchive/autoarchive.h delete mode 100644 autoarchive/org.gnome.desktop.archives.gschema.xml delete mode 100644 autoarchive/test-extract.c delete mode 100644 autoarchive/test-pref.c diff --git a/Makefile.am b/Makefile.am index 3583fbce9..e71acc96f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = autoarchive lib embed src data po doc +SUBDIRS = lib embed src data po doc if ENABLE_TESTS SUBDIRS += tests diff --git a/autoarchive/Makefile.am b/autoarchive/Makefile.am deleted file mode 100644 index a5f1189fd..000000000 --- a/autoarchive/Makefile.am +++ /dev/null @@ -1,91 +0,0 @@ -# vim: set sw=8 ts=8 sts=8 noet: - -NULL = - -noinst_PROGRAMS = - -EXTRA_DIST = \ - autoar-enum-types.h.template \ - autoar-enum-types.c.template \ - org.gnome.desktop.archives.gschema.xml \ - $(NULL) - -gsettings_ENUM_NAMESPACE = org.gnome.desktop.archives -gsettings_ENUM_FILES = $(top_srcdir)/autoarchive/autoar-pref.h - -gsettings_SCHEMAS = org.gnome.desktop.archives.gschema.xml - -@GSETTINGS_RULES@ - -noinst_LTLIBRARIES = libautoarchive.la - -libautoarchive_h_sources = \ - autoar-common.h \ - autoar-create.h \ - autoar-extract.h \ - autoar-pref.h \ - $(NULL) -libautoarchive_c_sources = \ - autoar-common.c \ - autoar-create.c \ - autoar-extract.c \ - autoar-pref.c \ - $(NULL) -libautoarchive_generated_sources = \ - autoar-enum-types.h \ - autoar-enum-types.c \ - $(NULL) - -libautoarchive_la_SOURCES = \ - $(libautoarchive_generated_sources) \ - $(libautoarchive_h_sources) \ - $(libautoarchive_c_sources) \ - $(NULL) -libautoarchive_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - $(NULL) -libautoarchive_la_CFLAGS = \ - $(DEPENDENCIES_CFLAGS) \ - $(AM_CFLAGS) \ - $(NULL) - -autoar-enum-types.h: autoar-enum-types.h.template $(libautoarchive_h_sources) $(GLIB_MKENUMS) - $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template autoar-enum-types.h.template $(libautoarchive_h_sources)) > $@ -autoar-enum-types.c: autoar-enum-types.c.template $(libautoarchive_h_sources) $(GLIB_MKENUMS) - $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template autoar-enum-types.c.template $(libautoarchive_h_sources)) > $@ - -noinst_PROGRAMS += test-extract -EXTRA_DIST += test-extract.c -test_extract_SOURCES = \ - test-extract.c \ - $(NULL) -test_extract_CFLAGS = \ - $(DEPENDENCIES_CFLAGS) \ - $(AM_CFLAGS) \ - $(NULL) -test_extract_LDADD = \ - $(DEPENDENCIES_LIBS) \ - libautoarchive.la \ - $(NULL) - -noinst_PROGRAMS += test-pref -EXTRA_DIST += test-pref.c -test_pref_SOURCES = \ - test-pref.c \ - $(NULL) -test_pref_CFLAGS = \ - $(DEPENDENCIES_CFLAGS) \ - $(AM_CFLAGS) \ - $(NULL) -test_pref_LDADD = \ - $(DEPENDENCIES_LIBS) \ - libautoarchive.la \ - $(NULL) - -BUILT_SOURCES = \ - $(libautoarchive_generated_sources) \ - $(NULL) - -CLEANFILES = $(BUILT_SOURCES) -DISTCLEANFILES = $(BUILT_SOURCES) -MAINTAINERCLEANFILES = $(BUILT_SOURCES) diff --git a/autoarchive/autoar-common.c b/autoarchive/autoar-common.c deleted file mode 100644 index a56c471d0..000000000 --- a/autoarchive/autoar-common.c +++ /dev/null @@ -1,163 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-common.c - * Some common functions used in several classes of autoarchive - * This file does NOT declare any new classes! - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "autoar-common.h" - -#include -#include -#include - -typedef struct _AutoarCommonSignalData AutoarCommonSignalData; - -struct _AutoarCommonSignalData -{ - GValue instance_and_params[3]; /* Maximum number of parameters + 1 */ - gssize used_values; /* Number of GValues to be unset */ - guint signal_id; - GQuark detail; -}; - -char* -autoar_common_get_filename_extension (const char *filename) -{ - char *dot_location; - - dot_location = strrchr (filename, '.'); - if (dot_location == NULL || dot_location == filename) { - return (char*)filename; - } - - if (dot_location - 4 > filename && strncmp (dot_location - 4, ".tar", 4) == 0) - dot_location -= 4; - else if (dot_location - 5 > filename && strncmp (dot_location - 5, ".cpio", 5) == 0) - dot_location -= 5; - - return dot_location; -} - -char* -autoar_common_get_basename_remove_extension (const char *filename) -{ - char *dot_location; - char *basename; - - if (filename == NULL) { - return NULL; - } - - /* filename must not be directory, so we do not get a bad basename. */ - basename = g_path_get_basename (filename); - - dot_location = autoar_common_get_filename_extension (basename); - *dot_location = '\0'; - - g_debug ("_g_filename_basename_remove_extension: %s => %s", - filename, - basename); - return basename; -} - -static void -autoar_common_signal_data_free (AutoarCommonSignalData *signal_data) -{ - int i; - - for (i = 0; i < signal_data->used_values; i++) - g_value_unset (signal_data->instance_and_params + i); - - g_free (signal_data); -} - -static gboolean -autoar_common_g_signal_emit_main_context (void *data) -{ - AutoarCommonSignalData *signal_data = data; - g_signal_emitv (signal_data->instance_and_params, - signal_data->signal_id, - signal_data->detail, - NULL); - autoar_common_signal_data_free (signal_data); - return FALSE; -} - -void -autoar_common_g_signal_emit (gboolean in_thread, - gpointer instance, - guint signal_id, - GQuark detail, - ...) -{ - va_list ap; - - va_start (ap, detail); - if (in_thread) { - int i; - gchar *error; - GSignalQuery query; - AutoarCommonSignalData *data; - - error = NULL; - data = g_new0 (AutoarCommonSignalData, 1); - data->signal_id = signal_id; - data->detail = detail; - data->used_values = 1; - g_value_init (data->instance_and_params, G_TYPE_FROM_INSTANCE (instance)); - g_value_set_instance (data->instance_and_params, instance); - - g_signal_query (signal_id, &query); - if (query.signal_id == 0) { - autoar_common_signal_data_free (data); - va_end (ap); - return; - } - - for (i = 0; i < query.n_params; i++) { - G_VALUE_COLLECT_INIT (data->instance_and_params + i + 1, - query.param_types[i], - ap, - 0, - &error); - if (error != NULL) - break; - data->used_values++; - } - - if (error == NULL) { - g_main_context_invoke (NULL, autoar_common_g_signal_emit_main_context, data); - } else { - autoar_common_signal_data_free (data); - g_debug ("G_VALUE_COLLECT_INIT: Error: %s", error); - g_free (error); - va_end (ap); - return; - } - } else { - g_signal_emit_valist (instance, signal_id, detail, ap); - } - va_end (ap); -} diff --git a/autoarchive/autoar-common.h b/autoarchive/autoar-common.h deleted file mode 100644 index 888eb0853..000000000 --- a/autoarchive/autoar-common.h +++ /dev/null @@ -1,41 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-common.h - * Some common functions used in several classes of autoarchive - * This file does NOT declare any new classes! - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOAR_COMMON_H -#define AUTOAR_COMMON_H - -#include - -char* autoar_common_get_basename_remove_extension (const char *filename); -char* autoar_common_get_filename_extension (const char *filename); - -void autoar_common_g_signal_emit (gboolean in_thread, - gpointer instance, - guint signal_id, - GQuark detail, - ...); - -#endif /* AUTOAR_COMMON_H */ diff --git a/autoarchive/autoar-create.c b/autoarchive/autoar-create.c deleted file mode 100644 index 4b946bd43..000000000 --- a/autoarchive/autoar-create.c +++ /dev/null @@ -1,507 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-create.c - * Automatically create archives in some GNOME programs - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "autoar-create.h" -#include "autoar-pref.h" - -#include -#include -#include - -G_DEFINE_TYPE (AutoarCreate, autoar_create, G_TYPE_OBJECT) - -#define AUTOAR_CREATE_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_CREATE, AutoarCreatePrivate)) - -#define BUFFER_SIZE (64 * 1024) - -struct _AutoarCreatePrivate -{ - char **source; - char *output; - - guint64 size; /* This field is currently unused */ - guint64 completed_size; - - guint files; - guint completed_files; - - AutoarPref *arpref; - - GOutputStream *ostream; - void *buffer; - gssize buffer_size; - GError *error; -}; - -enum -{ - DECIDE_DEST, - PROGRESS, - COMPLETED, - ERROR, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_SOURCE, - PROP_OUTPUT, - PROP_SIZE, /* This property is currently unused */ - PROP_COMPLETED_SIZE, - PROP_FILES, - PROP_COMPLETED_FILES -}; - -static guint autoar_create_signals[LAST_SIGNAL] = { 0 }; -static GQuark autoar_create_quark; - -static void -autoar_create_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - AutoarCreate *arcreate; - AutoarCreatePrivate *priv; - - GVariant *variant; - const char* const* strv; - - arcreate = AUTOAR_CREATE (object); - priv = arcreate->priv; - - switch (property_id) { - case PROP_SOURCE: - strv = (const char* const*)(priv->source); - variant = g_variant_new_strv (strv, -1); - g_value_take_variant (value, variant); - break; - case PROP_OUTPUT: - g_value_set_string (value, priv->output); - break; - case PROP_SIZE: - g_value_set_uint64 (value, priv->size); - case PROP_COMPLETED_SIZE: - g_value_set_uint64 (value, priv->completed_size); - break; - case PROP_FILES: - g_value_set_uint (value, priv->files); - break; - case PROP_COMPLETED_FILES: - g_value_set_uint (value, priv->completed_files); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -autoar_create_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - AutoarCreate *arcreate; - AutoarCreatePrivate *priv; - - const char **strv; - - arcreate = AUTOAR_CREATE (object); - priv = arcreate->priv; - - switch (property_id) { - case PROP_SIZE: - autoar_create_set_size (arcreate, g_value_get_uint64 (value)); - break; - case PROP_COMPLETED_SIZE: - autoar_create_set_completed_size (arcreate, g_value_get_uint64 (value)); - break; - case PROP_FILES: - autoar_create_set_files (arcreate, g_value_get_uint (value)); - break; - case PROP_COMPLETED_FILES: - autoar_create_set_completed_files (arcreate, g_value_get_uint (value)); - break; - case PROP_SOURCE: - strv = g_variant_get_strv (g_value_get_variant (value), NULL); - g_strfreev (arcreate->priv->source); - arcreate->priv->source = g_strdupv ((char**)strv); - break; - case PROP_OUTPUT: - g_free (priv->output); - priv->output = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -char** -autoar_create_get_source (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), NULL); - return arcreate->priv->source; -} - -char* -autoar_create_get_output (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), NULL); - return arcreate->priv->output; -} - -guint64 -autoar_create_get_size (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), 0); - return arcreate->priv->size; -} - -guint64 -autoar_create_get_completed_size (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), 0); - return arcreate->priv->completed_size; -} - -guint -autoar_create_get_files (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), 0); - return arcreate->priv->files; -} - -guint -autoar_create_get_completed_files (AutoarCreate *arcreate) -{ - g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), 0); - return arcreate->priv->completed_files; -} - -void -autoar_create_set_size (AutoarCreate *arcreate, - guint64 size) -{ - g_return_if_fail (AUTOAR_IS_CREATE (arcreate)); - arcreate->priv->size = size; -} - -void -autoar_create_set_completed_size (AutoarCreate *arcreate, - guint64 completed_size) -{ - g_return_if_fail (AUTOAR_IS_CREATE (arcreate)); - g_return_if_fail (completed_size <= arcreate->priv->completed_size); - arcreate->priv->completed_size = completed_size; -} - -void -autoar_create_set_files (AutoarCreate *arcreate, - guint files) -{ - g_return_if_fail (AUTOAR_IS_CREATE (arcreate)); - arcreate->priv->files = files; -} - -void -autoar_create_set_completed_files (AutoarCreate *arcreate, - guint completed_files) -{ - g_return_if_fail (AUTOAR_IS_CREATE (arcreate)); - g_return_if_fail (completed_files <= arcreate->priv->completed_files); - arcreate->priv->completed_files = completed_files; -} - -static void -autoar_create_dispose (GObject *object) -{ - AutoarCreate *arcreate; - arcreate = AUTOAR_CREATE (object); - - g_debug ("AutoarCreate: dispose"); - - g_clear_object (&(arcreate->priv->arpref)); - - G_OBJECT_CLASS (autoar_create_parent_class)->dispose (object); -} - -static void -autoar_create_finalize (GObject *object) -{ - AutoarCreate *arcreate; - AutoarCreatePrivate *priv; - - arcreate = AUTOAR_CREATE (object); - priv = arcreate->priv; - - g_debug ("AutoarCreate: finalize"); - - g_strfreev (priv->source); - priv->source = NULL; - - g_free (priv->output); - priv->output = NULL; - - if (priv->ostream != NULL) { - if (!g_output_stream_is_closed (priv->ostream)) { - g_output_stream_close (priv->ostream, NULL, NULL); - } - g_object_unref (priv->ostream); - } - - g_free (priv->buffer); - priv->buffer = NULL; - - if (priv->error != NULL) { - g_error_free (priv->error); - priv->error = NULL; - } - - G_OBJECT_CLASS (autoar_create_parent_class)->finalize (object); -} - -static void -autoar_create_class_init (AutoarCreateClass *klass) -{ - GObjectClass *object_class; - GType type; - GPtrArray *tmparr; - - object_class = G_OBJECT_CLASS (klass); - type = G_TYPE_FROM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (AutoarCreatePrivate)); - - autoar_create_quark = g_quark_from_static_string ("autoar-create"); - - object_class->get_property = autoar_create_get_property; - object_class->set_property = autoar_create_set_property; - object_class->dispose = autoar_create_dispose; - object_class->finalize = autoar_create_finalize; - - tmparr = g_ptr_array_new (); - g_ptr_array_add (tmparr, NULL); - - g_object_class_install_property (object_class, PROP_SOURCE, - g_param_spec_variant ("source", - "Source archive", - "The source files and directories to be compressed", - G_VARIANT_TYPE_STRING_ARRAY, - g_variant_new_strv ((const char* const*)tmparr->pdata, -1), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_OUTPUT, - g_param_spec_string ("output", - "Output directory", - "Output directory of created archive", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_SIZE, - g_param_spec_uint64 ("size", - "Size", - "Unused property", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_COMPLETED_SIZE, - g_param_spec_uint64 ("completed-size", - "Read file size", - "Bytes written to the archive", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_FILES, - g_param_spec_uint ("files", - "Files", - "Number of files to be compressed", - 0, G_MAXUINT32, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_COMPLETED_FILES, - g_param_spec_uint ("completed-files", - "Read files", - "Number of files has been read", - 0, G_MAXUINT32, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - autoar_create_signals[DECIDE_DEST] = - g_signal_new ("decide-dest", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarCreateClass, decide_dest), - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, - G_TYPE_FILE); - - autoar_create_signals[PROGRESS] = - g_signal_new ("progress", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarCreateClass, progress), - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 2, - G_TYPE_UINT64, - G_TYPE_UINT); - - autoar_create_signals[COMPLETED] = - g_signal_new ("completed", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarCreateClass, completed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - autoar_create_signals[ERROR] = - g_signal_new ("error", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarCreateClass, error), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); - - g_ptr_array_unref (tmparr); -} - -static void -autoar_create_init (AutoarCreate *arcreate) -{ - AutoarCreatePrivate *priv; - - priv = AUTOAR_CREATE_GET_PRIVATE (arcreate); - arcreate->priv = priv; - - priv->source = NULL; - priv->output = NULL; - - priv->completed_size = 0; - - priv->files = 0; - priv->completed_files = 0; - - priv->arpref = NULL; - - priv->ostream = NULL; - priv->buffer_size = BUFFER_SIZE; - priv->buffer = g_new (char, priv->buffer_size); - priv->error = NULL; -} - -AutoarCreate* -autoar_create_newv (AutoarPref *arpref, - const char *output, - const char **source) -{ - AutoarCreate *arcreate; - - g_return_val_if_fail (source != NULL, NULL); - g_return_val_if_fail (output != NULL, NULL); - - arcreate = g_object_new (AUTOAR_TYPE_CREATE, - "source", source, - "output", output, - NULL); - arcreate->priv->arpref = g_object_ref (arpref); - - return arcreate; -} - -AutoarCreate* -autoar_create_new (AutoarPref *arpref, - const char *output, - ...) -{ - AutoarCreate *arcreate; - char *str; - va_list ap; - GPtrArray *strv; - - va_start (ap, output); - strv = g_ptr_array_new_with_free_func (g_free); - while ((str = va_arg (ap, char*)) != NULL) { - g_ptr_array_add (strv, str); - } - g_ptr_array_add (strv, NULL); - va_end (ap); - - arcreate = autoar_create_newv (arpref, output, (const char**)(strv->pdata)); - g_ptr_array_unref (strv); - return arcreate; -} - -static void -autoar_create_run (AutoarCreate *arcreate, - gboolean in_thread) -{ - struct archive *a; - struct archive_entry *entry; - -} - -void -autoar_create_start (AutoarCreate *arcreate) -{ - autoar_create_run (arcreate, FALSE); -} - -void -autoar_create_start_async (AutoarCreate *arcreate) -{ -} diff --git a/autoarchive/autoar-create.h b/autoarchive/autoar-create.h deleted file mode 100644 index 3c37945b3..000000000 --- a/autoarchive/autoar-create.h +++ /dev/null @@ -1,95 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-create.h - * Automatically create archives in some GNOME programs - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOAR_CREATE_H -#define AUTOAR_CREATE_H - -#include -#include - -#include "autoar-pref.h" - -G_BEGIN_DECLS - -#define AUTOAR_TYPE_CREATE autoar_create_get_type () -#define AUTOAR_CREATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOAR_TYPE_CREATE, AutoarCreate)) -#define AUTOAR_CREATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AUTOAR_TYPE_CREATE, AutoarCreateClass)) -#define AUTOAR_IS_CREATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOAR_TYPE_CREATE)) -#define AUTOAR_IS_CREATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AUTOAR_TYPE_CREATE)) -#define AUTOAR_CREATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AUTOAR_TYPE_CREATE, AutoarCreateClass)) - -typedef struct _AutoarCreate AutoarCreate; -typedef struct _AutoarCreateClass AutoarCreateClass; -typedef struct _AutoarCreatePrivate AutoarCreatePrivate; - -struct _AutoarCreate -{ - GObject parent; - - AutoarCreatePrivate *priv; -}; - -struct _AutoarCreateClass -{ - GObjectClass parent_class; - - void (* decide_dest)(AutoarCreate *arcreate, - GFile *destination); - void (* progress) (AutoarCreate *arcreate, - guint64 completed_size, - guint completed_files); - void (* completed) (AutoarCreate *arcreate); - void (* error) (AutoarCreate *arcreate, - GError *error); -}; - -GType autoar_create_get_type (void) G_GNUC_CONST; - -AutoarCreate* autoar_create_new (AutoarPref *arpref, - const char *output, - ...); -AutoarCreate* autoar_create_newv (AutoarPref *arpref, - const char *output, - const char **source); - -void autoar_create_start (AutoarCreate *arcreate); -void autoar_create_start_async (AutoarCreate *arcreate); - -char **autoar_create_get_source (AutoarCreate *arcreate); -char *autoar_create_get_output (AutoarCreate *arcreate); -guint64 autoar_create_get_completed_size (AutoarCreate *arcreate); -guint autoar_create_get_files (AutoarCreate *arcreate); -guint autoar_create_get_completed_files (AutoarCreate *arcreate); - -void autoar_create_set_completed_size (AutoarCreate *arcreate, - guint64 completed_size); -void autoar_create_set_files (AutoarCreate *arcreate, - guint files); -void autoar_create_set_completed_files (AutoarCreate *arcreate, - guint completed_files); - -G_END_DECLS - -#endif /* AUTOAR_CREATE_H */ diff --git a/autoarchive/autoar-enum-types.c.template b/autoarchive/autoar-enum-types.c.template deleted file mode 100644 index 96aee6258..000000000 --- a/autoarchive/autoar-enum-types.c.template +++ /dev/null @@ -1,36 +0,0 @@ -/*** BEGIN file-header ***/ -#include "autoar-enum-types.h" - -/*** END file-header ***/ - -/*** BEGIN file-production ***/ -/* enumerations from "@filename@" */ -#include "@filename@" - -/*** END file-production ***/ - -/*** BEGIN value-header ***/ -GType -@enum_name@_get_type (void) -{ - static GType type = 0; - if (G_UNLIKELY (!type)) - { - static const G@Type@Value values[] = { -/*** END value-header ***/ - -/*** BEGIN value-production ***/ - { @VALUENAME@, - "@VALUENAME@", - "@valuenick@" }, -/*** END value-production ***/ - -/*** BEGIN value-tail ***/ - { 0, NULL, NULL } - }; - type = g_@type@_register_static ("@EnumName@", values); - } - return type; -} - -/*** END value-tail ***/ diff --git a/autoarchive/autoar-enum-types.h.template b/autoarchive/autoar-enum-types.h.template deleted file mode 100644 index d2dbecfe5..000000000 --- a/autoarchive/autoar-enum-types.h.template +++ /dev/null @@ -1,26 +0,0 @@ -/*** BEGIN file-header ***/ -#ifndef AUTOAR_ENUM_TYPES_H -#define AUTOAR_ENUM_TYPES_H - -#include - -G_BEGIN_DECLS - -/*** END file-header ***/ - -/*** BEGIN file-production ***/ -/* Enumerations from "@filename@" */ - -/*** END file-production ***/ - -/*** BEGIN enumeration-production ***/ -#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) -GType @enum_name@_get_type (void) G_GNUC_CONST; - -/*** END enumeration-production ***/ - -/*** BEGIN file-tail ***/ -G_END_DECLS - -#endif /* AUTOAR_ENUM_TYPES_H */ -/*** END file-tail ***/ diff --git a/autoarchive/autoar-extract.c b/autoarchive/autoar-extract.c deleted file mode 100644 index e7c4c7e61..000000000 --- a/autoarchive/autoar-extract.c +++ /dev/null @@ -1,1373 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-extract.c - * Automatically extract archives in some GNOME programs - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "autoar-extract.h" - -#include "autoar-common.h" -#include "autoar-pref.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined HAVE_MKFIFO || defined HAVE_MKNOD -# include -#endif - -#ifdef HAVE_GETPWNAM -# include -#endif - -#ifdef HAVE_GETGRNAM -# include -#endif - - -G_DEFINE_TYPE (AutoarExtract, autoar_extract, G_TYPE_OBJECT) - -#define AUTOAR_EXTRACT_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_EXTRACT, AutoarExtractPrivate)) - -#define BUFFER_SIZE (64 * 1024) -#define NOT_AN_ARCHIVE_ERRNO 2013 - -struct _AutoarExtractPrivate -{ - char *source; - char *output; - - guint64 size; - guint64 completed_size; - - guint files; - guint completed_files; - - AutoarPref *arpref; - - GInputStream *istream; - void *buffer; - gssize buffer_size; - GError *error; -}; - -enum -{ - SCANNED, - DECIDE_DEST, - PROGRESS, - COMPLETED, - ERROR, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_SOURCE, - PROP_OUTPUT, - PROP_SIZE, - PROP_COMPLETED_SIZE, - PROP_FILES, - PROP_COMPLETED_FILES -}; - -static guint autoar_extract_signals[LAST_SIGNAL] = { 0 }; -static GQuark autoar_extract_quark; - -static void -autoar_extract_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - AutoarExtract *arextract; - AutoarExtractPrivate *priv; - - arextract = AUTOAR_EXTRACT (object); - priv = arextract->priv; - - switch (property_id) { - case PROP_SOURCE: - g_value_set_string (value, priv->source); - break; - case PROP_OUTPUT: - g_value_set_string (value, priv->output); - break; - case PROP_SIZE: - g_value_set_uint64 (value, priv->size); - break; - case PROP_COMPLETED_SIZE: - g_value_set_uint64 (value, priv->completed_size); - break; - case PROP_FILES: - g_value_set_uint (value, priv->files); - break; - case PROP_COMPLETED_FILES: - g_value_set_uint (value, priv->completed_files); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -autoar_extract_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - AutoarExtract *arextract; - AutoarExtractPrivate *priv; - - arextract = AUTOAR_EXTRACT (object); - priv = arextract->priv; - - switch (property_id) { - case PROP_SIZE: - autoar_extract_set_size (arextract, g_value_get_uint64 (value)); - break; - case PROP_COMPLETED_SIZE: - autoar_extract_set_completed_size (arextract, g_value_get_uint64 (value)); - break; - case PROP_FILES: - autoar_extract_set_files (arextract, g_value_get_uint (value)); - break; - case PROP_COMPLETED_FILES: - autoar_extract_set_completed_files (arextract, g_value_get_uint (value)); - break; - case PROP_SOURCE: - g_free (priv->source); - priv->source = g_value_dup_string (value); - break; - case PROP_OUTPUT: - g_free (priv->output); - priv->output = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -char* -autoar_extract_get_source (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), NULL); - return arextract->priv->source; -} - -char* -autoar_extract_get_output (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), NULL); - return arextract->priv->output; -} - -guint64 -autoar_extract_get_size (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), 0); - return arextract->priv->size; -} - -guint64 -autoar_extract_get_completed_size (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), 0); - return arextract->priv->completed_size; -} - -guint -autoar_extract_get_files (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), 0); - return arextract->priv->files; -} - -guint -autoar_extract_get_completed_files (AutoarExtract *arextract) -{ - g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), 0); - return arextract->priv->completed_files; -} - -void -autoar_extract_set_size (AutoarExtract *arextract, - guint64 size) -{ - g_return_if_fail (AUTOAR_IS_EXTRACT (arextract)); - arextract->priv->size = size; -} - -void -autoar_extract_set_completed_size (AutoarExtract *arextract, - guint64 completed_size) -{ - g_return_if_fail (AUTOAR_IS_EXTRACT (arextract)); - g_return_if_fail (completed_size <= arextract->priv->completed_size); - arextract->priv->completed_size = completed_size; -} - -void -autoar_extract_set_files (AutoarExtract *arextract, - guint files) -{ - g_return_if_fail (AUTOAR_IS_EXTRACT (arextract)); - arextract->priv->files = files; -} - -void -autoar_extract_set_completed_files (AutoarExtract *arextract, - guint completed_files) -{ - g_return_if_fail (AUTOAR_IS_EXTRACT (arextract)); - g_return_if_fail (completed_files <= arextract->priv->completed_files); - arextract->priv->completed_files = completed_files; -} - -static void -autoar_extract_dispose (GObject *object) -{ - AutoarExtract *arextract; - arextract = AUTOAR_EXTRACT (object); - - g_debug ("AutoarExtract: dispose"); - - g_clear_object (&(arextract->priv->arpref)); - - G_OBJECT_CLASS (autoar_extract_parent_class)->dispose (object); -} - -static void -autoar_extract_finalize (GObject *object) -{ - AutoarExtract *arextract; - AutoarExtractPrivate *priv; - - arextract = AUTOAR_EXTRACT (object); - priv = arextract->priv; - - g_debug ("AutoarExtract: finalize"); - - g_free (priv->source); - priv->source = NULL; - - g_free (priv->output); - priv->output = NULL; - - if (priv->istream != NULL) { - if (!g_input_stream_is_closed (priv->istream)) { - g_input_stream_close (priv->istream, NULL, NULL); - } - g_object_unref (priv->istream); - } - - g_free (priv->buffer); - priv->buffer = NULL; - - if (priv->error != NULL) { - g_error_free (priv->error); - priv->error = NULL; - } - - G_OBJECT_CLASS (autoar_extract_parent_class)->finalize (object); -} - -static int -libarchive_read_open_cb (struct archive *ar_read, - void *client_data) -{ - AutoarExtract *arextract; - GFile *file; - - g_debug ("libarchive_read_open_cb: called"); - - arextract = (AutoarExtract*)client_data; - if (arextract->priv->error != NULL) { - return ARCHIVE_FATAL; - } - - file = g_file_new_for_commandline_arg (arextract->priv->source); - - arextract->priv->istream = (GInputStream*)g_file_read (file, - NULL, - &(arextract->priv->error)); - g_return_val_if_fail (arextract->priv->error == NULL, ARCHIVE_FATAL); - - g_debug ("libarchive_read_open_cb: ARCHIVE_OK"); - return ARCHIVE_OK; -} - -static int -libarchive_read_close_cb (struct archive *ar_read, - void *client_data) -{ - AutoarExtract *arextract; - - g_debug ("libarchive_read_close_cb: called"); - - arextract = (AutoarExtract*)client_data; - if (arextract->priv->error != NULL) { - return ARCHIVE_FATAL; - } - - if (arextract->priv->istream != NULL) { - g_input_stream_close (arextract->priv->istream, NULL, NULL); - g_object_unref (arextract->priv->istream); - arextract->priv->istream = NULL; - } - - g_debug ("libarchive_read_close_cb: ARCHIVE_OK"); - return ARCHIVE_OK; -} - -static ssize_t -libarchive_read_read_cb (struct archive *ar_read, - void *client_data, - const void **buffer) -{ - AutoarExtract *arextract; - gssize read_size; - - g_debug ("libarchive_read_read_cb: called"); - - arextract = (AutoarExtract*)client_data; - if (arextract->priv->error != NULL) { - return -1; - } - - *buffer = arextract->priv->buffer; - read_size = g_input_stream_read (arextract->priv->istream, - arextract->priv->buffer, - arextract->priv->buffer_size, - NULL, - &(arextract->priv->error)); - g_return_val_if_fail (arextract->priv->error == NULL, -1); - - g_debug ("libarchive_read_read_cb: %lu", read_size); - return read_size; -} - -static off_t -libarchive_read_seek_cb (struct archive *ar_read, - void *client_data, - off_t request, - int whence) -{ - AutoarExtract *arextract; - GSeekable *seekable; - GSeekType seektype; - off_t new_offset; - - g_debug ("libarchive_read_seek_cb: called"); - - arextract = (AutoarExtract*)client_data; - seekable = (GSeekable*)(arextract->priv->istream); - if (arextract->priv->error != NULL) { - return -1; - } - - switch (whence) { - case SEEK_SET: - seektype = G_SEEK_SET; - break; - case SEEK_CUR: - seektype = G_SEEK_CUR; - break; - case SEEK_END: - seektype = G_SEEK_END; - break; - default: - return -1; - } - - g_seekable_seek (seekable, - request, - seektype, - NULL, - &(arextract->priv->error)); - new_offset = g_seekable_tell (seekable); - g_return_val_if_fail (arextract->priv->error == NULL, -1); - - g_debug ("libarchive_read_seek_cb: %"G_GOFFSET_FORMAT, (goffset)new_offset); - return new_offset; -} - -static off_t -libarchive_read_skip_cb (struct archive *ar_read, - void *client_data, - off_t request) -{ - AutoarExtract *arextract; - GSeekable *seekable; - off_t old_offset, new_offset; - - g_debug ("libarchive_read_skip_cb: called"); - - arextract = (AutoarExtract*)client_data; - seekable = (GSeekable*)(arextract->priv->istream); - if (arextract->priv->error != NULL) { - return -1; - } - - old_offset = g_seekable_tell (seekable); - new_offset = libarchive_read_seek_cb (ar_read, client_data, request, SEEK_CUR); - if (new_offset > old_offset) - return (new_offset - old_offset); - - return 0; -} - -static void -g_pattern_spec_free_safe (void *pattern_compiled) -{ - if (pattern_compiled != NULL) - g_pattern_spec_free (pattern_compiled); -} - -static gboolean -autoar_extract_do_pattern_check (const char *path, - GPtrArray *pattern) -{ - char **path_components; - GArray *path_components_len; - - int i, j, len; - - path_components = g_strsplit (path, "/", G_MAXINT); - path_components_len = g_array_new (FALSE, FALSE, sizeof(size_t)); - for (i = 0; path_components[i] != NULL; i++) { - len = strlen (path_components[i]); - g_array_append_val (path_components_len, len); - } - - for (i = 0; g_ptr_array_index (pattern, i) != NULL; i++) { - for (j = 0; path_components[j] != NULL; j++) { - if (g_pattern_match (g_ptr_array_index (pattern, i), - g_array_index (path_components_len, size_t, j), - path_components[j], - NULL)) { - g_debug ("autoar_extract_do_pattern_check: ### %s", path_components[j]); - g_strfreev (path_components); - g_array_unref (path_components_len); - return FALSE; - } - } - } - - g_strfreev (path_components); - g_array_unref (path_components_len); - - return TRUE; -} - -static void -autoar_extract_do_write_entry (AutoarExtract *arextract, - struct archive *a, - struct archive_entry *entry, - GFile *dest, - GHashTable *userhash, - GHashTable *grouphash, - gboolean in_thread, - gboolean use_raw_format) -{ - GOutputStream *ostream; - GFileInfo *info; - GFile *parent; - mode_t filetype; - const void *buffer; - size_t size, written; - off_t offset; - int r; - -#ifdef HAVE_GETPWNAM - const char *uname; -#endif - -#ifdef HAVE_GETGRNAM - const char *gname; -#endif - - guint32 uid, gid; - - parent = g_file_get_parent (dest); - if (!g_file_query_exists (parent, NULL)) - g_file_make_directory_with_parents (parent, NULL, NULL); - g_object_unref (parent); - - info = g_file_info_new (); - - /* time */ - g_debug ("autoar_extract_do_write_entry: time"); - if (archive_entry_atime_is_set (entry)) { - g_file_info_set_attribute_uint64 (info, - G_FILE_ATTRIBUTE_TIME_ACCESS, - archive_entry_atime (entry)); - g_file_info_set_attribute_uint32 (info, - G_FILE_ATTRIBUTE_TIME_ACCESS_USEC, - archive_entry_atime_nsec (entry) / 1000); - } - if (archive_entry_birthtime_is_set (entry)) { - g_file_info_set_attribute_uint64 (info, - G_FILE_ATTRIBUTE_TIME_CREATED, - archive_entry_birthtime (entry)); - g_file_info_set_attribute_uint32 (info, - G_FILE_ATTRIBUTE_TIME_CREATED_USEC, - archive_entry_birthtime_nsec (entry) / 1000); - } - if (archive_entry_ctime_is_set (entry)) { - g_file_info_set_attribute_uint64 (info, - G_FILE_ATTRIBUTE_TIME_CHANGED, - archive_entry_ctime (entry)); - g_file_info_set_attribute_uint32 (info, - G_FILE_ATTRIBUTE_TIME_CHANGED_USEC, - archive_entry_ctime_nsec (entry) / 1000); - } - if (archive_entry_mtime_is_set (entry)) { - g_file_info_set_attribute_uint64 (info, - G_FILE_ATTRIBUTE_TIME_MODIFIED, - archive_entry_mtime (entry)); - g_file_info_set_attribute_uint32 (info, - G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC, - archive_entry_mtime_nsec (entry) / 1000); - } - - /* user */ - g_debug ("autoar_extract_do_write_entry: user"); -#ifdef HAVE_GETPWNAM - if ((uname = archive_entry_uname (entry)) != NULL) { - void *got_uid; - if (g_hash_table_lookup_extended (userhash, uname, NULL, &got_uid) == TRUE) { - uid = GPOINTER_TO_UINT (got_uid); - } else { - struct passwd *pwd = getpwnam (uname); - if (pwd == NULL) { - uid = archive_entry_uid (entry); - } else { - uid = pwd->pw_uid; - g_hash_table_insert (userhash, g_strdup (uname), GUINT_TO_POINTER (uid)); - } - } - g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID, uid); - } else -#endif - if ((uid = archive_entry_uid (entry)) != 0) { - g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID, uid); - } - - /* group */ - g_debug ("autoar_extract_do_write_entry: group"); -#ifdef HAVE_GETGRNAM - if ((gname = archive_entry_gname (entry)) != NULL) { - void *got_gid; - if (g_hash_table_lookup_extended (grouphash, gname, NULL, &got_gid) == TRUE) { - gid = GPOINTER_TO_UINT (got_gid); - } else { - struct group *grp = getgrnam (gname); - if (grp == NULL) { - gid = archive_entry_gid (entry); - } else { - gid = grp->gr_gid; - g_hash_table_insert (grouphash, g_strdup (gname), GUINT_TO_POINTER (gid)); - } - } - g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID, gid); - } else -#endif - if ((gid = archive_entry_gid (entry)) != 0) { - g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID, gid); - } - - /* permissions */ - g_debug ("autoar_extract_do_write_entry: permissions"); - g_file_info_set_attribute_uint32 (info, - G_FILE_ATTRIBUTE_UNIX_MODE, - archive_entry_mode (entry)); - - g_debug ("autoar_extract_do_write_entry: writing"); - r = 0; - switch (filetype = archive_entry_filetype (entry)) { - case AE_IFREG: - ostream = (GOutputStream*)g_file_replace (dest, - NULL, - FALSE, - G_FILE_CREATE_NONE, - NULL, - &(arextract->priv->error)); - if (arextract->priv->error != NULL) { - g_object_unref (info); - return; - } - if (ostream != NULL) { - /* Archive entry size may be zero if we use raw format. */ - if (archive_entry_size(entry) > 0 || use_raw_format) { - while (archive_read_data_block (a, &buffer, &size, &offset) == ARCHIVE_OK) { - /* buffer == NULL occurs in some zip archives when an entry is - * completely read. We just skip this situation to prevent GIO - * warnings. */ - if (buffer == NULL) - continue; - g_output_stream_write_all (ostream, - buffer, - size, - &written, - NULL, - &(arextract->priv->error)); - if (arextract->priv->error != NULL) { - g_output_stream_close (ostream, NULL, NULL); - g_object_unref (ostream); - g_object_unref (info); - return; - } - arextract->priv->completed_size += written; - autoar_common_g_signal_emit (in_thread, - arextract, - autoar_extract_signals[PROGRESS], - 0, - ((double)(arextract->priv->completed_size)) / - ((double)(arextract->priv->size)), - ((double)(arextract->priv->completed_files)) / - ((double)(arextract->priv->files))); - } - } - g_output_stream_close (ostream, NULL, NULL); - g_object_unref (ostream); - } - break; - case AE_IFDIR: - g_file_make_directory_with_parents (dest, NULL, &(arextract->priv->error)); - if (arextract->priv->error != NULL) { - /* "File exists" is not a fatal error */ - if (arextract->priv->error->code == G_IO_ERROR_EXISTS) { - g_error_free (arextract->priv->error); - arextract->priv->error = NULL; - } - } - break; - case AE_IFLNK: - g_file_make_symbolic_link (dest, - archive_entry_symlink (entry), - NULL, - &(arextract->priv->error)); - break; - /* FIFOs, sockets, block files, character files are not important - * in the regular archives, so errors are not fatal. */ -#if defined HAVE_MKFIFO || defined HAVE_MKNOD - case AE_IFIFO: -# ifdef HAVE_MKFIFO - r = mkfifo (g_file_get_path (dest), archive_entry_mode (entry)); -# else - r = mknod (g_file_get_path (dest), - S_IFIFO | archive_entry_mode (entry), - 0); -# endif - break; -#endif -#ifdef HAVE_MKNOD - case AE_IFSOCK: - r = mknod (g_file_get_path (dest), - S_IFSOCK | archive_entry_mode (entry), - 0); - break; - case AE_IFBLK: - r = mknod (g_file_get_path (dest), - S_IFBLK | archive_entry_mode (entry), - archive_entry_rdev (entry)); - break; - case AE_IFCHR: - r = mknod (g_file_get_path (dest), - S_IFCHR | archive_entry_mode (entry), - archive_entry_rdev (entry)); - break; -#endif - } - -#if defined HAVE_MKFIFO || defined HAVE_MKNOD - /* Create a empty regular file if we cannot create the special file. */ - if (r < 0 && (filetype == AE_IFIFO || - filetype == AE_IFSOCK || - filetype == AE_IFBLK || - filetype == AE_IFCHR)) { - ostream = (GOutputStream*)g_file_append_to (dest, G_FILE_CREATE_NONE, NULL, NULL); - if (ostream != NULL) { - g_output_stream_close (ostream, NULL, NULL); - g_object_unref (ostream); - } - } -#endif - - g_debug ("autoar_extract_do_write_entry: applying info"); - g_file_set_attributes_from_info (dest, - info, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - &(arextract->priv->error)); - - if (arextract->priv->error != NULL) { - g_debug ("autoar_extract_do_write_entry: %s\n", arextract->priv->error->message); - g_error_free (arextract->priv->error); - arextract->priv->error = NULL; - } - - g_object_unref (info); -} - -static void -autoar_extract_class_init (AutoarExtractClass *klass) -{ - GObjectClass *object_class; - GType type; - - object_class = G_OBJECT_CLASS (klass); - type = G_TYPE_FROM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (AutoarExtractPrivate)); - - autoar_extract_quark = g_quark_from_static_string ("autoar-extract"); - - object_class->get_property = autoar_extract_get_property; - object_class->set_property = autoar_extract_set_property; - object_class->dispose = autoar_extract_dispose; - object_class->finalize = autoar_extract_finalize; - - g_object_class_install_property (object_class, PROP_SOURCE, - g_param_spec_string ("source", - "Source archive", - "The archive file to be extracted", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_OUTPUT, - g_param_spec_string ("output", - "Output directory", - "Output directory of extracted archive", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_SIZE, - g_param_spec_uint64 ("size", - "File size", - "Size of the extracted files", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_COMPLETED_SIZE, - g_param_spec_uint64 ("completed-size", - "Written file size", - "Bytes written to disk", - 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_FILES, - g_param_spec_uint ("files", - "Files", - "Number of files in the archive", - 0, G_MAXUINT32, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_COMPLETED_FILES, - g_param_spec_uint ("completed-files", - "Written files", - "Number of files has been written", - 0, G_MAXUINT32, 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - autoar_extract_signals[SCANNED] = - g_signal_new ("scanned", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarExtractClass, scanned), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, - 1, - G_TYPE_UINT); - - autoar_extract_signals[DECIDE_DEST] = - g_signal_new ("decide-dest", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarExtractClass, decide_dest), - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, - G_TYPE_FILE); - - autoar_extract_signals[PROGRESS] = - g_signal_new ("progress", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarExtractClass, progress), - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 2, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE); - - autoar_extract_signals[COMPLETED] = - g_signal_new ("completed", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarExtractClass, completed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - autoar_extract_signals[ERROR] = - g_signal_new ("error", - type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (AutoarExtractClass, error), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); -} - -static void -autoar_extract_init (AutoarExtract *arextract) -{ - AutoarExtractPrivate *priv; - - priv = AUTOAR_EXTRACT_GET_PRIVATE (arextract); - arextract->priv = priv; - - priv->source = NULL; - priv->output = NULL; - - priv->size = 0; - priv->completed_size = 0; - - priv->files = 0; - priv->completed_files = 0; - - priv->arpref = NULL; - - priv->istream = NULL; - priv->buffer_size = BUFFER_SIZE; - priv->buffer = g_new (char, priv->buffer_size); - priv->error = NULL; -} - -AutoarExtract* -autoar_extract_new (const char *source, - const char *output, - AutoarPref *arpref) -{ - AutoarExtract* arextract; - - g_return_val_if_fail (source != NULL, NULL); - g_return_val_if_fail (output != NULL, NULL); - - arextract = g_object_new (AUTOAR_TYPE_EXTRACT, - "source", source, - "output", output, - NULL); - arextract->priv->arpref = g_object_ref (arpref); - - return arextract; -} - -static void -autoar_extract_run (AutoarExtract *arextract, - gboolean in_thread) -{ - struct archive *a; - struct archive_entry *entry; - - char *pathname_basename; - char *pathname_extension; - char *pathname_prefix; - int pathname_prefix_len; - - gboolean has_top_level_dir; - gboolean has_only_one_file; - gboolean use_raw_format; - char *top_level_dir_basename; - char *top_level_dir_basename_modified; - GFile *top_level_parent_dir; - GFile *top_level_dir; - - GHashTable *userhash; - GHashTable *grouphash; - GHashTable *bad_filename; - - const char **pattern; - GPtrArray *pattern_compiled; - - GFile *source; - char *source_basename; - - int i, r; - - g_return_if_fail (AUTOAR_IS_EXTRACT (arextract)); - g_return_if_fail (arextract->priv->source != NULL); - g_return_if_fail (arextract->priv->output != NULL); - - a = archive_read_new (); - archive_read_support_filter_all (a); - archive_read_support_format_all (a); - - /* Reset all counter variables */ - arextract->priv->size = 0; - arextract->priv->completed_size = 0; - arextract->priv->files = 0; - arextract->priv->completed_files = 0; - - pattern = autoar_pref_get_pattern_to_ignore (arextract->priv->arpref); - pattern_compiled = g_ptr_array_new_with_free_func (g_pattern_spec_free_safe); - if (pattern != NULL) { - for (i = 0; pattern[i] != NULL; i++) - g_ptr_array_add (pattern_compiled, g_pattern_spec_new (pattern[i])); - } - g_ptr_array_add (pattern_compiled, NULL); - - pathname_prefix = NULL; - pathname_prefix_len = 0; - has_top_level_dir = TRUE; - has_only_one_file = TRUE; - use_raw_format = FALSE; - - /* Step 1: Scan all file names in the archive - * We have to check whether the archive contains a top-level directory - * before performing the extraction. We emit the "scanned" signal when - * the checking is completed. */ - g_debug ("autoar_extract_run: Step 1, Scan"); - a = archive_read_new (); - archive_read_support_filter_all (a); - archive_read_support_format_all (a); - archive_read_set_open_callback (a, libarchive_read_open_cb); - archive_read_set_read_callback (a, libarchive_read_read_cb); - archive_read_set_close_callback (a, libarchive_read_close_cb); - archive_read_set_seek_callback (a, libarchive_read_seek_cb); - archive_read_set_skip_callback (a, libarchive_read_skip_cb); - archive_read_set_callback_data (a, arextract); - r = archive_read_open1 (a); - if (r != ARCHIVE_OK) { - archive_read_free (a); - a = archive_read_new (); - archive_read_support_filter_all (a); - archive_read_support_format_raw (a); - archive_read_set_open_callback (a, libarchive_read_open_cb); - archive_read_set_read_callback (a, libarchive_read_read_cb); - archive_read_set_close_callback (a, libarchive_read_close_cb); - archive_read_set_seek_callback (a, libarchive_read_seek_cb); - archive_read_set_skip_callback (a, libarchive_read_skip_cb); - archive_read_set_callback_data (a, arextract); - r = archive_read_open1 (a); - if (r != ARCHIVE_OK || archive_filter_count (a) <= 1) { - if (arextract->priv->error == NULL) { - if (r != ARCHIVE_OK) { - arextract->priv->error = g_error_new (autoar_extract_quark, - archive_errno (a), - "\'%s\': %s", - arextract->priv->source, - archive_error_string (a)); - } else { - /* If we only use raw format and filter count is one, libarchive will - * not do anything except for just copying the source file. We do not - * want this thing to happen because it does unnecesssary copying. */ - arextract->priv->error = g_error_new (autoar_extract_quark, - NOT_AN_ARCHIVE_ERRNO, - "\'%s\': %s", - arextract->priv->source, - "not an archive"); - } - } - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - archive_read_free (a); - g_ptr_array_unref (pattern_compiled); - return; - } - use_raw_format = TRUE; - } - bad_filename = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - while ((r = archive_read_next_header (a, &entry)) == ARCHIVE_OK) { - const char *pathname, *dir_sep_location; - size_t skip_len, prefix_len; - - pathname = archive_entry_pathname (entry); - g_debug ("autoar_extract_run: %d: pathname = %s", - arextract->priv->files, - pathname); - - if (!use_raw_format && !autoar_extract_do_pattern_check (pathname, pattern_compiled)) { - g_hash_table_insert (bad_filename, g_strdup (pathname), GUINT_TO_POINTER (TRUE)); - continue; - } - - g_debug ("autoar_extract_run: %d: pattern check passed", - arextract->priv->files); - - if (pathname_prefix == NULL) { - pathname_basename = g_path_get_basename (pathname); - skip_len = strspn (pathname, "./"); - dir_sep_location = strchr (pathname + skip_len, '/'); - if (dir_sep_location == NULL) { - prefix_len = strlen (pathname); - } else { - prefix_len = dir_sep_location - pathname; - } - pathname_prefix = g_strndup (pathname, prefix_len); - pathname_prefix_len = prefix_len; - g_debug ("autoar_extract_run: pathname_prefix = %s", pathname_prefix); - } else { - has_only_one_file = FALSE; - if (!g_str_has_prefix (pathname, pathname_prefix)) { - has_top_level_dir = FALSE; - } - } - arextract->priv->files++; - arextract->priv->size += archive_entry_size (entry); - archive_read_data_skip (a); - } - if (r != ARCHIVE_EOF) { - if (arextract->priv->error == NULL) { - arextract->priv->error = g_error_new (autoar_extract_quark, - archive_errno (a), - "\'%s\': %s", - arextract->priv->source, - archive_error_string (a)); - } - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_free (pathname_prefix); - g_free (pathname_basename); - g_ptr_array_unref (pattern_compiled); - g_hash_table_unref (bad_filename); - archive_read_close (a); - archive_read_free (a); - return; - } - - g_free (pathname_prefix); - g_ptr_array_unref (pattern_compiled); - archive_read_close (a); - archive_read_free (a); - if (arextract->priv->error != NULL) { - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_hash_table_unref (bad_filename); - return; - } - g_debug ("autoar_extract_run: has_top_level_dir = %s", - has_top_level_dir ? "TRUE" : "FALSE"); - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[SCANNED], - 0, arextract->priv->files); - - /* Step 2: Create necessary directories - * If the archive contains only one file, we don't create the directory */ - g_debug ("autoar_extract_run: Step 2, Mkdir-p"); - source = g_file_new_for_commandline_arg (arextract->priv->source); - source_basename = g_file_get_basename (source); - g_object_unref (source); - top_level_dir_basename = autoar_common_get_basename_remove_extension (source_basename); - top_level_parent_dir = g_file_new_for_commandline_arg (arextract->priv->output); - top_level_dir = g_file_get_child (top_level_parent_dir, top_level_dir_basename); - - pathname_extension = autoar_common_get_filename_extension (pathname_basename); - if (has_only_one_file && (pathname_extension != pathname_basename)) { - /* If we only have one file, we have to add the file extension. - * Although we use the variable `top_level_dir', it may be a regular - * file, so the extension is important. */ - char *new_filename; - new_filename = g_strconcat (top_level_dir_basename, pathname_extension, NULL); - top_level_dir = g_file_get_child (top_level_parent_dir, new_filename); - g_free (new_filename); - } else { - top_level_dir = g_file_get_child (top_level_parent_dir, top_level_dir_basename); - pathname_extension = ""; - } - - top_level_dir_basename_modified = NULL; - for (i = 1; g_file_query_exists (top_level_dir, NULL); i++) { - g_free (top_level_dir_basename_modified); - g_object_unref (top_level_dir); - if (has_only_one_file) { - top_level_dir_basename_modified = g_strdup_printf ("%s(%d)%s", - top_level_dir_basename, - i, - pathname_extension); - } else { - top_level_dir_basename_modified = g_strdup_printf ("%s(%d)", - top_level_dir_basename, - i); - } - top_level_dir = g_file_get_child (top_level_parent_dir, - top_level_dir_basename_modified); - } - - if (!has_only_one_file) - g_file_make_directory_with_parents (top_level_dir, NULL, &(arextract->priv->error)); - - g_free (pathname_basename); - g_free (top_level_dir_basename); - g_free (top_level_dir_basename_modified); - g_object_unref (top_level_parent_dir); - - if (arextract->priv->error != NULL) { - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_object_unref (top_level_dir); - g_hash_table_unref (bad_filename); - archive_read_free (a); - return; - } - - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[DECIDE_DEST], - 0, top_level_dir); - - /* Step 3: Extract files - * We have to re-open the archive to extract files */ - g_debug ("autoar_extract_run: Step 3, Extract"); - a = archive_read_new (); - archive_read_support_filter_all (a); - if (use_raw_format) - archive_read_support_format_raw (a); - else - archive_read_support_format_all (a); - archive_read_set_open_callback (a, libarchive_read_open_cb); - archive_read_set_read_callback (a, libarchive_read_read_cb); - archive_read_set_close_callback (a, libarchive_read_close_cb); - archive_read_set_seek_callback (a, libarchive_read_seek_cb); - archive_read_set_skip_callback (a, libarchive_read_skip_cb); - archive_read_set_callback_data (a, arextract); - r = archive_read_open1 (a); - if (r != ARCHIVE_OK) { - if (arextract->priv->error == NULL) { - arextract->priv->error = g_error_new (autoar_extract_quark, - archive_errno (a), - "\'%s\': %s", - arextract->priv->source, - archive_error_string (a)); - } - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_object_unref (top_level_dir); - g_hash_table_unref (bad_filename); - archive_read_free (a); - return; - } - userhash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - grouphash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - while ((r = archive_read_next_header (a, &entry)) == ARCHIVE_OK) { - const char *pathname; - const char *pathname_skip_prefix; - char **pathname_chunks; - - GFile *extracted_filename; - - pathname = archive_entry_pathname (entry); - if (GPOINTER_TO_UINT (g_hash_table_lookup (bad_filename, pathname))) - continue; - - if (!has_only_one_file) { - if (has_top_level_dir) - pathname_skip_prefix = pathname + pathname_prefix_len; - else - pathname_skip_prefix = pathname + strspn (pathname, "./"); - - for (; *pathname_skip_prefix == '/'; pathname_skip_prefix++); - extracted_filename = g_file_get_child (top_level_dir, pathname_skip_prefix); - - /* Extracted file should not be located outside the top level directory. */ - if (!g_file_has_prefix (extracted_filename, top_level_dir)) { - pathname_chunks = g_strsplit (pathname_skip_prefix, "/", G_MAXINT); - for (i = 0; pathname_chunks[i] != NULL; i++) { - if (strcmp (pathname_chunks[i], "..") == 0) { - char *pathname_sanitized; - - *pathname_chunks[i] = '\0'; - pathname_sanitized = g_strjoinv ("/", pathname_chunks); - - g_object_unref (extracted_filename); - extracted_filename = g_file_get_child (top_level_dir, pathname_sanitized); - - g_free (pathname_sanitized); - - if (g_file_has_prefix (extracted_filename, top_level_dir)) - break; - } - } - g_strfreev (pathname_chunks); - } - } else { - extracted_filename = g_object_ref (top_level_dir); - } - - autoar_extract_do_write_entry (arextract, - a, - entry, - extracted_filename, - userhash, - grouphash, - in_thread, - use_raw_format); - - if (arextract->priv->error != NULL) { - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_object_unref (extracted_filename); - g_object_unref (top_level_dir); - g_hash_table_unref (userhash); - g_hash_table_unref (grouphash); - g_hash_table_unref (bad_filename); - archive_read_close (a); - archive_read_free (a); - return; - } - - arextract->priv->completed_files++; - autoar_common_g_signal_emit (in_thread, - arextract, - autoar_extract_signals[PROGRESS], - 0, - ((double)(arextract->priv->completed_size)) / - ((double)(arextract->priv->size)), - ((double)(arextract->priv->completed_files)) / - ((double)(arextract->priv->files))); - g_object_unref (extracted_filename); - } - if (r != ARCHIVE_EOF) { - if (arextract->priv->error == NULL) { - arextract->priv->error = g_error_new (autoar_extract_quark, - archive_errno (a), - "\'%s\': %s", - arextract->priv->source, - archive_error_string (a)); - } - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - g_object_unref (top_level_dir); - g_hash_table_unref (userhash); - g_hash_table_unref (grouphash); - g_hash_table_unref (bad_filename); - archive_read_close (a); - archive_read_free (a); - return; - } - - g_object_unref (top_level_dir); - g_hash_table_unref (userhash); - g_hash_table_unref (grouphash); - g_hash_table_unref (bad_filename); - archive_read_close (a); - archive_read_free (a); - if (arextract->priv->error != NULL) { - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[ERROR], - 0, arextract->priv->error); - return; - } - - /* If the extraction is completed successfully, remove the source file. - * Errors are not fatal because we have completed our work. */ - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[PROGRESS], - 0, 1.0, 1.0); - g_debug ("autoar_extract_run: Finalize"); - if (autoar_pref_get_delete_if_succeed (arextract->priv->arpref)) { - g_debug ("autoar_extract_run: Delete"); - source = g_file_new_for_commandline_arg (arextract->priv->source); - g_file_delete (source, NULL, NULL); - g_object_unref (source); - } - autoar_common_g_signal_emit (in_thread, arextract, - autoar_extract_signals[COMPLETED], 0); -} - -void -autoar_extract_start (AutoarExtract *arextract) -{ - autoar_extract_run (arextract, FALSE); -} - -static void -autoar_extract_start_async_thread (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - AutoarExtract *arextract = source_object; - autoar_extract_run (arextract, TRUE); - g_task_return_pointer (task, NULL, g_free); - g_object_unref (arextract); -} - - -void -autoar_extract_start_async (AutoarExtract *arextract) -{ - GTask *task; - - g_object_ref (arextract); - - task = g_task_new (arextract, NULL, NULL, NULL); - g_task_set_task_data (task, NULL, NULL); - g_task_run_in_thread (task, autoar_extract_start_async_thread); -} diff --git a/autoarchive/autoar-extract.h b/autoarchive/autoar-extract.h deleted file mode 100644 index 8e2df6475..000000000 --- a/autoarchive/autoar-extract.h +++ /dev/null @@ -1,97 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-extract.h - * Automatically extract archives in some GNOME programs - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOAR_EXTRACT_H -#define AUTOAR_EXTRACT_H - -#include -#include - -#include "autoar-pref.h" - -G_BEGIN_DECLS - -#define AUTOAR_TYPE_EXTRACT autoar_extract_get_type () -#define AUTOAR_EXTRACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOAR_TYPE_EXTRACT, AutoarExtract)) -#define AUTOAR_EXTRACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AUTOAR_TYPE_EXTRACT, AutoarExtractClass)) -#define AUTOAR_IS_EXTRACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOAR_TYPE_EXTRACT)) -#define AUTOAR_IS_EXTRACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AUTOAR_TYPE_EXTRACT)) -#define AUTOAR_EXTRACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AUTOAR_TYPE_EXTRACT, AutoarExtractClass)) - -typedef struct _AutoarExtract AutoarExtract; -typedef struct _AutoarExtractClass AutoarExtractClass; -typedef struct _AutoarExtractPrivate AutoarExtractPrivate; - -struct _AutoarExtract -{ - GObject parent; - - AutoarExtractPrivate *priv; -}; - -struct _AutoarExtractClass -{ - GObjectClass parent_class; - - void (* scanned) (AutoarExtract *arextract, - guint files); - void (* decide_dest)(AutoarExtract *arextract, - GFile *destination); - void (* progress) (AutoarExtract *arextract, - gdouble fraction_size, - gdouble fraction_files); - void (* completed) (AutoarExtract *arextract); - void (* error) (AutoarExtract *arextract, - GError *error); -}; - -GType autoar_extract_get_type (void) G_GNUC_CONST; - -AutoarExtract *autoar_extract_new (const char *source, - const char *output, - AutoarPref *arpref); - -void autoar_extract_start (AutoarExtract *arextract); -void autoar_extract_start_async (AutoarExtract *arextract); - -char *autoar_extract_get_source (AutoarExtract *arextract); -char *autoar_extract_get_output (AutoarExtract *arextract); -guint64 autoar_extract_get_size (AutoarExtract *arextract); -guint64 autoar_extract_get_completed_size (AutoarExtract *arextract); -guint autoar_extract_get_files (AutoarExtract *arextract); -guint autoar_extract_get_completed_files (AutoarExtract *arextract); - -void autoar_extract_set_size (AutoarExtract *arextract, - guint64 size); -void autoar_extract_set_completed_size (AutoarExtract *arextract, - guint64 completed_size); -void autoar_extract_set_files (AutoarExtract *arextract, - guint files); -void autoar_extract_set_completed_files (AutoarExtract *arextract, - guint completed_files); - -G_END_DECLS - -#endif /* AUTOAR_EXTRACT_H */ diff --git a/autoarchive/autoar-pref.c b/autoarchive/autoar-pref.c deleted file mode 100644 index cdace5eef..000000000 --- a/autoarchive/autoar-pref.c +++ /dev/null @@ -1,567 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-pref.c - * User preferences of automatic archives creation and extraction - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "autoar-pref.h" -#include "autoar-enum-types.h" - -#include -#include -#include - -G_DEFINE_TYPE (AutoarPref, autoar_pref, G_TYPE_OBJECT) - -#define AUTOAR_PREF_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_PREF, AutoarPrefPrivate)) - -struct _AutoarPrefPrivate -{ - unsigned int modification_flags; - gboolean modification_enabled; - - /* Archive creating preferences */ - AutoarPrefFormat default_format; - AutoarPrefFilter default_filter; - - /* Archive extracting preferences */ - char **file_name_suffix; - char **file_mime_type; - char **pattern_to_ignore; - gboolean delete_if_succeed; -}; - -enum -{ - PROP_0, - PROP_DEFAULT_FORMAT, - PROP_DEFAULT_FILTER, - PROP_FILE_NAME_SUFFIX, - PROP_FILE_MIME_TYPE, - PROP_PATTERN_TO_IGNORE, - PROP_DELETE_IF_SUCCEED -}; - -enum -{ - MODIFIED_NONE = 0, - MODIFIED_DEFAULT_FORMAT = 1 << 0, - MODIFIED_DEFAULT_FILTER = 1 << 1, - MODIFIED_FILE_NAME_SUFFIX = 1 << 2, - MODIFIED_FILE_MIME_TYPE = 1 << 3, - MODIFIED_PATTERN_TO_IGNORE = 1 << 4, - MODIFIED_DELETE_IF_SUCCEED = 1 << 5 -}; - -#define KEY_DEFAULT_FORMAT "default-format" -#define KEY_DEFAULT_FILTER "default-filter" -#define KEY_FILE_NAME_SUFFIX "file-name-suffix" -#define KEY_FILE_MIME_TYPE "file-mime-type" -#define KEY_PATTERN_TO_IGNORE "pattern-to-ignore" -#define KEY_DELETE_IF_SUCCEED "delete-if-succeed" - -static void -autoar_pref_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - AutoarPref *arpref; - AutoarPrefPrivate *priv; - - GVariant *variant; - - const char* const* strv; - - arpref = AUTOAR_PREF (object); - priv = arpref->priv; - - switch (property_id) { - case PROP_DEFAULT_FORMAT: - g_value_set_enum (value, priv->default_format); - break; - case PROP_DEFAULT_FILTER: - g_value_set_enum (value, priv->default_filter); - break; - case PROP_FILE_NAME_SUFFIX: - strv = (const char* const*)(priv->file_name_suffix); - variant = g_variant_new_strv (strv, -1); - g_value_take_variant (value, variant); - break; - case PROP_FILE_MIME_TYPE: - strv = (const char* const*)(priv->file_mime_type); - variant = g_variant_new_strv (strv, -1); - g_value_take_variant (value, variant); - break; - case PROP_PATTERN_TO_IGNORE: - strv = (const char* const*)(priv->pattern_to_ignore); - variant = g_variant_new_strv (strv, -1); - g_value_take_variant (value, variant); - break; - case PROP_DELETE_IF_SUCCEED: - g_value_set_boolean (value, priv->delete_if_succeed); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -autoar_pref_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - AutoarPref *arpref; - const char **strv; - - arpref = AUTOAR_PREF (object); - - switch (property_id) { - case PROP_DEFAULT_FORMAT: - autoar_pref_set_default_format (arpref, g_value_get_enum (value)); - break; - case PROP_DEFAULT_FILTER: - autoar_pref_set_default_filter (arpref, g_value_get_enum (value)); - break; - case PROP_FILE_NAME_SUFFIX: - strv = g_variant_get_strv (g_value_get_variant (value), NULL); - autoar_pref_set_file_name_suffix (arpref, strv); - break; - case PROP_FILE_MIME_TYPE: - strv = g_variant_get_strv (g_value_get_variant (value), NULL); - autoar_pref_set_file_mime_type (arpref, strv); - break; - case PROP_PATTERN_TO_IGNORE: - strv = g_variant_get_strv (g_value_get_variant (value), NULL); - autoar_pref_set_pattern_to_ignore (arpref, strv); - break; - case PROP_DELETE_IF_SUCCEED: - autoar_pref_set_delete_if_succeed (arpref, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -AutoarPrefFormat -autoar_pref_get_default_format (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_PREF_FORMAT_ZIP); - return arpref->priv->default_format; -} - -AutoarPrefFilter -autoar_pref_get_default_filter (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_PREF_FILTER_NONE); - return arpref->priv->default_filter; -} - -const char** -autoar_pref_get_file_name_suffix (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), NULL); - return (const char**)(arpref->priv->file_name_suffix); -} - -const char** -autoar_pref_get_file_mime_type (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), NULL); - return (const char**)(arpref->priv->file_mime_type); -} - -const char** -autoar_pref_get_pattern_to_ignore (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), NULL); - return (const char**)(arpref->priv->pattern_to_ignore); -} - -gboolean -autoar_pref_get_delete_if_succeed (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), TRUE); - return arpref->priv->delete_if_succeed; -} - -void -autoar_pref_set_default_format (AutoarPref *arpref, - AutoarPrefFormat format) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (format > 0 && format < AUTOAR_PREF_FORMAT_LAST); - if (arpref->priv->modification_enabled && format != arpref->priv->default_format) - arpref->priv->modification_flags |= MODIFIED_DEFAULT_FORMAT; - arpref->priv->default_format = format; -} - -void -autoar_pref_set_default_filter (AutoarPref *arpref, - AutoarPrefFilter filter) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (filter > 0 && filter < AUTOAR_PREF_FILTER_LAST); - if (arpref->priv->modification_enabled && filter != arpref->priv->default_filter) - arpref->priv->modification_flags |= MODIFIED_DEFAULT_FILTER; - arpref->priv->default_filter = filter; -} - -void -autoar_pref_set_file_name_suffix (AutoarPref *arpref, - const char **strv) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (strv != NULL); - if (arpref->priv->modification_enabled) - arpref->priv->modification_flags |= MODIFIED_FILE_NAME_SUFFIX; - g_strfreev (arpref->priv->file_name_suffix); - arpref->priv->file_name_suffix = g_strdupv ((char**)strv); -} - -void -autoar_pref_set_file_mime_type (AutoarPref *arpref, - const char **strv) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (strv != NULL); - if (arpref->priv->modification_enabled) - arpref->priv->modification_flags |= MODIFIED_FILE_MIME_TYPE; - g_strfreev (arpref->priv->file_mime_type); - arpref->priv->file_mime_type = g_strdupv ((char**)strv); -} - -void -autoar_pref_set_pattern_to_ignore (AutoarPref *arpref, - const char **strv) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (strv != NULL); - if (arpref->priv->modification_enabled) - arpref->priv->modification_flags |= MODIFIED_PATTERN_TO_IGNORE; - g_strfreev (arpref->priv->pattern_to_ignore); - arpref->priv->pattern_to_ignore = g_strdupv ((char**)strv); -} - -void -autoar_pref_set_delete_if_succeed (AutoarPref *arpref, - gboolean delete_yes) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - if (delete_yes) - delete_yes = TRUE; - if (arpref->priv->modification_enabled && delete_yes != arpref->priv->delete_if_succeed) - arpref->priv->modification_flags |= MODIFIED_DELETE_IF_SUCCEED; - arpref->priv->delete_if_succeed = delete_yes; -} - -static void -autoar_pref_finalize (GObject *object) -{ - AutoarPref *arpref; - AutoarPrefPrivate *priv; - - arpref = AUTOAR_PREF (object); - priv = arpref->priv; - - g_strfreev (priv->file_name_suffix); - g_strfreev (priv->file_mime_type); - g_strfreev (priv->pattern_to_ignore); - - G_OBJECT_CLASS (autoar_pref_parent_class)->finalize (object); -} - -static void -autoar_pref_class_init (AutoarPrefClass *klass) -{ - GObjectClass *object_class; - GPtrArray *tmparr; - - object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (AutoarPrefPrivate)); - - object_class->get_property = autoar_pref_get_property; - object_class->set_property = autoar_pref_set_property; - object_class->finalize = autoar_pref_finalize; - - g_object_class_install_property (object_class, PROP_DEFAULT_FORMAT, - g_param_spec_enum (KEY_DEFAULT_FORMAT, - "Default format", - "Default file format for new archives", - AUTOAR_TYPE_PREF_FORMAT, - AUTOAR_PREF_FORMAT_ZIP, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_DEFAULT_FILTER, - g_param_spec_enum (KEY_DEFAULT_FILTER, - "Default format", - "Default filter to create archives", - AUTOAR_TYPE_PREF_FORMAT, - AUTOAR_PREF_FORMAT_ZIP, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - tmparr = g_ptr_array_new (); - g_ptr_array_add (tmparr, NULL); - - g_object_class_install_property (object_class, PROP_FILE_NAME_SUFFIX, - g_param_spec_variant (KEY_FILE_NAME_SUFFIX, - "File name suffix", - "File name suffix whitelist for automatic extraction", - G_VARIANT_TYPE_STRING_ARRAY, - g_variant_new_strv ((const char* const*)tmparr->pdata, -1), - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_FILE_MIME_TYPE, - g_param_spec_variant (KEY_FILE_MIME_TYPE, - "File MIME type", - "File MIME type whitelist for automatic extraction", - G_VARIANT_TYPE_STRING_ARRAY, - g_variant_new_strv ((const char* const*)tmparr->pdata, -1), - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_PATTERN_TO_IGNORE, - g_param_spec_variant (KEY_PATTERN_TO_IGNORE, - "Pattern to ignore", - "Pattern of file name to skip when extracting files", - G_VARIANT_TYPE_STRING_ARRAY, - g_variant_new_strv ((const char* const*)tmparr->pdata, -1), - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, PROP_DELETE_IF_SUCCEED, - g_param_spec_boolean (KEY_DELETE_IF_SUCCEED, - "Delete if succeed", - "Delete the archive file if extraction is succeeded", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - g_ptr_array_unref (tmparr); -} - -static void -autoar_pref_init (AutoarPref *arpref) -{ - AutoarPrefPrivate *priv; - - priv = AUTOAR_PREF_GET_PRIVATE (arpref); - arpref->priv = priv; - - priv->modification_flags = MODIFIED_NONE; - priv->modification_enabled = FALSE; - - priv->default_format = AUTOAR_PREF_FORMAT_ZIP; - priv->default_filter = AUTOAR_PREF_FILTER_NONE; - - priv->file_name_suffix = NULL; - priv->file_mime_type = NULL; - priv->pattern_to_ignore = NULL; - priv->delete_if_succeed = TRUE; -} - -AutoarPref* -autoar_pref_new (void) -{ - return g_object_new (AUTOAR_TYPE_PREF, NULL); -} - -AutoarPref* -autoar_pref_new_with_gsettings (GSettings *settings) -{ - AutoarPref *arpref; - arpref = autoar_pref_new (); - autoar_pref_read_gsettings (arpref, settings); - return arpref; -} - -void -autoar_pref_read_gsettings (AutoarPref *arpref, - GSettings *settings) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (settings != NULL); - - arpref->priv->default_format = g_settings_get_enum (settings, KEY_DEFAULT_FORMAT); - arpref->priv->default_filter = g_settings_get_enum (settings, KEY_DEFAULT_FILTER); - - g_strfreev (arpref->priv->file_name_suffix); - arpref->priv->file_name_suffix = g_settings_get_strv (settings, KEY_FILE_NAME_SUFFIX); - g_strfreev (arpref->priv->file_mime_type); - arpref->priv->file_mime_type = g_settings_get_strv (settings, KEY_FILE_MIME_TYPE); - g_strfreev (arpref->priv->pattern_to_ignore); - arpref->priv->pattern_to_ignore = g_settings_get_strv (settings, KEY_PATTERN_TO_IGNORE); - - arpref->priv->delete_if_succeed = g_settings_get_boolean (settings, KEY_DELETE_IF_SUCCEED); - - arpref->priv->modification_enabled = TRUE; - arpref->priv->modification_flags = MODIFIED_NONE; -} - -void -autoar_pref_write_gsettings (AutoarPref *arpref, - GSettings *settings) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (settings != NULL); - - if (arpref->priv->modification_enabled) { - if (arpref->priv->modification_flags & MODIFIED_DEFAULT_FORMAT) { - if (g_settings_set_enum (settings, KEY_DEFAULT_FORMAT, arpref->priv->default_format)) - arpref->priv->modification_flags ^= MODIFIED_DEFAULT_FORMAT; - } - if (arpref->priv->modification_flags & MODIFIED_DEFAULT_FILTER) { - if (g_settings_set_enum (settings, KEY_DEFAULT_FILTER, arpref->priv->default_filter)) - arpref->priv->modification_flags ^= MODIFIED_DEFAULT_FILTER; - } - if (arpref->priv->modification_flags & MODIFIED_FILE_NAME_SUFFIX) { - if (g_settings_set_strv (settings, KEY_FILE_NAME_SUFFIX, (const char* const*)(arpref->priv->file_name_suffix))) - arpref->priv->modification_flags ^= MODIFIED_FILE_NAME_SUFFIX; - } - if (arpref->priv->modification_flags & MODIFIED_FILE_MIME_TYPE) { - if (g_settings_set_strv (settings, KEY_FILE_MIME_TYPE, (const char* const*)(arpref->priv->file_mime_type))) - arpref->priv->modification_flags ^= MODIFIED_FILE_MIME_TYPE; - } - if (arpref->priv->modification_flags & MODIFIED_PATTERN_TO_IGNORE) { - if (g_settings_set_strv (settings, KEY_PATTERN_TO_IGNORE, (const char* const*)(arpref->priv->pattern_to_ignore))) - arpref->priv->modification_flags ^= MODIFIED_PATTERN_TO_IGNORE; - } - if (arpref->priv->modification_flags & MODIFIED_DELETE_IF_SUCCEED) { - if (g_settings_set_boolean (settings, KEY_DELETE_IF_SUCCEED, arpref->priv->delete_if_succeed)) - arpref->priv->modification_flags ^= MODIFIED_DELETE_IF_SUCCEED; - } - } else { - return autoar_pref_write_gsettings_force (arpref, settings); - } -} - -void -autoar_pref_write_gsettings_force (AutoarPref *arpref, - GSettings *settings) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - g_return_if_fail (settings != NULL); - - g_settings_set_enum (settings, KEY_DEFAULT_FORMAT, arpref->priv->default_format); - g_settings_set_enum (settings, KEY_DEFAULT_FILTER, arpref->priv->default_filter); - g_settings_set_strv (settings, KEY_FILE_NAME_SUFFIX, (const char* const*)(arpref->priv->file_name_suffix)); - g_settings_set_strv (settings, KEY_FILE_MIME_TYPE, (const char* const*)(arpref->priv->file_mime_type)); - g_settings_set_strv (settings, KEY_PATTERN_TO_IGNORE, (const char* const*)(arpref->priv->pattern_to_ignore)); - g_settings_set_boolean (settings, KEY_DELETE_IF_SUCCEED, arpref->priv->delete_if_succeed); -} - -gboolean -autoar_pref_has_changes (AutoarPref *arpref) -{ - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), FALSE); - return (arpref->priv->modification_enabled && arpref->priv->modification_flags); -} - -void -autoar_pref_forget_changes (AutoarPref *arpref) -{ - g_return_if_fail (AUTOAR_IS_PREF (arpref)); - arpref->priv->modification_flags = MODIFIED_NONE; -} - -gboolean -autoar_pref_check_file_name (AutoarPref *arpref, - const char *filepath) -{ - char *dot_location; - int i; - - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), FALSE); - g_return_val_if_fail (arpref->priv->file_name_suffix != NULL, FALSE); - - dot_location = strrchr (filepath, '.'); - if (dot_location == NULL) - return FALSE; - - for (i = 0; arpref->priv->file_name_suffix[i] != NULL; i++) { - if (strcmp (dot_location + 1, arpref->priv->file_name_suffix[i]) == 0) - return TRUE; - } - - return FALSE; -} - -gboolean -autoar_pref_check_mime_type (AutoarPref *arpref, - const char *filepath) -{ - int i; - GFile *file; - GFileInfo *fileinfo; - const char *content_type; - const char *mime_type; - - g_return_val_if_fail (AUTOAR_IS_PREF (arpref), FALSE); - g_return_val_if_fail (arpref->priv->file_mime_type != NULL, FALSE); - - file = g_file_new_for_commandline_arg (filepath); - fileinfo = g_file_query_info (file, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - NULL); - g_object_unref (file); - - if (fileinfo == NULL) - return FALSE; - - content_type = g_file_info_get_content_type (fileinfo); - g_debug ("Content Type: %s\n", content_type); - mime_type = g_content_type_get_mime_type (content_type); - g_debug ("MIME Type: %s\n", mime_type); - - for (i = 0; arpref->priv->file_mime_type[i] != NULL; i++) { - if (strcmp (mime_type, arpref->priv->file_mime_type[i]) == 0) { - g_object_unref (fileinfo); - return TRUE; - } - } - - g_object_unref (fileinfo); - return FALSE; -} diff --git a/autoarchive/autoar-pref.h b/autoarchive/autoar-pref.h deleted file mode 100644 index a935ad324..000000000 --- a/autoarchive/autoar-pref.h +++ /dev/null @@ -1,134 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-pref.h - * User preferences of automatic archives creation and extraction - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOAR_PREF_H -#define AUTOAR_PREF_H - -#include -#include - -G_BEGIN_DECLS - -#define AUTOAR_PREF_DEFAULT_GSCHEMA_ID "org.gnome.desktop.archives" - -typedef enum { - AUTOAR_PREF_FORMAT_0, /*< skip >*/ - AUTOAR_PREF_FORMAT_ZIP = 1, /* .zip */ - AUTOAR_PREF_FORMAT_TAR, /* .tar, pax_restricted */ - AUTOAR_PREF_FORMAT_CPIO, /* .cpio, odc */ - AUTOAR_PREF_FORMAT_7ZIP, /* .7z */ - AUTOAR_PREF_FORMAT_AR_BSD, /* .a */ - AUTOAR_PREF_FORMAT_AR_SVR4, /* .a */ - AUTOAR_PREF_FORMAT_CPIO_NEWC, /* .cpio, newc */ - AUTOAR_PREF_FORMAT_GNUTAR, /* .tar, gnutar */ - AUTOAR_PREF_FORMAT_ISO9660, /* .iso */ - AUTOAR_PREF_FORMAT_PAX, /* .tar, pax */ - AUTOAR_PREF_FORMAT_USTAR, /* .tar, ustar */ - AUTOAR_PREF_FORMAT_XAR, /* .xar, xar */ - AUTOAR_PREF_FORMAT_LAST /*< skip >*/ -} AutoarPrefFormat; - -typedef enum { - AUTOAR_PREF_FILTER_0, /*< skip >*/ - AUTOAR_PREF_FILTER_NONE = 1, - AUTOAR_PREF_FILTER_COMPRESS, /* .Z */ - AUTOAR_PREF_FILTER_GZIP, /* .gz */ - AUTOAR_PREF_FILTER_BZIP2, /* .bz2 */ - AUTOAR_PREF_FILTER_XZ, /* .xz */ - AUTOAR_PREF_FILTER_LZMA, /* .lzma */ - AUTOAR_PREF_FILTER_LZIP, /* .lz */ - AUTOAR_PREF_FILTER_LZOP, /* .lzo */ - AUTOAR_PREF_FILTER_GRZIP, /* .grz */ - AUTOAR_PREF_FILTER_LRZIP, /* .lrz */ - AUTOAR_PREF_FILTER_LAST /*< skip >*/ -} AutoarPrefFilter; - -#define AUTOAR_TYPE_PREF autoar_pref_get_type () -#define AUTOAR_PREF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOAR_TYPE_PREF, AutoarPref)) -#define AUTOAR_PREF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AUTOAR_TYPE_PREF, AutoarPrefClass)) -#define AUTOAR_IS_PREF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOAR_TYPE_PREF)) -#define AUTOAR_IS_PREF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AUTOAR_TYPE_PREF)) -#define AUTOAR_PREF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AUTOAR_TYPE_PREF, AutoarPrefClass)) - -typedef struct _AutoarPref AutoarPref; -typedef struct _AutoarPrefClass AutoarPrefClass; -typedef struct _AutoarPrefPrivate AutoarPrefPrivate; - -struct _AutoarPref -{ - GObject parent; - - AutoarPrefPrivate *priv; -}; - -struct _AutoarPrefClass -{ - GObjectClass parent_class; -}; - -GType autoar_pref_get_type (void) G_GNUC_CONST; - -AutoarPref *autoar_pref_new (void); -AutoarPref *autoar_pref_new_with_gsettings (GSettings *settings); - -void autoar_pref_read_gsettings (AutoarPref *arpref, - GSettings *settings); -void autoar_pref_write_gsettings (AutoarPref *arpref, - GSettings *settings); -void autoar_pref_write_gsettings_force (AutoarPref *arpref, - GSettings *settings); - -gboolean autoar_pref_has_changes (AutoarPref *arpref); -void autoar_pref_forget_changes (AutoarPref *arpref); - -gboolean autoar_pref_check_file_name (AutoarPref *arpref, - const char *filepath); -gboolean autoar_pref_check_mime_type (AutoarPref *arpref, - const char *filepath); - -AutoarPrefFormat autoar_pref_get_default_format (AutoarPref *arpref); -AutoarPrefFilter autoar_pref_get_default_filter (AutoarPref *arpref); -const char **autoar_pref_get_file_name_suffix (AutoarPref *arpref); -const char **autoar_pref_get_file_mime_type (AutoarPref *arpref); -const char **autoar_pref_get_pattern_to_ignore (AutoarPref *arpref); -gboolean autoar_pref_get_delete_if_succeed (AutoarPref *arpref); - -void autoar_pref_set_default_format (AutoarPref *arpref, - AutoarPrefFormat format); -void autoar_pref_set_default_filter (AutoarPref *arpref, - AutoarPrefFilter filter); -void autoar_pref_set_file_name_suffix (AutoarPref *arpref, - const char **strv); -void autoar_pref_set_file_mime_type (AutoarPref *arpref, - const char **strv); -void autoar_pref_set_pattern_to_ignore (AutoarPref *arpref, - const char **strv); -void autoar_pref_set_delete_if_succeed (AutoarPref *arpref, - gboolean delete_yes); - - -G_END_DECLS - -#endif /* AUTOAR_PREF_H */ diff --git a/autoarchive/autoarchive.h b/autoarchive/autoarchive.h deleted file mode 100644 index 664981ea1..000000000 --- a/autoarchive/autoarchive.h +++ /dev/null @@ -1,34 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-extract.h - * Automatically extract archives in some GNOME programs - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOARCHIVE_H -#define AUTOARHICVE_H - -/* #include */ -#include -#include -/* #include */ - -#endif /* AUTOARCHIVE_H */ diff --git a/autoarchive/org.gnome.desktop.archives.gschema.xml b/autoarchive/org.gnome.desktop.archives.gschema.xml deleted file mode 100644 index 1d946c214..000000000 --- a/autoarchive/org.gnome.desktop.archives.gschema.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - 'zip' - Default file format for new archives (archive creation) - The default file format used to create new archives. - - - 'none' - Default filter to create archives (archive creation) - The default filter used to compress new archives. - - - ['zip', 'tar', 'cpio', '7z', 'rar', 'lha', 'lzh', 'xar', 'Z', 'gz', 'bz2', 'uue', 'xz', 'lz', 'lzma'] - File extensions of archives (archive extraction) - This list is used by applications to determine whether a file should be automatically extracted. - - - ['application/x-7z-compressed', 'application/x-7z-compressed-tar', 'application/x-bzip', 'application/x-bzip-compressed-tar', 'application/x-compress', 'application/x-compressed-tar', 'application/x-cpio', 'application/x-gzip', 'application/x-lha', 'application/x-lzip', 'application/x-lzip-compressed-tar', 'application/x-lzma', 'application/x-lzma-compressed-tar', 'application/x-rar', 'application/x-tar', 'application/x-tarz', 'application/x-xar', 'application/x-xz', 'application/x-xz-compressed-tar', 'application/zip'] - >File MIME types of archives (archive extraction) - This list is used by applications to determine whether a file should be automatically extracted. - - - ['__MACOSX', '.DS_Store', '._.*'] - Patterns of file names will not be extracted (archive extraction) - This list contains glob-style patterns, and it is used by applications to determine whether an entry in an archive should be written to disk. - - - true - Whether to delete the source archive if the extraction is successful (archive extraction) - If TRUE, the source archive will be deleted after the extraction succeed - - - diff --git a/autoarchive/test-extract.c b/autoarchive/test-extract.c deleted file mode 100644 index b6721fc04..000000000 --- a/autoarchive/test-extract.c +++ /dev/null @@ -1,97 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ - -#include -#include -#include - -static void -my_handler_scanned (AutoarExtract *arextract, - guint files, - gpointer data) -{ - g_print ("Scanning OK, %d files to be extracted.\n", files); -} - -static void -my_handler_decide_dest (AutoarExtract *arextract, - GFile *dest) -{ - char *path, *uri; - path = g_file_get_path (dest); - uri = g_file_get_uri (dest); - g_print ("Destination Path: %s\n", path); - g_print ("Destination URI: %s\n", uri); - g_free (path); - g_free (uri); -} - -static void -my_handler_progress (AutoarExtract *arextract, - gdouble fraction_size, - gdouble fraction_files, - gpointer data) -{ - g_print ("\rProgress: Archive Size %.2lf %%, Files %.2lf %%", - fraction_size * 100, - fraction_files * 100); -} - -static void -my_handler_error (AutoarExtract *arextract, - GError *error, - gpointer data) -{ - g_printerr ("\nError %d: %s\n", error->code, error->message); -} - -static void -my_handler_completed (AutoarExtract *arextract, - gpointer data) -{ - g_print ("\nCompleted!\n"); -} - -int -main (int argc, - char *argv[]) -{ - AutoarExtract *arextract; - AutoarPref *arpref; - GSettings *settings; - const char *pattern[] = { - "__MACOSX", - ".DS_Store", - "._.*", - "*.in", - NULL - }; - - if (argc < 3) { - g_printerr ("Usage: %s archive_file output_dir\n", argv[0]); - return 255; - } - - settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID); - - arpref = autoar_pref_new_with_gsettings (settings); - autoar_pref_set_delete_if_succeed (arpref, FALSE); - autoar_pref_set_pattern_to_ignore (arpref, pattern); - - autoar_pref_forget_changes (arpref); - autoar_pref_write_gsettings (arpref, settings); - - arextract = autoar_extract_new (argv[1], argv[2], arpref); - g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL); - g_signal_connect (arextract, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL); - g_signal_connect (arextract, "progress", G_CALLBACK (my_handler_progress), NULL); - g_signal_connect (arextract, "error", G_CALLBACK (my_handler_error), NULL); - g_signal_connect (arextract, "completed", G_CALLBACK (my_handler_completed), NULL); - - autoar_extract_start (arextract); - - g_object_unref (arextract); - g_object_unref (arpref); - g_object_unref (settings); - - return 0; -} diff --git a/autoarchive/test-pref.c b/autoarchive/test-pref.c deleted file mode 100644 index 449e5eec8..000000000 --- a/autoarchive/test-pref.c +++ /dev/null @@ -1,26 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ - -#include - -int -main (int argc, - char *argv[]) -{ - AutoarPref *arpref; - GSettings *settings; - - if (argc < 2) { - g_printerr ("Usage: %s archive_file\n", argv[0]); - return 255; - } - - settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID); - arpref = autoar_pref_new_with_gsettings (settings); - - g_print ("file-name-suffix check: %d\n", autoar_pref_check_file_name (arpref, argv[1])); - g_print ("file-mime-type check: %d\n", autoar_pref_check_mime_type (arpref, argv[1])); - - g_object_unref (arpref); - - return 0; -} diff --git a/configure.ac b/configure.ac index e68e9e2d4..136bdaf42 100644 --- a/configure.ac +++ b/configure.ac @@ -84,7 +84,6 @@ GSETTINGS_DESKTOP_SCHEMAS_REQUIRED=0.0.1 LIBNOTIFY_REQUIRED=0.5.1 GCR_REQUIRED=3.5.5 AVAHI_REQUIRED=0.6.22 -LIBARCHIVE_REQUIRED=3.0.0 WEBKIT_GTK_PC_NAME=webkit2gtk-3.0 AC_DEFINE([HAVE_WEBKIT2],[1],[Define if building with WebKit2]) @@ -121,7 +120,7 @@ PKG_CHECK_MODULES([DEPENDENCIES], [ gcr-3 >= $GCR_REQUIRED avahi-gobject >= $AVAHI_REQUIRED avahi-client >= $AVAHI_REQUIRED - libarchive >= $LIBARCHIVE_REQUIRED + gnome-autoar ]) PKG_CHECK_MODULES(WEB_EXTENSION, [ @@ -135,7 +134,7 @@ AC_SUBST(WEB_EXTENSION_LIBS) # Portability checks # ****************** -AC_CHECK_FUNCS([getgrnam getpwnam link localtime_r memchr memmove memset mkdir mkdtemp mkfifo mknod realpath sqrt strchr strcspn strdup strerror strrchr strtol strtoul strstr]) +AC_CHECK_FUNCS([localtime_r memchr memmove memset mkdir mkdtemp realpath sqrt strchr strcspn strdup strerror strrchr strtol strtoul strstr]) # for backtrace() AC_CHECK_HEADERS([execinfo.h fcntl.h]) @@ -250,7 +249,6 @@ lib/history/Makefile lib/widgets/Makefile embed/Makefile embed/web-extension/Makefile -autoarchive/Makefile src/Makefile src/bookmarks/Makefile po/Makefile.in diff --git a/embed/ephy-download.h b/embed/ephy-download.h index 7d140693b..6aa38f2a3 100644 --- a/embed/ephy-download.h +++ b/embed/ephy-download.h @@ -29,8 +29,8 @@ #ifndef _EPHY_DOWNLOAD_H #define _EPHY_DOWNLOAD_H -#include #include +#include #include G_BEGIN_DECLS diff --git a/src/Makefile.am b/src/Makefile.am index 34d980fc6..b7e6448ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,7 +158,6 @@ epiphany_LDADD = \ $(top_builddir)/lib/history/libephyhistory.la \ $(top_builddir)/lib/libephymisc.la \ $(top_builddir)/lib/egg/libegg.la \ - $(top_builddir)/autoarchive/libautoarchive.la \ $(DEPENDENCIES_LIBS) \ $(CODE_COVERAGE_LDFLAGS) \ $(LIBINTL) diff --git a/tests/Makefile.am b/tests/Makefile.am index 91523bc25..1db8a32c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -113,7 +113,6 @@ LDADD = \ $(top_builddir)/lib/history/libephyhistory.la \ $(top_builddir)/lib/libephymisc.la \ $(top_builddir)/lib/egg/libegg.la \ - $(top_builddir)/autoarchive/libautoarchive.la \ $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) \ $(DEPENDENCIES_LIBS) -- cgit v1.2.3