22namespace asset_system {
28 "# This is an Asset Catalog Definition file for Blender.\n"
30 "# Empty lines and lines starting with `#` will be ignored.\n"
31 "# The first non-ignored line should be the version indicator.\n"
32 "# Other lines are of the format \"UUID:catalog/path/for/assets:simple catalog name\"\n";
58 fstream infile(catalog_definition_file_path, std::ios::in);
60 if (!infile.is_open()) {
61 CLOG_ERROR(&
LOG,
"%s: unable to open file", catalog_definition_file_path.c_str());
64 bool seen_version_number =
false;
66 while (std::getline(infile, line)) {
68 if (trimmed_line.
is_empty() || trimmed_line[0] ==
'#') {
72 if (!seen_version_number) {
75 if (!is_valid_version) {
76 std::cerr << catalog_definition_file_path
77 <<
": first line should be version declaration; ignoring file." << std::endl;
80 seen_version_number =
true;
90 const bool keep_catalog = catalog_loaded_callback(std::move(catalog));
107 const int file_version = std::atoi(version_string.c_str());
115 const char delim =
':';
118 std::cerr <<
"Invalid catalog line in " << this->
file_path <<
": " << line << std::endl;
119 return std::unique_ptr<AssetCatalog>(
nullptr);
123 const std::string id_as_string = line.
substr(0, first_delim).
trim();
126 if (!uuid_parsed_ok) {
127 std::cerr <<
"Invalid UUID in " << this->
file_path <<
": " << line << std::endl;
128 return std::unique_ptr<AssetCatalog>(
nullptr);
135 std::string path_in_file;
136 std::string simple_name;
137 if (second_delim == 0) {
139 return std::unique_ptr<AssetCatalog>(
nullptr);
144 path_in_file = path_and_simple_name;
148 path_in_file = path_and_simple_name.
substr(0, second_delim);
149 simple_name = path_and_simple_name.
substr(second_delim + 1).
trim();
153 return std::make_unique<AssetCatalog>(catalog_id, catalog_path.
cleanup(), simple_name);
211 output <<
"" << std::endl;
213 output <<
"" << std::endl;
218 if (catalog->flags.is_deleted) {
221 catalogs_by_path.insert(catalog);
225 output << catalog->catalog_id <<
":" << catalog->path <<
":" << catalog->simple_name
237 if (directory_path.empty()) {
239 <<
"AssetCatalogService: no asset library root configured, unable to ensure it exists."
246 std::cerr <<
"AssetCatalogService: " << directory_path
247 <<
" exists but is not a directory, this is not a supported situation."
257 std::error_code err_code;
259 std::cerr <<
"AssetCatalogService: error creating directory " << directory_path <<
": "
260 << err_code << std::endl;
271 auto copy = std::make_unique<AssetCatalogDefinitionFile>(*
this);
272 copy->catalogs_.clear();
277 const std::unique_ptr<AssetCatalog> *remapped_catalog_uptr_ptr = catalogs.
lookup_ptr(
279 if (remapped_catalog_uptr_ptr) {
280 copy->catalogs_.add_new(catalog_id, remapped_catalog_uptr_ptr->get());
284 remapped_catalog_uptr_ptr = deleted_catalogs.
lookup_ptr(catalog_id);
285 if (remapped_catalog_uptr_ptr) {
286 copy->catalogs_.add_new(catalog_id, remapped_catalog_uptr_ptr->get());
290 BLI_assert_msg(
false,
"A CDF should only reference known catalogs.");
File and directory operations.
#define CLOG_ERROR(clg_ref,...)
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) 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 exists_on_disk() 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)
FunctionRef< bool(std::unique_ptr< AssetCatalog >)> AssetCatalogParsedFn
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
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr StringRef trim() const
constexpr bool startswith(StringRef prefix) const
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr StringRef substr(int64_t start, int64_t size) const
Map< CatalogID, std::unique_ptr< AssetCatalog > > OwningAssetCatalogMap
std::set< const AssetCatalog *, AssetCatalogLessThan > AssetCatalogOrderedSet
std::string CatalogFilePath
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
Universally Unique Identifier according to RFC4122.