45 const char *asset_name,
50 lapp_params.
bmain = &global_main;
57 lapp_context, asset_name, id_type,
nullptr);
74 if (local_asset && local_asset->
lib) {
105 return std::string(libpath) +
SEP +
"Saved" +
SEP +
name;
125 std::min(
sizeof(base_name_filesafe),
size_t(base_name.
size() + 1)));
141 for (
int i = 1;;
i++) {
142 const std::string filepath = root_path +
SEP + base_name_filesafe +
"_" + std::to_string(
i++) +
156 std::string &final_full_file_path,
161 ID &
id =
const_cast<ID &
>(id_const);
167 ID *new_id = lib_write_ctx.
id_add(&
id,
174 "Could not create a copy of ID '%s' to write it in the library",
179 std::string new_name =
name;
187 const bool success = lib_write_ctx.
write(filepath.
c_str(), write_flags, remap_mode, reports);
191 final_full_file_path = std::string(filepath) +
SEP + std::string(idtype->
name) +
SEP +
name;
202 const std::string filepath =
id.lib->runtime->filepath_abs;
220 const char *filepath)
227 char user_library_dirpath[
FILE_MAX];
232 STRNCPY(relative_filepath, filepath);
234 const char *asset_blend_path = relative_filepath + 2;
244 const char *filepath)
267 std::string final_full_asset_filepath;
269 global_main,
id,
name, filepath, final_full_asset_filepath, reports);
276 user_library,
GS(
id.
name),
name.c_str(), filepath.c_str());
280 return final_full_asset_filepath;
289 std::string final_full_asset_filepath;
293 id.
lib->runtime->filepath_abs,
294 final_full_asset_filepath,
317 if (
BLI_delete(
id.
lib->runtime->filepath_abs,
false,
false) != 0) {
336 char *asset_lib_path, *asset_group, *asset_name;
339 &weak_ref, asset_full_path_buffer, &asset_lib_path, &asset_group, &asset_name);
340 if (asset_lib_path ==
nullptr && asset_group ==
nullptr && asset_name ==
nullptr) {
345 if (asset_lib_path &&
STREQ(asset_lib_path, global_main.
filepath)) {
346 asset_lib_path =
nullptr;
353 &global_main, id_type, asset_name, asset_lib_path);
359 if (asset_lib_path ==
nullptr) {
363 return asset_link_id(global_main, id_type, asset_lib_path, asset_name);
384 &
U,
id.
lib->runtime->filepath_abs);
386 const short idcode =
GS(
id.
name);
388 if (user_library && user_library->
dirpath[0]) {
390 *user_library, idcode,
id.
name + 2,
id.
lib->runtime->filepath_abs);
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)
#define BLENDER_ASSET_FILE_SUFFIX
void BKE_blendfile_link_append_context_finalize(BlendfileLinkAppendContext *lapp_context)
void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *lapp_context, const char *libname, BlendHandle *blo_handle)
BlendfileLinkAppendContextItem * BKE_blendfile_link_append_context_item_add(BlendfileLinkAppendContext *lapp_context, const char *idname, short idcode, void *userdata)
void BKE_blendfile_link_append_context_free(BlendfileLinkAppendContext *lapp_context)
void BKE_blendfile_link_append_context_flag_set(BlendfileLinkAppendContext *lapp_context, int flag, bool do_set)
void BKE_blendfile_link_append_context_item_library_index_enable(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, int library_index)
BlendfileLinkAppendContext * BKE_blendfile_link_append_context_new(LibraryLink_Params *params)
void BKE_blendfile_link_append_context_init_done(BlendfileLinkAppendContext *lapp_context)
ID * BKE_blendfile_link_append_context_item_newid_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
const IDTypeInfo * BKE_idtype_get_info_from_id(const ID *id)
const IDTypeInfo * BKE_idtype_get_info_from_idcode(short id_code)
const char * BKE_idtype_idcode_to_name(short idcode)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
@ LIB_ID_MAKELOCAL_INDIRECT
@ LIB_ID_MAKELOCAL_ASSET_DATA_CLEAR
@ LIB_ID_MAKELOCAL_FORCE_COPY
ID * BKE_libblock_find_name_and_library_filepath(Main *bmain, short type, const char *name, const char *lib_filepath_abs)
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
bool BKE_lib_id_make_local(Main *bmain, ID *id, int flags)
const char * BKE_id_name(const ID &id)
@ LIBRARY_IS_ASSET_EDIT_FILE
@ LIBRARY_ASSET_FILE_WRITABLE
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
ID * BKE_main_library_weak_reference_find(Main *bmain, const char *library_filepath, const char *library_id_name)
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
File and directory operations.
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char BLI_toupper_ascii(const char c) ATTR_WARN_UNUSED_RESULT
char * STRNCPY(char(&dst)[N], const char *src)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
external readfile function prototypes.
@ BLO_LIBLINK_FORCE_INDIRECT
external writefile.cc function prototypes.
@ BLO_WRITE_PATH_REMAP_RELATIVE
void DEG_relations_tag_update(Main *bmain)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
#define ID_IS_LINKED(_id)
@ ASSET_LIBRARY_ESSENTIALS
#define FILE_MAX_LIBEXTRA
constexpr int64_t size() const
constexpr const char * data() const
constexpr const char * c_str() const
ID * id_add(const ID *id, IDAddOptions options, blender::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)
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 AssetWeakReference asset_weak_reference_for_essentials(const short idcode, const char *idname, const char *filepath)
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_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 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)
bool asset_edit_id_save(Main &global_main, const ID &id, ReportList &reports)
const char * relative_asset_identifier
const char * asset_library_identifier
LibraryRuntimeHandle * runtime
bool is_locked_for_linking
static DynamicLibrary lib