Cleanup: extract functions for PackedFile .blend I/O
This commit is contained in:
parent
4a82d792b0
commit
fbc12e6cc5
|
@ -37,6 +37,8 @@ struct ReportList;
|
|||
struct VFont;
|
||||
struct Volume;
|
||||
struct bSound;
|
||||
struct BlendWriter;
|
||||
struct BlendDataReader;
|
||||
|
||||
enum ePF_FileCompare {
|
||||
PF_CMP_EQUAL = 0,
|
||||
|
@ -121,6 +123,9 @@ void BKE_packedfile_id_unpack(struct Main *bmain,
|
|||
struct ReportList *reports,
|
||||
enum ePF_FileStatus how);
|
||||
|
||||
void BKE_packedfile_blend_write(struct BlendWriter *writer, struct PackedFile *pf);
|
||||
void BKE_packedfile_blend_read(struct BlendDataReader *reader, struct PackedFile **pf_p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
#include "BKE_sound.h"
|
||||
#include "BKE_volume.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
int BKE_packedfile_seek(PackedFile *pf, int offset, int whence)
|
||||
{
|
||||
int oldseek = -1, seek = 0;
|
||||
|
@ -852,3 +854,29 @@ void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_packedfile_blend_write(BlendWriter *writer, PackedFile *pf)
|
||||
{
|
||||
if (pf == NULL) {
|
||||
return;
|
||||
}
|
||||
BLO_write_struct(writer, PackedFile, pf);
|
||||
BLO_write_raw(writer, pf->size, pf->data);
|
||||
}
|
||||
|
||||
void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p)
|
||||
{
|
||||
BLO_read_packed_address(reader, pf_p);
|
||||
PackedFile *pf = *pf_p;
|
||||
if (pf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
BLO_read_packed_address(reader, &pf->data);
|
||||
if (pf->data == NULL) {
|
||||
/* We cannot allow a PackedFile with a NULL data field,
|
||||
* the whole code assumes this is not possible. See T70315. */
|
||||
printf("%s: NULL packedfile data, cleaning up...\n", __func__);
|
||||
MEM_SAFE_FREE(pf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,6 +147,7 @@
|
|||
#include "BKE_nla.h"
|
||||
#include "BKE_node.h" // for tree type defines
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_particle.h"
|
||||
#include "BKE_pointcache.h"
|
||||
|
@ -2604,29 +2605,6 @@ static void direct_link_paint_curve(BlendDataReader *reader, PaintCurve *pc)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read PackedFile
|
||||
* \{ */
|
||||
|
||||
static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *pf)
|
||||
{
|
||||
BLO_read_packed_address(reader, &pf);
|
||||
|
||||
if (pf) {
|
||||
BLO_read_packed_address(reader, &pf->data);
|
||||
if (pf->data == NULL) {
|
||||
/* We cannot allow a PackedFile with a NULL data field,
|
||||
* the whole code assumes this is not possible. See T70315. */
|
||||
printf("%s: NULL packedfile data, cleaning up...\n", __func__);
|
||||
MEM_SAFE_FREE(pf);
|
||||
}
|
||||
}
|
||||
|
||||
return pf;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read Animation (legacy for version patching)
|
||||
* \{ */
|
||||
|
@ -3184,7 +3162,7 @@ static void direct_link_vfont(BlendDataReader *reader, VFont *vf)
|
|||
{
|
||||
vf->data = NULL;
|
||||
vf->temp_pf = NULL;
|
||||
vf->packedfile = direct_link_packedfile(reader, vf->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &vf->packedfile);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -3219,12 +3197,12 @@ static void direct_link_image(BlendDataReader *reader, Image *ima)
|
|||
|
||||
if (ima->packedfiles.first) {
|
||||
LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) {
|
||||
imapf->packedfile = direct_link_packedfile(reader, imapf->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &imapf->packedfile);
|
||||
}
|
||||
ima->packedfile = NULL;
|
||||
}
|
||||
else {
|
||||
ima->packedfile = direct_link_packedfile(reader, ima->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &ima->packedfile);
|
||||
}
|
||||
|
||||
BLI_listbase_clear(&ima->anims);
|
||||
|
@ -6834,7 +6812,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
|
|||
// printf("direct_link_library: filepath_abs %s\n", lib->filepath_abs);
|
||||
|
||||
BlendDataReader reader = {fd};
|
||||
lib->packedfile = direct_link_packedfile(&reader, lib->packedfile);
|
||||
BKE_packedfile_blend_read(&reader, &lib->packedfile);
|
||||
|
||||
/* new main */
|
||||
newmain = BKE_main_new();
|
||||
|
@ -6947,8 +6925,8 @@ static void direct_link_sound(BlendDataReader *reader, bSound *sound)
|
|||
/* clear waveform loading flag */
|
||||
sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
|
||||
|
||||
sound->packedfile = direct_link_packedfile(reader, sound->packedfile);
|
||||
sound->newpackedfile = direct_link_packedfile(reader, sound->newpackedfile);
|
||||
BKE_packedfile_blend_read(reader, &sound->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &sound->newpackedfile);
|
||||
}
|
||||
|
||||
static void lib_link_sound(BlendLibReader *reader, bSound *sound)
|
||||
|
@ -7218,7 +7196,7 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume)
|
|||
BLO_read_data_address(reader, &volume->adt);
|
||||
BKE_animdata_blend_read_data(reader, volume->adt);
|
||||
|
||||
volume->packedfile = direct_link_packedfile(reader, volume->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &volume->packedfile);
|
||||
volume->runtime.frame = 0;
|
||||
|
||||
/* materials */
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
#include "BKE_modifier.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_pointcache.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_sequencer.h"
|
||||
|
@ -1404,11 +1405,7 @@ static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address)
|
|||
BKE_id_blend_write(writer, &vf->id);
|
||||
|
||||
/* direct data */
|
||||
if (vf->packedfile) {
|
||||
PackedFile *pf = vf->packedfile;
|
||||
BLO_write_struct(writer, PackedFile, pf);
|
||||
BLO_write_raw(writer, pf->size, pf->data);
|
||||
}
|
||||
BKE_packedfile_blend_write(writer, vf->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1542,11 +1539,7 @@ static void write_image(BlendWriter *writer, Image *ima, const void *id_address)
|
|||
|
||||
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
|
||||
BLO_write_struct(writer, ImagePackedFile, imapf);
|
||||
if (imapf->packedfile) {
|
||||
PackedFile *pf = imapf->packedfile;
|
||||
BLO_write_struct(writer, PackedFile, pf);
|
||||
BLO_write_raw(writer, pf->size, pf->data);
|
||||
}
|
||||
BKE_packedfile_blend_write(writer, imapf->packedfile);
|
||||
}
|
||||
|
||||
BKE_previewimg_blend_write(writer, ima->preview);
|
||||
|
@ -2442,11 +2435,7 @@ static void write_sound(BlendWriter *writer, bSound *sound, const void *id_addre
|
|||
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
|
||||
BKE_id_blend_write(writer, &sound->id);
|
||||
|
||||
if (sound->packedfile) {
|
||||
PackedFile *pf = sound->packedfile;
|
||||
BLO_write_struct(writer, PackedFile, pf);
|
||||
BLO_write_raw(writer, pf->size, pf->data);
|
||||
}
|
||||
BKE_packedfile_blend_write(writer, sound->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2760,11 +2749,7 @@ static void write_volume(BlendWriter *writer, Volume *volume, const void *id_add
|
|||
BKE_animdata_blend_write(writer, volume->adt);
|
||||
}
|
||||
|
||||
if (volume->packedfile) {
|
||||
PackedFile *pf = volume->packedfile;
|
||||
BLO_write_struct(writer, PackedFile, pf);
|
||||
BLO_write_raw(writer, pf->size, pf->data);
|
||||
}
|
||||
BKE_packedfile_blend_write(writer, volume->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2866,9 +2851,7 @@ static void write_libraries(WriteData *wd, Main *main)
|
|||
BKE_id_blend_write(&writer, &main->curlib->id);
|
||||
|
||||
if (main->curlib->packedfile) {
|
||||
PackedFile *pf = main->curlib->packedfile;
|
||||
writestruct(wd, DATA, PackedFile, 1, pf);
|
||||
writedata(wd, DATA, pf->size, pf->data);
|
||||
BKE_packedfile_blend_write(&writer, main->curlib->packedfile);
|
||||
if (wd->use_memfile == false) {
|
||||
printf("write packed .blend: %s\n", main->curlib->filepath);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue