mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 09:16:00 +01:00
Guess the content from the actual data if it fails to do so from the file name alone.
This commit is contained in:
parent
98a1d2bc95
commit
2572c2a5cc
2 changed files with 28 additions and 2 deletions
25
document.c
25
document.c
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue