Blender V5.3
asset_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_assert.hh"
10#include "BLI_fileops.hh"
11#include "BLI_ghash.hh"
12#include "BLI_listbase.hh"
13#include "BLI_memory_utils.hh"
14#include "BLI_path_utils.hh"
15#include "BLI_string.hh"
16
17#include "DNA_ID.h"
18#include "DNA_asset_types.h"
19#include "DNA_space_enums.h"
20#include "DNA_userdef_types.h"
21
22#include "AS_asset_library.hh"
24
25#include "BKE_asset.hh"
26#include "BKE_asset_edit.hh"
27#include "BKE_blendfile.hh"
29#include "BKE_global.hh"
30#include "BKE_idtype.hh"
31#include "BKE_lib_id.hh"
32#include "BKE_lib_query.hh"
33#include "BKE_lib_remap.hh"
34#include "BKE_library.hh"
35#include "BKE_main.hh"
36#include "BKE_packedFile.hh"
37#include "BKE_preferences.h"
38#include "BKE_report.hh"
39
40#include "BLO_read_write.hh"
41#include "BLO_readfile.hh"
42#include "BLO_writefile.hh"
43
44#include "DEG_depsgraph.hh"
46
47namespace blender::bke {
48
49static const char *asset_name_in_library(const ID &id)
50{
51 /* Get the original name from the weak reference, in case the datablock was renamed. */
52 if (ID_IS_LINKED(&id) && id.library_weak_reference) {
53 return id.library_weak_reference->library_id_name + 2;
54 }
55
56 return BKE_id_name(id);
57}
58
59static void asset_name_in_library_set(ID &id, const char *name)
60{
62
63 char id_name[MAX_ID_NAME];
64 STRNCPY(id_name, id.name);
65 BLI_strncpy(id_name + 2, name, sizeof(id_name) - 2);
66
67 BKE_main_library_weak_reference_add(&id, id.lib->filepath, id_name);
68}
69
70static ID *asset_link_id(Main &global_main,
71 const ID_Type id_type,
72 const char *filepath,
73 const char *asset_name,
74 ReportList *reports = nullptr)
75{
76 /* Load asset from asset library. */
77 LibraryLink_Params lapp_params{};
78 lapp_params.bmain = &global_main;
81
82 BKE_blendfile_link_append_context_library_add(lapp_context, filepath, nullptr);
83
85 lapp_context, asset_name, id_type, nullptr);
87
89
90 BKE_blendfile_link(lapp_context, reports);
91
93
94 ID *local_asset = BKE_blendfile_link_append_context_item_newid_get(lapp_context, lapp_item);
95
97
98 /* Verify that the name matches. It must for referencing the same asset again to work. */
99 BLI_assert(local_asset == nullptr || STREQ(local_asset->name + 2, asset_name));
100
101 /* Tag library as being editable. */
102 if (local_asset && local_asset->lib) {
103 local_asset->lib->runtime->tag |= LIBRARY_ASSET_EDITABLE;
104
105 if ((local_asset->lib->runtime->tag & LIBRARY_IS_ASSET_EDIT_FILE) &&
106 StringRef(filepath).endswith(BLENDER_ASSET_FILE_SUFFIX) &&
108 BLI_file_is_writable(filepath))
109 {
110 local_asset->lib->runtime->tag |= LIBRARY_ASSET_FILE_WRITABLE;
111 }
112
113 /* Keep original name in weak reference, in case this datablock gets renamed. */
114 asset_name_in_library_set(*local_asset, asset_name);
115 }
116
117 return local_asset;
118}
119
120static std::string asset_root_path_for_save(const bUserAssetLibrary &user_library,
121 const ID_Type id_type)
122{
123 BLI_assert(user_library.resolved_dirpath[0] != '\0');
124
125 char libpath[FILE_MAX];
126 STRNCPY(libpath, user_library.resolved_dirpath);
127 BLI_path_slash_native(libpath);
128 BLI_path_normalize(libpath);
129 BLI_path_slash_rstrip(libpath);
130
131 /* Capitalize folder name. Ideally this would already available in
132 * the type info to work correctly with multiple words. */
133 const IDTypeInfo *id_type_info = BKE_idtype_get_info_from_idcode(id_type);
134 std::string name = id_type_info->name_plural;
135 name[0] = BLI_toupper_ascii(name[0]);
136
137 return std::string(libpath) + SEP + "Saved" + SEP + name;
138}
139
140static std::string asset_blendfile_path_for_save(const bUserAssetLibrary &user_library,
141 const StringRef base_name,
142 const ID_Type id_type,
143 ReportList &reports)
144{
145 std::string root_path = asset_root_path_for_save(user_library, id_type);
146 BLI_assert(!root_path.empty());
147
148 if (!BLI_dir_create_recursive(root_path.c_str())) {
149 BKE_report(&reports, RPT_ERROR, "Failed to create asset library directory to save asset");
150 return "";
151 }
152
153 /* Make sure filename only contains valid characters for file-system. */
154 char base_name_filesafe[FILE_MAXFILE];
155 BLI_strncpy(base_name_filesafe,
156 base_name.data(),
157 std::min(sizeof(base_name_filesafe), size_t(base_name.size() + 1)));
158 BLI_path_make_safe_filename(base_name_filesafe);
159
160 /* FIXME: MAX_ID_NAME & FILE_MAXFILE
161 *
162 * This already does not respect the FILE_MAXFILE max length of filenames for the final filepath
163 * it seems?
164 */
165 {
166 const std::string filepath = root_path + SEP + base_name_filesafe + BLENDER_ASSET_FILE_SUFFIX;
167 if (!BLI_is_file(filepath.c_str())) {
168 return filepath;
169 }
170 }
171
172 /* Avoid overwriting existing file by adding number suffix. */
173 for (int i = 1;; i++) {
174 const std::string filepath = root_path + SEP + base_name_filesafe + "_" + std::to_string(i++) +
176 if (!BLI_is_file(filepath.c_str())) {
177 return filepath;
178 }
179 }
180
181 return "";
182}
183
184static bool asset_write_in_library(Main &bmain,
185 const ID &id_const,
186 const StringRef name,
187 const StringRefNull filepath,
188 std::string &final_full_file_path,
189 ReportList &reports)
190{
191 using namespace blender::bke::blendfile;
192
193 ID &id = const_cast<ID &>(id_const);
194
195 /* This is not expected to ever happen currently from this code-path. */
197
198 PartialWriteContext lib_write_ctx{bmain};
199 ID *new_id = lib_write_ctx.id_add(&id,
203 if (!new_id) {
204 BKE_reportf(&reports,
205 RPT_ERROR,
206 "Could not create a copy of ID '%s' to write it in the library",
207 id.name);
208 return false;
209 }
210
211 std::string new_name = name;
212 BKE_libblock_rename(lib_write_ctx.bmain, *new_id, new_name);
213
214 BKE_packedfile_pack_all(&lib_write_ctx.bmain, nullptr, false);
215 lib_write_ctx.bmain.is_asset_edit_file = true;
216
217 const int write_flags = G_FILE_COMPRESS | G_FILE_ASSET_EDIT_FILE;
218 const int remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE;
219 const bool success = lib_write_ctx.write(filepath.c_str(), write_flags, remap_mode, reports);
220
221 if (success) {
222 const IDTypeInfo *idtype = BKE_idtype_get_info_from_id(&id);
223 final_full_file_path = std::string(filepath) + SEP + std::string(idtype->name) + SEP + name;
224 }
225
226 return success;
227}
228
229static ID *asset_reload(Main &global_main, ID &id, ReportList *reports)
230{
232
233 const std::string name = asset_name_in_library(id);
234 const std::string filepath = id.lib->runtime->filepath_abs;
235 const ID_Type id_type = GS(id.name);
236
237 /* TODO: There's no API to reload a single data block (and its dependencies) yet. For now
238 * deleting the brush and re-linking it is the best way to get reloading to work. */
239 BKE_id_delete(&global_main, &id);
240 ID *new_id = asset_link_id(global_main, id_type, filepath.c_str(), name.c_str(), reports);
241
242 /* Recreate dependency graph to include new IDs. */
243 DEG_relations_tag_update(&global_main);
244
245 return new_id;
246}
247
249 const bUserAssetLibrary &user_library,
250 const short idcode,
251 const char *idname,
252 const char *filepath)
253{
254 AssetWeakReference weak_ref;
256 weak_ref.asset_library_identifier = BLI_strdup(user_library.name);
257
258 /* BLI_path_rel requires a trailing slash. */
259 char user_library_dirpath[FILE_MAX];
260 STRNCPY(user_library_dirpath, user_library.resolved_dirpath);
261 BLI_path_slash_ensure(user_library_dirpath, sizeof(user_library_dirpath));
262
263 char relative_filepath[FILE_MAX];
264 STRNCPY(relative_filepath, filepath);
265 BLI_path_rel(relative_filepath, user_library_dirpath);
266 const char *asset_blend_path = relative_filepath + 2; /* Strip out // prefix. */
267
269 "%s/%s/%s", asset_blend_path, BKE_idtype_idcode_to_name(idcode), idname);
270
271 return weak_ref;
272}
273
275 const char *idname,
276 const char *filepath)
277{
278 BLI_assert(!BLI_path_is_rel(filepath));
282
283 char relative_filepath[FILE_MAX];
284 STRNCPY(relative_filepath, filepath);
285 char online_essentials_path[FILE_MAXDIR];
286 STRNCPY(online_essentials_path, asset_system::online_essentials_cache_directory_path().c_str());
287 BLI_path_slash_ensure(online_essentials_path, sizeof(online_essentials_path));
288 BLI_path_rel(relative_filepath, online_essentials_path);
289 const char *asset_blend_path = relative_filepath + 2; /* Strip out // prefix. */
290
291 AssetWeakReference weak_ref;
294 "%s/%s/%s", asset_blend_path, BKE_idtype_idcode_to_name(idcode), idname);
295
296 return weak_ref;
297}
298
300 const char *idname,
301 const char *filepath)
302{
303 BLI_assert(!BLI_path_is_rel(filepath));
306 filepath));
307
308 AssetWeakReference weak_ref;
310 weak_ref.relative_asset_identifier = BLI_sprintfN("%s/%s/%s/%s",
312 BLI_path_basename(filepath),
314 idname);
315
316 return weak_ref;
317}
318
319std::optional<std::string> asset_edit_id_save_as(Main &global_main,
320 const ID &id,
321 const StringRefNull name,
322 const bUserAssetLibrary &user_library,
323 AssetWeakReference &r_weak_ref,
324 ReportList &reports)
325{
326 const std::string filepath = asset_blendfile_path_for_save(
327 user_library, name, GS(id.name), reports);
328
329 std::string final_full_asset_filepath;
330 const bool success = asset_write_in_library(
331 global_main, id, name, filepath, final_full_asset_filepath, reports);
332 if (!success) {
333 BKE_report(&reports, RPT_ERROR, "Failed to write to asset library");
334 return std::nullopt;
335 }
336
338 user_library, GS(id.name), name.c_str(), filepath.c_str());
339
340 BKE_reportf(&reports, RPT_INFO, "Saved \"%s\"", filepath.c_str());
341
342 return final_full_asset_filepath;
343}
344
345bool asset_edit_id_save(Main &global_main, ID &id, ReportList &reports)
346{
347 if (!asset_edit_id_is_writable(id)) {
348 return false;
349 }
350
351 std::string final_full_asset_filepath;
352 const bool success = asset_write_in_library(global_main,
353 id,
354 id.name + 2,
355 id.lib->runtime->filepath_abs,
356 final_full_asset_filepath,
357 reports);
358
359 if (!success) {
360 BKE_report(&reports, RPT_ERROR, "Failed to write to asset library");
361 return false;
362 }
363
364 const std::optional<AssetWeakReference> old_weak_ref = asset_edit_weak_reference_from_id(id);
365
367
368 const std::optional<AssetWeakReference> new_weak_ref = asset_edit_weak_reference_from_id(id);
369
370 /* Update any weak references to the renamed asset. */
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;
375 }
376 });
377 }
378
379 return true;
380}
381
382bool asset_edit_id_rename(Main &global_main,
383 ID &id,
384 const StringRefNull new_name,
385 const bUserAssetLibrary &user_library,
386 ReportList &reports)
387{
389
390 /* Check the asset blend file for writability. */
391 if (!asset_edit_id_is_editable(id)) {
392 BKE_report(&reports, RPT_ERROR, "Asset is not from an editable .asset.blend file.");
393 return false;
394 }
395 if (!asset_edit_id_is_writable(id)) {
396 BKE_report(&reports, RPT_ERROR, "Asset is not from a writable .asset.blend file.");
397 return false;
398 }
399
400 const std::optional<AssetWeakReference> old_weak_ref = asset_edit_weak_reference_from_id(id);
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;
404
405 /* Brushes have their own rename logic, so renaming their files has more consequences than for
406 * other assets. For now, just avoid renaming the blend files. This means renaming just the ID,
407 * and then saving it into the library it came from. */
408 /* TODO: is this special case for brushes still needed? The
409 * #BKE_asset_weak_reference_foreach_main() should handle brush references correctly already. */
410 if (id.id_type() == ID_BR) {
412 global_main, id, new_name, IDNewNameMode::RenameExistingAlways);
414 BKE_report(&reports, RPT_WARNING, "Asset name was not changed.");
415 return false;
416 }
417
418 if (!asset_edit_id_save(global_main, id, reports)) {
419 return false;
420 }
421
422 new_weak_ref = asset_edit_weak_reference_from_id(id);
423 }
424 else {
425 /* Save the asset under a new name, which also means saving to a new file. */
426 AssetWeakReference weak_ref;
427 const std::optional<std::string> saved_as_filepath = asset_edit_id_save_as(
428 global_main, id, new_name, user_library, weak_ref, reports);
429 if (!saved_as_filepath) {
430 return false;
431 }
432
433 /* Saving was successful, so now delete the old file path. */
434 if (old_filepath != *saved_as_filepath) {
435 const char *error_message = nullptr;
436 if (!BLI_delete_soft(old_filepath.c_str(), &error_message)) {
437 /* In case of error removing the old asset file, report it but do continue. The new,
438 * renamed asset has been written already, and so the work should continue. */
439 BKE_reportf(&reports, RPT_WARNING, "Could not remove old asset file: %s", error_message);
440 }
441 }
442
443 new_weak_ref = weak_ref;
444 }
445
446 /* Update any weak references to the renamed asset. */
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;
451 }
452 });
453 }
454
456 &reports, RPT_INFO, "Asset '%s' was renamed to '%s'.", old_name.c_str(), new_name.c_str());
457 return true;
458}
459
460ID *asset_edit_id_revert(Main &global_main, ID &id, ReportList &reports)
461{
462 if (!asset_edit_id_is_editable(id)) {
463 return nullptr;
464 }
465
466 return asset_reload(global_main, id, &reports);
467}
468
469bool asset_edit_id_delete(Main &global_main, ID &id, ReportList &reports)
470{
472 if (BLI_delete(id.lib->runtime->filepath_abs, false, false) != 0) {
473 BKE_report(&reports, RPT_ERROR, "Failed to delete asset library file");
474 return false;
475 }
476 }
477
478 BKE_id_delete(&global_main, &id);
479
480 return true;
481}
482
484 const ID_Type id_type,
485 const AssetWeakReference &weak_ref)
486{
487 /* Don't do this in file load. */
488 BLI_assert(!global_main.is_locked_for_linking);
489
490 char asset_full_path_buffer[FILE_MAX_LIBEXTRA];
491 char *asset_lib_path, *asset_group, *asset_name;
492
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) {
496 return nullptr;
497 }
498
499 /* If this is the same file as we have open, use local datablock. */
500 if (asset_lib_path && STREQ(asset_lib_path, global_main.filepath)) {
501 asset_lib_path = nullptr;
502 }
503
504 BLI_assert(asset_name != nullptr);
505
506 /* Is the asset already in the file we have loaded? */
507 if (asset_lib_path == nullptr) {
508 return BKE_libblock_find_name(&global_main, id_type, asset_name, nullptr);
509 }
510
511 /* Find already loaded asset in a library. */
512 if (Library *lib = library::search_filepath_abs(&global_main.libraries, asset_lib_path)) {
513 for (ID &local_asset : *which_libbase(&global_main, id_type)) {
514 if (local_asset.lib == lib && STREQ(asset_name_in_library(local_asset), asset_name)) {
515 return &local_asset;
516 }
517 }
518 }
519
520 /* Try linking in the required file. */
521 return asset_link_id(global_main, id_type, asset_lib_path, asset_name);
522}
523
524std::optional<AssetWeakReference> asset_edit_weak_reference_from_id(const ID &id)
525{
526 /* Brush is local to the file. */
527 if (!id.lib) {
528 AssetWeakReference weak_ref;
529
532 "%s/%s", BKE_idtype_idcode_to_name(GS(id.name)), id.name + 2);
533
534 return weak_ref;
535 }
536
537 if (!asset_edit_id_is_editable(id)) {
538 return std::nullopt;
539 }
540
542 &U, id.lib->runtime->filepath_abs);
543
544 const short idcode = GS(id.name);
545 const char *idname = asset_name_in_library(id);
546
547 if (user_library && user_library->resolved_dirpath[0]) {
549 *user_library, idcode, idname, id.lib->runtime->filepath_abs);
550 }
551
552 const bool is_online_essential = BLI_path_contains(
554 id.lib->runtime->filepath_abs);
555 if (is_online_essential) {
557 idcode, idname, id.lib->runtime->filepath_abs);
558 }
559
560 return asset_weak_reference_for_essentials(idcode, idname, id.lib->runtime->filepath_abs);
561}
562
564{
565 return (id.lib && (id.lib->runtime->tag & LIBRARY_ASSET_EDITABLE));
566}
567
569{
570 return asset_edit_id_is_editable(id) && (id.lib->runtime->tag & LIBRARY_ASSET_FILE_WRITABLE);
571}
572
574{
575 if (!asset_edit_id_is_editable(id)) {
576 return &id;
577 }
578
579 return BKE_main_library_weak_reference_find(&global_main, id.lib->filepath, id.name);
580}
581
583{
584 ID *local_id = asset_edit_id_find_local(global_main, id);
585 if (local_id) {
586 return local_id;
587 }
588
589 /* Keep a copy in case the ID gets made local in-place and the library data cleared. */
590 std::string filepath = id.lib->filepath;
591
592 /* Recursively make local (creating copies of the given ID and its dependencies) and create weak
593 * library reference for reuse. */
594
595 {
596 /* Recurse to collect IDs to make local. */
597
598 /* #BKE_library_make_local() only processes IDs not tagged with #ID_TAG_PRE_EXISTING (for
599 * historic reasons). */
600 BKE_main_id_tag_all(&global_main, ID_TAG_PRE_EXISTING, true);
601
602 /* Mark this ID for processing. */
603 id.tag &= ~ID_TAG_PRE_EXISTING;
605 &global_main,
606 &id,
607 [&](const LibraryIDLinkCallbackData *cb_data) {
608 /* A direct or indirect dependency of #id. */
609 ID *dependency_id = *cb_data->id_pointer;
610 if (!dependency_id || !ID_TYPE_SUPPORTS_ASSET_EDITABLE(GS(dependency_id->name))) {
612 }
613 /* Mark this ID for processing. */
614 dependency_id->tag &= ~ID_TAG_PRE_EXISTING;
615 return IDWALK_RET_NOP;
616 },
617 nullptr,
619 }
620
621 GHash *old_to_new_id = BLI_ghash_ptr_new_ex(__func__, 4);
622 BLI_SCOPED_DEFER([&] { BLI_ghash_free(old_to_new_id, nullptr, nullptr); });
623
624 BKE_library_make_local(&global_main, nullptr, old_to_new_id, true, false, true);
625
626 /* #ID_TAG_PRE_EXISTING should be reset after use. */
627 BKE_main_id_tag_all(&global_main, ID_TAG_PRE_EXISTING, false);
628
629 /* #BKE_library_foreach_ID_link() may modify IDs in-place and doesn't add it to the hash
630 * table then. Can be recognized by the fact that the library pointer is null now. */
631 if (id.lib == nullptr) {
632 BLI_ghash_insert(old_to_new_id, &id, &id);
633 }
634
635 /* If any of the processed IDs are still using linked IDs (probably because they are not covered
636 * by #ID_TYPE_SUPPORTS_ASSET_EDITABLE()), clear that usage so the IDs are definitely only using
637 * local data. */
638 {
639 GHashIterator gh_iter;
640 GHASH_ITER (gh_iter, old_to_new_id) {
641 ID *now_local_id = static_cast<ID *>(BLI_ghashIterator_getValue(&gh_iter));
643 &global_main,
644 now_local_id,
645 [&](const LibraryIDLinkCallbackData *cb_data) {
646 if (*cb_data->id_pointer && ID_IS_LINKED(*cb_data->id_pointer)) {
647 *cb_data->id_pointer = nullptr;
648 }
649 return IDWALK_RET_NOP;
650 },
651 nullptr,
652 IDWALK_NOP);
653 }
654 }
655
656 ID *newid = reinterpret_cast<ID *>(BLI_ghash_lookup(old_to_new_id, &id));
657 if (!newid) {
659 return nullptr;
660 }
661
662 BKE_main_library_weak_reference_add(newid, filepath.c_str(), id.name);
663
664 return newid;
665}
666
667} // namespace blender::bke
#define BLENDER_ASSET_FILE_SUFFIX
File and directory operations.
#define GHASH_ITER(gh_iter_, ghash_)
Definition BLI_ghash.hh:320
#define BLI_SCOPED_DEFER(function_to_defer)
#define FILE_MAXFILE
#define FILE_MAX
#define FILE_MAXDIR
external readfile function prototypes.
external writefile.cc function prototypes.
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
Definition DNA_ID.h:703
#define ID_TYPE_SUPPORTS_ASSET_EDITABLE(id_type)
Definition DNA_ID.h:705
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define FILE_MAX_LIBEXTRA
#define BLI_assert_unreachable()
#define STREQ(a, b)
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)
Definition library.cc:492
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)
Definition asset_edit.cc:59
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)
Definition asset_edit.cc:49
static ID * asset_link_id(Main &global_main, const ID_Type id_type, const char *filepath, const char *asset_name, ReportList *reports=nullptr)
Definition asset_edit.cc:70
bool asset_edit_id_is_editable(const ID &id)
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
UserDef U
Definition blender.cc:58
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)
Definition idtype.cc:227
char * STRNCPY(char(&dst)[N], const char *src)
@ LIBRARY_IS_ASSET_EDIT_FILE
@ LIBRARY_ASSET_EDITABLE
@ 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()
Definition lib_id.cc:1808
@ RPT_WARNING
Definition BKE_report.hh:40
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
Definition BLI_ghash.cc:735
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()
Definition fileops_c.cc:416
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)
Definition main.cc:971
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_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ONLINE_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
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
Definition BLI_ghash.hh:301
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
@ G_FILE_COMPRESS
@ G_FILE_ASSET_EDIT_FILE
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)
Definition idtype.cc:232
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
@ BLO_WRITE_PATH_REMAP_RELATIVE
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
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)
Definition idtype.cc:268
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()
Definition fileops_c.cc:293
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)
Definition lib_id.cc:1314
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)
Definition lib_id.cc:2632
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ 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)
Definition DNA_ID.h:410
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:929
ID * BKE_main_library_weak_reference_find(Main *bmain, const char *library_filepath, const char *library_id_name)
Definition main.cc:937
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)
Definition lib_id.cc:2654
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
constexpr char SEP
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
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)
Definition lib_id.cc:2395
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)
Definition main.cc:1073
eAssetLibraryType asset_library_type
const char * name_plural
const char * name
char name[258]
Definition DNA_ID.h:433
struct Library * lib
Definition DNA_ID.h:421
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
char filepath[1024]
Definition BKE_main.hh:267
bool is_locked_for_linking
Definition BKE_main.hh:313
ListBaseT< Library > libraries
Definition BKE_main.hh:387
bool is_asset_edit_file
Definition BKE_main.hh:288