11#include <fmt/format.h>
34using namespace blender::io::serialize;
43 other.datablock_info = {};
44 this->
idcode = other.idcode;
54 std::destroy_at(
this);
74 is.open(filepath.
c_str());
83 if (!url_with_hash_dict) {
87 const std::optional<StringRefNull> url = url_with_hash_dict->
lookup_str(
"url");
88 const std::optional<StringRefNull>
hash = url_with_hash_dict->
lookup_str(
"hash");
113 std::optional<Timestamp> ignore_before_timestamp);
122 std::error_code error;
123 Timestamp file_timestamp = std::filesystem::last_write_time(filepath, error);
126 printf(
"Can't find file at path %s: %s\n", filepath, error.message().c_str());
130 return file_timestamp < timestamp;
137 const StringRefNull root_dirpath,
const std::optional<Timestamp> ignore_before_timestamp)
142 root_dirpath.
c_str(),
147 fmt::format(
N_(
"file does not exist: {:s}"), filepath));
150 if (ignore_before_timestamp) {
154 fmt::format(
N_(
"file does not exist: {:s}"), filepath));
158 fmt::format(
N_(
"file is too old: {:s}"), filepath));
162 const std::unique_ptr<Value> contents =
read_contents(filepath);
165 fmt::format(
N_(
"file does not contain JSON: {:s}"), filepath));
171 fmt::format(
N_(
"file is not a JSON dictionary: {:s}"), filepath));
176 if (entries ==
nullptr) {
178 fmt::format(
N_(
"no API versions defined: {:s}"), filepath));
185 const DictionaryValue *index_path_info = version.second->as_dictionary_value();
186 if (!index_path_info) {
188 "Error reading asset listing API version '%s' in %s - ignoring",
189 version.first.c_str(),
196 if (!url_with_hash) {
198 "Error reading asset listing API version '%s' in %s, no URL+hash found - ignoring",
199 version.first.c_str(),
203 library_meta.
api_versions.add(version.first, std::move(*url_with_hash));
227 for (
const auto &[version_nr, version_str] : readable_versions) {
231 ApiVersionInfo version_info{version_nr, url_with_hash->url, url_with_hash->hash};
237 N_(
"remote does not offer an API version supported by this version of Blender"));
245 const std::optional<Timestamp> ignore_before_timestamp)
249 auto get_result = [&]() {
251 ignore_before_timestamp);
262 switch (api_version_info->version_nr) {
277 if (
result.is_failure()) {
280 "Asset Library '%s': %s",
281 asset_library_name.
c_str(),
285 "Could not read asset listing '%s', see Info Editor for details",
286 asset_library_name.
c_str());
289 if (
result.is_cancelled()) {
292 if (
result.has_warnings()) {
293 for (
const std::string &warning :
result.warnings) {
296 "Asset Library '%s': %s",
297 asset_library_name.
c_str(),
298 RPT_(warning.c_str()));
302 "Could not read asset listing for '%s', see Info Editor for details",
303 asset_library_name.
c_str());
File and directory operations.
#define BLI_SCOPED_DEFER(function_to_defer)
#define BLI_path_join(...)
#define CLOG_WARN(clg_ref,...)
#define BLI_assert_unreachable()
constexpr const char * c_str() const
ReadingResult without_success_value() const
static ReadingResult Success()
std::optional< StringRefNull > lookup_str(StringRef key) const
std::pair< std::string, std::shared_ptr< Value > > Item
Span< Item > elements() const
const DictionaryValue * lookup_dict(StringRef key) const
constexpr StringRefNull REMOTE_LIBRARY_TOP_META_FILE_NAME
void hash(const IDProperty &base_prop, XXH3_state_t *hash_state)
static ReadingResult< ApiVersionInfo > choose_api_version(const AssetLibraryMeta &library_meta)
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)
std::filesystem::file_time_type Timestamp
FunctionRef< bool(RemoteListingAssetEntry &)> RemoteListingEntryProcessFn
FunctionRef< bool()> RemoteListingWaitForPagesFn
std::optional< bool > file_older_than_timestamp(const char *filepath, Timestamp timestamp)
bool read_remote_listing(StringRefNull root_dirpath, StringRefNull asset_library_name, ReportList &reports, RemoteListingEntryProcessFn process_fn, RemoteListingWaitForPagesFn wait_fn=nullptr, std::optional< Timestamp > ignore_before_timestamp=std::nullopt)
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()
void BLO_datablock_info_free(BLODataBlockInfo *datablock_info)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
std::string listing_relpath
BLODataBlockInfo datablock_info
RemoteListingAssetEntry()=default
asset_system::OnlineAssetInfo online_info
~RemoteListingAssetEntry()
RemoteListingAssetEntry & operator=(RemoteListingAssetEntry &&)