--- backend/comics/comics-document.c	2008-12-23 20:44:08.000000000 +0100
+++ /home/jjmarin/Escritorio/comics-document.p7zip.c	2008-12-23 20:47:44.000000000 +0100
@@ -111,6 +111,8 @@
 	GSList *supported_extensions;
 	gchar *list_files_command = NULL, *std_out, *quoted_file;
 	gchar *mime_type;
+	gchar *selected_command = NULL;
+ 	gchar *tmp = NULL;
 	gchar **cbr_files;
 	gboolean success;
 	int i, retval;
@@ -138,14 +140,34 @@
 			g_strdup_printf ("zipinfo -1 -- %s", quoted_file);
 		comics_document->regex_arg = TRUE;
 	} else if (!strcmp (mime_type, "application/x-cb7") ||
-		   !strcmp (mime_type, "application/x-7z-compressed")) {
-		comics_document->extract_command =
-			g_strdup ("7zr x -so");
-		list_files_command = 
-			g_strdup_printf ("7zr l -- %s", quoted_file);
-		comics_document->regex_arg = TRUE;
-	}
+		   !strcmp (mime_type, "application/x-7z-compressed")) {	   	
 
+	/*
+	7zr is a light stand-alone executable that supports only 7z/LZMA/BCJ
+	7za is a stand-alone executable.7za handles less archive formats than 7z.exe.
+	7z uses plugins (7z.so and Codecs/Rar29.so) to handle archives.
+	*/
+		if (g_find_program_in_path ("7zr") != NULL) selected_command = g_strdup ("7zr");
+		else if (g_find_program_in_path ("7za") != NULL) selected_command = g_strdup ("7za");
+		else  selected_command = g_strdup ("7z");
+
+		tmp = g_strdup(g_get_tmp_dir());
+        
+	/*For perfomance reasons of 7z* we choose to decompress on the temporary
+      directory instead of decompressing on the stdout*/      
+		g_spawn_command_line_sync (g_strdup_printf ("/bin/sh -c \"%s x -y -o%s %s >/dev/null\"",selected_command,tmp,quoted_file),
+			NULL, NULL, NULL, error);
+		list_files_command = 
+			g_strdup_printf ("/bin/sh -c \"%s l -- %s | cut -c54-\"",selected_command,quoted_file);
+		   
+		comics_document->extract_command =
+			g_strdup_printf ("cat %s/",tmp);
+		comics_document->regex_arg = FALSE;
+		        
+		g_free (selected_command);
+		g_free (tmp);
+    }
+    
 	g_free (mime_type);
 	g_free (quoted_file);
 
@@ -493,13 +515,19 @@
 			g_slist_nth_data (comics_document->page_names, page));
 	}
 
-	command_line = g_strdup_printf ("%s -- %s %s",
+	if (!strcmp(comics_document->extract_command,g_strdup_printf ("cat %s/",g_get_tmp_dir()))){
+		command_line = g_strdup_printf ("%s%s",
+					comics_document->extract_command,
+					quoted_filename);	
+	}
+	else {
+		command_line = g_strdup_printf ("%s -- %s %s",
 					comics_document->extract_command,
 					quoted_archive,
 					quoted_filename);
-
+	}
 	g_shell_parse_argv (command_line, NULL, &argv, &err);
-	
+
 	if (err) {
 		g_warning ("Error %s", err->message);
 		return NULL;
