file-roller r2327 - in trunk: . data nautilus src



Author: paobac
Date: Thu Jun 19 16:05:37 2008
New Revision: 2327
URL: http://svn.gnome.org/viewvc/file-roller?rev=2327&view=rev

Log:
2008-06-19  Paolo Bacchilega  <paobac svn gnome org>

	* src/main.c: register the alz command and mime type.
	
	* src/Makefile.am: 
	* src/fr-command-alz.h: 
	* src/fr-command-alz.c: new files
	
	* nautilus/nautilus-fileroller.c: 
	* data/file-roller.desktop.in.in: added application/alz mime type.

	Added support for reading and extractin alz archives.
	Patch by Changwoo Ryu
	Fixed bug #521324 â ALZ archive support

Added:
   trunk/src/fr-command-alz.c
   trunk/src/fr-command-alz.h
Modified:
   trunk/ChangeLog
   trunk/data/file-roller.desktop.in.in
   trunk/nautilus/nautilus-fileroller.c
   trunk/src/Makefile.am
   trunk/src/main.c

Modified: trunk/data/file-roller.desktop.in.in
==============================================================================
--- trunk/data/file-roller.desktop.in.in	(original)
+++ trunk/data/file-roller.desktop.in.in	Thu Jun 19 16:05:37 2008
@@ -10,7 +10,7 @@
 Type=Application
 Icon=file-roller
 Categories=GTK;GNOME;Utility;
-MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-ar;application/x-arj;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-executable; application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-jar;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;multipart/x-zip;
+MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-ar;application/x-arj;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-executable; application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-jar;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;multipart/x-zip;
 X-GNOME-DocPath=file-roller/file-roller.xml
 X-GNOME-Bugzilla-Bugzilla=GNOME
 X-GNOME-Bugzilla-Product=file-roller

Modified: trunk/nautilus/nautilus-fileroller.c
==============================================================================
--- trunk/nautilus/nautilus-fileroller.c	(original)
+++ trunk/nautilus/nautilus-fileroller.c	Thu Jun 19 16:05:37 2008
@@ -144,6 +144,7 @@
 	"application/x-7z-compressed",
  	"application/x-7z-compressed-tar",
  	"application/x-ace",
+ 	"application/x-alz",
 	"application/x-ar", 
 	"application/x-arj",
 	"application/x-bzip",

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Thu Jun 19 16:05:37 2008
@@ -69,6 +69,8 @@
 	fr-command.h			\
 	fr-command-ace.c		\
 	fr-command-ace.h		\
+	fr-command-alz.c		\
+	fr-command-alz.h		\
 	fr-command-ar.c			\
 	fr-command-ar.h			\
 	fr-command-arj.c		\

Added: trunk/src/fr-command-alz.c
==============================================================================
--- (empty file)
+++ trunk/src/fr-command-alz.c	Thu Jun 19 16:05:37 2008
@@ -0,0 +1,391 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001 The Free Software Foundation, Inc.
+ *
+ *  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 <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "file-data.h"
+#include "file-utils.h"
+#include "fr-command.h"
+#include "fr-command-alz.h"
+#include "glib-utils.h"
+
+static void fr_command_alz_class_init  (FrCommandAlzClass *class);
+static void fr_command_alz_init        (FrCommand         *afile);
+static void fr_command_alz_finalize    (GObject           *object);
+
+/* Parent Class */
+
+static FrCommandClass *parent_class = NULL;
+
+
+/* -- list -- */
+
+
+static time_t
+mktime_from_string (char *date_s, 
+		    char *time_s)
+{
+	struct tm   tm = {0, };
+	char      **fields;
+
+	/* date */
+
+	fields = g_strsplit (date_s, "/", 3);
+	if (fields[0] != NULL) {
+		tm.tm_mon = atoi (fields[0]) - 1;
+		if (fields[1] != NULL) {
+			tm.tm_mday = atoi (fields[1]);
+			if (fields[2] != NULL)
+				tm.tm_year = 100 + atoi (fields[2]);
+		}
+	}
+	g_strfreev (fields);
+
+	/* time */
+
+	fields = g_strsplit (time_s, ":", 3);
+	if (fields[0] != NULL) {
+		tm.tm_hour = atoi (fields[0]);
+		if (fields[1] != NULL) 
+			tm.tm_min = atoi (fields[1]);
+	}
+	g_strfreev (fields);
+
+	return mktime (&tm);
+}
+
+
+static void
+process_line (char     *line, 
+	      gpointer  data)
+{
+	FrCommand     *comm = FR_COMMAND (data);
+	FrCommandAlz  *alz_comm = FR_COMMAND_ALZ (comm);
+	FileData      *fdata;
+	char         **fields;
+	char          *name_field;
+	char           name_last;
+	gsize	       name_len;
+
+	g_return_if_fail (line != NULL);
+
+
+	if (! alz_comm->list_started) {
+		if (strncmp (line, "-----", 5 ) == 0 ) 
+			alz_comm->list_started = TRUE;
+		return;
+	}
+
+	if (strncmp (line, "-----", 5 ) == 0) {
+		alz_comm->list_started = FALSE;
+		return;
+
+	}
+
+	if (! alz_comm->list_started) 
+		return;
+
+	fdata = file_data_new ();
+	fields = split_line (line, 5);
+	fdata->modified = mktime_from_string (fields[0], fields[1]);
+	fdata->size = g_ascii_strtoull (fields[3], NULL, 10);
+
+	name_field = g_strdup (get_last_field (line, 6));
+	name_len = strlen (name_field);
+
+	name_last = name_field[name_len - 1];
+	fdata->dir = name_last == '\\';
+	fdata->encrypted = name_last == '*';
+
+	if (fdata->dir || fdata->encrypted)
+		name_field[--name_len] = '\0';
+
+	if (*name_field == '/') {
+		fdata->full_path = g_strdup (name_field);
+		fdata->original_path = fdata->full_path;
+	} 
+	else {
+		fdata->full_path = g_strconcat ("/", name_field, NULL);
+		fdata->original_path = fdata->full_path + 1;
+	}
+
+	if (fdata->dir) {
+		char *s;
+		for (s = fdata->full_path; *s != '\0'; ++s)
+			if (*s == '\\') *s = '/';
+		for (s = fdata->original_path; *s != '\0'; ++s)
+			if (*s == '\\') *s = '/';
+		fdata->name = dir_name_from_path (fdata->full_path);
+	} 
+	else {
+		fdata->name = g_strdup (file_name_from_path (fdata->full_path));
+	}
+
+	fdata->path = remove_level_from_path (fdata->full_path);
+
+	if (*fdata->name == 0)
+		file_data_free (fdata);
+	else
+		fr_command_add_file (comm, fdata);
+
+	g_free (name_field);
+	g_strfreev (fields);
+}
+
+
+static void
+add_codepage_arg (FrCommand *comm)
+{
+	const char  *env_list[] = { "LC_CTYPE", "LC_ALL", "LANG", NULL };
+	const char **scan;
+	const char  *arg = "-cp949";
+
+	for (scan = env_list; *scan != NULL; ++scan) {
+		char *env = getenv (*scan);
+		
+		if (! env) 
+			continue;
+
+		if (strstr (env, "UTF-8") ||  strstr (env, "utf-8"))
+			arg = "-utf8";
+		else if (strstr (env, "euc") || strstr (env, "EUC"))
+			arg = "-euc-kr";
+		else
+			continue;
+		break;
+	}
+
+	fr_process_add_arg (comm->process, arg);
+}
+
+
+static void
+add_password_arg (FrCommand  *comm,
+		  const char *password,
+		  gboolean    disable_query)
+{
+	if (password != NULL) {
+		fr_process_add_arg (comm->process, "-pwd");
+		fr_process_add_arg (comm->process, password);
+	} 
+	else if (disable_query) {
+		fr_process_add_arg (comm->process, "-pwd");
+		fr_process_add_arg (comm->process, "");
+	}
+}
+
+
+static void
+fr_command_alz_list (FrCommand  *comm,
+		     const char *password)
+{
+	FR_COMMAND_ALZ (comm)->list_started = FALSE;
+	FR_COMMAND_ALZ (comm)->invalid_password = FALSE;
+
+	fr_process_set_out_line_func (FR_COMMAND (comm)->process, 
+				      process_line,
+				      comm);
+
+	fr_process_begin_command (comm->process, "unalz");
+	fr_process_add_arg (comm->process, "-l");
+	add_codepage_arg(comm);
+	fr_process_add_arg (comm->process, comm->filename);
+	fr_process_end_command (comm->process);
+	fr_process_use_standard_locale (comm->process, TRUE);
+	fr_process_start (comm->process);
+}
+
+
+/* -- extract -- */
+
+static void
+process_extract_line (char     *line, 
+		      gpointer  data)
+{
+	FrCommand     *comm = FR_COMMAND (data);
+	FrCommandAlz  *alz_comm = FR_COMMAND_ALZ (comm);
+
+	g_return_if_fail (line != NULL);
+
+	/* - error check - */
+
+	if (strncmp (line, "err code(28) (invalid password)", 31) == 0) {
+		alz_comm->invalid_password = TRUE;
+		fr_process_stop (comm->process);
+		return;
+	}
+
+	if (alz_comm->extract_none && (strncmp (line, "unalziiiing :", 13) == 0)) {
+		alz_comm->extract_none = FALSE;
+	} 
+	else if ((strncmp (line, "done..", 6) == 0) && alz_comm->extract_none) {
+		fr_process_stop (comm->process);
+		return;
+	}
+}
+
+
+static void
+fr_command_alz_extract (FrCommand  *comm,
+			GList      *file_list,
+			const char *dest_dir,
+			gboolean    overwrite,
+			gboolean    skip_older,
+			gboolean    junk_paths,
+			const char *password)
+{
+	GList *scan;
+
+	FR_COMMAND_ALZ (comm)->extract_none = TRUE;
+	
+	fr_process_set_out_line_func (FR_COMMAND (comm)->process,
+				      process_extract_line,
+				      comm);
+
+	fr_process_begin_command (comm->process, "unalz");
+	if (dest_dir != NULL) {
+		fr_process_add_arg (comm->process, "-d");
+		fr_process_add_arg (comm->process, dest_dir);
+	}
+	add_codepage_arg (comm);
+	add_password_arg (comm, password, TRUE);
+	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_alz_handle_error (FrCommand   *comm, 
+			     FrProcError *error)
+{
+	if ((error->type == FR_PROC_ERROR_STOPPED)) {
+		if  (FR_COMMAND_ALZ (comm)->extract_none ||
+		     FR_COMMAND_ALZ (comm)->invalid_password ) {
+			error->type = FR_PROC_ERROR_ASK_PASSWORD;
+		}
+	}
+}
+
+
+const char *alz_mime_type[] = { "application/x-alz", NULL };
+
+
+const char **  
+fr_command_alz_get_mime_types (FrCommand *comm)
+{
+	return alz_mime_type;
+}
+
+
+FrCommandCap   
+fr_command_alz_get_capabilities (FrCommand  *comm,
+			         const char *mime_type)
+{
+	FrCommandCap capabilities;
+	
+	capabilities = FR_COMMAND_CAP_ARCHIVE_MANY_FILES;
+	if (is_program_in_path ("unalz")) 
+		capabilities |= FR_COMMAND_CAP_READ;
+		
+	return capabilities;
+}
+
+
+static void 
+fr_command_alz_class_init (FrCommandAlzClass *class)
+{
+        GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+        FrCommandClass *afc;
+
+        parent_class = g_type_class_peek_parent (class);
+	afc = (FrCommandClass*) class;
+
+	gobject_class->finalize = fr_command_alz_finalize;
+
+        afc->list             = fr_command_alz_list;
+	afc->add              = NULL;
+	afc->delete           = NULL;
+	afc->extract          = fr_command_alz_extract;
+	afc->handle_error     = fr_command_alz_handle_error;
+	afc->get_mime_types   = fr_command_alz_get_mime_types;
+	afc->get_capabilities = fr_command_alz_get_capabilities;
+}
+
+ 
+static void 
+fr_command_alz_init (FrCommand *comm)
+{
+	comm->propAddCanUpdate             = TRUE;
+	comm->propAddCanReplace            = TRUE;
+	comm->propExtractCanAvoidOverwrite = FALSE;
+	comm->propExtractCanSkipOlder      = FALSE;
+	comm->propExtractCanJunkPaths      = FALSE;
+	comm->propPassword                 = TRUE;
+	comm->propTest                     = FALSE;
+}
+
+
+static void 
+fr_command_alz_finalize (GObject *object)
+{
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (FR_IS_COMMAND_ALZ (object));
+
+	/* Chain up */
+        if (G_OBJECT_CLASS (parent_class)->finalize)
+		G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+GType
+fr_command_alz_get_type ()
+{
+        static GType type = 0;
+
+        if (! type) {
+                GTypeInfo type_info = {
+			sizeof (FrCommandAlzClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) fr_command_alz_class_init,
+			NULL,
+			NULL,
+			sizeof (FrCommandAlz),
+			0,
+			(GInstanceInitFunc) fr_command_alz_init
+		};
+
+		type = g_type_register_static (FR_TYPE_COMMAND,
+					       "FrCommandAlz",
+					       &type_info,
+					       0);
+        }
+
+        return type;
+}

Added: trunk/src/fr-command-alz.h
==============================================================================
--- (empty file)
+++ trunk/src/fr-command-alz.h	Thu Jun 19 16:05:37 2008
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001 The Free Software Foundation, Inc.
+ *
+ *  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_ALZ_H
+#define FR_COMMAND_ALZ_H
+
+#include <glib.h>
+#include "file-data.h"
+#include "fr-command.h"
+#include "fr-process.h"
+
+#define FR_TYPE_COMMAND_ALZ            (fr_command_alz_get_type ())
+#define FR_COMMAND_ALZ(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), FR_TYPE_COMMAND_ALZ, FrCommandAlz))
+#define FR_COMMAND_ALZ_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), FR_TYPE_COMMAND_ALZ, FrCommandAlzClass))
+#define FR_IS_COMMAND_ALZ(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FR_TYPE_COMMAND_ALZ))
+#define FR_IS_COMMAND_ALZ_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FR_TYPE_COMMAND_ALZ))
+#define FR_COMMAND_ALZ_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), FR_TYPE_COMMAND_ALZ, FrCommandAlzClass))
+
+typedef struct _FrCommandAlz       FrCommandAlz;
+typedef struct _FrCommandAlzClass  FrCommandAlzClass;
+
+struct _FrCommandAlz
+{
+	FrCommand  __parent;
+
+	gboolean extract_none;
+	gboolean invalid_password;
+	gboolean list_started;
+};
+
+struct _FrCommandAlzClass
+{
+	FrCommandClass __parent_class;
+};
+
+GType fr_command_alz_get_type (void);
+
+#endif /* FR_COMMAND_ALZ_H */

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Thu Jun 19 16:05:37 2008
@@ -32,6 +32,7 @@
 #include "glib-utils.h"
 #include "fr-command.h"
 #include "fr-command-ace.h"
+#include "fr-command-alz.h"
 #include "fr-command-ar.h"
 #include "fr-command-arj.h"
 #include "fr-command-cfile.h"
@@ -82,6 +83,7 @@
 	{ "application/x-7z-compressed",        ".7z",       N_("7-Zip (.7z)"), TRUE, TRUE },
 	{ "application/x-7z-compressed-tar",    ".tar.7z",   N_("Tar compressed with 7z (.tar.7z)"), FALSE, TRUE },
 	{ "application/x-ace",                  ".ace",      N_("Ace (.ace)"), FALSE, FALSE },
+	{ "application/x-alz",                  ".alz",      NULL, TRUE, TRUE },
 	{ "application/x-ar",                   ".ar",       N_("Ar (.ar)"), FALSE, TRUE },
 	{ "application/x-arj",                  ".arj",      N_("Arj (.arj)"), TRUE, TRUE },
 	{ "application/x-bzip",                 ".bz2",      NULL, FALSE, FALSE },
@@ -119,6 +121,7 @@
 FrExtensionType file_ext_type[] = {
 	{ ".7z", "application/x-7z-compressed" },
 	{ ".ace", "application/x-ace" },
+	{ ".alz", "application/x-alz" },
 	{ ".ar", "application/x-ar" },
 	{ ".arj", "application/x-arj" },
 	{ ".bin", "application/x-stuffit" },
@@ -510,17 +513,19 @@
 	register_command (FR_TYPE_COMMAND_TAR);
 	register_command (FR_TYPE_COMMAND_CFILE);
 	register_command (FR_TYPE_COMMAND_7Z);
-	register_command (FR_TYPE_COMMAND_ZIP);
-	register_command (FR_TYPE_COMMAND_RAR);
-	register_command (FR_TYPE_COMMAND_ARJ);
+	
 	register_command (FR_TYPE_COMMAND_ACE);
+	register_command (FR_TYPE_COMMAND_ALZ);
 	register_command (FR_TYPE_COMMAND_AR);
+	register_command (FR_TYPE_COMMAND_ARJ);
 	register_command (FR_TYPE_COMMAND_CPIO);
 	register_command (FR_TYPE_COMMAND_ISO);
 	register_command (FR_TYPE_COMMAND_JAR);
 	register_command (FR_TYPE_COMMAND_LHA);
+	register_command (FR_TYPE_COMMAND_RAR);
 	register_command (FR_TYPE_COMMAND_RPM);
 	register_command (FR_TYPE_COMMAND_UNSTUFF);
+	register_command (FR_TYPE_COMMAND_ZIP);	
 	register_command (FR_TYPE_COMMAND_ZOO);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]