Guess the content from the actual data if it fails to do so from the file name alone.

This commit is contained in:
Sebastian Ramacher 2011-10-21 15:00:57 +02:00
parent 98a1d2bc95
commit 2572c2a5cc
2 changed files with 28 additions and 2 deletions

View file

@ -162,16 +162,37 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
}
if (file_exists(path) == false) {
girara_error("File does not exist");
girara_error("File '%s' does not exist", path);
return NULL;
}
const gchar* content_type = g_content_type_guess(path, NULL, 0, NULL);
gboolean uncertain;
const gchar* content_type = g_content_type_guess(path, NULL, 0, &uncertain);
if (content_type == NULL) {
girara_error("Could not determine file type");
return NULL;
}
if (uncertain == TRUE) {
g_free((void*)content_type);
content_type = NULL;
gchar* contents = NULL;
gsize length = 0;
if (g_file_get_contents(path, &contents, &length, NULL) == FALSE) {
girara_error("Could not determine file type");
return NULL;
}
content_type = g_content_type_guess(NULL, (guchar*) contents, length, &uncertain);
g_free(contents);
if (content_type == NULL || uncertain == TRUE) {
g_free((void*)content_type);
girara_error("Could not determine file type");
return NULL;
}
}
/* determine real path */
long path_max;
#ifdef PATH_MAX

View file

@ -104,6 +104,11 @@ typedef struct zathura_s
girara_list_t* bookmarks; /**> bookmarks */
} bookmarks;
struct
{
gchar* file;
} stdin_support;
zathura_document_t* document; /**> The current document */
zathura_database_t* database; /**> The database */
} zathura_t;