Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset_library.cc
| Show All 25 Lines | |||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "DNA_asset_types.h" | #include "DNA_asset_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "asset_library_service.hh" | |||||
| #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::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); | ||||
| lib->on_save_handler_register(); | blender::bke::AssetLibrary *lib; | ||||
| lib->load(library_path); | if (library_path == nullptr || library_path[0] == '\0') { | ||||
| return reinterpret_cast<struct AssetLibrary *>(lib); | lib = service->get_asset_library_current_file(); | ||||
| } | } | ||||
| else { | |||||
| void BKE_asset_library_free(struct AssetLibrary *asset_library) | lib = service->get_asset_library_on_disk(library_path); | ||||
| { | } | ||||
| blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | return reinterpret_cast<struct AssetLibrary *>(lib); | ||||
| lib->on_save_handler_unregister(); | |||||
| delete lib; | |||||
| } | } | ||||
| bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path, | bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path, | ||||
| char *r_library_path) | char *r_library_path) | ||||
| { | { | ||||
| if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( | if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( | ||||
| &U, input_path)) { | &U, input_path)) { | ||||
| BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR); | BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR); | ||||
| Show All 36 Lines | void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library, | ||||
| struct AssetMetaData *asset_data) | struct AssetMetaData *asset_data) | ||||
| { | { | ||||
| blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | ||||
| lib->refresh_catalog_simplename(asset_data); | lib->refresh_catalog_simplename(asset_data); | ||||
| } | } | ||||
| namespace blender::bke { | namespace blender::bke { | ||||
| AssetLibrary::~AssetLibrary() | |||||
| { | |||||
| if (on_save_callback_store_.func) { | |||||
| on_save_handler_unregister(); | |||||
| } | |||||
| } | |||||
| 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); | ||||
| } | } | ||||
| namespace { | namespace { | ||||
| Show All 16 Lines | void AssetLibrary::on_save_handler_register() | ||||
| on_save_callback_store_.arg = this; | on_save_callback_store_.arg = this; | ||||
| BKE_callback_add(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST); | BKE_callback_add(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST); | ||||
| } | } | ||||
| void AssetLibrary::on_save_handler_unregister() | void AssetLibrary::on_save_handler_unregister() | ||||
| { | { | ||||
| BKE_callback_remove(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST); | BKE_callback_remove(&on_save_callback_store_, BKE_CB_EVT_SAVE_POST); | ||||
| on_save_callback_store_.func = nullptr; | |||||
| on_save_callback_store_.arg = nullptr; | |||||
| } | } | ||||
| void AssetLibrary::on_save_post(struct Main *main, | void AssetLibrary::on_save_post(struct Main *main, | ||||
| struct PointerRNA ** /*pointers*/, | struct PointerRNA ** /*pointers*/, | ||||
| const int /*num_pointers*/) | const int /*num_pointers*/) | ||||
| { | { | ||||
| if (this->catalog_service == nullptr) { | if (this->catalog_service == nullptr) { | ||||
| return; | return; | ||||
| Show All 23 Lines | |||||