53 return id.library_weak_reference->library_id_name + 2;
65 BLI_strncpy(id_name + 2, name,
sizeof(id_name) - 2);
73 const char *asset_name,
78 lapp_params.
bmain = &global_main;
85 lapp_context, asset_name, id_type,
nullptr);
102 if (local_asset && local_asset->
lib) {
137 return std::string(libpath) +
SEP +
"Saved" +
SEP + name;
157 std::min(
sizeof(base_name_filesafe),
size_t(base_name.
size() + 1)));
173 for (
int i = 1;; i++) {
174 const std::string filepath = root_path +
SEP + base_name_filesafe +
"_" + std::to_string(i++) +
188 std::string &final_full_file_path,
193 ID &
id =
const_cast<ID &
>(id_const);
199 ID *new_id = lib_write_ctx.
id_add(&
id,
206 "Could not create a copy of ID '%s' to write it in the library",
211 std::string new_name = name;
219 const bool success = lib_write_ctx.
write(filepath.
c_str(), write_flags, remap_mode, reports);
223 final_full_file_path = std::string(filepath) +
SEP + std::string(idtype->
name) +
SEP + name;
234 const std::string filepath =
id.lib->runtime->filepath_abs;
240 ID *new_id =
asset_link_id(global_main, id_type, filepath.c_str(), name.c_str(), reports);
252 const char *filepath)
259 char user_library_dirpath[
FILE_MAX];
264 STRNCPY(relative_filepath, filepath);
266 const char *asset_blend_path = relative_filepath + 2;
276 const char *filepath)
284 STRNCPY(relative_filepath, filepath);
288 BLI_path_rel(relative_filepath, online_essentials_path);
289 const char *asset_blend_path = relative_filepath + 2;
301 const char *filepath)
327 user_library, name,
GS(
id.name), reports);
329 std::string final_full_asset_filepath;
331 global_main,
id, name, filepath, final_full_asset_filepath, reports);
338 user_library,
GS(
id.name), name.
c_str(), filepath.c_str());
342 return final_full_asset_filepath;
351 std::string final_full_asset_filepath;
355 id.lib->runtime->filepath_abs,
356 final_full_asset_filepath,
371 if (old_weak_ref && new_weak_ref && *old_weak_ref != *new_weak_ref) {
373 if (weak_ref == *old_weak_ref) {
374 weak_ref = *new_weak_ref;
401 std::optional<AssetWeakReference> new_weak_ref;
402 const std::string old_name =
id.name + 2;
403 const std::string old_filepath =
id.lib->runtime->filepath_abs;
410 if (
id.id_type() ==
ID_BR) {
428 global_main,
id, new_name, user_library, weak_ref, reports);
429 if (!saved_as_filepath) {
434 if (old_filepath != *saved_as_filepath) {
435 const char *error_message =
nullptr;
443 new_weak_ref = weak_ref;
447 if (old_weak_ref && new_weak_ref && *old_weak_ref != *new_weak_ref) {
449 if (weak_ref == *old_weak_ref) {
450 weak_ref = *new_weak_ref;
456 &reports,
RPT_INFO,
"Asset '%s' was renamed to '%s'.", old_name.c_str(), new_name.
c_str());
472 if (
BLI_delete(
id.lib->runtime->filepath_abs,
false,
false) != 0) {
491 char *asset_lib_path, *asset_group, *asset_name;
494 &weak_ref, asset_full_path_buffer, &asset_lib_path, &asset_group, &asset_name);
495 if (asset_lib_path ==
nullptr && asset_group ==
nullptr && asset_name ==
nullptr) {
500 if (asset_lib_path &&
STREQ(asset_lib_path, global_main.
filepath)) {
501 asset_lib_path =
nullptr;
507 if (asset_lib_path ==
nullptr) {
521 return asset_link_id(global_main, id_type, asset_lib_path, asset_name);
542 &
U,
id.lib->runtime->filepath_abs);
544 const short idcode =
GS(
id.name);
549 *user_library, idcode, idname,
id.lib->runtime->filepath_abs);
554 id.lib->runtime->filepath_abs);
555 if (is_online_essential) {
557 idcode, idname,
id.lib->runtime->filepath_abs);
590 std::string filepath =
id.lib->filepath;
631 if (
id.lib ==
nullptr) {
#define BLENDER_ASSET_FILE_SUFFIX
File and directory operations.
#define GHASH_ITER(gh_iter_, ghash_)
#define BLI_SCOPED_DEFER(function_to_defer)
external readfile function prototypes.
external writefile.cc function prototypes.
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
#define ID_TYPE_SUPPORTS_ASSET_EDITABLE(id_type)
#define ID_IS_LINKED(_id)
#define FILE_MAX_LIBEXTRA
#define BLI_assert_unreachable()
constexpr const char * c_str() const
ID * id_add(const ID *id, IDAddOptions options, FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports)
constexpr int64_t size() const
constexpr const char * data() const
StringRefNull online_essentials_cache_directory_path()
Library * search_filepath_abs(ListBaseT< Library > *libraries, StringRef filepath_abs)
ID * asset_edit_id_from_weak_reference(Main &global_main, ID_Type id_type, const AssetWeakReference &weak_ref)
static std::string asset_root_path_for_save(const bUserAssetLibrary &user_library, const ID_Type id_type)
static AssetWeakReference asset_weak_reference_for_user_library(const bUserAssetLibrary &user_library, const short idcode, const char *idname, const char *filepath)
std::optional< AssetWeakReference > asset_edit_weak_reference_from_id(const ID &id)
static void asset_name_in_library_set(ID &id, const char *name)
static AssetWeakReference asset_weak_reference_for_essentials(const short idcode, const char *idname, const char *filepath)
static AssetWeakReference asset_weak_reference_for_online_essentials(const short idcode, const char *idname, const char *filepath)
bool asset_edit_id_save(Main &global_main, ID &id, ReportList &reports)
std::optional< std::string > asset_edit_id_save_as(Main &global_main, const ID &id, StringRefNull name, const bUserAssetLibrary &user_library, AssetWeakReference &r_weak_ref, ReportList &reports)
static bool asset_write_in_library(Main &bmain, const ID &id_const, const StringRef name, const StringRefNull filepath, std::string &final_full_file_path, ReportList &reports)
static std::string asset_blendfile_path_for_save(const bUserAssetLibrary &user_library, const StringRef base_name, const ID_Type id_type, ReportList &reports)
ID * asset_edit_id_revert(Main &global_main, ID &id, ReportList &reports)
bool asset_edit_id_delete(Main &global_main, ID &id, ReportList &reports)
ID * asset_edit_id_find_local(Main &global_main, ID &id)
bool asset_edit_id_rename(Main &global_main, ID &id, StringRefNull new_name, const bUserAssetLibrary &user_library, ReportList &reports)
bool asset_edit_id_is_writable(const ID &id)
ID * asset_edit_id_ensure_local(Main &global_main, ID &id)
static ID * asset_reload(Main &global_main, ID &id, ReportList *reports)
static const char * asset_name_in_library(const ID &id)
static ID * asset_link_id(Main &global_main, const ID_Type id_type, const char *filepath, const char *asset_name, ReportList *reports=nullptr)
bool asset_edit_id_is_editable(const ID &id)
const char * BKE_idtype_idcode_to_name(short idcode)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BlendfileLinkAppendContext * BKE_blendfile_link_append_context_new(LibraryLink_Params *params)
const IDTypeInfo * BKE_idtype_get_info_from_idcode(short id_code)
char * STRNCPY(char(&dst)[N], const char *src)
@ LIBRARY_IS_ASSET_EDIT_FILE
@ LIBRARY_ASSET_FILE_WRITABLE
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
void BKE_asset_weak_reference_foreach_main(Main &bmain, FunctionRef< void(AssetWeakReference &weak_ref)> fn)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_ptr_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
void BKE_blendfile_link_append_context_free(BlendfileLinkAppendContext *lapp_context)
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
BlendfileLinkAppendContextItem * BKE_blendfile_link_append_context_item_add(BlendfileLinkAppendContext *lapp_context, const char *idname, short idcode, void *userdata)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
void BKE_blendfile_link_append_context_item_library_index_enable(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, int library_index)
void AS_asset_full_path_explode_from_weak_ref(const AssetWeakReference *asset_reference, char r_path_buffer[1282], char **r_dir, char **r_group, char **r_name)
const char * BKE_id_name(const ID &id)
char BLI_toupper_ascii(const char c) ATTR_WARN_UNUSED_RESULT
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
@ BLO_LIBLINK_FORCE_INDIRECT
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ONLINE_ESSENTIALS
void BLI_ghash_insert(GHash *gh, void *key, void *val)
ID * BKE_blendfile_link_append_context_item_newid_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
const IDTypeInfo * BKE_idtype_get_info_from_id(const ID *id)
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
@ BLO_WRITE_PATH_REMAP_RELATIVE
void BKE_report(ReportList *reports, eReportType type, const char *message)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void BKE_blendfile_link_append_context_finalize(BlendfileLinkAppendContext *lapp_context)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
void BKE_blendfile_link_append_context_flag_set(BlendfileLinkAppendContext *lapp_context, int flag, bool do_set)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
int BLI_delete_soft(const char *filepath, const char **r_error_message) ATTR_NONNULL()
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ IDWALK_RET_STOP_RECURSION
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *lapp_context, const char *libname, BlendHandle *blo_handle)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
ID_Type GS(const char *name)
ID * BKE_main_library_weak_reference_find(Main *bmain, const char *library_filepath, const char *library_id_name)
void DEG_relations_tag_update(Main *bmain)
void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
IDNewNameResult BKE_id_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
void BKE_blendfile_link_append_context_init_done(BlendfileLinkAppendContext *lapp_context)
void BKE_library_make_local(Main *bmain, const Library *lib, GHash *old_to_new_ids, bool untagged_only, bool set_fake, bool clear_asset_data)
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
ListBaseT< ID > * which_libbase(Main *bmain, short type)
const char * asset_library_identifier
const char * relative_asset_identifier
eAssetLibraryType asset_library_type
bke::library::LibraryRuntime * runtime
bool is_locked_for_linking
ListBaseT< Library > libraries
char resolved_dirpath[1024]