Cleanup: Clarify path variable name in thumbnail create function
"filepath" was misleading since this path could also point into a .blend file. Further, the convention was to use "filepath" for such files, and "file_path" for when only an actual file path was expected. This is highly confusing and non-obvious. Plus a (newer?) function broke with the convention. Just be explicit about the type of path, even if a bit verbose. It's good to always have the reminder that this may be more than just a file path when passing it around.
This commit is contained in:
@@ -51,6 +51,7 @@ typedef enum ThumbSource {
|
||||
|
||||
/**
|
||||
* Create thumbnail for file and returns new imbuf for thumbnail.
|
||||
* \param filepath: File path (but not a library path!) to the thumbnail to be created.
|
||||
*/
|
||||
struct ImBuf *IMB_thumb_create(const char *filepath,
|
||||
ThumbSize size,
|
||||
@@ -59,18 +60,24 @@ struct ImBuf *IMB_thumb_create(const char *filepath,
|
||||
|
||||
/**
|
||||
* Read thumbnail for file and returns new imbuf for thumbnail.
|
||||
* \param file_or_lib_path: File path or library-ID path (e.g. `/a/b.blend/Material/MyMaterial`) to
|
||||
* the thumbnail to be read.
|
||||
*/
|
||||
struct ImBuf *IMB_thumb_read(const char *filepath, ThumbSize size);
|
||||
struct ImBuf *IMB_thumb_read(const char *file_or_lib_path, ThumbSize size);
|
||||
|
||||
/**
|
||||
* Delete all thumbs for the file.
|
||||
* \param file_or_lib_path: File path or library-ID path (e.g. `/a/b.blend/Material/MyMaterial`) to
|
||||
* the thumbnail to be deleted.
|
||||
*/
|
||||
void IMB_thumb_delete(const char *filepath, ThumbSize size);
|
||||
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size);
|
||||
|
||||
/**
|
||||
* Create the thumb if necessary and manage failed and old thumbs.
|
||||
* \param file_or_lib_path: File path or library-ID path (e.g. `/a/b.blend/Material/MyMaterial`) to
|
||||
* the thumbnail to be created/managed.
|
||||
*/
|
||||
struct ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source);
|
||||
struct ImBuf *IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source);
|
||||
|
||||
/**
|
||||
* Create the necessary directories to store the thumbnails.
|
||||
|
||||
@@ -495,13 +495,13 @@ ImBuf *IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source
|
||||
filepath, uri, thumb_name, false, THUMB_DEFAULT_HASH, nullptr, nullptr, size, source, img);
|
||||
}
|
||||
|
||||
ImBuf *IMB_thumb_read(const char *filepath, ThumbSize size)
|
||||
ImBuf *IMB_thumb_read(const char *file_or_lib_path, ThumbSize size)
|
||||
{
|
||||
char thumb[FILE_MAX];
|
||||
char uri[URI_MAX];
|
||||
ImBuf *img = nullptr;
|
||||
|
||||
if (!uri_from_filename(filepath, uri)) {
|
||||
if (!uri_from_filename(file_or_lib_path, uri)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
|
||||
@@ -511,16 +511,16 @@ ImBuf *IMB_thumb_read(const char *filepath, ThumbSize size)
|
||||
return img;
|
||||
}
|
||||
|
||||
void IMB_thumb_delete(const char *filepath, ThumbSize size)
|
||||
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size)
|
||||
{
|
||||
char thumb[FILE_MAX];
|
||||
char uri[URI_MAX];
|
||||
|
||||
if (!uri_from_filename(filepath, uri)) {
|
||||
if (!uri_from_filename(file_or_lib_path, uri)) {
|
||||
return;
|
||||
}
|
||||
if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
|
||||
if (BLI_path_ncmp(filepath, thumb, sizeof(thumb)) == 0) {
|
||||
if (BLI_path_ncmp(file_or_lib_path, thumb, sizeof(thumb)) == 0) {
|
||||
return;
|
||||
}
|
||||
if (BLI_exists(thumb)) {
|
||||
@@ -529,16 +529,16 @@ void IMB_thumb_delete(const char *filepath, ThumbSize size)
|
||||
}
|
||||
}
|
||||
|
||||
ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source)
|
||||
ImBuf *IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source)
|
||||
{
|
||||
char path_buff[FILE_MAX_LIBEXTRA];
|
||||
char *blen_group = nullptr, *blen_id = nullptr;
|
||||
|
||||
/* Will be the actual path to the file, i.e. the same as #filepath, or if that points into a
|
||||
* .blend, the path of the .blend. */
|
||||
const char *file_path = filepath;
|
||||
/* Will be the actual path to the file, i.e. the same as #file_or_lib_path, or if that points
|
||||
* into a .blend, the path of the .blend. */
|
||||
const char *file_path = file_or_lib_path;
|
||||
if (source == THB_SOURCE_BLEND) {
|
||||
if (BKE_blendfile_library_path_explode(filepath, path_buff, &blen_group, &blen_id)) {
|
||||
if (BKE_blendfile_library_path_explode(file_or_lib_path, path_buff, &blen_group, &blen_id)) {
|
||||
if (blen_group) {
|
||||
if (!blen_id) {
|
||||
/* No preview for blen groups */
|
||||
@@ -554,7 +554,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
|
||||
return nullptr;
|
||||
}
|
||||
char uri[URI_MAX];
|
||||
if (!uri_from_filename(filepath, uri)) {
|
||||
if (!uri_from_filename(file_or_lib_path, uri)) {
|
||||
return nullptr;
|
||||
}
|
||||
char thumb_path[FILE_MAX];
|
||||
@@ -578,8 +578,8 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
|
||||
{
|
||||
/* The requested path points to a generated thumbnail already (path into the thumbnail cache
|
||||
* directory). Attempt to load that, there's nothing we can recreate. */
|
||||
if (BLI_path_ncmp(filepath, thumb_path, sizeof(thumb_path)) == 0) {
|
||||
img = IMB_loadiffname(filepath, IB_rect, nullptr);
|
||||
if (BLI_path_ncmp(file_or_lib_path, thumb_path, sizeof(thumb_path)) == 0) {
|
||||
img = IMB_loadiffname(file_or_lib_path, IB_rect, nullptr);
|
||||
}
|
||||
else {
|
||||
img = IMB_loadiffname(thumb_path, IB_rect | IB_metadata, nullptr);
|
||||
@@ -615,9 +615,9 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
|
||||
/* recreate all thumbs */
|
||||
IMB_freeImBuf(img);
|
||||
img = nullptr;
|
||||
IMB_thumb_delete(filepath, THB_NORMAL);
|
||||
IMB_thumb_delete(filepath, THB_LARGE);
|
||||
IMB_thumb_delete(filepath, THB_FAIL);
|
||||
IMB_thumb_delete(file_or_lib_path, THB_NORMAL);
|
||||
IMB_thumb_delete(file_or_lib_path, THB_LARGE);
|
||||
IMB_thumb_delete(file_or_lib_path, THB_FAIL);
|
||||
img = thumb_create_or_fail(
|
||||
file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id, size, source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user