Blender V5.3
filelist_readjob_asset_library_all.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "AS_asset_library.hh"
11
12#include "BLI_listbase.hh"
13#include "BLI_string.hh"
14
15#include "BKE_preferences.h"
16
17#include "filelist_intern.hh"
18#include "filelist_readjob.hh"
19
20namespace blender {
21
23 bool *stop,
24 bool *do_update,
25 float *progress)
26{
27 FileList *filelist = job_params->tmp_filelist; /* Use the thread-safe filelist queue. */
28 BLI_assert(filelist->filelist.entries.is_empty() &&
30
31 filelist_readjob_load_asset_library_data(job_params, do_update);
32
33 /* A valid, but empty file-list from now. */
34 filelist->filelist.entries_num = 0;
35
36 asset_system::AssetLibrary *current_file_library;
37 {
38 AssetLibraryReference library_ref{};
39 library_ref.custom_library_index = -1;
40 library_ref.type = ASSET_LIBRARY_LOCAL;
41
42 current_file_library = AS_asset_library_load(job_params->current_main, library_ref);
43 }
44
45 job_params->load_asset_library = current_file_library;
46 filelist_readjob_main_assets_add_items(job_params, stop, do_update, progress);
47
48 /* When only doing partially reload for main data, we're done. */
49 if (job_params->only_main_data) {
50 return;
51 }
52
53 /* Count how many asset libraries need to be loaded, for progress reporting. Not very precise. */
54 int library_count = 0;
55 asset_system::AssetLibrary::foreach_loaded([&](const auto &) { library_count++; }, false);
56
57 BLI_assert(filelist->asset_library != nullptr);
58
59 int libraries_done_count = 0;
60 /* The "All" asset library was loaded, which means all other asset libraries are also loaded.
61 * Load their assets from disk into the "All" library. */
63 [&](asset_system::AssetLibrary &nested_library) {
64 StringRefNull root_path = nested_library.root_path();
65 if (root_path.is_empty()) {
66 return;
67 }
68 if (&nested_library == current_file_library) {
69 /* Skip the "Current File" library, it's already loaded above. */
70 return;
71 }
72
73 /* Override library info to read this library. */
74 job_params->load_asset_library = &nested_library;
75 STRNCPY(filelist->filelist.root, root_path.c_str());
76
77 float progress_this = 0.0f;
78 /* Online asset libraries: */
79 if (std::optional<std::string> remote_url = nested_library.remote_url()) {
80 if (std::unique_ptr<RemoteLibraryRequest> *request =
81 job_params->remote_library_requests.lookup_ptr(*remote_url))
82 {
83 remote_asset_library_load(job_params, **request, stop, do_update, &progress_this);
84 /* A new catalog file might have been put in place by the download that was picked up
85 * by the remote library. Make sure it propagates to the "All" library. */
88 }
89 /* When online assets or online access are disabled, there will be no requests. In that
90 * case, just list the assets that are downloaded already. */
91 else {
93 true, job_params, stop, do_update, &progress_this);
94 }
95 }
96 /* Simple directory based reading. */
97 else {
99 true, job_params, stop, do_update, &progress_this);
100 }
101
102 libraries_done_count++;
103 *progress = float(libraries_done_count) / library_count;
104 },
105 false);
106}
107
109{
110 Set<StringRef> requested_urls;
111
112 /* Request online essentials library. */
113 {
114 asset_system::RemoteLibraryDefinitionRef online_essentials_library_def{
117 remote_asset_library_request(job_params, online_essentials_library_def);
118 }
119
122 return;
123 }
124
125 if (!requested_urls.contains(library.remote_url)) {
126 requested_urls.add(library.remote_url);
127
129 }
130 });
131}
132
143
144} // namespace blender
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr const char * c_str() const
virtual std::optional< StringRefNull > remote_url() const
static void foreach_loaded(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library)
constexpr bool is_empty() const
#define FILEDIR_NBR_ENTRIES_UNSET
void foreach_registered_user_remote_library(FunctionRef< void(bUserAssetLibrary &)> fn)
void all_library_reload_catalogs_if_dirty()
StringRefNull online_essentials_cache_directory_path()
StringRefNull online_essentials_url()
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void filelist_set_readjob_all_asset_library(FileList *filelist)
char * STRNCPY(char(&dst)[N], const char *src)
static void filelist_start_job_all_asset_library(FileListReadJob *job_params)
void filelist_readjob_main_assets_add_items(FileListReadJob *job_params, bool *, bool *do_update, float *)
void remote_asset_library_request(FileListReadJob *job_params, const asset_system::RemoteLibraryDefinitionRef &library)
bool is_filtered_asset_library(FileListInternEntry *file, const char *root, FileListFilter *filter)
void prepare_filter_asset_library(const FileList *filelist, FileListFilter *filter)
@ ASSET_LIBRARY_LOCAL
void remote_asset_library_load(FileListReadJob *job_params, RemoteLibraryRequest &request, bool *stop, bool *do_update, float *progress)
bool filelist_checkdir_return_always_valid(const FileList *, char[1024+258], const bool)
void filelist_readjob_load_asset_library_data(FileListReadJob *job_params, bool *do_update)
asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
@ FILELIST_TAGS_USES_MAIN_DATA
@ FILELIST_TAGS_APPLY_FUZZY_SEARCH
void filelist_timer_step_remote_asset_library(FileListReadJob *job_params)
bool BKE_preferences_asset_library_is_available(const struct UserDef *userdef, const struct bUserAssetLibrary *library) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void filelist_readjob_recursive_dir_add_items(const bool do_lib, FileListReadJob *job_params, const bool *stop, bool *do_update, float *progress)
static void filelist_readjob_all_asset_library(FileListReadJob *job_params, bool *stop, bool *do_update, float *progress)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< struct FileListInternEntry > entries
asset_system::AssetLibrary * load_asset_library
Map< std::string, std::unique_ptr< RemoteLibraryRequest > > remote_library_requests
void(*) prepare_filter_fn(const FileList *filelist, FileListFilter *filter)
void(*) timer_step_fn(FileListReadJob *job_params)
bool(*) check_dir_fn(const FileList *filelist, char dirpath[FILE_MAX_LIBEXTRA], const bool do_change)
void(*) start_job_fn(FileListReadJob *job_params)
void(*) read_job_fn(FileListReadJob *job_params, bool *stop, bool *do_update, float *progress)
FileDirEntryArr filelist
bool(*) filter_fn(FileListInternEntry *file, const char *root, FileListFilter *filter)
asset_system::AssetLibrary * asset_library