From 06ead314b63f068ae9deaed369021b01aa5f1029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 19 Nov 2021 16:04:24 +0100 Subject: Asset Preferences: disallow single file as asset library Asset libraries should be directories on disk. By manually entering a file path it was possible to have a single blend file as asset library, but that was not a designed-for situation, and it doesn't play well with the asset catalog system. --- source/blender/blenkernel/BKE_preferences.h | 3 +++ source/blender/blenkernel/intern/preferences.c | 13 +++++++++++++ source/blender/makesrna/intern/rna_userdef.c | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/source/blender/blenkernel/BKE_preferences.h b/source/blender/blenkernel/BKE_preferences.h index fd4d13f4125..e9cb024f117 100644 --- a/source/blender/blenkernel/BKE_preferences.h +++ b/source/blender/blenkernel/BKE_preferences.h @@ -42,6 +42,9 @@ void BKE_preferences_asset_library_name_set(struct UserDef *userdef, struct bUserAssetLibrary *library, const char *name) ATTR_NONNULL(); +void BKE_preferences_asset_library_path_set(struct bUserAssetLibrary *library, const char *path) + ATTR_NONNULL(); + struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_index( const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_name( diff --git a/source/blender/blenkernel/intern/preferences.c b/source/blender/blenkernel/intern/preferences.c index 0a10601f751..41046563f98 100644 --- a/source/blender/blenkernel/intern/preferences.c +++ b/source/blender/blenkernel/intern/preferences.c @@ -24,6 +24,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" @@ -83,6 +84,18 @@ void BKE_preferences_asset_library_name_set(UserDef *userdef, sizeof(library->name)); } +/* Set the library path, ensuring it is pointing to a directory. + * Single blend files can only act as "Current File" library; libraries on disk + * should always be directories. If the path does not exist, that's fine; it can + * created as directory if necessary later. */ +void BKE_preferences_asset_library_path_set(bUserAssetLibrary *library, const char *path) +{ + BLI_strncpy_utf8(library->path, path, sizeof(library->path)); + if (BLI_is_file(library->path)) { + BLI_path_parent_dir(library->path); + } +} + bUserAssetLibrary *BKE_preferences_asset_library_find_from_index(const UserDef *userdef, int index) { return BLI_findlink(&userdef->asset_libraries, index); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 32b3be9ee09..4542f8fa1d7 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -344,6 +344,12 @@ static void rna_userdef_asset_library_name_set(PointerRNA *ptr, const char *valu BKE_preferences_asset_library_name_set(&U, library, value); } +static void rna_userdef_asset_library_path_set(PointerRNA *ptr, const char *value) +{ + bUserAssetLibrary *library = (bUserAssetLibrary *)ptr->data; + BKE_preferences_asset_library_path_set(library, value); +} + static void rna_userdef_script_autoexec_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) @@ -6092,6 +6098,7 @@ static void rna_def_userdef_filepaths_asset_library(BlenderRNA *brna) prop = RNA_def_property(srna, "path", PROP_STRING, PROP_DIRPATH); RNA_def_property_ui_text( prop, "Path", "Path to a directory with .blend files to use as an asset library"); + RNA_def_property_string_funcs(prop, NULL, NULL, "rna_userdef_asset_library_path_set"); RNA_def_property_update(prop, 0, "rna_userdef_update"); } -- cgit v1.2.3 From 1a1ddcb5e22b2e6ad4d7506c709ca93ca64096d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 19 Nov 2021 16:29:25 +0100 Subject: Asset Browser: don't display linked-in asset datablocks Datablocks marked as asset, linked from another file, were shown in the "Current File" asset library. This is now resolved. --- source/blender/editors/space_file/filelist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 481f1f8e240..51a5c451f6d 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -3696,7 +3696,7 @@ static void filelist_readjob_main_assets_add_items(FileListReadJob *job_params, BKE_main_lock(job_params->current_main); FOREACH_MAIN_ID_BEGIN (job_params->current_main, id_iter) { - if (!id_iter->asset_data) { + if (!id_iter->asset_data || ID_IS_LINKED(id_iter)) { continue; } -- cgit v1.2.3