Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/thumbs.c
| Show All 15 Lines | |||||
| * The Original Code is Copyright (C) 2007 Blender Foundation | * The Original Code is Copyright (C) 2007 Blender Foundation | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup imbuf | * \ingroup imbuf | ||||
| */ | */ | ||||
| #include <stdbool.h> | |||||
| #include <stddef.h> | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "BKE_appdir.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_hash_md5.h" | #include "BLI_hash_md5.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_system.h" | #include "BLI_system.h" | ||||
| Show All 27 Lines | |||||
| /* For SHGetSpecialFolderPath, has to be done before BLI_winstuff | /* For SHGetSpecialFolderPath, has to be done before BLI_winstuff | ||||
| * because 'near' is disabled through BLI_windstuff */ | * because 'near' is disabled through BLI_windstuff */ | ||||
| # include "BLI_winstuff.h" | # include "BLI_winstuff.h" | ||||
| # include "utfconv.h" | # include "utfconv.h" | ||||
| # include <direct.h> /* #chdir */ | # include <direct.h> /* #chdir */ | ||||
| # include <shlobj.h> | # include <shlobj.h> | ||||
| #endif | #endif | ||||
| #if defined(WIN32) || defined(__APPLE__) | |||||
| /* pass */ | |||||
| #else | |||||
| # define USE_FREEDESKTOP | |||||
| #endif | |||||
| /* '$HOME/.cache/thumbnails' or '$HOME/.thumbnails' */ | |||||
| #ifdef USE_FREEDESKTOP | |||||
| # define THUMBNAILS "thumbnails" | #define THUMBNAILS "thumbnails" | ||||
| #else | |||||
| # define THUMBNAILS ".thumbnails" | |||||
| #endif | |||||
| #define URI_MAX (FILE_MAX * 3 + 8) | #define URI_MAX (FILE_MAX * 3 + 8) | ||||
| static bool get_thumb_dir(char *dir, ThumbSize size) | static bool get_thumb_dir(char *r_dir, const size_t dir_len, const ThumbSize size) | ||||
| { | { | ||||
| char *s = dir; | char cache_dir[FILE_MAX]; | ||||
| const char *subdir; | const bool ok = BKE_appdir_folder_caches(cache_dir, sizeof(cache_dir)); | ||||
| #ifdef WIN32 | if (!ok) { | ||||
| wchar_t dir_16[MAX_PATH]; | return false; | ||||
| /* Yes, applications shouldn't store data there, but so does GIMP :). */ | |||||
| SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0); | |||||
| conv_utf_16_to_8(dir_16, dir, FILE_MAX); | |||||
| s += strlen(dir); | |||||
| #else | |||||
| # if defined(USE_FREEDESKTOP) | |||||
| const char *home_cache = BLI_getenv("XDG_CACHE_HOME"); | |||||
| const char *home = home_cache ? home_cache : BLI_getenv("HOME"); | |||||
| # else | |||||
| const char *home = BLI_getenv("HOME"); | |||||
| # endif | |||||
| if (!home) { | |||||
| return 0; | |||||
| } | |||||
| s += BLI_strncpy_rlen(s, home, FILE_MAX); | |||||
| # ifdef USE_FREEDESKTOP | |||||
| if (!home_cache) { | |||||
| s += BLI_strncpy_rlen(s, "/.cache", FILE_MAX - (s - dir)); | |||||
| } | } | ||||
| # endif | const char *thumb_dir = NULL; | ||||
| #endif | |||||
| switch (size) { | switch (size) { | ||||
| case THB_NORMAL: | case THB_NORMAL: | ||||
| subdir = SEP_STR THUMBNAILS SEP_STR "normal" SEP_STR; | thumb_dir = SEP_STR THUMBNAILS SEP_STR "normal" SEP_STR; | ||||
| break; | break; | ||||
| case THB_LARGE: | case THB_LARGE: | ||||
| subdir = SEP_STR THUMBNAILS SEP_STR "large" SEP_STR; | thumb_dir = SEP_STR THUMBNAILS SEP_STR "large" SEP_STR; | ||||
| break; | break; | ||||
| case THB_FAIL: | case THB_FAIL: | ||||
| subdir = SEP_STR THUMBNAILS SEP_STR "fail" SEP_STR "blender" SEP_STR; | thumb_dir = SEP_STR THUMBNAILS SEP_STR "fail" SEP_STR "blender" SEP_STR; | ||||
LazyDodo: Why is blender still appended here? it makes this rather strange path for me locally
`C… | |||||
| break; | break; | ||||
| default: | default: | ||||
| return 0; /* unknown size */ | return false; /* unknown size */ | ||||
| } | } | ||||
| BLI_path_join(r_dir, dir_len, cache_dir, thumb_dir, SEP_STR, NULL); | |||||
| s += BLI_strncpy_rlen(s, subdir, FILE_MAX - (s - dir)); | return true; | ||||
| (void)s; | |||||
| return 1; | |||||
| } | } | ||||
| #undef THUMBNAILS | #undef THUMBNAILS | ||||
| /* --- Begin of adapted code from glib. --- */ | /* --- Begin of adapted code from glib. --- */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Escape URI String | /** \name Escape URI String | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | if (r_name) { | ||||
| hexdigest[0] = '\0'; | hexdigest[0] = '\0'; | ||||
| BLI_snprintf(r_name, name_len, "%s.png", BLI_hash_md5_to_hexdigest(digest, hexdigest)); | BLI_snprintf(r_name, name_len, "%s.png", BLI_hash_md5_to_hexdigest(digest, hexdigest)); | ||||
| // printf("%s: '%s' --> '%s'\n", __func__, uri, r_name); | // printf("%s: '%s' --> '%s'\n", __func__, uri, r_name); | ||||
| } | } | ||||
| if (r_path) { | if (r_path) { | ||||
| char tmppath[FILE_MAX]; | char tmppath[FILE_MAX]; | ||||
| if (get_thumb_dir(tmppath, size)) { | if (get_thumb_dir(tmppath, sizeof(tmppath), size)) { | ||||
| BLI_snprintf(r_path, path_len, "%s%s", tmppath, r_name); | BLI_snprintf(r_path, path_len, "%s%s", tmppath, r_name); | ||||
| // printf("%s: '%s' --> '%s'\n", __func__, uri, r_path); | // printf("%s: '%s' --> '%s'\n", __func__, uri, r_path); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_len) | static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_len) | ||||
| { | { | ||||
| thumbpathname_from_uri(uri, NULL, 0, thumb, thumb_len, THB_FAIL); | thumbpathname_from_uri(uri, NULL, 0, thumb, thumb_len, THB_FAIL); | ||||
| } | } | ||||
| static bool thumbpath_from_uri(const char *uri, char *path, const int path_len, ThumbSize size) | static bool thumbpath_from_uri(const char *uri, char *path, const int path_len, ThumbSize size) | ||||
| { | { | ||||
| return thumbpathname_from_uri(uri, path, path_len, NULL, 0, size); | return thumbpathname_from_uri(uri, path, path_len, NULL, 0, size); | ||||
| } | } | ||||
| void IMB_thumb_makedirs(void) | void IMB_thumb_makedirs(void) | ||||
| { | { | ||||
| char tpath[FILE_MAX]; | char tpath[FILE_MAX]; | ||||
| #if 0 /* UNUSED */ | #if 0 /* UNUSED */ | ||||
| if (get_thumb_dir(tpath, THB_NORMAL)) { | if (get_thumb_dir(tpath, sizeof(tpath), THB_NORMAL)) { | ||||
| BLI_dir_create_recursive(tpath); | BLI_dir_create_recursive(tpath); | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (get_thumb_dir(tpath, THB_LARGE)) { | if (get_thumb_dir(tpath, sizeof(tpath), THB_LARGE)) { | ||||
| BLI_dir_create_recursive(tpath); | BLI_dir_create_recursive(tpath); | ||||
| } | } | ||||
| if (get_thumb_dir(tpath, THB_FAIL)) { | if (get_thumb_dir(tpath, sizeof(tpath), THB_FAIL)) { | ||||
| BLI_dir_create_recursive(tpath); | BLI_dir_create_recursive(tpath); | ||||
| } | } | ||||
| } | } | ||||
| /* create thumbnail for file and returns new imbuf for thumbnail */ | /* create thumbnail for file and returns new imbuf for thumbnail */ | ||||
| static ImBuf *thumb_create_ex(const char *file_path, | static ImBuf *thumb_create_ex(const char *file_path, | ||||
| const char *uri, | const char *uri, | ||||
| const char *thumb, | const char *thumb, | ||||
| Show All 35 Lines | static ImBuf *thumb_create_ex(const char *file_path, | ||||
| if (source == THB_SOURCE_IMAGE) { | if (source == THB_SOURCE_IMAGE) { | ||||
| const size_t file_size = BLI_file_size(file_path); | const size_t file_size = BLI_file_size(file_path); | ||||
| if (file_size != -1 && file_size > THUMB_SIZE_MAX) { | if (file_size != -1 && file_size > THUMB_SIZE_MAX) { | ||||
| // printf("file too big: %d, skipping %s\n", (int)size, file_path); | // printf("file too big: %d, skipping %s\n", (int)size, file_path); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| if (get_thumb_dir(tdir, size)) { | if (get_thumb_dir(tdir, sizeof(tdir), size)) { | ||||
| BLI_snprintf(tpath, FILE_MAX, "%s%s", tdir, thumb); | BLI_snprintf(tpath, FILE_MAX, "%s%s", tdir, thumb); | ||||
| // thumb[8] = '\0'; /* shorten for tempname, not needed anymore */ | // thumb[8] = '\0'; /* shorten for tempname, not needed anymore */ | ||||
| BLI_snprintf(temp, FILE_MAX, "%sblender_%d_%s.png", tdir, abs(getpid()), thumb); | BLI_snprintf(temp, FILE_MAX, "%sblender_%d_%s.png", tdir, abs(getpid()), thumb); | ||||
| if (BLI_path_ncmp(file_path, tdir, sizeof(tdir)) == 0) { | if (BLI_path_ncmp(file_path, tdir, sizeof(tdir)) == 0) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (size == THB_FAIL) { | if (size == THB_FAIL) { | ||||
| img = IMB_allocImBuf(1, 1, 32, IB_rect | IB_metadata); | img = IMB_allocImBuf(1, 1, 32, IB_rect | IB_metadata); | ||||
| ▲ Show 20 Lines • Show All 372 Lines • Show Last 20 Lines | |||||
Why is blender still appended here? it makes this rather strange path for me locally
C:\Users\ray\AppData\Local\Blender Foundation\Blender\Cache\thumbnails\fail\blender\