Blender V5.3
asset_indexer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <ctime>
10#include <fstream>
11#include <iomanip>
12#include <optional>
13
14#include "ED_asset_indexer.hh"
15#include "asset_index.hh"
16
17#include "DNA_ID.h"
18#include "DNA_asset_types.h"
19
20#include "BLI_fileops.hh"
21#include "BLI_hash.hh"
22#include "BLI_linklist.hh"
23#include "BLI_listbase.hh"
24#include "BLI_path_utils.hh"
25#include "BLI_serialize.hh"
26#include "BLI_set.hh"
27#include "BLI_string.hh"
28#include "BLI_string_ref.hh"
29#include "BLI_string_utf8.hh"
30
31#include "AS_asset_catalog.hh"
32#include "BKE_appdir.hh"
33#include "BKE_asset.hh"
34#include "BKE_idprop.hh"
35#include "BKE_preferences.h"
36
37/* For converting enum values to/from identifiers. */
38#include "RNA_access.hh"
39#include "RNA_enum_types.hh"
40
41#include "CLG_log.h"
42
43#include <sstream>
44
45namespace blender {
46
47static CLG_LogRef LOG = {"asset.index"};
48
49namespace ed::asset::index {
50
51using namespace blender::asset_system;
52using namespace blender::io::serialize;
53using namespace blender::bke::idprop;
54
90constexpr StringRef ATTRIBUTE_VERSION("version");
91constexpr StringRef ATTRIBUTE_ENTRIES("entries");
94constexpr StringRef ATTRIBUTE_ENTRIES_CATALOG_NAME("catalog_name");
101constexpr StringRef ATTRIBUTE_ENTRIES_PREFERRED_IMPORT_METHOD("preferred_import_method");
102
105 public:
106 virtual ~AbstractFile() = default;
107
108 virtual const char *get_file_path() const = 0;
109
110 bool exists() const
111 {
112 return BLI_exists(this->get_file_path());
113 }
114
115 size_t get_file_size() const
116 {
117 return BLI_file_size(this->get_file_path());
118 }
119};
120
124class BlendFile : public AbstractFile {
125 StringRefNull file_path_;
126
127 public:
128 BlendFile(StringRefNull file_path) : file_path_(file_path) {}
129
131 {
133 return hasher(file_path_);
134 }
135
136 std::string get_filename() const
137 {
138 char filename[FILE_MAX];
140 return std::string(filename);
141 }
142
143 const char *get_file_path() const override
144 {
145 return file_path_.c_str();
146 }
147};
148
154static void add_id_name(DictionaryValue &result, const short idcode, const StringRefNull name)
155{
156 char idcode_prefix[2];
157 /* Similar to `BKE_libblock_alloc`. */
158 *(reinterpret_cast<short *>(idcode_prefix)) = idcode;
159 std::string name_with_idcode = std::string(idcode_prefix, sizeof(idcode_prefix)) + name;
160
161 result.append_str(ATTRIBUTE_ENTRIES_NAME, name_with_idcode);
162}
163
165 const FileIndexerEntry *indexer_entry)
166{
167 const BLODataBlockInfo &datablock_info = indexer_entry->datablock_info;
168
169 add_id_name(result, indexer_entry->idcode, datablock_info.name);
170
171 const AssetMetaData &asset_data = *datablock_info.asset_data;
174
175 if (const char *description = asset_data.description) {
176 result.append_str(ATTRIBUTE_ENTRIES_DESCRIPTION, description);
177 }
178 if (const char *author = asset_data.author) {
179 result.append_str(ATTRIBUTE_ENTRIES_AUTHOR, author);
180 }
181 if (const char *copyright = asset_data.copyright) {
182 result.append_str(ATTRIBUTE_ENTRIES_COPYRIGHT, copyright);
183 }
184 if (const char *license = asset_data.license) {
185 result.append_str(ATTRIBUTE_ENTRIES_LICENSE, license);
186 }
187
188 if (!asset_data.tags.is_empty()) {
189 ArrayValue &tags = *result.append_array(ATTRIBUTE_ENTRIES_TAGS);
190 for (AssetTag &tag : asset_data.tags) {
191 tags.append_str(tag.name);
192 }
193 }
194
195 if (asset_data.flag & ASSETDATA_USE_OWN_IMPORT_METHOD) {
196 const char *identifier = nullptr;
199 if (identifier) {
201 }
202 }
203
204 if (const IDProperty *properties = asset_data.properties) {
205 if (std::unique_ptr<Value> value = convert_to_serialize_values(properties)) {
206 result.append(ATTRIBUTE_ENTRIES_PROPERTIES, std::move(value));
207 }
208 }
209}
210
212 const FileIndexerEntries &indexer_entries)
213{
214 auto entries = std::make_shared<ArrayValue>();
215
216 for (LinkNode *ln = indexer_entries.entries; ln; ln = ln->next) {
217 const FileIndexerEntry *indexer_entry = static_cast<const FileIndexerEntry *>(ln->link);
218 /* We also get non asset types (brushes, work-spaces), when browsing using the asset browser.
219 */
220 if (indexer_entry->datablock_info.asset_data == nullptr) {
221 continue;
222 }
223 init_value_from_file_indexer_entry(*entries->append_dict(), indexer_entry);
224 }
225
226 /* When no entries to index, we should not store the entries attribute as this would make the
227 * size bigger than the #MIN_FILE_SIZE_WITH_ENTRIES. */
228 if (entries->elements().is_empty()) {
229 return;
230 }
231
232 result.append(ATTRIBUTE_ENTRIES, entries);
233}
234
236{
238
239 if (const std::optional<StringRef> value = entry.lookup_str(ATTRIBUTE_ENTRIES_DESCRIPTION)) {
240 asset_data->description = BLI_strdupn(value->data(), value->size());
241 }
242 if (const std::optional<StringRef> value = entry.lookup_str(ATTRIBUTE_ENTRIES_AUTHOR)) {
243 asset_data->author = BLI_strdupn(value->data(), value->size());
244 }
245 if (const std::optional<StringRef> value = entry.lookup_str(ATTRIBUTE_ENTRIES_COPYRIGHT)) {
246 asset_data->copyright = BLI_strdupn(value->data(), value->size());
247 }
248 if (const std::optional<StringRef> value = entry.lookup_str(ATTRIBUTE_ENTRIES_LICENSE)) {
249 asset_data->license = BLI_strdupn(value->data(), value->size());
250 }
251
252 if (const std::optional<StringRefNull> catalog_name = entry.lookup_str(
254 {
255 STRNCPY_UTF8(asset_data->catalog_simple_name, catalog_name->c_str());
256 }
257
258 if (const std::optional<StringRefNull> catalog_id = entry.lookup_str(
260 {
261 asset_data->catalog_id = CatalogID(*catalog_id);
262 }
263
264 if (const ArrayValue *array_value = entry.lookup_array(ATTRIBUTE_ENTRIES_TAGS)) {
265 for (const std::shared_ptr<Value> &item : array_value->elements()) {
266 BKE_asset_metadata_tag_add(asset_data, item->as_string_value()->value().c_str());
267 }
268 }
269
270 if (const std::optional<StringRefNull> import_method_identifier = entry.lookup_str(
272 {
273 int preferred_import_method = 0;
275 import_method_identifier->c_str(),
276 &preferred_import_method))
277 {
278 asset_data->preferred_import_method = eAssetImportMethod(preferred_import_method);
280 }
281 }
282
283 if (const std::shared_ptr<Value> *value = entry.lookup(ATTRIBUTE_ENTRIES_PROPERTIES)) {
284 IDProperty *properties = convert_from_serialize_value(**value);
285
286 /* The top level property must be a group, further asset metadata property lookups assume
287 * that. This is also the only way to support more than a single property. */
288 if (properties && (properties->next || properties->type != IDP_GROUP)) {
289 asset_data->properties = bke::idprop::create_group("AssetMetaData.properties").release();
290 for (IDProperty *property = properties; property != nullptr;) {
291 /* Save next before IDP_AddToGroup (via BLI_addtail) overwrites property->next. */
292 IDProperty *next = property->next;
293 IDP_AddToGroup(asset_data->properties, property);
294 property = next;
295 }
296 }
297 else {
298 asset_data->properties = properties;
299 }
300 }
301
302 return asset_data;
303}
304
306 const DictionaryValue &entry)
307{
308 const StringRef idcode_name = *entry.lookup_str(ATTRIBUTE_ENTRIES_NAME);
309
310 indexer_entry.idcode = GS(idcode_name.data());
311
312 idcode_name.substr(2).copy_utf8_truncated(indexer_entry.datablock_info.name);
313
315 indexer_entry.datablock_info.free_asset_data = true;
316}
317
319 const DictionaryValue &value)
320{
321 const ArrayValue *entries = value.lookup_array(ATTRIBUTE_ENTRIES);
322 BLI_assert(entries != nullptr);
323 if (entries == nullptr) {
324 return 0;
325 }
326
327 int num_entries_read = 0;
328 for (const std::shared_ptr<Value> &element : entries->elements()) {
329 FileIndexerEntry *entry = MEM_new<FileIndexerEntry>(__func__);
330 init_indexer_entry_from_value(*entry, *element->as_dictionary_value());
331
332 BLI_linklist_prepend(&indexer_entries.entries, entry);
333 num_entries_read += 1;
334 }
335
336 return num_entries_read;
337}
338
349 bool is_used = false;
350 };
351
360
366 std::string indices_base_path;
367
368 std::string library_path;
369
374
376 {
377 return get_default_hash(this->library_path);
378 }
379
381 {
382 return this->library_path;
383 }
384
391 {
392 char index_path[FILE_MAX];
393 BKE_appdir_folder_caches(index_path, sizeof(index_path));
394
395 BLI_path_append(index_path, sizeof(index_path), "asset-library-indices");
396
397 std::stringstream ss;
398 ss << std::setfill('0') << std::setw(16) << std::hex << hash() << SEP_STR;
399 BLI_path_append(index_path, sizeof(index_path), ss.str().c_str());
400
401 this->indices_base_path = std::string(index_path);
402 }
403
409 std::string index_file_path(const BlendFile &asset_file) const
410 {
411 std::stringstream ss;
412 ss << this->indices_base_path;
413 ss << std::setfill('0') << std::setw(16) << std::hex << asset_file.hash() << "_"
414 << asset_file.get_filename() << ".index.json";
415 return ss.str();
416 }
417
423 {
424 const char *index_path = this->indices_base_path.c_str();
425 if (!BLI_is_dir(index_path)) {
426 return;
427 }
428 direntry *dir_entries = nullptr;
429 const int dir_entries_num = BLI_filelist_dir_contents(index_path, &dir_entries);
430 for (int i = 0; i < dir_entries_num; i++) {
431 direntry *entry = &dir_entries[i];
432 if (BLI_str_endswith(entry->relname, ".index.json")) {
433 this->preexisting_file_indices.add_as(std::string(entry->path));
434 }
435 }
436
437 BLI_filelist_free(dir_entries, dir_entries_num);
438 }
439
440 void mark_as_used(const std::string &filename)
441 {
442 PreexistingFileIndexInfo *preexisting = this->preexisting_file_indices.lookup_ptr(filename);
443 if (preexisting) {
444 preexisting->is_used = true;
445 }
446 }
447
453 bool delete_file_index(const std::string &filename)
454 {
455 if (BLI_delete(filename.c_str(), false, false) == 0) {
456 this->preexisting_file_indices.remove(filename);
457 return true;
458 }
459 return false;
460 }
461
466 /* Implemented further below. */
468
470 {
471 int num_files_deleted = 0;
472
473 Set<StringRef> files_to_remove;
474
475 for (auto preexisting_index : this->preexisting_file_indices.items()) {
476 if (preexisting_index.value.is_used) {
477 continue;
478 }
479
480 const std::string &file_path = preexisting_index.key;
481 CLOG_DEBUG(&LOG, "Remove unused index file \"%s\".", file_path.c_str());
482 files_to_remove.add(preexisting_index.key);
483 }
484
485 for (StringRef file_to_remove : files_to_remove) {
486 if (delete_file_index(file_to_remove)) {
487 num_files_deleted++;
488 }
489 }
490
491 return num_files_deleted;
492 }
493};
494
513 static const int CURRENT_VERSION = 1;
514
518 const int UNKNOWN_VERSION = -1;
519
527 std::unique_ptr<Value> contents;
528
533 AssetIndex(const FileIndexerEntries &indexer_entries)
534 {
535 std::unique_ptr<DictionaryValue> root = std::make_unique<DictionaryValue>();
536 root->append_int(ATTRIBUTE_VERSION, CURRENT_VERSION);
537 init_value_from_file_indexer_entries(*root, indexer_entries);
538
539 this->contents = std::move(root);
540 }
541
546 AssetIndex(std::unique_ptr<Value> &value) : contents(std::move(value)) {}
547
548 int get_version() const
549 {
550 const DictionaryValue *root = this->contents->as_dictionary_value();
551 if (root == nullptr) {
552 return UNKNOWN_VERSION;
553 }
554 const std::optional<int64_t> version_value = root->lookup_int(ATTRIBUTE_VERSION);
555 return version_value.value_or(UNKNOWN_VERSION);
556 }
557
558 bool is_latest_version() const
559 {
560 return get_version() == CURRENT_VERSION;
561 }
562
568 int extract_into(FileIndexerEntries &indexer_entries) const
569 {
570 const DictionaryValue *root = this->contents->as_dictionary_value();
571 const int num_entries_read = init_indexer_entries_from_value(indexer_entries, *root);
572 return num_entries_read;
573 }
574};
575
577 public:
583 const size_t MIN_FILE_SIZE_WITH_ENTRIES = 32;
584 std::string filename;
585
587 : library_index(library_index), filename(index_file_path)
588 {
589 }
590
592 : AssetIndexFile(library_index, library_index.index_file_path(asset_filename))
593 {
594 }
595
597 {
598 this->library_index.mark_as_used(this->filename);
599 }
600
601 const char *get_file_path() const override
602 {
603 return filename.c_str();
604 }
605
609 bool is_older_than(const BlendFile &asset_file) const
610 {
611 return BLI_file_older(this->get_file_path(), asset_file.get_file_path());
612 }
613
617 bool constains_entries() const
618 {
619 const size_t file_size = get_file_size();
620 return file_size >= MIN_FILE_SIZE_WITH_ENTRIES;
621 }
622
623 std::unique_ptr<AssetIndex> read_contents() const
624 {
625 JsonFormatter formatter;
626 std::ifstream is;
627 is.open(this->filename);
628 BLI_SCOPED_DEFER([&]() { is.close(); });
629
630 std::unique_ptr<Value> read_data = formatter.deserialize(is);
631 if (!read_data) {
632 return nullptr;
633 }
634
635 return std::make_unique<AssetIndex>(read_data);
636 }
637
639 {
641 }
642
644 {
645 JsonFormatter formatter;
647 CLOG_ERROR(&LOG, "Index not created: couldn't create folder \"%s\".", this->get_file_path());
648 return;
649 }
650
651 std::ofstream os;
652 os.open(this->filename, std::ios::out | std::ios::trunc);
653 formatter.serialize(os, *content.contents);
654 os.close();
655 }
656};
657
658/* TODO(Julian): remove this after a short while. Just necessary for people who've been using alpha
659 * builds from a certain period. */
661{
662 Set<StringRef> files_to_remove;
663
664 for (const std::string &index_path : this->preexisting_file_indices.keys()) {
665 AssetIndexFile index_file(*this, index_path);
666
667 /* Bug was causing empty index files, so non-empty ones can be skipped. */
668 if (index_file.constains_entries()) {
669 continue;
670 }
671
672 /* Use the file modification time stamp to attempt to remove empty index files from a
673 * certain period (when the bug was in there). Starting from a day before the bug was
674 * introduced until a day after the fix should be enough to mitigate possible local time
675 * zone issues. */
676
677 std::tm tm_from{};
678 tm_from.tm_year = 2022 - 1900; /* 2022 */
679 tm_from.tm_mon = 11 - 1; /* November */
680 tm_from.tm_mday = 8; /* Day before bug was introduced. */
681 std::tm tm_to{};
682 tm_from.tm_year = 2022 - 1900; /* 2022 */
683 tm_from.tm_mon = 12 - 1; /* December */
684 tm_from.tm_mday = 3; /* Day after fix. */
685 std::time_t timestamp_from = std::mktime(&tm_from);
686 std::time_t timestamp_to = std::mktime(&tm_to);
687 BLI_stat_t stat = {};
688 if (BLI_stat(index_file.get_file_path(), &stat) == -1) {
689 continue;
690 }
691 if (IN_RANGE(stat.st_mtime, timestamp_from, timestamp_to)) {
692 CLOG_DEBUG(&LOG, "Remove potentially broken index file \"%s\".", index_path.c_str());
693 files_to_remove.add(index_path);
694 }
695 }
696
697 int num_files_deleted = 0;
698 for (StringRef filepath : files_to_remove) {
699 if (delete_file_index(filepath)) {
700 num_files_deleted++;
701 }
702 }
703
704 return num_files_deleted;
705}
706
708 FileIndexerEntries *entries,
709 int *r_read_entries_len,
710 void *user_data)
711{
712 AssetLibraryIndex &library_index = *static_cast<AssetLibraryIndex *>(user_data);
713 BlendFile asset_file(filename);
714 AssetIndexFile asset_index_file(library_index, asset_file);
715
716 if (!asset_index_file.exists()) {
718 }
719
720 /* Mark index as used, even when it will be recreated. When not done it would remove the index
721 * when the indexing has finished (see `AssetLibraryIndex.remove_unused_index_files`), thereby
722 * removing the newly created index.
723 */
724 asset_index_file.mark_as_used();
725
726 if (asset_index_file.is_older_than(asset_file)) {
728 &LOG,
729 "Asset index file \"%s\" needs to be refreshed as it is older than the asset file \"%s\".",
730 asset_index_file.filename.c_str(),
731 filename);
733 }
734
735 if (!asset_index_file.constains_entries()) {
737 "Asset file index is to small to contain any entries. \"%s\"",
738 asset_index_file.filename.c_str());
739 *r_read_entries_len = 0;
741 }
742
743 std::unique_ptr<AssetIndex> contents = asset_index_file.read_contents();
744 if (!contents) {
745 CLOG_DEBUG(&LOG, "Asset file index is ignored; failed to read contents.");
747 }
748
749 if (!contents->is_latest_version()) {
751 "Asset file index is ignored; expected version %d but file is version %d \"%s\".",
753 contents->get_version(),
754 asset_index_file.filename.c_str());
756 }
757
758 if (entries) {
759 const int read_entries_len = contents->extract_into(*entries);
760 CLOG_INFO(&LOG, "Read %d entries for \"%s\".", read_entries_len, filename);
761 *r_read_entries_len = read_entries_len;
762 }
763
765}
766
767static void update_index(const char *filename, FileIndexerEntries *entries, void *user_data)
768{
769 AssetLibraryIndex &library_index = *static_cast<AssetLibraryIndex *>(user_data);
770 BlendFile asset_file(filename);
771 AssetIndexFile asset_index_file(library_index, asset_file);
772 CLOG_INFO(&LOG,
773 "Update for \"%s\" store index in \"%s\".",
774 asset_file.get_file_path(),
775 asset_index_file.get_file_path());
776
777 AssetIndex content(*entries);
778 asset_index_file.write_contents(content);
779}
780
781static void *init_user_data(const char *root_directory, size_t root_directory_maxncpy)
782{
783 AssetLibraryIndex *library_index = MEM_new<AssetLibraryIndex>(
784 __func__, StringRef(root_directory, BLI_strnlen(root_directory, root_directory_maxncpy)));
785 library_index->collect_preexisting_file_indices();
786 library_index->remove_broken_index_files();
787 return library_index;
788}
789
790static void free_user_data(void *user_data)
791{
792 MEM_delete(static_cast<AssetLibraryIndex *>(user_data));
793}
794
795static void filelist_finished(void *user_data)
796{
797 AssetLibraryIndex &library_index = *static_cast<AssetLibraryIndex *>(user_data);
798 const int num_indices_removed = library_index.remove_unused_index_files();
799 if (num_indices_removed > 0) {
800 CLOG_INFO(&LOG, "Removed %d unused indices.", num_indices_removed);
801 }
802}
803
805{
806 FileIndexerType indexer = {nullptr};
807 indexer.read_index = read_index;
808 indexer.update_index = update_index;
812 return indexer;
813}
814
816
817} // namespace ed::asset::index
818} // namespace blender
File and directory operations.
#define BLI_SCOPED_DEFER(function_to_defer)
#define FILE_MAX
#define STRNCPY_UTF8(dst, src)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
ID and Library types, which are fundamental for SDNA.
#define IN_RANGE(a, b, c)
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr StringRef()
std::string str() const
Definition uuid.cc:162
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr const char * data() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Definition string_ref.cc:28
virtual const char * get_file_path() const =0
const char * get_file_path() const override
AssetIndexFile(AssetLibraryIndex &library_index, BlendFile &asset_filename)
std::unique_ptr< AssetIndex > read_contents() const
bool is_older_than(const BlendFile &asset_file) const
AssetIndexFile(AssetLibraryIndex &library_index, StringRef index_file_path)
Reference to a blend file that can be indexed.
BlendFile(StringRefNull file_path)
const char * get_file_path() const override
Span< std::shared_ptr< Value > > elements() const
void append_str(std::string value)
Definition serialize.cc:232
const std::shared_ptr< Value > * lookup(StringRef key) const
Definition serialize.cc:265
std::optional< StringRefNull > lookup_str(StringRef key) const
Definition serialize.cc:275
std::optional< int64_t > lookup_int(StringRef key) const
Definition serialize.cc:285
const ArrayValue * lookup_array(StringRef key) const
Definition serialize.cc:323
std::unique_ptr< Value > deserialize(std::istream &is) override
Definition serialize.cc:382
void serialize(std::ostream &os, const Value &value) override
Definition serialize.cc:370
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
IDProperty * convert_from_serialize_value(const io::serialize::Value &value)
Convert the given value (which must be an array) to an IDProperty.
std::unique_ptr< io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
static void free_user_data(void *user_data)
constexpr StringRef ATTRIBUTE_ENTRIES_CATALOG_NAME("catalog_name")
constexpr StringRef ATTRIBUTE_ENTRIES_TAGS("tags")
constexpr StringRef ATTRIBUTE_ENTRIES_NAME("name")
static void * init_user_data(const char *root_directory, size_t root_directory_maxncpy)
constexpr StringRef ATTRIBUTE_ENTRIES_CATALOG_ID("catalog_id")
static int init_indexer_entries_from_value(FileIndexerEntries &indexer_entries, const DictionaryValue &value)
constexpr StringRef ATTRIBUTE_ENTRIES_DESCRIPTION("description")
constexpr StringRef ATTRIBUTE_ENTRIES_PROPERTIES("properties")
const FileIndexerType file_indexer_asset
constexpr StringRef ATTRIBUTE_ENTRIES_PREFERRED_IMPORT_METHOD("preferred_import_method")
AssetMetaData * asset_metadata_from_dictionary(const io::serialize::DictionaryValue &entry)
static void filelist_finished(void *user_data)
static eFileIndexerResult read_index(const char *filename, FileIndexerEntries *entries, int *r_read_entries_len, void *user_data)
constexpr StringRef ATTRIBUTE_ENTRIES_LICENSE("license")
constexpr StringRef ATTRIBUTE_VERSION("version")
Indexer for asset libraries.
static void init_indexer_entry_from_value(FileIndexerEntry &indexer_entry, const DictionaryValue &entry)
static void init_value_from_file_indexer_entry(DictionaryValue &result, const FileIndexerEntry *indexer_entry)
constexpr StringRef ATTRIBUTE_ENTRIES("entries")
static void add_id_name(DictionaryValue &result, const short idcode, const StringRefNull name)
add id + name to the attributes.
static void init_value_from_file_indexer_entries(DictionaryValue &result, const FileIndexerEntries &indexer_entries)
constexpr StringRef ATTRIBUTE_ENTRIES_COPYRIGHT("copyright")
constexpr StringRef ATTRIBUTE_ENTRIES_AUTHOR("author")
constexpr FileIndexerType asset_indexer()
static void update_index(const char *filename, FileIndexerEntries *entries, void *user_data)
std::string filename(const std::string_view &str, size_t pos)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
const EnumPropertyItem rna_enum_asset_import_method_items[]
Definition rna_asset.cc:54
unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
AssetTag * BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name) ATTR_NONNULL(1
Definition asset.cc:114
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
@ ASSETDATA_USE_OWN_IMPORT_METHOD
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:457
size_t BLI_file_size(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:228
bool RNA_enum_value_from_identifier(const EnumPropertyItem *item, const char *identifier, int *r_value)
AssetMetaData * BKE_asset_metadata_create()
Definition asset.cc:31
@ FILE_INDEXER_ENTRIES_LOADED
@ FILE_INDEXER_NEEDS_UPDATE
void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries)
void void void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy) ATTR_NONNULL(1
void BKE_appdir_folder_caches(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
Definition appdir.cc:206
ID_Type GS(const char *name)
Definition DNA_ID.h:410
bool BLI_file_older(const char *file1, const char *file2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:642
static CLG_LogRef LOG
Definition logging.cpp:12
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
struct stat BLI_stat_t
ATTR_WARN_UNUSED_RESULT const void * element
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
Definition fileops_c.cc:454
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
AssetMetaDataFlag flag
struct IDProperty * properties
eAssetImportMethod preferred_import_method
ListBaseT< AssetTag > tags
User defined tag. Currently only used by assets, could be used more often at some point....
BLODataBlockInfo datablock_info
FileIndexerReadIndexFunc read_index
FileIndexerFinishedFunc filelist_finished
FileIndexerUpdateIndexFunc update_index
FileIndexerFreeUserDataFunc free_user_data
FileIndexerInitUserDataFunc init_user_data
eIDPropertyType type
Definition DNA_ID.h:145
struct IDProperty * next
Definition DNA_ID.h:144
struct LinkNode * next
AssetIndex(std::unique_ptr< Value > &value)
int extract_into(FileIndexerEntries &indexer_entries) const
AssetIndex(const FileIndexerEntries &indexer_entries)
static const int CURRENT_VERSION
Version to store in new index files.
References the asset library directory.
void mark_as_used(const std::string &filename)
AssetLibraryIndex(const StringRef library_path)
std::string index_file_path(const BlendFile &asset_file) const
Map< std::string, PreexistingFileIndexInfo > preexisting_file_indices
bool delete_file_index(const std::string &filename)
void init_indices_base_path()
Initializes AssetLibraryIndex.indices_base_path.
std::string indices_base_path
Absolute path where the indices of library are stored.
#define SEP_STR
Definition unit.cc:41