Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset_library.cc
| Show All 15 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include "BKE_asset_library.hh" | #include "BKE_asset_library.hh" | ||||
| #include "BKE_callbacks.h" | #include "BKE_callbacks.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_preferences.h" | |||||
| #include "BLI_path_util.h" | |||||
| #include "DNA_userdef_types.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include <memory> | #include <memory> | ||||
| /** | /** | ||||
| * Loading an asset library at this point only means loading the catalogs. Later on this should | * Loading an asset library at this point only means loading the catalogs. Later on this should | ||||
| * invoke reading of asset representations too. | * invoke reading of asset representations too. | ||||
| */ | */ | ||||
| struct AssetLibrary *BKE_asset_library_load(const char *library_path) | struct AssetLibrary *BKE_asset_library_load(const char *library_path) | ||||
| { | { | ||||
| blender::bke::AssetLibrary *lib = new blender::bke::AssetLibrary(); | blender::bke::AssetLibrary *lib = new blender::bke::AssetLibrary(); | ||||
| lib->on_save_handler_register(); | lib->on_save_handler_register(); | ||||
| lib->load(library_path); | lib->load(library_path); | ||||
| return reinterpret_cast<struct AssetLibrary *>(lib); | return reinterpret_cast<struct AssetLibrary *>(lib); | ||||
| } | } | ||||
| void BKE_asset_library_free(struct AssetLibrary *asset_library) | void BKE_asset_library_free(struct AssetLibrary *asset_library) | ||||
| { | { | ||||
| blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | ||||
| lib->on_save_handler_unregister(); | lib->on_save_handler_unregister(); | ||||
| delete lib; | delete lib; | ||||
| } | } | ||||
| /** | |||||
| * Try to find an appropriate location for an asset library root from a file or directory path. | |||||
| * Does not check if \a filepath exists. | |||||
| * | |||||
| * Design is: | |||||
| * * If \a filepath lies within a known asset library path (i.e. an asset library registered in | |||||
| * the Preferences), return the asset library path. | |||||
| * * Otherwise, if \a filepath is not empty, return the directory path it is stored in. | |||||
| * * If \a bmain is not saved to disk yet, there is no suitable path. The caller has to | |||||
| * decide how to handle this case. | |||||
sybren: There is no `bmain` in this function; this part of the comment should go with the one below. | |||||
| * | |||||
| * \param r_library_path: The returned asset library path, may be empty if no suitable path is | |||||
| * found. Assumed to be a buffer of at least #FILE_MAXDIR bytes. | |||||
sybrenUnsubmitted Done Inline ActionsDocument whether this returns a path with a trailing slash or not. BLI_split_dir_part produces a trailing slash on the returned directory. sybren: Document whether this returns a path with a trailing slash or not. `BLI_split_dir_part`… | |||||
| */ | |||||
| bool BKE_asset_library_find_suitable_root_path_from_filepath(const char *filepath, | |||||
| char *r_library_path) | |||||
| { | |||||
| if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( | |||||
| &U, filepath)) { | |||||
| BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR); | |||||
| return true; | |||||
| } | |||||
| BLI_split_dir_part(filepath, r_library_path, FILE_MAXDIR); | |||||
| return r_library_path[0] != '\0'; | |||||
| } | |||||
| /** | |||||
| * Uses the current location on disk of the file represented by \a bmain as input to | |||||
| * #BKE_asset_library_find_suitable_root_path_from_filepath(). | |||||
| */ | |||||
| 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_filepath(bmain->name, r_library_path); | |||||
| } | |||||
| namespace blender::bke { | namespace blender::bke { | ||||
| void AssetLibrary::load(StringRefNull library_root_directory) | void AssetLibrary::load(StringRefNull library_root_directory) | ||||
| { | { | ||||
| auto catalog_service = std::make_unique<AssetCatalogService>(library_root_directory); | auto catalog_service = std::make_unique<AssetCatalogService>(library_root_directory); | ||||
| catalog_service->load_from_disk(); | catalog_service->load_from_disk(); | ||||
| this->catalog_service = std::move(catalog_service); | this->catalog_service = std::move(catalog_service); | ||||
| } | } | ||||
| Show All 40 Lines | |||||
There is no bmain in this function; this part of the comment should go with the one below.