Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-12 18:53:05 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-12 19:07:58 +0300
commita6da1884ba9f4d3d37c98b48bc18a8d26dd489fc (patch)
tree5879311a882714ff4ca5fb45dfc141068509a866 /source/blender/blenkernel/intern/asset_library.cc
parent5e3877e0c8560f27a5cd7b303666b235fb148165 (diff)
Asset Catalogs: Refresh catalog simple name when assigning catalog ID
When assigning a new catalog ID to an asset, also refresh the "catalog simple name". This "simple name" is stored on the asset metadata next to the catalog UUID, to allow some emergency data recovery when the catalog definition file is somehow lost.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_library.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index 27e66ee5725..5956a4af0cb 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -18,6 +18,7 @@
* \ingroup bke
*/
+#include "BKE_asset_catalog.hh"
#include "BKE_asset_library.hh"
#include "BKE_callbacks.h"
#include "BKE_main.h"
@@ -25,6 +26,7 @@
#include "BLI_path_util.h"
+#include "DNA_asset_types.h"
#include "DNA_userdef_types.h"
#include "MEM_guardedalloc.h"
@@ -91,6 +93,13 @@ blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::Asset
return catalog_service->get_catalog_tree();
}
+void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library,
+ struct AssetMetaData *asset_data)
+{
+ blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library);
+ lib->refresh_catalog_simplename(asset_data);
+}
+
namespace blender::bke {
void AssetLibrary::load(StringRefNull library_root_directory)
@@ -138,4 +147,21 @@ void AssetLibrary::on_save_post(struct Main *main,
this->catalog_service->write_to_disk_on_blendfile_save(main->name);
}
+void AssetLibrary::refresh_catalog_simplename(struct AssetMetaData *asset_data)
+{
+ if (BLI_uuid_is_nil(asset_data->catalog_id)) {
+ asset_data->catalog_simple_name[0] = '\0';
+ return;
+ }
+
+ const AssetCatalog *catalog = this->catalog_service->find_catalog(asset_data->catalog_id);
+ if (catalog == nullptr) {
+ /* No-op if the catalog cannot be found. This could be the kind of "the catalog definition file
+ * is corrupt/lost" scenario that the simple name is meant to help recover from. */
+ return;
+ }
+
+ STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
+}
+
} // namespace blender::bke