[file-roller: 25/123] implemented _g_uri_is_archive
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller: 25/123] implemented _g_uri_is_archive
- Date: Mon, 6 Aug 2012 13:42:58 +0000 (UTC)
commit 3d9b8d55eeca091bf8ca75d93f8dccc9f61ff708
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Jul 20 22:46:44 2012 +0200
implemented _g_uri_is_archive
src/fr-archive.c | 35 +++++++++++++++++++++++------------
1 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/src/fr-archive.c b/src/fr-archive.c
index 77b0026..61cc628 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -462,7 +462,6 @@ void
fr_archive_update_capabilities (FrArchive *self)
{
self->priv->capabilities = fr_archive_get_capabilities (self, self->mime_type, TRUE);
- /* FIXME: check if this is correct */
self->read_only = ! fr_archive_is_capable_of (self, FR_ARCHIVE_CAN_WRITE);
}
@@ -1675,30 +1674,42 @@ fr_archive_add_file (FrArchive *self,
}
-/* FIXME: use sniffer as in fr_archive_open */
gboolean
_g_uri_is_archive (const char *uri)
{
GFile *file;
const char *mime_type = NULL;
gboolean is_archive = FALSE;
+ char *buffer;
+ int buffer_size;
file = g_file_new_for_uri (uri);
- /* FIXME: libarchive
- mime_type = get_mime_type_from_magic_numbers (file); */
- if (mime_type == NULL)
- mime_type = get_mime_type_from_filename (file);
+ buffer_size = BUFFER_SIZE_FOR_PRELOAD;
+ buffer = g_new (char, buffer_size);
+
+ if (g_load_file_in_buffer (file, buffer, buffer_size, NULL)) {
+ gboolean result_uncertain;
- if (mime_type != NULL) {
- int i;
+ g_content_type_guess (uri, (guchar *) buffer, buffer_size, &result_uncertain);
+ if (result_uncertain) {
+ mime_type = get_mime_type_from_magic_numbers (buffer, buffer_size);
+ if (mime_type == NULL)
+ mime_type = get_mime_type_from_filename (file);
+ }
- for (i = 0; mime_type_desc[i].mime_type != NULL; i++) {
- if (strcmp (mime_type_desc[i].mime_type, mime_type) == 0) {
- is_archive = TRUE;
- break;
+ if (mime_type != NULL) {
+ int i;
+
+ for (i = 0; mime_type_desc[i].mime_type != NULL; i++) {
+ if (strcmp (mime_type_desc[i].mime_type, mime_type) == 0) {
+ is_archive = TRUE;
+ break;
+ }
}
}
}
+
+ g_free (buffer);
g_object_unref (file);
return is_archive;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]