26 "# This is an Asset Catalog Definition file for Blender.\n"
28 "# Empty lines and lines starting with `#` will be ignored.\n"
29 "# The first non-ignored line should be the version indicator.\n"
30 "# Other lines are of the format \"UUID:catalog/path/for/assets:simple catalog name\"\n";
56 fstream infile(catalog_definition_file_path, std::ios::in);
58 if (!infile.is_open()) {
59 CLOG_ERROR(&
LOG,
"%s: unable to open file", catalog_definition_file_path.c_str());
62 bool seen_version_number =
false;
64 while (std::getline(infile, line)) {
66 if (trimmed_line.
is_empty() || trimmed_line[0] ==
'#') {
70 if (!seen_version_number) {
73 if (!is_valid_version) {
74 std::cerr << catalog_definition_file_path
75 <<
": first line should be version declaration; ignoring file." << std::endl;
78 seen_version_number =
true;
88 const bool keep_catalog = catalog_loaded_callback(std::move(catalog));
104 const std::string version_string = line.substr(
VERSION_MARKER.length());
105 const int file_version = std::atoi(version_string.c_str());
113 const char delim =
':';
114 const int64_t first_delim = line.find_first_of(delim);
116 std::cerr <<
"Invalid catalog line in " << this->
file_path <<
": " << line << std::endl;
117 return std::unique_ptr<AssetCatalog>(
nullptr);
121 const std::string id_as_string = line.substr(0, first_delim).trim();
124 if (!uuid_parsed_ok) {
125 std::cerr <<
"Invalid UUID in " << this->
file_path <<
": " << line << std::endl;
126 return std::unique_ptr<AssetCatalog>(
nullptr);
133 std::string path_in_file;
134 std::string simple_name;
135 if (second_delim == 0) {
137 return std::unique_ptr<AssetCatalog>(
nullptr);
142 path_in_file = path_and_simple_name;
146 path_in_file = path_and_simple_name.
substr(0, second_delim);
147 simple_name = path_and_simple_name.
substr(second_delim + 1).
trim();
151 return std::make_unique<AssetCatalog>(catalog_id, catalog_path.
cleanup(), simple_name);
155 : file_path(file_path)
204 output <<
"" << std::endl;
206 output <<
"" << std::endl;
211 if (catalog->flags.is_deleted) {
214 catalogs_by_path.insert(catalog);
218 output << catalog->catalog_id <<
":" << catalog->path <<
":" << catalog->simple_name
222 return !output.bad();
230 if (directory_path.empty()) {
232 <<
"AssetCatalogService: no asset library root configured, unable to ensure it exists."
239 std::cerr <<
"AssetCatalogService: " << directory_path
240 <<
" exists but is not a directory, this is not a supported situation."
250 std::error_code err_code;
252 std::cerr <<
"AssetCatalogService: error creating directory " << directory_path <<
": "
253 << err_code << std::endl;
264 auto copy = std::make_unique<AssetCatalogDefinitionFile>(*
this);
265 copy->catalogs_.clear();
270 const std::unique_ptr<AssetCatalog> *remapped_catalog_uptr_ptr = catalogs.
lookup_ptr(
272 if (remapped_catalog_uptr_ptr) {
273 copy->catalogs_.add_new(catalog_id, remapped_catalog_uptr_ptr->get());
277 remapped_catalog_uptr_ptr = deleted_catalogs.
lookup_ptr(catalog_id);
278 if (remapped_catalog_uptr_ptr) {
279 copy->catalogs_.add_new(catalog_id, remapped_catalog_uptr_ptr->get());
283 BLI_assert_msg(
false,
"A CDF should only reference known catalogs.");
#define BLI_assert_msg(a, msg)
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
File and directory operations.
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
#define CLOG_ERROR(clg_ref,...)
const Value * lookup_ptr(const Key &key) const
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr StringRef trim() const
static const std::string HEADER
Map< CatalogID, AssetCatalog * > catalogs_
bool parse_version_line(StringRef line)
bool ensure_directory_exists(const CatalogFilePath &directory_path) const
void parse_catalog_file(const CatalogFilePath &catalog_definition_file_path, AssetCatalogParsedFn catalog_loaded_callback)
AssetCatalogDefinitionFile(const CatalogFilePath &file_path)
void add_new(AssetCatalog *catalog)
std::unique_ptr< AssetCatalogDefinitionFile > copy_and_remap(const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const
bool write_to_disk_unsafe(const CatalogFilePath &dest_file_path) const
static const int SUPPORTED_VERSION
std::unique_ptr< AssetCatalog > parse_catalog_line(StringRef line)
void forget(CatalogID catalog_id)
void add_overwrite(AssetCatalog *catalog)
bool contains(CatalogID catalog_id) const
static const std::string VERSION_MARKER
const CatalogFilePath file_path
bool write_to_disk() const
AssetCatalogPath cleanup() const
const CatalogID catalog_id
std::set< const AssetCatalog *, AssetCatalogLessThan > AssetCatalogOrderedSet
std::string CatalogFilePath
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
Universally Unique Identifier according to RFC4122.