diff -Nur gimageview-0.2.2-bak/plugins/archiver/Makefile.am gimageview-0.2.2/plugins/archiver/Makefile.am --- gimageview-0.2.2-bak/plugins/archiver/Makefile.am Tue Apr 9 18:17:38 2002 +++ gimageview-0.2.2/plugins/archiver/Makefile.am Wed Jun 5 02:46:09 2002 @@ -2,7 +2,8 @@ libarc_lha_ext.la \ libarc_rar_ext.la \ libarc_tar_ext.la \ - libarc_zip_ext.la + libarc_zip_ext.la \ + libarc_leafpak_ext.la archiver_plugindir = $(DESTDIR)$(plugindir)/$(ARCHIVER_PLUGIN_DIR) @@ -19,3 +20,7 @@ libarc_zip_ext_la_LDFLAGS = -module -avoid-version libarc_zip_ext_la_SOURCES = zip-ext.c zip-ext.h + +libarc_leafpak_ext_la_LDFLAGS = -module -avoid-version +libarc_leafpak_ext_la_SOURCES = leafpak-ext.c leafpak-ext.h + diff -Nur gimageview-0.2.2-bak/plugins/archiver/leafpak-ext.c gimageview-0.2.2/plugins/archiver/leafpak-ext.c --- gimageview-0.2.2-bak/plugins/archiver/leafpak-ext.c Thu Jan 1 09:00:00 1970 +++ gimageview-0.2.2/plugins/archiver/leafpak-ext.c Wed Jun 5 02:46:09 2002 @@ -0,0 +1,260 @@ +/* + * leafpak archiver plugin + * + * Copyright (C) 2002 Takuro Ashie + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "gimageview.h" + +#include "fileutil.h" +#include "fr-archive.h" +#include "fr-command.h" +#include "image_info.h" +#include "leafpak-ext.h" +#include "plugin.h" + +#define LEAFPAK_COMMAND "leafpak" + +/* plugin implement definition */ +static ExtArchiver plugin_impl[] = +{ + {".pak", fr_command_leafpak_new, TRUE}, +}; + + +/* plugin definition */ +PluginInfo gimv_plugin_info = +{ + type: PLUGIN_EXT_ARCHIVER, + name: N_("Leaf PAK archive support"), + version: "0.0.1", + author: N_("Takuro Ashie"), + description: NULL, + about: NULL, + config: NULL, + n_entries: 1, + implement: plugin_impl, +}; + + +static void fr_command_leafpak_class_init (FRCommandLeafpakClass *class); +static void fr_command_leafpak_init (FRCommand *afile); +static void fr_command_leafpak_destroy (GtkObject *object); + + +/* Parent Class */ +static FRCommandClass *parent_class = NULL; + + +/* -- list -- */ +static char * +eat_spaces (char *line) +{ + gint i = 0; + while ((*line == ' ') && (*line != 0)) { + line++; + i++; + } + + return line; +} + + +static char ** +split_line (char *line, int n_fields) +{ + char **fields; + char *scan, *field_end; + int i; + + fields = g_new0 (char *, n_fields + 1); + fields[n_fields] = NULL; + + scan = eat_spaces (line); + for (i = 0; i < n_fields; i++) { + field_end = strchr (scan, ' '); + if (!field_end) field_end = line + strlen (line); + fields[i] = g_strndup (scan, field_end - scan); + scan = eat_spaces (field_end); + } + + return fields; +} + + +static void +process_line (char *line, gpointer data) +{ + ImageInfo *info = NULL; + FRCommand *comm = FR_COMMAND (data); + char **fields; + char *filename; + int len; + struct stat *st; + + g_return_if_fail (line); + if (!*line) return; + len = strlen (line); + if (len >= 13 && !strncmp (line, "Archive file:", 13)) return; + if (len >= 21 && !strncmp (line, "Filename Length", 21)) return; + if (len >= 22 && !strncmp (line, "------------ -------", 22)) return; + + fields = split_line (line, 2); + if (fields && fields[1] && *fields[1] && !strcmp (fields[1], "files.")) + goto ERROR; + st = g_new0 (struct stat, 1); + st->st_size = atol (fields[1]); + st->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO; + filename = fields[0]; + + if (*filename && *comm->filename) { + info = image_info_get_with_archive (filename, + FR_ARCHIVE (comm->archive), + st); + } + g_free (st); + if (info) + comm->file_list = g_list_prepend (comm->file_list, info); + + ERROR: + g_strfreev (fields); +} + + +static void +fr_command_leafpak_list (FRCommand *comm) +{ + fr_process_clear (comm->process); + fr_process_begin_command (comm->process, LEAFPAK_COMMAND); + fr_process_add_arg (comm->process, comm->filename); + fr_process_end_command (comm->process); + fr_process_start (comm->process, TRUE); +} + + +static void +fr_command_leafpak_extract (FRCommand *comm, + GList *file_list, + char *dest_dir, + gboolean overwrite, + gboolean skip_older, + gboolean junk_paths) +{ + GList *scan; + char *option = "x"; + + fr_process_begin_command (comm->process, LEAFPAK_COMMAND); + + if (dest_dir != NULL) + fr_process_set_working_dir (comm->process, dest_dir); + + fr_process_add_arg (comm->process, option); + fr_process_add_arg (comm->process, comm->filename); + + for (scan = file_list; scan; scan = scan->next) + fr_process_add_arg (comm->process, scan->data); + + fr_process_end_command (comm->process); +} + + +static void +fr_command_leafpak_class_init (FRCommandLeafpakClass *class) +{ + FRCommandClass *afc; + GtkObjectClass *object_class; + + parent_class = gtk_type_class (FR_COMMAND_TYPE); + object_class = (GtkObjectClass*) class; + afc = (FRCommandClass*) class; + + object_class->destroy = fr_command_leafpak_destroy; + + afc->list = fr_command_leafpak_list; + afc->extract = fr_command_leafpak_extract; +} + + +static void +fr_command_leafpak_init (FRCommand *comm) +{ + comm->propAddCanUpdate = FALSE; + comm->propExtractCanAvoidOverwrite = FALSE; + comm->propExtractCanSkipOlder = FALSE; + comm->propExtractCanJunkPaths = TRUE; + + comm->propHasRatio = TRUE; +} + + +static void +fr_command_leafpak_destroy (GtkObject *object) +{ + g_return_if_fail (object != NULL); + g_return_if_fail (IS_FR_COMMAND_LEAFPAK (object)); + + /* Chain up */ + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + +GtkType +fr_command_leafpak_get_type () +{ + static guint fr_command_leafpak_type = 0; + + if (!fr_command_leafpak_type) { + GtkTypeInfo fr_command_leafpak_info = { + "FRCommandLeafpak", + sizeof (FRCommandLeafpak), + sizeof (FRCommandLeafpakClass), + (GtkClassInitFunc) fr_command_leafpak_class_init, + (GtkObjectInitFunc) fr_command_leafpak_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + fr_command_leafpak_type = gtk_type_unique (fr_command_get_type(), + &fr_command_leafpak_info); + } + + return fr_command_leafpak_type; +} + + +FRCommand * +fr_command_leafpak_new (FRProcess *process, + const char *filename, + FRArchive *archive) +{ + FRCommand *comm; + + comm = FR_COMMAND (gtk_type_new (fr_command_leafpak_get_type ())); + fr_command_construct (comm, process, filename); + fr_process_set_proc_line_func (FR_COMMAND (comm)->process, + process_line, + comm); + comm->archive = archive; + + return comm; +} diff -Nur gimageview-0.2.2-bak/plugins/archiver/leafpak-ext.h gimageview-0.2.2/plugins/archiver/leafpak-ext.h --- gimageview-0.2.2-bak/plugins/archiver/leafpak-ext.h Thu Jan 1 09:00:00 1970 +++ gimageview-0.2.2/plugins/archiver/leafpak-ext.h Wed Jun 5 02:46:09 2002 @@ -0,0 +1,59 @@ +/* + * leafpak archiver plugin + * + * Copyright (C) 2002 Takuro Ashie + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + */ + +#ifndef FR_COMMAND_LEAFPAK_H +#define FR_COMMAND_LEAFPAK_H + + +#include +#include "fr-command.h" +#include "fr-process.h" + + +#define FR_COMMAND_LEAFPAK_TYPE fr_command_leafpak_get_type () +#define FR_COMMAND_LEAFPAK(o) GTK_CHECK_CAST (o, FR_COMMAND_LEAFPAK_TYPE, FRCommandLeahpak) +#define FR_COMMAND_LEAFPAK_CLASS(k) GTK_CHECK_CLASS_CAST (k, FR_COMMAND_LEAFPAK_TYPE, FRCommandLeafpakClass) +#define IS_FR_COMMAND_LEAFPAK(o) GTK_CHECK_TYPE (o, FR_COMMAND_LEAFPAK_TYPE) + + +typedef struct _FRCommandLeafpak FRCommandLeafpak; +typedef struct _FRCommandLeafpakClass FRCommandLeafpakClass; + + +struct _FRCommandLeafpak +{ + FRCommand __parent; +}; + + +struct _FRCommandLeafpakClass +{ + FRCommandClass __parent_class; +}; + + +GtkType fr_command_leafpak_get_type (void); + +FRCommand* fr_command_leafpak_new (FRProcess *process, + const char *filename, + FRArchive *archive); + + +#endif /* FR_COMMAND_LEAFPAK_H */