Steps to reproduce were:
- Open a .blend file that is located inside of an asset library and
contains assets.
- Save and close the file.
- Open a new file (Ctrl+N -> General).
- Open asset browser and load the asset library from above.
- If the assets from the file above still show up, press refresh button.
- -> Assets from the file above don't appear.
Likely fixes the underlying issue for T102610. A followup will be needed
to correct the empty asset index files written because of this bug.
We're in the process of moving responsibilities from the file/asset
browser backend to the asset system. 1efc94bb2f introduces a new
representation for asset, which would own the asset metadata now instead
of the file data.
Since the file-list code still does the loading of asset libraries,
ownership of the asset metadata has to be transferred to the asset
system. However, the asset indexing still requires it to be available,
so it can update the index with latest data. So transfer the ownership,
but still keep a non-owning pointer set.
Differential Revision: https://developer.blender.org/D16665
Reviewed by: Bastien Montagne
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup edfile
|
|
*
|
|
* This file implements the default file browser indexer and has some helper function to work with
|
|
* `FileIndexerEntries`.
|
|
*/
|
|
#include "file_indexer.h"
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "BLI_linklist.h"
|
|
#include "BLI_listbase.h"
|
|
#include "BLI_string.h"
|
|
#include "BLI_utildefines.h"
|
|
|
|
namespace blender::ed::file::indexer {
|
|
|
|
static eFileIndexerResult read_index(const char * /*file_name*/,
|
|
FileIndexerEntries * /*entries*/,
|
|
int * /*r_read_entries_len*/,
|
|
void * /*user_data*/)
|
|
{
|
|
return FILE_INDEXER_NEEDS_UPDATE;
|
|
}
|
|
|
|
static void update_index(const char * /*file_name*/,
|
|
FileIndexerEntries * /*entries*/,
|
|
void * /*user_data*/)
|
|
{
|
|
}
|
|
|
|
constexpr FileIndexerType default_indexer()
|
|
{
|
|
FileIndexerType indexer = {nullptr};
|
|
indexer.read_index = read_index;
|
|
indexer.update_index = update_index;
|
|
return indexer;
|
|
}
|
|
|
|
static FileIndexerEntry *file_indexer_entry_create_from_datablock_info(
|
|
const BLODataBlockInfo *datablock_info, const int idcode)
|
|
{
|
|
FileIndexerEntry *entry = static_cast<FileIndexerEntry *>(
|
|
MEM_mallocN(sizeof(FileIndexerEntry), __func__));
|
|
entry->datablock_info = *datablock_info;
|
|
entry->idcode = idcode;
|
|
return entry;
|
|
}
|
|
|
|
} // namespace blender::ed::file::indexer
|
|
|
|
extern "C" {
|
|
|
|
void ED_file_indexer_entries_extend_from_datablock_infos(
|
|
FileIndexerEntries *indexer_entries,
|
|
const LinkNode * /* BLODataBlockInfo */ datablock_infos,
|
|
const int idcode)
|
|
{
|
|
for (const LinkNode *ln = datablock_infos; ln; ln = ln->next) {
|
|
const BLODataBlockInfo *datablock_info = static_cast<const BLODataBlockInfo *>(ln->link);
|
|
FileIndexerEntry *file_indexer_entry =
|
|
blender::ed::file::indexer::file_indexer_entry_create_from_datablock_info(datablock_info,
|
|
idcode);
|
|
BLI_linklist_prepend(&indexer_entries->entries, file_indexer_entry);
|
|
}
|
|
}
|
|
|
|
static void ED_file_indexer_entry_free(void *indexer_entry_ptr)
|
|
{
|
|
FileIndexerEntry *indexer_entry = static_cast<FileIndexerEntry *>(indexer_entry_ptr);
|
|
BLO_datablock_info_free(&indexer_entry->datablock_info);
|
|
MEM_freeN(indexer_entry);
|
|
}
|
|
|
|
void ED_file_indexer_entries_clear(FileIndexerEntries *indexer_entries)
|
|
{
|
|
BLI_linklist_free(indexer_entries->entries, ED_file_indexer_entry_free);
|
|
indexer_entries->entries = nullptr;
|
|
}
|
|
|
|
const FileIndexerType file_indexer_noop = blender::ed::file::indexer::default_indexer();
|
|
}
|