Commit 2572c2a5 authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

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

parent 98a1d2bc
......@@ -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
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment