64 int oldseek = -1, seek = 0;
70 seek = oldseek + offset;
73 seek =
pf->size + offset;
85 else if (seek >
pf->size) {
101 if ((
pf !=
nullptr) && (size >= 0) && (
data !=
nullptr)) {
102 if (size +
pf->seek >
pf->size) {
103 size =
pf->size -
pf->seek;
107 memcpy(
data, (
static_cast<const char *
>(
pf->data)) +
pf->seek, size);
132 for (ima = bmain->
images.first(); ima; ima =
static_cast<Image *
>(ima->id.next)) {
138 for (vf = bmain->
fonts.first(); vf; vf =
static_cast<VFont *
>(vf->
id.
next)) {
144 for (sound = bmain->
sounds.first(); sound; sound =
static_cast<bSound *
>(sound->
id.
next)) {
150 for (volume = bmain->
volumes.first(); volume; volume =
static_cast<Volume *
>(volume->
id.
next)) {
181 pf->sharing_info->remove_user_and_delete_if_last();
185 printf(
"%s: Trying to free a nullptr pointer\n", __func__);
196 pf_dst = MEM_dupalloc(pf_src);
215 pf->sharing_info = sharing_info;
226 if (filepath_rel[0] ==
'\0') {
234 STRNCPY(filepath, filepath_rel);
248 if (file_size ==
size_t(-1)) {
281 for (ima = bmain->
images.first(); ima; ima =
static_cast<Image *
>(ima->id.next)) {
290 "Image '%s' skipped, packing movies or image sequences not supported",
296 for (vfont = bmain->
fonts.first(); vfont; vfont =
static_cast<VFont *
>(vfont->
id.
next)) {
306 for (sound = bmain->
sounds.first(); sound; sound =
static_cast<bSound *
>(sound->
id.
next)) {
314 for (volume = bmain->
volumes.first(); volume; volume =
static_cast<Volume *
>(volume->
id.
next)) {
345 const char *ref_file_name,
346 const char *filepath_rel,
351 bool remove_tmp =
false;
356 STRNCPY(filepath, filepath_rel);
360 for (number = 1; number <= 999; number++) {
361 SNPRINTF(filepath_temp,
"%s.%03d_", filepath, number);
379 if (write(file,
pf->data,
pf->size) !=
pf->size) {
395 "Error restoring temp file (check files '%s' '%s')",
401 if (
BLI_delete(filepath_temp,
false,
false) != 0) {
411 const char *filepath_rel,
419 STRNCPY(filepath, filepath_rel);
422 if (
BLI_stat(filepath, &st) == -1) {
425 else if (st.st_size !=
pf->size) {
438 for (
int i = 0; i <
pf->size; i +=
sizeof(buf)) {
439 int len =
pf->size - i;
440 len = std::min<ulong>(
len,
sizeof(buf));
448 if (memcmp(buf, (
static_cast<const char *
>(
pf->data)) + i,
len) != 0) {
462 const char *ref_file_name,
463 const char *abs_name,
464 const char *local_name,
468 char *newname =
nullptr;
469 const char *temp =
nullptr;
518 printf(
"%s: unknown return_value %d\n", __func__, how);
533 size_t abspath_maxncpy,
535 size_t relpath_maxncpy)
537 const short id_type =
GS(
id->name);
542 filepath, temp_dirname,
sizeof(temp_dirname), temp_filename,
sizeof(temp_filename));
544 if (temp_filename[0] ==
'\0') {
547 printf(
"%s\n", temp_filename);
551 if (id_type ==
ID_IM) {
552 Image *ima = id_cast<Image *>(
id);
554 if (imapf !=
nullptr && imapf->
packedfile !=
nullptr) {
571 printf(
"%s\n", temp_filename);
574 if (temp_dirname[0] ==
'\0') {
580 const char *dir_name =
nullptr;
589 dir_name =
"textures";
592 dir_name =
"volumes";
598 BLI_path_join(r_relpath, relpath_maxncpy,
"//", dir_name, temp_filename);
611 const char *orig_file_path,
616 char *new_name =
nullptr;
620 orig_file_path,
id, absname,
sizeof(absname), localname,
sizeof(localname));
638 if (new_file_path !=
nullptr) {
643 MEM_delete(new_file_path);
657 if (sound !=
nullptr) {
660 if (new_file_path !=
nullptr) {
662 MEM_delete(new_file_path);
683 if (ima !=
nullptr) {
684 while (ima->packedfiles.last()) {
689 if (new_file_path !=
nullptr) {
705 STRNCPY(ima->filepath, new_file_path);
711 MEM_delete(new_file_path);
722 if (ret_value ==
RET_OK) {
736 if (volume !=
nullptr) {
739 if (new_file_path !=
nullptr) {
741 MEM_delete(new_file_path);
770 if (newname !=
nullptr) {
773 printf(
"Unpacked .blend library: %s\n", newname);
828 for (ima = bmain->
images.first(); ima; ima =
static_cast<Image *
>(ima->id.next)) {
834 for (vf = bmain->
fonts.first(); vf; vf =
static_cast<VFont *
>(vf->
id.
next)) {
840 for (sound = bmain->
sounds.first(); sound; sound =
static_cast<bSound *
>(sound->
id.
next)) {
846 for (volume = bmain->
volumes.first(); volume; volume =
static_cast<Volume *
>(volume->
id.
next)) {
869 switch (
GS(
id->name)) {
871 const Image *ima = id_cast<const Image *>(
id);
875 const VFont *vf = id_cast<const VFont *>(
id);
879 const bSound *snd = id_cast<const bSound *>(
id);
883 const Volume *volume = id_cast<const Volume *>(
id);
887 const Library *li = id_cast<const Library *>(
id);
903 switch (
GS(
id->name)) {
905 Image *ima = id_cast<Image *>(
id);
912 VFont *vf = id_cast<VFont *>(
id);
919 bSound *snd = id_cast<bSound *>(
id);
926 Volume *volume = id_cast<Volume *>(
id);
933 Library *li = id_cast<Library *>(
id);
948 pf->data,
pf->size,
pf->sharing_info, [&]() { writer->write_raw(pf->size, pf->data); });
962 BLO_read_array_and_validate_size(
963 reader, reinterpret_cast<std::byte **>(const_cast<void **>(&pf->data)), &pf->size);
966 implicit_sharing::info_for_mem_free(static_cast<const std::byte *>(pf->data)) :
969 if (
pf->data ==
nullptr) {
973 "%s: nullptr packedfile data (source: '%s'), cleaning up...",
977 MEM_SAFE_DELETE(*pf_p);
#define IMA_SIGNAL_RELOAD
#define BLI_path_join(...)
#define STRNCPY_RLEN(dst, src)
#define SNPRINTF(dst, format,...)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define CLOG_WARN(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
#define ID_BLEND_PATH(_bmain, _id)
#define ID_IS_EDITABLE(_id)
Read Blender memory allocation and freeing.
constexpr const char * c_str() const
#define pf(_x, _i)
Prefetch 64.
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
StringRefNull essentials_directory_path()
UnpackGeometryNodesBakeResult unpack_geometry_nodes_bake(Main &bmain, ReportList *reports, Object &object, NodesModifierData &nmd, NodesModifierBake &bake, ePF_FileStatus how)
PackGeometryNodesBakeResult pack_geometry_nodes_bake(Main &bmain, ReportList *reports, Object &object, NodesModifierData &nmd, NodesModifierBake &bake)
const ImplicitSharingInfo * info_for_mem_free(T *data)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_packedfile_blend_write(BlendWriter *writer, const PackedFile *pf)
int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
ePF_FileCompare BKE_packedfile_compare_to_file(const char *ref_file_name, const char *filepath_rel, const PackedFile *pf)
const ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, FunctionRef< const ImplicitSharingInfo *()> read_fn)
char * STRNCPY(char(&dst)[N], const char *src)
int BKE_packedfile_read(PackedFile *pf, void *data, int size)
PackedFile * BKE_packedfile_duplicate(const PackedFile *pf_src)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool BKE_vfont_is_builtin(const VFont *vfont)
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
bool BKE_packedfile_id_check(const ID *id)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int64_t BLI_read(int fd, void *buf, size_t nbytes)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_packedfile_free(PackedFile *pf)
int BKE_packedfile_seek(PackedFile *pf, int offset, int whence)
void BKE_packedfile_rewind(PackedFile *pf)
PackedFile * BKE_packedfile_new(ReportList *reports, const char *filepath_rel, const char *basepath)
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF_FileStatus how)
void MEM_delete_void(void *vmemh)
int BKE_packedfile_unpack_vfont(Main *bmain, ReportList *reports, VFont *vfont, enum ePF_FileStatus how)
PackedFileCount BKE_packedfile_count_all(Main *bmain)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
void BKE_packedfile_pack_all_libraries(Main *bmain, ReportList *reports)
void BKE_packedfile_unpack_all(Main *bmain, ReportList *reports, enum ePF_FileStatus how)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BKE_report(ReportList *reports, eReportType type, const char *message)
int BKE_packedfile_unpack_image(Main *bmain, ReportList *reports, Image *ima, enum ePF_FileStatus how)
BMesh const char void * data
char * BKE_packedfile_unpack_to_file(ReportList *reports, const char *ref_file_name, const char *abs_name, const char *local_name, PackedFile *pf, enum ePF_FileStatus how)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath)
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BKE_packedfile_unpack_volume(Main *bmain, ReportList *reports, Volume *volume, enum ePF_FileStatus how)
void BKE_volume_unload(Volume *volume)
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
void BKE_image_ensure_tile_token(char *filepath, size_t filepath_maxncpy)
static void unpack_generate_paths(const char *filepath, ID *id, char *r_abspath, size_t abspath_maxncpy, char *r_relpath, size_t relpath_maxncpy)
int BLI_copy(const char *path_src, const char *path_dst) ATTR_NONNULL()
char BKE_ftype_to_imtype(eImbFileType ftype, const ImbFormatOptions *options)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
eImbFileType IMB_test_image_type_from_memory(const unsigned char *buf, size_t buf_size)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BKE_packedfile_unpack(Main *bmain, ReportList *reports, ID *id, const char *orig_file_path, PackedFile *pf, enum ePF_FileStatus how)
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
constexpr int64_t PACKED_FILE_MAX_SIZE
ID_Type GS(const char *name)
void BKE_sound_load(Main *bmain, bSound *sound)
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT
void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p, StringRefNull filepath)
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
bool BKE_image_has_packedfile(const Image *image)
PackedFile * BKE_packedfile_new_from_memory(const void *mem, int memlen, const ImplicitSharingInfo *sharing_info=nullptr)
int BKE_image_path_ext_from_imtype_ensure(char *filepath, size_t filepath_maxncpy, char imtype)
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
int BKE_packedfile_unpack_sound(Main *bmain, ReportList *reports, bSound *sound, enum ePF_FileStatus how)
int BKE_packedfile_write_to_file(ReportList *reports, const char *ref_file_name, const char *filepath_rel, PackedFile *pf)
void write_shared(const void *data, size_t approximate_size_in_bytes, const ImplicitSharingInfo *sharing_info, FunctionRef< void()> write_fn)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
struct PackedFile * packedfile
struct PackedFile * packedfile
bke::library::LibraryRuntime * runtime
ListBaseT< Library > libraries
ListBaseT< Object > objects
ListBaseT< bSound > sounds
ListBaseT< Image > images
ListBaseT< Volume > volumes
NodesModifierBake * bakes
const ImplicitSharingInfoHandle * sharing_info
struct PackedFile * packedfile
struct PackedFile * packedfile
struct PackedFile * packedfile