fix home directory spam, that could've been bad
This commit is contained in:
parent
5ae0fc4eea
commit
f2db911334
117
libs/img.c
117
libs/img.c
|
@ -189,80 +189,83 @@ loadimagecache(const char *file, int *width, int *height)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try find image from cache first */
|
if (generatecache) {
|
||||||
if(!(xdg_cache = getenv("XDG_CACHE_HOME")) && generatecache) {
|
/* try find image from cache first */
|
||||||
if(!(home = getenv("HOME")) && (pw = getpwuid(getuid())))
|
if(!(xdg_cache = getenv("XDG_CACHE_HOME"))) {
|
||||||
home = pw->pw_dir;
|
if(!(home = getenv("HOME")) && (pw = getpwuid(getuid())))
|
||||||
if(!home) {
|
home = pw->pw_dir;
|
||||||
fprintf(stderr, "spmenu: could not find home directory");
|
if(!home) {
|
||||||
return;
|
fprintf(stderr, "spmenu: could not find home directory");
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* which cache do we try? */
|
/* which cache do we try? */
|
||||||
dsize = "normal";
|
dsize = "normal";
|
||||||
if (longestedge > 128)
|
if (longestedge > 128)
|
||||||
dsize = "large";
|
dsize = "large";
|
||||||
|
|
||||||
slen = snprintf(NULL, 0, "file://%s", file)+1;
|
slen = snprintf(NULL, 0, "file://%s", file)+1;
|
||||||
|
|
||||||
if(!(buf = malloc(slen))) {
|
if(!(buf = malloc(slen))) {
|
||||||
fprintf(stderr, "spmenu: out of memory");
|
fprintf(stderr, "spmenu: out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate md5 from path */
|
/* calculate md5 from path */
|
||||||
sprintf(buf, "file://%s", file);
|
sprintf(buf, "file://%s", file);
|
||||||
MD5((unsigned char*)buf, slen, digest);
|
MD5((unsigned char*)buf, slen, digest);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
for(i = 0; i < MD5_DIGEST_LENGTH; ++i)
|
for(i = 0; i < MD5_DIGEST_LENGTH; ++i)
|
||||||
sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]);
|
sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]);
|
||||||
|
|
||||||
/* path for cached thumbnail */
|
/* path for cached thumbnail */
|
||||||
if (xdg_cache && generatecache)
|
if (xdg_cache)
|
||||||
slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1;
|
slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1;
|
||||||
else if (generatecache)
|
else
|
||||||
slen = snprintf(NULL, 0, "%s/.thumbnails/%s/%s.png", home, dsize, md5)+1;
|
slen = snprintf(NULL, 0, "%s/.thumbnails/%s/%s.png", home, dsize, md5)+1;
|
||||||
|
|
||||||
if(!(buf = malloc(slen))) {
|
if(!(buf = malloc(slen))) {
|
||||||
fprintf(stderr, "out of memory");
|
fprintf(stderr, "out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xdg_cache && generatecache)
|
if (xdg_cache)
|
||||||
sprintf(buf, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5);
|
sprintf(buf, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5);
|
||||||
else if (generatecache)
|
else
|
||||||
sprintf(buf, "%s/.thumbnails/%s/%s.png", home, dsize, md5);
|
sprintf(buf, "%s/.thumbnails/%s/%s.png", home, dsize, md5);
|
||||||
|
|
||||||
if (generatecache) loadimage(buf, width, height);
|
loadimage(buf, width, height);
|
||||||
|
|
||||||
if (image && *width < imagewidth && *height < imageheight) {
|
if (image && *width < imagewidth && *height < imageheight) {
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
image = NULL;
|
image = NULL;
|
||||||
} else if(image && (*width > imagewidth || *height > imageheight)) {
|
} else if(image && (*width > imagewidth || *height > imageheight)) {
|
||||||
scaleimage(width, height);
|
scaleimage(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we are done */
|
/* we are done */
|
||||||
if (image) {
|
if (image) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* we din't find anything from cache, or it was just wrong */
|
/* we din't find anything from cache, or it was just wrong */
|
||||||
loadimage(file, width, height);
|
loadimage(file, width, height);
|
||||||
if (!image) {
|
|
||||||
free(buf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scaleimage(width, height);
|
scaleimage(width, height);
|
||||||
|
|
||||||
|
if (!generatecache) return;
|
||||||
|
|
||||||
imlib_image_set_format("png");
|
imlib_image_set_format("png");
|
||||||
createifnexist_rec(buf);
|
|
||||||
imlib_save_image(buf);
|
if (buf && generatecache) {
|
||||||
free(buf);
|
createifnexist_rec(buf);
|
||||||
|
imlib_save_image(buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue