39using namespace blender::io::serialize;
64 if (std::from_chars(major_str.
begin(), major_str.
end(), major).ec != std::errc() ||
65 std::from_chars(minor_str.
begin(), minor_str.
end(), minor).ec != std::errc())
69 if (major < 0 || minor < 0 || minor >= 100) {
72 return major * 100 + minor;
78 if (!bl_versions_dict) {
80 N_(
"could not read asset Blender versions, 'bl_versions' field not set"));
84 const std::optional<StringRef> min_opt = bl_versions_dict->
lookup_str(
"min");
87 N_(
"could not read asset Blender versions, 'bl_versions.min' field not set"));
91 if (!bl_version_min) {
93 N_(
"could not read asset Blender versions, 'bl_versions.min' field not in X.Y notation"));
101 const std::optional<StringRef> until_opt = bl_versions_dict->
lookup_str(
"until");
109 if (!bl_version_until) {
111 N_(
"could not read asset Blender versions, 'bl_versions.min' field not in X.Y notation"));
129 if (!*version_check) {
136 const std::optional<StringRefNull> asset_name_opt = dictionary.
lookup_str(
"name");
137 if (!asset_name_opt) {
139 N_(
"could not read asset name, 'name' field not set"));
146 if (
const std::optional<StringRefNull> idtype_name = dictionary.
lookup_str(
"id_type")) {
148 if (!normalized_name) {
152 N_(
"could not read type of asset '%s': 'id_type' field is not a valid type (%s)"),
154 idtype_name->c_str());
161 fmt::format(
N_(
"could not read type of asset '{:s}', 'type' field not set"), asset_name));
166 if (file_paths->elements().is_empty()) {
168 fmt::format(
N_(
"asset '{:s}' has no files"), asset_name));
170 for (
const std::shared_ptr<Value> &file_path_element : file_paths->elements()) {
174 if (!file_path_string) {
176 N_(
"asset '{:s}' has a non-string entry in its 'files' list"), asset_name));
179 if (
file.path.empty()) {
188 file.url = file_entry->download_url;
189 file.size_in_bytes = file_entry->size_in_bytes;
193 fmt::format(
N_(
"asset '{:s}' references unknown file '{:s}'"), asset_name,
file.path));
201 fmt::format(
N_(
"asset '{:s}' has no 'files' field"), asset_name));
225 if (
const std::optional<StringRefNull> path = dictionary.
lookup_str(
"path")) {
230 N_(
"Error reading asset listing file entry, skipping. Reason: found a file without 'path' "
235 if (
const std::optional<StringRefNull>
hash = dictionary.
lookup_str(
"hash")) {
240 N_(
"Error reading asset listing file entry, skipping. Reason: found a file ({:s}) without "
246 if (
const std::optional<int64_t> size_in_bytes = dictionary.
lookup_int(
"size_in_bytes")) {
251 N_(
"Error reading asset listing file entry, skipping. Reason: found a file ({:s}) without "
252 "'size_in_bytes' field"),
270 if (assets ==
nullptr) {
277 if (files ==
nullptr) {
280 N_(
"error reading asset listing, page file has no files section"));
285 for (
const std::shared_ptr<Value> &file_element : files->
elements()) {
287 *file_element->as_dictionary_value());
300 std::string local_path = file_entry.
local_path;
301 path_to_file_info.
add_overwrite(local_path, std::move(file_entry));
308 for (
const std::shared_ptr<Value> &asset_element : assets->
elements()) {
310 *asset_element->as_dictionary_value(), path_to_file_info);
311 if (
result.is_failure()) {
312 if (!
result.failure_reason.empty()) {
328 BLI_assert_msg(file_entry,
"Assets without file info should have been filtered out by now");
332 if (!process_fn(entry)) {
338 overall_result.
warnings.extend(std::move(warnings));
339 return overall_result;
351 const std::unique_ptr<Value> contents =
read_contents(filepath);
359 fmt::format(
N_(
"file is not a JSON dictionary: {:s}"), filepath));
380 static std::optional<AssetLibraryListingV1>
read(
const StringRefNull listing_filepath);
391 const std::unique_ptr<Value> contents =
read_contents(listing_filepath);
405 if (entries ==
nullptr) {
414 element->as_dictionary_value());
416 printf(
"Error reading asset listing page path at index %i in %s - ignoring\n",
418 listing_filepath.
c_str());
434 const std::optional<Timestamp> ignore_before_timestamp)
437 constexpr const char *asset_index_relpath =
"_v1/asset-index.processed.json";
441 sizeof(asset_index_abspath),
442 listing_root_dirpath.
c_str(),
443 asset_index_relpath);
445 if (ignore_before_timestamp) {
447 *ignore_before_timestamp);
450 fmt::format(
N_(
"Couldn't find index file {:s}"), asset_index_abspath));
462 asset_index_abspath);
465 fmt::format(
N_(
"Couldn't read V1 listing from {:s}"), asset_index_abspath));
475 for (
const std::string &page_path : listing->page_rel_paths) {
476 if (done_pages.
contains(page_path)) {
480 BLI_path_join(filepath,
sizeof(filepath), listing_root_dirpath.
c_str(), page_path.c_str());
485 if (ignore_before_timestamp &&
488 CLOG_DEBUG(&
LOG,
"Ignoring old listing file %s - waiting for a new version\n", filepath);
494 listing_root_dirpath, filepath, process_fn);
495 done_pages.
add(page_path);
500 printf(
"Couldn't read V1 listing from %s%c%s: %s\n",
501 listing_root_dirpath.
c_str(),
516 if (done_pages.
size() >= listing->page_rel_paths.size()) {
529 result.warnings.extend(std::move(warnings));
File and directory operations.
#define BLI_path_join(...)
#define CLOG_DEBUG(clg_ref,...)
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
bool add_overwrite(const Key &key, const Value &value)
bool contains(const Key &key) const
constexpr const char * c_str() const
void append(const T &value)
void extend(Span< T > array)
constexpr const char * end() const
constexpr const char * begin() const
static constexpr int64_t not_found
void copy_utf8_truncated(char *dst, int64_t dst_size) const
asset_system::RemoteAssetFileStatus remote_file_status(RemoteListingFileEntry &file_to_check)
Vector< std::string > warnings
bool is_cancelled() const
std::string failure_reason
static ReadingResult Success()
bool has_warnings() const
static ReadingResult Cancelled()
Span< std::shared_ptr< Value > > elements() const
std::optional< StringRefNull > lookup_str(StringRef key) const
std::optional< int64_t > lookup_int(StringRef key) const
const DictionaryValue * lookup_dict(StringRef key) const
const ArrayValue * lookup_array(StringRef key) const
const std::string & value() const
const StringValue * as_string_value() const
float dot(VecOp< float, D >, VecOp< float, D >) RET
void hash(const IDProperty &base_prop, XXH3_state_t *hash_state)
ReadingResult read_remote_listing_v1(StringRefNull listing_root_dirpath, RemoteListingEntryProcessFn process_fn, RemoteListingWaitForPagesFn wait_fn=nullptr, const std::optional< Timestamp > ignore_before_timestamp=std::nullopt)
static ReadingResult< bool > blender_version_matches(const DictionaryValue &asset_dictionary)
FunctionRef< bool(RemoteListingAssetEntry &)> RemoteListingEntryProcessFn
FunctionRef< bool()> RemoteListingWaitForPagesFn
std::optional< bool > file_older_than_timestamp(const char *filepath, Timestamp timestamp)
static ReadingResult listing_entries_from_root(const StringRefNull listing_root_dirpath, const DictionaryValue &value, const RemoteListingEntryProcessFn process_fn)
AssetMetaData * asset_metadata_from_dictionary(const io::serialize::DictionaryValue &entry)
static ReadingResult< RemoteListingFileEntry > listing_file_from_asset_dictionary(const DictionaryValue &dictionary)
static std::optional< int > blender_version_from_string(const blender::StringRef str)
static ReadingResult< RemoteListingAssetEntry > listing_entry_from_asset_dictionary(const DictionaryValue &dictionary, const Map< std::string, RemoteListingFileEntry > &file_path_to_entry_map)
std::optional< asset_system::URLWithHash > parse_url_with_hash_dict(const DictionaryValue *url_with_hash_dict)
std::unique_ptr< io::serialize::Value > read_contents(StringRefNull filepath)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
const char * BKE_idtype_name_normalize(const char *idtype_name)
AssetMetaData * BKE_asset_metadata_create()
short BKE_idtype_idcode_from_name(const char *idtype_name)
ATTR_WARN_UNUSED_RESULT const void * element
AssetMetaData * asset_data
StringRefNull asset_file() const
std::optional< URLWithHash > preview_url
Vector< OnlineAssetFile > files
static ReadingResult read_asset_entries(const StringRefNull listing_root_dirpath, const StringRefNull filepath, RemoteListingEntryProcessFn process_fn)
Vector< std::string > page_rel_paths
static std::optional< AssetLibraryListingV1 > read(const StringRefNull listing_filepath)
BLODataBlockInfo datablock_info
asset_system::OnlineAssetInfo online_info
asset_system::RemoteAssetFileStatus remote_file_status
asset_system::URLWithHash download_url