diff options
author | Julian Eisel <julian@blender.org> | 2021-09-29 14:18:44 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-09-29 14:18:44 +0300 |
commit | adaf4f56e1ed2d8ff55be4681838c9705da022ad (patch) | |
tree | 45e3551e250709edad62e220f1c3b41075ae4856 /source/blender/blenkernel/intern/asset_library.cc | |
parent | 78b9a8c7b993991c22ac2bd1ffbfaf1d896e4431 (diff) |
Support loading catalogs in the Current File asset library
When the Asset Browser shows the "Current File" asset library, now it
also attempts to load an asset catalog definition file from location of
the current .blend file. This happens as follows:
* First, see if the file is inside of an asset library that is "mounted" in the
Preferences. Load the catalogs from there if so.
* Otherwise, if the file is saved, load the catalogs from the directory the
file is saved in.
* If the file is not saved, no catalogs will be loaded.
Unit tests are being worked on in D12689.
Creating catalogs from the "Current File" asset library still doesn't work, as
the asset catalog service doesn't construct an in-memory catalog definition
file in that case yet.
Differential Revision: https://developer.blender.org/D12675
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library.cc')
-rw-r--r-- | source/blender/blenkernel/intern/asset_library.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc index 8d38f2106c1..1086efe45fd 100644 --- a/source/blender/blenkernel/intern/asset_library.cc +++ b/source/blender/blenkernel/intern/asset_library.cc @@ -21,6 +21,11 @@ #include "BKE_asset_library.hh" #include "BKE_callbacks.h" #include "BKE_main.h" +#include "BKE_preferences.h" + +#include "BLI_path_util.h" + +#include "DNA_userdef_types.h" #include "MEM_guardedalloc.h" @@ -45,6 +50,24 @@ void BKE_asset_library_free(struct AssetLibrary *asset_library) delete lib; } +bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path, + char *r_library_path) +{ + if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( + &U, input_path)) { + BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR); + return true; + } + + BLI_split_dir_part(input_path, r_library_path, FILE_MAXDIR); + return r_library_path[0] != '\0'; +} + +bool BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain, char *r_library_path) +{ + return BKE_asset_library_find_suitable_root_path_from_path(bmain->name, r_library_path); +} + namespace blender::bke { void AssetLibrary::load(StringRefNull library_root_directory) |