nsxiv426edfb
Readded file-type check at startup
+27 −5
3 files changed
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110404 | |
| 3 | + | VERSION=git-20110405 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -56,6 +56,23 @@ void img_free(img_t* img) { | |||
| 56 | 56 | imlib_free_image(); | |
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | + | int img_check(const char *filename) { | |
| 60 | + | Imlib_Image *im; | |
| 61 | + | ||
| 62 | + | if (!filename) | |
| 63 | + | return 0; | |
| 64 | + | ||
| 65 | + | if ((im = imlib_load_image(filename))) { | |
| 66 | + | imlib_context_set_image(im); | |
| 67 | + | imlib_image_set_changes_on_disk(); | |
| 68 | + | imlib_free_image(); | |
| 69 | + | return 1; | |
| 70 | + | } else { | |
| 71 | + | warn("invalid file: %s", filename); | |
| 72 | + | return 0; | |
| 73 | + | } | |
| 74 | + | } | |
| 75 | + | ||
| 59 | 76 | int img_load(img_t *img, const char *filename) { | |
| 60 | 77 | if (!img || !filename) | |
| 61 | 78 | return 0; | |
| @@ -66,7 +83,7 @@ int img_load(img_t *img, const char *filename) { | |||
| 66 | 83 | imlib_context_set_anti_alias(img->aa); | |
| 67 | 84 | img->scalemode = options->scalemode; | |
| 68 | 85 | } else { | |
| 69 | − | warn("not an image: %s", filename); | |
| 86 | + | warn("invalid file: %s", filename); | |
| 70 | 87 | imlib_context_set_image(im_invalid); | |
| 71 | 88 | imlib_context_set_anti_alias(0); | |
| 72 | 89 | } | |
| @@ -178,7 +178,7 @@ void update_title() { | |||
| 178 | 178 | fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit, | |
| 179 | 179 | filenames[fileidx]); | |
| 180 | 180 | } else { | |
| 181 | − | n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] not an image: %s", | |
| 181 | + | n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] invalid: %s", | |
| 182 | 182 | fileidx + 1, filecnt, filenames[fileidx]); | |
| 183 | 183 | } | |
| 184 | 184 | } | |
| @@ -193,7 +193,13 @@ void update_title() { | |||
| 193 | 193 | } | |
| 194 | 194 | ||
| 195 | 195 | int check_append(const char *filename) { | |
| 196 | − | if (filename && !access(filename, R_OK)) { | |
| 196 | + | if (!filename) | |
| 197 | + | return 0; | |
| 198 | + | ||
| 199 | + | if (access(filename, R_OK)) { | |
| 200 | + | warn("could not open file: %s", filename); | |
| 201 | + | return 0; | |
| 202 | + | } else if (img_check(filename)) { | |
| 197 | 203 | if (fileidx == filecnt) { | |
| 198 | 204 | filecnt *= 2; | |
| 199 | 205 | filenames = (const char**) s_realloc(filenames, | |
| @@ -202,7 +208,6 @@ int check_append(const char *filename) { | |||
| 202 | 208 | filenames[fileidx++] = filename; | |
| 203 | 209 | return 1; | |
| 204 | 210 | } else { | |
| 205 | − | warn("could not open file: %s", filename); | |
| 206 | 211 | return 0; | |
| 207 | 212 | } | |
| 208 | 213 | } | |