file-roller r2397 - in trunk: . help src



Author: paobac
Date: Wed Jul 30 08:59:17 2008
New Revision: 2397
URL: http://svn.gnome.org/viewvc/file-roller?rev=2397&view=rev

Log:
2008-07-30  Paolo Bacchilega  <paobac svn gnome org>

	* src/fr-command-cfile.c (get_uncompressed_name_from_archive): use
	gio to read the file.
	
	* src/fr-archive.c (get_mime_type_from_magic_numbers): added gzip
	magic numbers.


Modified:
   trunk/ChangeLog
   trunk/help/ChangeLog
   trunk/src/fr-archive.c
   trunk/src/fr-command-cfile.c

Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c	(original)
+++ trunk/src/fr-archive.c	Wed Jul 30 08:59:17 2008
@@ -536,6 +536,7 @@
 		{ "application/x-7z-compressed", "7z\274\257\047\034", 0, 5 },
 		{ "application/x-ace", "**ACE**", 7, 7 },
 		{ "application/x-arj", "\x60\xea", 0, 2 },
+		{ "application/x-gzip", "\037\213", 0, 2 },
 		{ "application/x-rar", "Rar!", 0, 4 },
 		{ "application/x-rzip", "RZIP", 0, 4 },
 		{ "application/x-zoo", "\xdc\xa7\xc4\xfd", 20, 4 },

Modified: trunk/src/fr-command-cfile.c
==============================================================================
--- trunk/src/fr-command-cfile.c	(original)
+++ trunk/src/fr-command-cfile.c	Wed Jul 30 08:59:17 2008
@@ -45,56 +45,51 @@
 get_uncompressed_name_from_archive (FrCommand  *comm,
 				    const char *archive)
 {
-	int      fd;
-	char     buffer[11];
-	char    *filename = NULL;
-	GString *str = NULL;
+	GFile        *file;
+	GInputStream *stream;
+	char         *filename = NULL;
 
 	if (! is_mime_type (comm->mime_type, "application/x-gzip"))
 		return NULL;
 
-	fd = open (archive, O_RDONLY);
-	if (fd < 0)
-		return NULL;
+	file = g_file_new_for_path (archive);
 
-	if (read (fd, &buffer, 11) < 11) {
-		close (fd);
-		return NULL;
-	}
+	stream = (GInputStream *) g_file_read (file, NULL, NULL);
+	if (stream != NULL) {
+		gboolean filename_present = TRUE;
+		char     buffer[10];
+
+		if (g_input_stream_read (stream, buffer, 10, NULL, NULL) >= 0) {
+			/* Check whether the FLG.FNAME is set */
+			if (((unsigned char)(buffer[3]) & 0x08) != 0x08)
+				filename_present = FALSE;
+
+			/* Check whether the FLG.FEXTRA is set */
+			if (((unsigned char)(buffer[3]) & 0x04) == 0x04)
+				filename_present = FALSE;
+		}
 
-	/* Check whether the FLG.FNAME is set */
-	if (((unsigned char)(buffer[3]) & 0x08) != 0x08) {
-		close (fd);
-		return NULL;
-	}
+		if (filename_present) {
+			GString *str = NULL;
 
-	/* Check whether the FLG.FEXTRA is set */
-	if (((unsigned char)(buffer[3]) & 0x04) == 0x04) {
-		close (fd);
-		return NULL;
-	}
-
-	str = g_string_new ("");
-	/* Don't lose the first character */
-	g_string_append_c (str, buffer[10]);
-	while (read (fd, &buffer, 1) > 0) {
-		if (buffer[0] == '\0') {
-			close (fd);
-			filename = g_strdup (file_name_from_path (str->str));
-			g_string_free (str, TRUE);
+			str = g_string_new ("");
+			while (g_input_stream_read (stream, buffer, 1, NULL, NULL) > 0) {
+				if (buffer[0] == '\0') {
+					filename = g_strdup (file_name_from_path (str->str));
 #ifdef DEBUG
-			g_message ("filename is: %s", filename);
+					g_message ("filename is: %s", filename);
 #endif
-			return filename;
+					break;
+				}
+				g_string_append_c (str, buffer[0]);
+			}
+			g_string_free (str, TRUE);
 		}
-
-		g_string_append_c (str, buffer[0]);
+		g_object_unref (stream);
 	}
+	g_object_unref (file);
 
-	close (fd);
-	g_string_free (str, TRUE);
-
-	return NULL;
+	return filename;
 }
 
 



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