63#define AUTH_TOKEN_MAYBE_OVERRIDE_FROM_EXTENSIONS \
64 "from _bpy_internal.extensions.asset_library_query import token_from_asset_url\n" \
65 "if (auth_token_override := token_from_asset_url(library_url)) is not None:\n" \
66 " auth_token = auth_token_override\n"
104 if (
U.experimental.no_data_block_packing) {
132 custom_library.dirpath),
133 user_library_(custom_library)
141 const bUserAssetLibrary *library_definition = user_library_.user_asset_library();
142 if (library_definition ==
nullptr) {
162 return user_library_.user_asset_library();
167 const bUserAssetLibrary *library_definition = user_library_.user_asset_library();
168 if (!library_definition) {
177 const bUserAssetLibrary *library_definition = user_library_.user_asset_library();
178 if (library_definition ==
nullptr) {
182 if (library_definition->
auth_token ==
nullptr) {
197 const bUserAssetLibrary *library_definition = user_library_.user_asset_library();
198 if (!library_definition) {
281 std::string &&abs_url,
303 std::string &&abs_url,
307 abs_url,
FileProgress{.expected_size_in_bytes = size_in_bytes});
326 progress->current_size_in_bytes = size_in_bytes;
372 expected_bytes += progress.expected_size_in_bytes;
373 current_bytes += progress.current_size_in_bytes;
377 expected_bytes += finished.expected_size_in_bytes;
378 current_bytes += finished.expected_size_in_bytes;
381 if (!expected_bytes) {
385 const float progress =
float(current_bytes) / expected_bytes;
386 BLI_assert(progress >= -0.0001f && progress <= 1.0001f);
387 return std::clamp(progress, 0.0f, 1.0f);
417 "Remote library status isn't synchronized and should only be accessed from the main thread");
421void RemoteLibraryLoadingStatus::reset_timeout()
423 this->last_updated_time_point_ = std::chrono::steady_clock::now();
431 new_status.timeout_ = timeout;
433 new_status.reset_timeout();
434 new_status.loading_start_time_point_ = FileSystemTimePoint::clock::now();
435 new_status.last_new_pages_time_point_ = std::chrono::steady_clock::now();
447 this_->reset_timeout();
459 this_->reset_timeout();
460 this_->last_new_pages_time_point_ = std::chrono::steady_clock::now();
524 this_->metafiles_in_place_ =
true;
535 return this_->status_;
545 return this_->metafiles_in_place_;
555 if (this_->status_ !=
Loading) {
559 return this_->loading_start_time_point_;
570 return this_->last_new_pages_time_point_;
582 this_->reset_timeout();
595 this_->reset_timeout();
610 this_->reset_timeout();
622 return this_->failure_message_;
635 const TimePoint now = std::chrono::steady_clock::now();
639 if ((now - this_->last_timeout_handled_time_point_).count() > (0.9f * this_->timeout_)) {
642 this_->last_timeout_handled_time_point_ = now;
644 const std::chrono::duration<float> elapsed = now - this_->last_updated_time_point_;
645 if (elapsed.count() < this_->timeout_) {
650 this_->failure_message_ =
RPT_(
"Asset system lost connection to downloader (timed out).");
674 "The online essentials library must be downloaded to "
675 "online_essentials_cache_directory_path()");
693 "from pathlib import Path\n"
696 "bl_pkg.remote_asset_library_sync(\n"
697 " library_url, auth_token, Path(library_path)\n"
715 constexpr const char *SCRIPT = R
"(
718bl_pkg.remote_asset_library_sync_cancel()
738static std::optional<std::string> remote_library_request_asset_download_file(
752 "Asset listing does not indicate where the file should be downloaded to, for asset '%s'",
763 "Asset '%s' references a file with an absolute path, which is not allowed",
770 std::string path_native(dst_filepath);
773 static constexpr char slash_dot_dot_slash[]{
SEP,
'.',
'.',
SEP,
'\0'};
774 static constexpr char const *dot_dot_slash = slash_dot_dot_slash + 1;
776 if (path_native.starts_with(dot_dot_slash) ||
777 path_native.find(slash_dot_dot_slash) != std::string::npos)
781 "Asset '%s' references a file with '..' in its path, which is not allowed",
790 "import _bpy_internal.assets.remote_library.asset_downloader as asset_dl\n"
791 "from pathlib import Path\n"
794 "_result = asset_dl.download_asset_file(\n"
795 " library_url, auth_token, Path(library_path),\n"
796 " asset_url, asset_hash, Path(dst_filepath),\n"
807 std::optional<IDProperty *> abs_url_idptr =
811 const_cast<bContext *
>(&
C), script, *locals,
"_result");
813 if (!abs_url_idptr) {
820 "Could not queue the download of asset '%s', check the system console for more info",
825 if (!*abs_url_idptr) {
830 CLOG_ERROR(&
LOG,
"Failed to retrieve URL from downloader - expected string return value");
857 const std::optional<StringRefNull> library_url =
library.remote_url();
858 if (!library_url || library_url->is_empty()) {
861 "Could not find asset library URL for asset '%s'",
877 for (
int i = asset_files.
size() - 1; i >= 0; i--) {
879 std::optional<std::string> abs_url = remote_library_request_asset_download_file(
898 reports,
RPT_ERROR,
"Downloading assets requires Python, and this Blender is built without");
923 const std::optional<StringRef> library_url =
library.remote_url();
927 "Could not find asset library URL for asset '%s'",
937 "import _bpy_internal.assets.remote_library.asset_downloader as asset_dl\n"
938 "from pathlib import Path\n"
941 "asset_dl.download_preview(\n"
942 " library_url, auth_token, Path(library_path),\n"
943 " preview_url, preview_hash, Path(dst_filepath),\n"
965 "Downloading asset previews requires Python, and this Blender is built without");
978 constexpr const char *SCRIPT = R
"(
979import _bpy_internal.assets.remote_library.asset_downloader as asset_dl
981asset_dl.cancel_download_all_assets()
995 if (this->
files.is_empty()) {
998 return this->
files[0].path;
1017 "Online Essentials URL should use asset_system::online_essentials_cache_directory_path()");
1024 char hex_digest[33];
1040 sizeof(library_cache_path),
1043 library_dirname.
c_str());
1045 return library_cache_path;
1054 thumbs_dir_path,
sizeof(thumbs_dir_path), library_cache_dir.
c_str(),
"_thumbs",
"large");
1062 const std::string asset_path = asset.
full_path();
1064 char thumb_name[40];
1075 SNPRINTF(thumb_name,
"%s%s", hexdigest, ext);
1079 char thumb_prefix[3];
1080 thumb_prefix[0] = thumb_name[0];
1081 thumb_prefix[1] = thumb_name[1];
1082 thumb_prefix[2] =
'\0';
1086 BLI_path_join(thumb_path,
sizeof(thumb_path), thumbs_dir_path, thumb_prefix, thumb_name + 2);
1102 library.cache_dirpath.c_str(),
Main runtime representation of an asset.
#define IDP_string_get(prop)
File and directory operations.
#define BLI_SCOPED_DEFER(function_to_defer)
#define BLI_path_join(...)
#define SNPRINTF(dst, format,...)
#define CLOG_ERROR(clg_ref,...)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
bool add_overwrite(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr const char * c_str() const
eAssetLibraryType library_type() const
bool may_override_import_method_
virtual std::optional< StringRefNull > remote_url() const
AssetLibrary(eAssetLibraryType library_type, bool is_read_only, StringRef name="", StringRef root_path="")
bool is_read_only() const
AssetCatalogService & catalog_service() const
virtual std::optional< StringRefNull > auth_token() const
StringRefNull name() const
StringRefNull root_path() const
std::string full_path() const
bool needs_download() const
AssetLibrary & owner_asset_library() const
std::optional< StringRefNull > online_asset_preview_url() const
Span< OnlineAssetFile > online_asset_files() const
StringRefNull get_name() const
std::optional< StringRefNull > online_asset_preview_hash() const
std::optional< AssetLibraryReference > library_reference() const override
PreferencesRemoteAssetLibrary(const bUserAssetLibrary &custom_library)
std::optional< StringRefNull > auth_token() const override
std::optional< eAssetImportMethod > import_method() const override
const bUserAssetLibrary * user_asset_library() const override
void refresh_catalogs() override
RemoteAssetLibrary(eAssetLibraryType library_type, bool is_read_only, StringRef remote_url, StringRef name, StringRef root_path)
std::optional< StringRefNull > remote_url() const override
std::optional< eAssetImportMethod > import_method() const override
void force_remote_listing_download() const override
static void ping_asset_file_download_succeeded(const bContext &C, StringRef library_url, StringRef absolute_file_url, StringRef local_file_abspath)
static void ping_still_loading(StringRef url)
static void ping_new_pages(StringRef url)
static void set_failure(StringRef url, std::optional< StringRefNull > failure_message)
static std::optional< bool > metafiles_in_place(StringRef url)
std::chrono::time_point< std::chrono::steady_clock > TimePoint
static std::optional< StringRefNull > failure_message(StringRef url)
static void begin_loading(StringRef url, float timeout)
static std::optional< RemoteLibraryLoadingStatus::Status > status(StringRef url)
static std::optional< TimePoint > last_new_pages_time(StringRef url)
static void set_finished(StringRef url)
static void ping_download_queue_done(const bContext &C)
static void ping_asset_file_download_failed(const bContext &C, StringRef library_url, StringRef absolute_file_url, StringRef local_file_abspath)
static void ping_asset_file_progress(StringRef absolute_file_url, int64_t size_in_bytes)
static void set_cancelled(const StringRef url)
static std::optional< FileSystemTimePoint > loading_start_time(const StringRef url)
static void ping_new_preview(const bContext &C, StringRef preview_full_filepath)
static void ping_metafiles_in_place(StringRef url)
static bool handle_timeout(StringRef url)
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
constexpr bool endswith(StringRef suffix) const
static void ping_asset_file_done_impl(const bContext &C, const StringRef library_url, const StringRef absolute_file_url, const StringRef local_file_abspath, const DownloadOutcome outcome)
bool remote_library_has_unfinished_asset_downloads()
void foreach_registered_user_remote_library(FunctionRef< void(bUserAssetLibrary &)> fn)
bool is_online_essentials_dirpath(StringRef dirpath)
float remote_library_total_asset_downloads_progress()
void remote_library_cancel_all_listing_downloads(const bContext &C)
void remote_library_request_preview_download(const bContext &C, const AssetRepresentation &asset, const StringRef dst_filepath, ReportList *reports)
std::string remote_library_asset_preview_path(const AssetRepresentation &asset)
Map< std::string, asset_system::RemoteLibraryLoadingStatus > UrlToLibraryStatusMap
constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME
StringRefNull online_essentials_url()
void remote_library_cancel_all_asset_downloads(bContext &C)
std::string remote_library_cache_directory_path(StringRefNull library_dirname)
void remote_library_request_asset_download(const bContext &C, const AssetRepresentation &asset, ReportList *reports)
constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME_LEADING_SLASH
void remote_library_request_download(const RemoteLibraryDefinitionRef &library_definition)
static UrlToLibraryStatusMap & library_to_status_map()
const int8_t REMOTE_LIBRARY_DIRNAME_LEN
bool is_online_essentials_url(StringRef url)
std::string remote_library_top_meta_file_path(const RemoteLibraryDefinitionRef &library)
bool remote_library_url_ends_with_top_meta_file_name(const StringRef url)
std::string remote_library_cache_directory_path_from_url(StringRef remote_url)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void on_remote_assets_downloaded(wmWindowManager &wm, StringRef library_url, StringRef downloaded_file_abspath)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
const char * BLI_path_extension_or_end(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
bool BPY_run_string_exec_with_locals(bContext *C, StringRefNull script, IDProperty &locals)
void * BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
@ ASSET_LIBRARY_USE_AUTH_TOKEN
@ ASSET_LIBRARY_USE_REMOTE_URL
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
wmWindow * CTX_wm_window(const bContext *C)
IDProperty * IDP_NewString(const char *st, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
wmTimer * WM_event_timer_add_notifier(wmWindowManager *wm, wmWindow *win, const uint type, const double time_step)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
@ ASSET_IMPORT_APPEND_REUSE
void BKE_report(ReportList *reports, eReportType type, const char *message)
wmWindowManager * CTX_wm_manager(const bContext *C)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void ED_preview_online_download_finished(wmWindowManager *wm, StringRef preview_full_filepath)
bool BKE_preferences_asset_library_is_available(const struct UserDef *userdef, const struct bUserAssetLibrary *library) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_appdir_folder_caches(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
char * BLI_hash_md5_to_hexdigest(const void *resblock, char r_hex_digest[33])
void IDP_FreeProperty(IDProperty *prop)
std::optional< IDProperty * > BPY_run_string_exec_with_locals_return_idprop(bContext *C, StringRefNull script, IDProperty &locals, StringRefNull result_var_name)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void ED_preview_online_download_requested(StringRef preview_full_filepath)
void WM_event_add_mousemove(wmWindow *win)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
#define AUTH_TOKEN_MAYBE_OVERRIDE_FROM_EXTENSIONS
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
int64_t expected_size_in_bytes
int64_t current_size_in_bytes
StringRefNull asset_file() const
Vector< OnlineAssetFile > files
Map< std::string, FileProgress > done_files
bool any_asset_file_loading
Map< std::string, FileProgress > requested_files
Map< RequestIdentifier, std::string > req_to_full_urls
static wmTimer * notification_timer
static ProgressData current
static void file_requested(wmWindowManager &wm, RequestIdentifier &&request, std::string &&abs_url, int64_t size_in_bytes)
static void on_all_finished(wmWindowManager &wm)
static void file_finished(StringRef absolute_file_url, DownloadOutcome outcome)
static void file_report_progress(StringRef absolute_file_url, int64_t size_in_bytes)
static bool is_any_loading()
StringRefNull cache_dirpath
std::optional< StringRefNull > auth_token
RemoteLibraryDefinitionRef(const bUserAssetLibrary &library_definition)
std::string file_request_url
bool operator==(const RequestIdentifier &other) const