4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
30 FILEFORMAT: IFF-style structure (but not IFF compatible!)
33 BLENDER_V100 12 bytes (versie 1.00)
34 V = big endian, v = little endian
35 _ = 4 byte pointer, - = 8 byte pointer
37 datablocks: also see struct BHead
39 <bh.len> int, len data after BHead
40 <bh.old> void, old pointer
42 <bh.nr> int, in case of array: amount of structs
47 Almost all data in Blender are structures. Each struct saved
48 gets a BHead header. With BHead the struct can be linked again
49 and compared with StructDNA .
53 Preferred writing order: (not really a must, but why would you do it random?)
54 Any case: direct data is ALWAYS after the lib block
59 - write associated direct data
64 - write the ID of LibBlock
65 - write FileGlobal (some global vars)
67 - write USER if filename is ~/.B.blend
81 #include "BLI_winstuff.h"
83 #include <process.h> // for getpid
92 #include "DNA_anim_types.h"
93 #include "DNA_armature_types.h"
94 #include "DNA_action_types.h"
95 #include "DNA_actuator_types.h"
96 #include "DNA_boid_types.h"
97 #include "DNA_brush_types.h"
98 #include "DNA_camera_types.h"
99 #include "DNA_cloth_types.h"
100 #include "DNA_color_types.h"
101 #include "DNA_constraint_types.h"
102 #include "DNA_controller_types.h"
103 #include "DNA_curve_types.h"
104 #include "DNA_customdata_types.h"
105 #include "DNA_effect_types.h"
106 #include "DNA_genfile.h"
107 #include "DNA_group_types.h"
108 #include "DNA_gpencil_types.h"
109 #include "DNA_image_types.h"
110 #include "DNA_ipo_types.h" // XXX depreceated - animsys
111 #include "DNA_fileglobal_types.h"
112 #include "DNA_key_types.h"
113 #include "DNA_lattice_types.h"
114 #include "DNA_listBase.h" /* for Listbase, the type of samples, ...*/
115 #include "DNA_lamp_types.h"
116 #include "DNA_meta_types.h"
117 #include "DNA_mesh_types.h"
118 #include "DNA_meshdata_types.h"
119 #include "DNA_material_types.h"
120 #include "DNA_modifier_types.h"
121 #include "DNA_nla_types.h"
122 #include "DNA_node_types.h"
123 #include "DNA_object_types.h"
124 #include "DNA_object_force.h"
125 #include "DNA_outliner_types.h"
126 #include "DNA_packedFile_types.h"
127 #include "DNA_particle_types.h"
128 #include "DNA_property_types.h"
129 #include "DNA_scene_types.h"
130 #include "DNA_sdna_types.h"
131 #include "DNA_sequence_types.h"
132 #include "DNA_sensor_types.h"
133 #include "DNA_space_types.h"
134 #include "DNA_screen_types.h"
135 #include "DNA_sound_types.h"
136 #include "DNA_texture_types.h"
137 #include "DNA_text_types.h"
138 #include "DNA_view3d_types.h"
139 #include "DNA_vfont_types.h"
140 #include "DNA_userdef_types.h"
141 #include "DNA_world_types.h"
142 #include "DNA_windowmanager_types.h"
144 #include "MEM_guardedalloc.h" // MEM_freeN
145 #include "BLI_blenlib.h"
146 #include "BLI_linklist.h"
148 #include "BKE_action.h"
149 #include "BKE_blender.h"
150 #include "BKE_cloth.h"
151 #include "BKE_curve.h"
152 #include "BKE_customdata.h"
153 #include "BKE_constraint.h"
154 #include "BKE_global.h" // for G
155 #include "BKE_library.h" // for set_listbasepointers
156 #include "BKE_main.h"
157 #include "BKE_node.h"
158 #include "BKE_packedFile.h" // for packAll
159 #include "BKE_report.h"
160 #include "BKE_screen.h" // for waitcursor
161 #include "BKE_sequence.h"
162 #include "BKE_sound.h" /* ... and for samples */
163 #include "BKE_utildefines.h" // for defines
164 #include "BKE_modifier.h"
165 #include "BKE_idprop.h"
166 #include "BKE_fcurve.h"
168 #include "BLO_writefile.h"
169 #include "BLO_readfile.h"
170 #include "BLO_undofile.h"
172 #include "readfile.h"
176 /* ********* my write, buffered writing with minimum size chunks ************ */
178 #define MYWRITE_BUFFER_SIZE 100000
179 #define MYWRITE_MAX_CHUNK 32768
186 MemFile *compare, *current;
188 int tot, count, error, memsize;
191 static WriteData *writedata_new(int file)
193 WriteData *wd= MEM_callocN(sizeof(*wd), "writedata");
195 /* XXX, see note about this in readfile.c, remove
196 * once we have an xp lock - zr
199 if (wd == NULL) return NULL;
201 wd->sdna= DNA_sdna_from_data(DNAstr, DNAlen, 0);
205 wd->buf= MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
210 static void writedata_do_write(WriteData *wd, void *mem, int memlen)
212 if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) return;
213 if (wd->error) return;
215 /* memory based save */
217 add_memfilechunk(NULL, wd->current, mem, memlen);
220 if (write(wd->file, mem, memlen) != memlen)
226 static void writedata_free(WriteData *wd)
228 DNA_sdna_free(wd->sdna);
239 * Low level WRITE(2) wrapper that buffers data
240 * @param adr Pointer to new chunk of data
241 * @param len Length of new chunk of data
242 * @warning Talks to other functions with global parameters
245 #define MYWRITE_FLUSH NULL
247 static void mywrite( WriteData *wd, void *adr, int len)
249 if (wd->error) return;
251 /* flush helps compression for undo-save */
252 if(adr==MYWRITE_FLUSH) {
254 writedata_do_write(wd, wd->buf, wd->count);
262 /* if we have a single big chunk, write existing data in
263 * buffer and write out big chunk in smaller pieces */
264 if(len>MYWRITE_MAX_CHUNK) {
266 writedata_do_write(wd, wd->buf, wd->count);
271 int writelen= MIN2(len, MYWRITE_MAX_CHUNK);
272 writedata_do_write(wd, adr, writelen);
273 adr = (char*)adr + writelen;
280 /* if data would overflow buffer, write out the buffer */
281 if(len+wd->count>MYWRITE_BUFFER_SIZE-1) {
282 writedata_do_write(wd, wd->buf, wd->count);
286 /* append data at end of buffer */
287 memcpy(&wd->buf[wd->count], adr, len);
292 * BeGiN initializer for mywrite
293 * @param file File descriptor
294 * @param write_flags Write parameters
295 * @warning Talks to other functions with global parameters
297 static WriteData *bgnwrite(int file, MemFile *compare, MemFile *current, int write_flags)
299 WriteData *wd= writedata_new(file);
301 if (wd == NULL) return NULL;
303 wd->compare= compare;
304 wd->current= current;
305 /* this inits comparing */
306 add_memfilechunk(compare, NULL, NULL, 0);
312 * END the mywrite wrapper
313 * @return 1 if write failed
314 * @return unknown global variable otherwise
315 * @warning Talks to other functions with global parameters
317 static int endwrite(WriteData *wd)
322 writedata_do_write(wd, wd->buf, wd->count);
332 /* ********** WRITE FILE ****************** */
334 static void writestruct(WriteData *wd, int filecode, char *structname, int nr, void *adr)
339 if(adr==NULL || nr==0) return;
346 bh.SDNAnr= DNA_struct_find_nr(wd->sdna, structname);
348 printf("error: can't find SDNA code <%s>\n", structname);
351 sp= wd->sdna->structs[bh.SDNAnr];
353 bh.len= nr*wd->sdna->typelens[sp[0]];
355 if(bh.len==0) return;
357 mywrite(wd, &bh, sizeof(BHead));
358 mywrite(wd, adr, bh.len);
361 static void writedata(WriteData *wd, int filecode, int len, void *adr) /* do not use for structs */
378 mywrite(wd, &bh, sizeof(BHead));
379 if(len) mywrite(wd, adr, len);
382 /* *************** writing some direct data structs used in more code parts **************** */
383 /*These functions are used by blender's .blend system for file saving/loading.*/
384 void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd);
385 void IDP_WriteProperty(IDProperty *prop, void *wd);
386 static void write_animdata(WriteData *wd, AnimData *adt); // XXX code needs reshuffling, but not before NLA SoC is merged back into 2.5
388 static void IDP_WriteArray(IDProperty *prop, void *wd)
390 /*REMEMBER to set totalen to len in the linking code!!*/
391 if (prop->data.pointer) {
392 writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
394 if(prop->subtype == IDP_GROUP) {
395 IDProperty **array= prop->data.pointer;
398 for(a=0; a<prop->len; a++)
399 IDP_WriteProperty(array[a], wd);
404 static void IDP_WriteIDPArray(IDProperty *prop, void *wd)
406 /*REMEMBER to set totalen to len in the linking code!!*/
407 if (prop->data.pointer) {
408 IDProperty **array = prop->data.pointer;
411 writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
413 for(a=0; a<prop->len; a++)
414 IDP_WriteProperty(array[a], wd);
418 static void IDP_WriteString(IDProperty *prop, void *wd)
420 /*REMEMBER to set totalen to len in the linking code!!*/
421 writedata(wd, DATA, prop->len+1, prop->data.pointer);
424 static void IDP_WriteGroup(IDProperty *prop, void *wd)
428 for (loop=prop->data.group.first; loop; loop=loop->next) {
429 IDP_WriteProperty(loop, wd);
433 /* Functions to read/write ID Properties */
434 void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd)
436 switch (prop->type) {
438 IDP_WriteGroup(prop, wd);
441 IDP_WriteString(prop, wd);
444 IDP_WriteArray(prop, wd);
447 IDP_WriteIDPArray(prop, wd);
452 void IDP_WriteProperty(IDProperty *prop, void *wd)
454 writestruct(wd, DATA, "IDProperty", 1, prop);
455 IDP_WriteProperty_OnlyData(prop, wd);
458 static void write_curvemapping(WriteData *wd, CurveMapping *cumap)
462 writestruct(wd, DATA, "CurveMapping", 1, cumap);
463 for(a=0; a<CM_TOT; a++)
464 writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve);
467 /* this is only direct data, tree itself should have been written */
468 static void write_nodetree(WriteData *wd, bNodeTree *ntree)
474 /* for link_list() speed, we write per list */
476 for(node= ntree->nodes.first; node; node= node->next)
477 writestruct(wd, DATA, "bNode", 1, node);
479 for(node= ntree->nodes.first; node; node= node->next) {
480 if(node->storage && node->type!=NODE_DYNAMIC) {
481 /* could be handlerized at some point, now only 1 exception still */
482 if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
483 write_curvemapping(wd, node->storage);
484 else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_TIME || node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB))
485 write_curvemapping(wd, node->storage);
486 else if(ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) )
487 write_curvemapping(wd, node->storage);
489 writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
491 for(sock= node->inputs.first; sock; sock= sock->next)
492 writestruct(wd, DATA, "bNodeSocket", 1, sock);
493 for(sock= node->outputs.first; sock; sock= sock->next)
494 writestruct(wd, DATA, "bNodeSocket", 1, sock);
497 for(link= ntree->links.first; link; link= link->next)
498 writestruct(wd, DATA, "bNodeLink", 1, link);
501 static void write_scriptlink(WriteData *wd, ScriptLink *slink)
503 writedata(wd, DATA, sizeof(void *)*slink->totscript, slink->scripts);
504 writedata(wd, DATA, sizeof(short)*slink->totscript, slink->flag);
507 static void current_screen_compat(Main *mainvar, bScreen **screen)
512 /* find a global current screen in the first open window, to have
513 * a reasonable default for reading in older versions */
514 wm= mainvar->wm.first;
515 window= (wm)? wm->windows.first: NULL;
516 *screen= (window)? window->screen: NULL;
519 static void write_renderinfo(WriteData *wd, Main *mainvar) /* for renderdeamon */
525 /* XXX in future, handle multiple windows with multiple screnes? */
526 current_screen_compat(mainvar, &curscreen);
528 for(sce= mainvar->scene.first; sce; sce= sce->id.next) {
529 if(sce->id.lib==NULL && ( sce==curscreen->scene || (sce->r.scemode & R_BG_RENDER)) ) {
530 data[0]= sce->r.sfra;
531 data[1]= sce->r.efra;
533 memset(data+2, 0, sizeof(int)*6);
534 strncpy((char *)(data+2), sce->id.name+2, 21);
536 writedata(wd, REND, 32, data);
541 static void write_userdef(WriteData *wd)
545 writestruct(wd, USER, "UserDef", 1, &U);
547 btheme= U.themes.first;
549 writestruct(wd, DATA, "bTheme", 1, btheme);
550 btheme= btheme->next;
554 static void write_boid_state(WriteData *wd, BoidState *state)
556 BoidRule *rule = state->rules.first;
557 //BoidCondition *cond = state->conditions.first;
559 writestruct(wd, DATA, "BoidState", 1, state);
561 for(; rule; rule=rule->next) {
563 case eBoidRuleType_Goal:
564 case eBoidRuleType_Avoid:
565 writestruct(wd, DATA, "BoidRuleGoalAvoid", 1, rule);
567 case eBoidRuleType_AvoidCollision:
568 writestruct(wd, DATA, "BoidRuleAvoidCollision", 1, rule);
570 case eBoidRuleType_FollowLeader:
571 writestruct(wd, DATA, "BoidRuleFollowLeader", 1, rule);
573 case eBoidRuleType_AverageSpeed:
574 writestruct(wd, DATA, "BoidRuleAverageSpeed", 1, rule);
576 case eBoidRuleType_Fight:
577 writestruct(wd, DATA, "BoidRuleFight", 1, rule);
580 writestruct(wd, DATA, "BoidRule", 1, rule);
584 //for(; cond; cond=cond->next)
585 // writestruct(wd, DATA, "BoidCondition", 1, cond);
587 /* TODO: replace *cache with *cachelist once it's coded */
588 #define PTCACHE_WRITE_PSYS 0
589 #define PTCACHE_WRITE_CLOTH 1
590 static void write_pointcaches(WriteData *wd, PointCache *cache, int type)
592 writestruct(wd, DATA, "PointCache", 1, cache);
594 if((cache->flag & PTCACHE_DISK_CACHE)==0) {
595 PTCacheMem *pm = cache->mem_cache.first;
597 for(; pm; pm=pm->next) {
598 writestruct(wd, DATA, "PTCacheMem", 1, pm);
599 if(type==PTCACHE_WRITE_PSYS)
600 writestruct(wd, DATA, "ParticleKey", pm->totpoint, pm->data);
601 else if(type==PTCACHE_WRITE_CLOTH)
602 writedata(wd, DATA, 9 * sizeof(float) * pm->totpoint, pm->data);
606 static void write_particlesettings(WriteData *wd, ListBase *idbase)
608 ParticleSettings *part;
612 if(part->id.us>0 || wd->current) {
614 writestruct(wd, ID_PA, "ParticleSettings", 1, part);
615 if (part->id.properties) IDP_WriteProperty(part->id.properties, wd);
616 if (part->adt) write_animdata(wd, part->adt);
617 writestruct(wd, DATA, "PartDeflect", 1, part->pd);
618 writestruct(wd, DATA, "PartDeflect", 1, part->pd2);
620 if(part->boids && part->phystype == PART_PHYS_BOIDS) {
621 BoidState *state = part->boids->states.first;
623 writestruct(wd, DATA, "BoidSettings", 1, part->boids);
625 for(; state; state=state->next)
626 write_boid_state(wd, state);
632 static void write_particlesystems(WriteData *wd, ListBase *particles)
634 ParticleSystem *psys= particles->first;
638 for(; psys; psys=psys->next) {
639 writestruct(wd, DATA, "ParticleSystem", 1, psys);
641 if(psys->particles) {
642 writestruct(wd, DATA, "ParticleData", psys->totpart ,psys->particles);
644 if(psys->particles->hair) {
645 ParticleData *pa = psys->particles;
647 for(a=0; a<psys->totpart; a++, pa++)
648 writestruct(wd, DATA, "HairKey", pa->totkey, pa->hair);
651 if(psys->particles->boid && psys->part->phystype == PART_PHYS_BOIDS)
652 writestruct(wd, DATA, "BoidData", psys->totpart, psys->particles->boid);
654 pt = psys->targets.first;
655 for(; pt; pt=pt->next)
656 writestruct(wd, DATA, "ParticleTarget", 1, pt);
658 if(psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchild ,psys->child);
659 writestruct(wd, DATA, "SoftBody", 1, psys->soft);
660 if(psys->soft) write_pointcaches(wd, psys->soft->pointcache, PTCACHE_WRITE_PSYS);
661 write_pointcaches(wd, psys->pointcache, PTCACHE_WRITE_PSYS);
665 static void write_properties(WriteData *wd, ListBase *lb)
671 writestruct(wd, DATA, "bProperty", 1, prop);
673 if(prop->poin && prop->poin != &prop->data)
674 writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin);
680 static void write_sensors(WriteData *wd, ListBase *lb)
686 writestruct(wd, DATA, "bSensor", 1, sens);
688 writedata(wd, DATA, sizeof(void *)*sens->totlinks, sens->links);
692 writestruct(wd, DATA, "bNearSensor", 1, sens->data);
695 writestruct(wd, DATA, "bMouseSensor", 1, sens->data);
698 writestruct(wd, DATA, "bTouchSensor", 1, sens->data);
701 writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data);
704 writestruct(wd, DATA, "bPropertySensor", 1, sens->data);
707 writestruct(wd, DATA, "bActuatorSensor", 1, sens->data);
710 writestruct(wd, DATA, "bDelaySensor", 1, sens->data);
713 writestruct(wd, DATA, "bCollisionSensor", 1, sens->data);
716 writestruct(wd, DATA, "bRadarSensor", 1, sens->data);
719 writestruct(wd, DATA, "bRandomSensor", 1, sens->data);
722 writestruct(wd, DATA, "bRaySensor", 1, sens->data);
725 writestruct(wd, DATA, "bMessageSensor", 1, sens->data);
728 writestruct(wd, DATA, "bJoystickSensor", 1, sens->data);
731 ; /* error: don't know how to write this file */
738 static void write_controllers(WriteData *wd, ListBase *lb)
744 writestruct(wd, DATA, "bController", 1, cont);
746 writedata(wd, DATA, sizeof(void *)*cont->totlinks, cont->links);
749 case CONT_EXPRESSION:
750 writestruct(wd, DATA, "bExpressionCont", 1, cont->data);
753 writestruct(wd, DATA, "bPythonCont", 1, cont->data);
756 ; /* error: don't know how to write this file */
763 static void write_actuators(WriteData *wd, ListBase *lb)
769 writestruct(wd, DATA, "bActuator", 1, act);
773 case ACT_SHAPEACTION:
774 writestruct(wd, DATA, "bActionActuator", 1, act->data);
777 writestruct(wd, DATA, "bSoundActuator", 1, act->data);
780 writestruct(wd, DATA, "bCDActuator", 1, act->data);
783 writestruct(wd, DATA, "bObjectActuator", 1, act->data);
786 writestruct(wd, DATA, "bIpoActuator", 1, act->data);
789 writestruct(wd, DATA, "bPropertyActuator", 1, act->data);
792 writestruct(wd, DATA, "bCameraActuator", 1, act->data);
795 writestruct(wd, DATA, "bConstraintActuator", 1, act->data);
797 case ACT_EDIT_OBJECT:
798 writestruct(wd, DATA, "bEditObjectActuator", 1, act->data);
801 writestruct(wd, DATA, "bSceneActuator", 1, act->data);
804 writestruct(wd, DATA, "bGroupActuator", 1, act->data);
807 writestruct(wd, DATA, "bRandomActuator", 1, act->data);
810 writestruct(wd, DATA, "bMessageActuator", 1, act->data);
813 writestruct(wd, DATA, "bGameActuator", 1, act->data);
816 writestruct(wd, DATA, "bVisibilityActuator", 1, act->data);
819 writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data);
822 writestruct(wd, DATA, "bParentActuator", 1, act->data);
825 writestruct(wd, DATA, "bStateActuator", 1, act->data);
828 ; /* error: don't know how to write this file */
835 static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
840 for (fcm= fmodifiers->first; fcm; fcm= fcm->next) {
841 FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
843 /* Write the specific data */
844 if (fmi && fcm->data) {
845 /* firstly, just write the plain fmi->data struct */
846 writestruct(wd, DATA, fmi->structName, 1, fcm->data);
848 /* do any modifier specific stuff */
850 case FMODIFIER_TYPE_GENERATOR:
852 FMod_Generator *data= (FMod_Generator *)fcm->data;
854 /* write coefficients array */
855 if (data->coefficients)
856 writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
859 case FMODIFIER_TYPE_ENVELOPE:
861 FMod_Envelope *data= (FMod_Envelope *)fcm->data;
863 /* write envelope data */
865 writedata(wd, DATA, sizeof(FCM_EnvelopeData)*(data->totvert), data->data);
868 case FMODIFIER_TYPE_PYTHON:
870 FMod_Python *data = (FMod_Python *)fcm->data;
872 /* Write ID Properties -- and copy this comment EXACTLY for easy finding
873 of library blocks that implement this.*/
874 IDP_WriteProperty(data->prop, wd);
880 /* Write the modifier */
881 writestruct(wd, DATA, "FModifier", 1, fcm);
885 static void write_fcurves(WriteData *wd, ListBase *fcurves)
889 for (fcu=fcurves->first; fcu; fcu=fcu->next) {
891 writestruct(wd, DATA, "FCurve", 1, fcu);
895 writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt);
897 writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt);
900 writedata(wd, DATA, strlen(fcu->rna_path)+1, fcu->rna_path);
904 ChannelDriver *driver= fcu->driver;
907 writestruct(wd, DATA, "ChannelDriver", 1, driver);
910 for (dtar= driver->targets.first; dtar; dtar= dtar->next) {
911 writestruct(wd, DATA, "DriverTarget", 1, dtar);
914 writedata(wd, DATA, strlen(dtar->rna_path)+1, dtar->rna_path);
918 /* write F-Modifiers */
919 write_fmodifiers(wd, &fcu->modifiers);
923 static void write_actions(WriteData *wd, ListBase *idbase)
929 for(act=idbase->first; act; act= act->id.next) {
930 if (act->id.us>0 || wd->current) {
931 writestruct(wd, ID_AC, "bAction", 1, act);
932 if (act->id.properties) IDP_WriteProperty(act->id.properties, wd);
934 write_fcurves(wd, &act->curves);
936 for (grp=act->groups.first; grp; grp=grp->next) {
937 writestruct(wd, DATA, "bActionGroup", 1, grp);
940 for (marker=act->markers.first; marker; marker=marker->next) {
941 writestruct(wd, DATA, "TimeMarker", 1, marker);
946 /* flush helps the compression for undo-save */
947 mywrite(wd, MYWRITE_FLUSH, 0);
950 static void write_keyingsets(WriteData *wd, ListBase *list)
955 for (ks= list->first; ks; ks= ks->next) {
957 writestruct(wd, DATA, "KeyingSet", 1, ks);
960 for (ksp= ks->paths.first; ksp; ksp= ksp->next) {
962 writestruct(wd, DATA, "KS_Path", 1, ksp);
965 writedata(wd, DATA, strlen(ksp->rna_path)+1, ksp->rna_path);
970 static void write_nlastrips(WriteData *wd, ListBase *strips)
974 for (strip= strips->first; strip; strip= strip->next) {
975 /* write the strip first */
976 writestruct(wd, DATA, "NlaStrip", 1, strip);
978 /* write the strip's F-Curves and modifiers */
979 write_fcurves(wd, &strip->fcurves);
980 write_fmodifiers(wd, &strip->modifiers);
982 /* write the strip's children */
983 write_nlastrips(wd, &strip->strips);
987 static void write_nladata(WriteData *wd, ListBase *nlabase)
991 /* write all the tracks */
992 for (nlt= nlabase->first; nlt; nlt= nlt->next) {
993 /* write the track first */
994 writestruct(wd, DATA, "NlaTrack", 1, nlt);
996 /* write the track's strips */
997 write_nlastrips(wd, &nlt->strips);
1001 static void write_animdata(WriteData *wd, AnimData *adt)
1005 /* firstly, just write the AnimData block */
1006 writestruct(wd, DATA, "AnimData", 1, adt);
1009 write_fcurves(wd, &adt->drivers);
1011 /* write overrides */
1012 // FIXME: are these needed?
1013 for (aor= adt->overrides.first; aor; aor= aor->next) {
1014 /* overrides consist of base data + rna_path */
1015 writestruct(wd, DATA, "AnimOverride", 1, aor);
1016 writedata(wd, DATA, strlen(aor->rna_path)+1, aor->rna_path);
1019 // TODO write the remaps (if they are needed)
1021 /* write NLA data */
1022 write_nladata(wd, &adt->nla_tracks);
1025 static void write_constraints(WriteData *wd, ListBase *conlist)
1029 for (con=conlist->first; con; con=con->next) {
1030 bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
1032 /* Write the specific data */
1033 if (cti && con->data) {
1034 /* firstly, just write the plain con->data struct */
1035 writestruct(wd, DATA, cti->structName, 1, con->data);
1037 /* do any constraint specific stuff */
1038 switch (con->type) {
1039 case CONSTRAINT_TYPE_PYTHON:
1041 bPythonConstraint *data = (bPythonConstraint *)con->data;
1042 bConstraintTarget *ct;
1045 for (ct= data->targets.first; ct; ct= ct->next)
1046 writestruct(wd, DATA, "bConstraintTarget", 1, ct);
1048 /* Write ID Properties -- and copy this comment EXACTLY for easy finding
1049 of library blocks that implement this.*/
1050 IDP_WriteProperty(data->prop, wd);
1056 /* Write the constraint */
1057 writestruct(wd, DATA, "bConstraint", 1, con);
1061 static void write_pose(WriteData *wd, bPose *pose)
1066 /* Write each channel */
1070 /* Write channels */
1071 for (chan=pose->chanbase.first; chan; chan=chan->next) {
1072 /* Write ID Properties -- and copy this comment EXACTLY for easy finding
1073 of library blocks that implement this.*/
1075 IDP_WriteProperty(chan->prop, wd);
1077 write_constraints(wd, &chan->constraints);
1079 /* prevent crashes with autosave, when a bone duplicated in editmode has not yet been assigned to its posechannel */
1081 chan->selectflag= chan->bone->flag & (BONE_SELECTED|BONE_ACTIVE); /* gets restored on read, for library armatures */
1083 writestruct(wd, DATA, "bPoseChannel", 1, chan);
1087 for (grp=pose->agroups.first; grp; grp=grp->next)
1088 writestruct(wd, DATA, "bActionGroup", 1, grp);
1090 /* Write this pose */
1091 writestruct(wd, DATA, "bPose", 1, pose);
1094 static void write_defgroups(WriteData *wd, ListBase *defbase)
1096 bDeformGroup *defgroup;
1098 for (defgroup=defbase->first; defgroup; defgroup=defgroup->next)
1099 writestruct(wd, DATA, "bDeformGroup", 1, defgroup);
1102 static void write_modifiers(WriteData *wd, ListBase *modbase, int write_undo)
1106 if (modbase == NULL) return;
1107 for (md=modbase->first; md; md= md->next) {
1108 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
1109 if (mti == NULL) return;
1111 writestruct(wd, DATA, mti->structName, 1, md);
1113 if (md->type==eModifierType_Hook) {
1114 HookModifierData *hmd = (HookModifierData*) md;
1116 writedata(wd, DATA, sizeof(int)*hmd->totindex, hmd->indexar);
1118 else if(md->type==eModifierType_Cloth) {
1119 ClothModifierData *clmd = (ClothModifierData*) md;
1121 writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms);
1122 writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms);
1123 write_pointcaches(wd, clmd->point_cache, PTCACHE_WRITE_CLOTH);
1125 else if(md->type==eModifierType_Fluidsim) {
1126 FluidsimModifierData *fluidmd = (FluidsimModifierData*) md;
1128 writestruct(wd, DATA, "FluidsimSettings", 1, fluidmd->fss);
1130 else if (md->type==eModifierType_Collision) {
1133 CollisionModifierData *collmd = (CollisionModifierData*) md;
1134 // TODO: CollisionModifier should use pointcache
1135 // + have proper reset events before enabling this
1136 writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x);
1137 writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew);
1138 writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces);
1141 else if (md->type==eModifierType_MeshDeform) {
1142 MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
1143 int size = mmd->dyngridsize;
1145 writedata(wd, DATA, sizeof(float)*mmd->totvert*mmd->totcagevert,
1147 writedata(wd, DATA, sizeof(float)*3*mmd->totcagevert,
1149 writestruct(wd, DATA, "MDefCell", size*size*size, mmd->dyngrid);
1150 writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences);
1151 writedata(wd, DATA, sizeof(int)*mmd->totvert, mmd->dynverts);
1153 else if (md->type==eModifierType_Multires) {
1154 MultiresModifierData *mmd = (MultiresModifierData*) md;
1156 if(mmd->undo_verts && write_undo)
1157 writestruct(wd, DATA, "MVert", mmd->undo_verts_tot, mmd->undo_verts);
1162 static void write_objects(WriteData *wd, ListBase *idbase, int write_undo)
1168 if(ob->id.us>0 || wd->current) {
1170 writestruct(wd, ID_OB, "Object", 1, ob);
1172 /*Write ID Properties -- and copy this comment EXACTLY for easy finding
1173 of library blocks that implement this.*/
1174 if (ob->id.properties) IDP_WriteProperty(ob->id.properties, wd);
1176 if (ob->adt) write_animdata(wd, ob->adt);
1179 writedata(wd, DATA, sizeof(void *)*ob->totcol, ob->mat);
1180 writedata(wd, DATA, sizeof(char)*ob->totcol, ob->matbits);
1181 /* write_effects(wd, &ob->effect); */ /* not used anymore */
1182 write_properties(wd, &ob->prop);
1183 write_sensors(wd, &ob->sensors);
1184 write_controllers(wd, &ob->controllers);
1185 write_actuators(wd, &ob->actuators);
1186 write_scriptlink(wd, &ob->scriptlink);
1187 write_pose(wd, ob->pose);
1188 write_defgroups(wd, &ob->defbase);
1189 write_constraints(wd, &ob->constraints);
1191 writestruct(wd, DATA, "PartDeflect", 1, ob->pd);
1192 writestruct(wd, DATA, "SoftBody", 1, ob->soft);
1193 if(ob->soft) writestruct(wd, DATA, "PointCache", 1, ob->soft->pointcache);
1194 writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft);
1196 write_particlesystems(wd, &ob->particlesystem);
1197 write_modifiers(wd, &ob->modifiers, write_undo);
1202 /* flush helps the compression for undo-save */
1203 mywrite(wd, MYWRITE_FLUSH, 0);
1207 static void write_vfonts(WriteData *wd, ListBase *idbase)
1214 if(vf->id.us>0 || wd->current) {
1216 writestruct(wd, ID_VF, "VFont", 1, vf);
1217 if (vf->id.properties) IDP_WriteProperty(vf->id.properties, wd);
1221 if (vf->packedfile) {
1222 pf = vf->packedfile;
1223 writestruct(wd, DATA, "PackedFile", 1, pf);
1224 writedata(wd, DATA, pf->size, pf->data);
1233 static void write_keys(WriteData *wd, ListBase *idbase)
1240 if(key->id.us>0 || wd->current) {
1242 writestruct(wd, ID_KE, "Key", 1, key);
1243 if (key->id.properties) IDP_WriteProperty(key->id.properties, wd);
1245 if (key->adt) write_animdata(wd, key->adt);
1248 kb= key->block.first;
1250 writestruct(wd, DATA, "KeyBlock", 1, kb);
1251 if(kb->data) writedata(wd, DATA, kb->totelem*key->elemsize, kb->data);
1258 /* flush helps the compression for undo-save */
1259 mywrite(wd, MYWRITE_FLUSH, 0);
1262 static void write_cameras(WriteData *wd, ListBase *idbase)
1268 if(cam->id.us>0 || wd->current) {
1270 writestruct(wd, ID_CA, "Camera", 1, cam);
1271 if (cam->id.properties) IDP_WriteProperty(cam->id.properties, wd);
1273 if (cam->adt) write_animdata(wd, cam->adt);
1276 write_scriptlink(wd, &cam->scriptlink);
1283 static void write_mballs(WriteData *wd, ListBase *idbase)
1290 if(mb->id.us>0 || wd->current) {
1292 writestruct(wd, ID_MB, "MetaBall", 1, mb);
1293 if (mb->id.properties) IDP_WriteProperty(mb->id.properties, wd);
1296 writedata(wd, DATA, sizeof(void *)*mb->totcol, mb->mat);
1298 ml= mb->elems.first;
1300 writestruct(wd, DATA, "MetaElem", 1, ml);
1308 static int amount_of_chars(char *str)
1310 // Since the data is saved as UTF-8 to the cu->str
1311 // The cu->len is not same as the strlen(cu->str)
1315 static void write_curves(WriteData *wd, ListBase *idbase)
1322 if(cu->id.us>0 || wd->current) {
1324 writestruct(wd, ID_CU, "Curve", 1, cu);
1327 writedata(wd, DATA, sizeof(void *)*cu->totcol, cu->mat);
1328 if (cu->id.properties) IDP_WriteProperty(cu->id.properties, wd);
1329 if (cu->adt) write_animdata(wd, cu->adt);
1332 writedata(wd, DATA, amount_of_chars(cu->str)+1, cu->str);
1333 writestruct(wd, DATA, "CharInfo", cu->len, cu->strinfo);
1334 writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb);
1337 /* is also the order of reading */
1340 writestruct(wd, DATA, "Nurb", 1, nu);
1345 if( (nu->type & 7)==CU_BEZIER)
1346 writestruct(wd, DATA, "BezTriple", nu->pntsu, nu->bezt);
1348 writestruct(wd, DATA, "BPoint", nu->pntsu*nu->pntsv, nu->bp);
1349 if(nu->knotsu) writedata(wd, DATA, KNOTSU(nu)*sizeof(float), nu->knotsu);
1350 if(nu->knotsv) writedata(wd, DATA, KNOTSV(nu)*sizeof(float), nu->knotsv);
1359 /* flush helps the compression for undo-save */
1360 mywrite(wd, MYWRITE_FLUSH, 0);
1363 static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist)
1368 /* Write the dvert list */
1369 writestruct(wd, DATA, "MDeformVert", count, dvlist);
1371 /* Write deformation data for each dvert */
1372 for (i=0; i<count; i++) {
1374 writestruct(wd, DATA, "MDeformWeight", dvlist[i].totweight, dvlist[i].dw);
1379 static void write_mdisps(WriteData *wd, int count, MDisps *mdlist)
1384 writestruct(wd, DATA, "MDisps", count, mdlist);
1385 for(i = 0; i < count; ++i) {
1387 writedata(wd, DATA, sizeof(float)*3*mdlist[i].totdisp, mdlist[i].disps);
1392 static void write_customdata(WriteData *wd, int count, CustomData *data, int partial_type, int partial_count)
1396 writestruct(wd, DATA, "CustomDataLayer", data->maxlayer, data->layers);
1398 for (i=0; i<data->totlayer; i++) {
1399 CustomDataLayer *layer= &data->layers[i];
1401 int structnum, datasize;
1403 if (layer->type == CD_MDEFORMVERT) {
1404 /* layer types that allocate own memory need special handling */
1405 write_dverts(wd, count, layer->data);
1407 else if (layer->type == CD_MDISPS) {
1408 write_mdisps(wd, count, layer->data);
1411 CustomData_file_write_info(layer->type, &structname, &structnum);
1413 /* when using partial visibility, the MEdge and MFace layers
1414 are smaller than the original, so their type and count is
1415 passed to make this work */
1416 if (layer->type != partial_type) datasize= structnum*count;
1417 else datasize= structnum*partial_count;
1419 writestruct(wd, DATA, structname, datasize, layer->data);
1422 printf("error: this CustomDataLayer must not be written to file\n");
1427 static void write_meshs(WriteData *wd, ListBase *idbase)
1431 mesh= idbase->first;
1433 if(mesh->id.us>0 || wd->current) {
1435 writestruct(wd, ID_ME, "Mesh", 1, mesh);
1438 if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd);
1440 writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
1443 write_customdata(wd, mesh->pv->totvert, &mesh->vdata, -1, 0);
1444 write_customdata(wd, mesh->pv->totedge, &mesh->edata,
1445 CD_MEDGE, mesh->totedge);
1446 write_customdata(wd, mesh->pv->totface, &mesh->fdata,
1447 CD_MFACE, mesh->totface);
1450 write_customdata(wd, mesh->totvert, &mesh->vdata, -1, 0);
1451 write_customdata(wd, mesh->totedge, &mesh->edata, -1, 0);
1452 write_customdata(wd, mesh->totface, &mesh->fdata, -1, 0);
1457 writestruct(wd, DATA, "PartialVisibility", 1, mesh->pv);
1458 writedata(wd, DATA, sizeof(unsigned int)*mesh->pv->totvert, mesh->pv->vert_map);
1459 writedata(wd, DATA, sizeof(int)*mesh->pv->totedge, mesh->pv->edge_map);
1460 writestruct(wd, DATA, "MFace", mesh->pv->totface, mesh->pv->old_faces);
1461 writestruct(wd, DATA, "MEdge", mesh->pv->totedge, mesh->pv->old_edges);
1464 mesh= mesh->id.next;
1468 static void write_lattices(WriteData *wd, ListBase *idbase)
1474 if(lt->id.us>0 || wd->current) {
1476 writestruct(wd, ID_LT, "Lattice", 1, lt);
1477 if (lt->id.properties) IDP_WriteProperty(lt->id.properties, wd);
1480 writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def);
1482 write_dverts(wd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert);
1489 static void write_previews(WriteData *wd, PreviewImage *prv)
1492 short w = prv->w[1];
1493 short h = prv->h[1];
1494 unsigned int *rect = prv->rect[1];
1495 /* don't write out large previews if not requested */
1496 if (!(U.flag & USER_SAVE_PREVIEWS) ) {
1499 prv->rect[1] = NULL;
1501 writestruct(wd, DATA, "PreviewImage", 1, prv);
1502 if (prv->rect[0]) writedata(wd, DATA, prv->w[0]*prv->h[0]*sizeof(unsigned int), prv->rect[0]);
1503 if (prv->rect[1]) writedata(wd, DATA, prv->w[1]*prv->h[1]*sizeof(unsigned int), prv->rect[1]);
1505 /* restore preview, we still want to keep it in memory even if not saved to file */
1506 if (!(U.flag & USER_SAVE_PREVIEWS) ) {
1509 prv->rect[1] = rect;
1514 static void write_images(WriteData *wd, ListBase *idbase)
1522 if(ima->id.us>0 || wd->current) {
1524 writestruct(wd, ID_IM, "Image", 1, ima);
1525 if (ima->id.properties) IDP_WriteProperty(ima->id.properties, wd);
1527 if (ima->packedfile) {
1528 pf = ima->packedfile;
1529 writestruct(wd, DATA, "PackedFile", 1, pf);
1530 writedata(wd, DATA, pf->size, pf->data);
1533 write_previews(wd, ima->preview);
1535 /* exception: render text only saved in undo files (wd->current) */
1536 if (ima->render_text && wd->current)
1537 writedata(wd, DATA, IMA_RW_MAXTEXT, ima->render_text);
1541 /* flush helps the compression for undo-save */
1542 mywrite(wd, MYWRITE_FLUSH, 0);
1545 static void write_textures(WriteData *wd, ListBase *idbase)
1551 if(tex->id.us>0 || wd->current) {
1553 writestruct(wd, ID_TE, "Tex", 1, tex);
1554 if (tex->id.properties) IDP_WriteProperty(tex->id.properties, wd);
1556 if (tex->adt) write_animdata(wd, tex->adt);
1559 if(tex->type == TEX_PLUGIN && tex->plugin) writestruct(wd, DATA, "PluginTex", 1, tex->plugin);
1560 if(tex->coba) writestruct(wd, DATA, "ColorBand", 1, tex->coba);
1561 if(tex->type == TEX_ENVMAP && tex->env) writestruct(wd, DATA, "EnvMap", 1, tex->env);
1563 /* nodetree is integral part of texture, no libdata */
1565 writestruct(wd, DATA, "bNodeTree", 1, tex->nodetree);
1566 write_nodetree(wd, tex->nodetree);
1569 write_previews(wd, tex->preview);
1574 /* flush helps the compression for undo-save */
1575 mywrite(wd, MYWRITE_FLUSH, 0);
1578 static void write_materials(WriteData *wd, ListBase *idbase)
1585 if(ma->id.us>0 || wd->current) {
1587 writestruct(wd, ID_MA, "Material", 1, ma);
1589 /*Write ID Properties -- and copy this comment EXACTLY for easy finding
1590 of library blocks that implement this.*/
1591 /*manually set head group property to IDP_GROUP, just in case it hadn't been
1593 if (ma->id.properties) IDP_WriteProperty(ma->id.properties, wd);
1595 if (ma->adt) write_animdata(wd, ma->adt);
1597 for(a=0; a<MAX_MTEX; a++) {
1598 if(ma->mtex[a]) writestruct(wd, DATA, "MTex", 1, ma->mtex[a]);
1601 if(ma->ramp_col) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col);
1602 if(ma->ramp_spec) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec);
1604 write_scriptlink(wd, &ma->scriptlink);
1606 /* nodetree is integral part of material, no libdata */
1608 writestruct(wd, DATA, "bNodeTree", 1, ma->nodetree);
1609 write_nodetree(wd, ma->nodetree);
1612 write_previews(wd, ma->preview);
1618 static void write_worlds(WriteData *wd, ListBase *idbase)
1623 wrld= idbase->first;
1625 if(wrld->id.us>0 || wd->current) {
1627 writestruct(wd, ID_WO, "World", 1, wrld);
1628 if (wrld->id.properties) IDP_WriteProperty(wrld->id.properties, wd);
1630 if (wrld->adt) write_animdata(wd, wrld->adt);
1632 for(a=0; a<MAX_MTEX; a++) {
1633 if(wrld->mtex[a]) writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]);
1636 write_scriptlink(wd, &wrld->scriptlink);
1638 write_previews(wd, wrld->preview);
1640 wrld= wrld->id.next;
1644 static void write_lamps(WriteData *wd, ListBase *idbase)
1651 if(la->id.us>0 || wd->current) {
1653 writestruct(wd, ID_LA, "Lamp", 1, la);
1654 if (la->id.properties) IDP_WriteProperty(la->id.properties, wd);
1656 if (la->adt) write_animdata(wd, la->adt);
1659 for(a=0; a<MAX_MTEX; a++) {
1660 if(la->mtex[a]) writestruct(wd, DATA, "MTex", 1, la->mtex[a]);
1664 write_curvemapping(wd, la->curfalloff);
1666 write_scriptlink(wd, &la->scriptlink);
1668 write_previews(wd, la->preview);
1676 static void write_scenes(WriteData *wd, ListBase *scebase)
1685 TransformOrientation *ts;
1686 SceneRenderLayer *srl;
1688 sce= scebase->first;
1691 writestruct(wd, ID_SCE, "Scene", 1, sce);
1692 if (sce->id.properties) IDP_WriteProperty(sce->id.properties, wd);
1694 if (sce->adt) write_animdata(wd, sce->adt);
1695 write_keyingsets(wd, &sce->keyingsets);
1698 base= sce->base.first;
1700 writestruct(wd, DATA, "Base", 1, base);
1704 writestruct(wd, DATA, "ToolSettings", 1, sce->toolsettings);
1705 if(sce->toolsettings->vpaint)
1706 writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->vpaint);
1707 if(sce->toolsettings->wpaint)
1708 writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->wpaint);
1709 if(sce->toolsettings->sculpt)
1710 writestruct(wd, DATA, "Sculpt", 1, sce->toolsettings->sculpt);
1714 writestruct(wd, DATA, "Editing", 1, ed);
1716 /* reset write flags too */
1718 SEQ_BEGIN(ed, seq) {
1719 if(seq->strip) seq->strip->done= 0;
1720 writestruct(wd, DATA, "Sequence", 1, seq);
1724 SEQ_BEGIN(ed, seq) {
1725 if(seq->strip && seq->strip->done==0) {
1726 /* write strip with 'done' at 0 because readfile */
1728 if(seq->plugin) writestruct(wd, DATA, "PluginSeq", 1, seq->plugin);
1729 if(seq->effectdata) {
1732 writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata);
1735 writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata);
1738 writestruct(wd, DATA, "WipeVars", 1, seq->effectdata);
1741 writestruct(wd, DATA, "GlowVars", 1, seq->effectdata);
1744 writestruct(wd, DATA, "TransformVars", 1, seq->effectdata);
1750 writestruct(wd, DATA, "Strip", 1, strip);
1751 if(seq->flag & SEQ_USE_CROP && strip->crop) {
1752 writestruct(wd, DATA, "StripCrop", 1, strip->crop);
1754 if(seq->flag & SEQ_USE_TRANSFORM && strip->transform) {
1755 writestruct(wd, DATA, "StripTransform", 1, strip->transform);
1757 if(seq->flag & SEQ_USE_PROXY && strip->proxy) {
1758 writestruct(wd, DATA, "StripProxy", 1, strip->proxy);
1760 if(seq->flag & SEQ_USE_COLOR_BALANCE && strip->color_balance) {
1761 writestruct(wd, DATA, "StripColorBalance", 1, strip->color_balance);
1763 if(seq->type==SEQ_IMAGE)
1764 writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata);
1765 else if(seq->type==SEQ_MOVIE || seq->type==SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND)
1766 writestruct(wd, DATA, "StripElem", 1, strip->stripdata);
1773 /* new; meta stack too, even when its nasty restore code */
1774 for(ms= ed->metastack.first; ms; ms= ms->next) {
1775 writestruct(wd, DATA, "MetaStack", 1, ms);
1779 write_scriptlink(wd, &sce->scriptlink);
1781 if (sce->r.avicodecdata) {
1782 writestruct(wd, DATA, "AviCodecData", 1, sce->r.avicodecdata);
1783 if (sce->r.avicodecdata->lpFormat) writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat);
1784 if (sce->r.avicodecdata->lpParms) writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
1787 if (sce->r.qtcodecdata) {
1788 writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata);
1789 if (sce->r.qtcodecdata->cdParms) writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms);
1791 if (sce->r.ffcodecdata.properties) {
1792 IDP_WriteProperty(sce->r.ffcodecdata.properties, wd);
1795 /* writing dynamic list of TimeMarkers to the blend file */
1796 for(marker= sce->markers.first; marker; marker= marker->next)
1797 writestruct(wd, DATA, "TimeMarker", 1, marker);
1799 /* writing dynamic list of TransformOrientations to the blend file */
1800 for(ts = sce->transform_spaces.first; ts; ts = ts->next)
1801 writestruct(wd, DATA, "TransformOrientation", 1, ts);
1803 for(srl= sce->r.layers.first; srl; srl= srl->next)
1804 writestruct(wd, DATA, "SceneRenderLayer", 1, srl);
1807 writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree);
1808 write_nodetree(wd, sce->nodetree);
1813 /* flush helps the compression for undo-save */
1814 mywrite(wd, MYWRITE_FLUSH, 0);
1817 static void write_gpencils(WriteData *wd, ListBase *lb)
1824 for (gpd= lb->first; gpd; gpd= gpd->id.next) {
1825 /* write gpd data block to file */
1826 writestruct(wd, ID_GD, "bGPdata", 1, gpd);
1828 /* write grease-pencil layers to file */
1829 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
1830 writestruct(wd, DATA, "bGPDlayer", 1, gpl);
1832 /* write this layer's frames to file */
1833 for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
1834 writestruct(wd, DATA, "bGPDframe", 1, gpf);
1837 for (gps= gpf->strokes.first; gps; gps= gps->next) {
1838 writestruct(wd, DATA, "bGPDstroke", 1, gps);
1839 writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points);
1846 static void write_windowmanagers(WriteData *wd, ListBase *lb)
1848 wmWindowManager *wm;
1851 for(wm= lb->first; wm; wm= wm->id.next) {
1852 writestruct(wd, ID_WM, "wmWindowManager", 1, wm);
1854 for(win= wm->windows.first; win; win= win->next)
1855 writestruct(wd, DATA, "wmWindow", 1, win);
1859 static void write_region(WriteData *wd, ARegion *ar, int spacetype)
1861 writestruct(wd, DATA, "ARegion", 1, ar);
1863 if(ar->regiondata) {
1866 if(ar->regiontype==RGN_TYPE_WINDOW) {
1867 RegionView3D *rv3d= ar->regiondata;
1868 writestruct(wd, DATA, "RegionView3D", 1, rv3d);
1871 writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd);
1873 writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb);
1877 printf("regiondata write missing!\n");
1880 printf("regiondata write missing!\n");
1885 static void write_screens(WriteData *wd, ListBase *scrbase)
1896 /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
1897 writestruct(wd, ID_SCRN, "Screen", 1, sc);
1898 if (sc->id.properties)
1899 IDP_WriteProperty(sc->id.properties, wd);
1902 for(sv= sc->vertbase.first; sv; sv= sv->next)
1903 writestruct(wd, DATA, "ScrVert", 1, sv);
1905 for(se= sc->edgebase.first; se; se= se->next)
1906 writestruct(wd, DATA, "ScrEdge", 1, se);
1908 for(sa= sc->areabase.first; sa; sa= sa->next) {
1913 writestruct(wd, DATA, "ScrArea", 1, sa);
1915 for(ar= sa->regionbase.first; ar; ar= ar->next) {
1916 write_region(wd, ar, sa->spacetype);
1918 for(pa= ar->panels.first; pa; pa= pa->next)
1919 writestruct(wd, DATA, "Panel", 1, pa);
1922 /* space handler scriptlinks */
1923 write_scriptlink(wd, &sa->scriptlink);
1925 sl= sa->spacedata.first;
1927 for(ar= sl->regionbase.first; ar; ar= ar->next)
1928 write_region(wd, ar, sl->spacetype);
1930 if(sl->spacetype==SPACE_VIEW3D) {
1931 View3D *v3d= (View3D *) sl;
1932 writestruct(wd, DATA, "View3D", 1, v3d);
1933 if(v3d->bgpic) writestruct(wd, DATA, "BGpic", 1, v3d->bgpic);
1934 if(v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd);
1936 else if(sl->spacetype==SPACE_IPO) {
1937 SpaceIpo *sipo= (SpaceIpo *)sl;
1938 ListBase tmpGhosts = sipo->ghostCurves;
1940 /* temporarily disable ghost curves when saving */
1941 sipo->ghostCurves.first= sipo->ghostCurves.last= NULL;
1943 writestruct(wd, DATA, "SpaceIpo", 1, sl);
1944 if(sipo->ads) writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads);
1946 /* reenable ghost curves */
1947 sipo->ghostCurves= tmpGhosts;
1949 else if(sl->spacetype==SPACE_BUTS) {
1950 writestruct(wd, DATA, "SpaceButs", 1, sl);
1952 else if(sl->spacetype==SPACE_FILE) {
1953 writestruct(wd, DATA, "SpaceFile", 1, sl);
1955 else if(sl->spacetype==SPACE_SEQ) {
1956 writestruct(wd, DATA, "SpaceSeq", 1, sl);
1958 else if(sl->spacetype==SPACE_OUTLINER) {
1959 SpaceOops *so= (SpaceOops *)sl;
1961 writestruct(wd, DATA, "SpaceOops", 1, so);
1965 writestruct(wd, DATA, "TreeStore", 1, so->treestore);
1966 if(so->treestore->data)
1967 writestruct(wd, DATA, "TreeStoreElem", so->treestore->usedelem, so->treestore->data);
1970 else if(sl->spacetype==SPACE_IMAGE) {
1971 SpaceImage *sima= (SpaceImage *)sl;
1973 writestruct(wd, DATA, "SpaceImage", 1, sl);
1975 write_curvemapping(wd, sima->cumap);
1977 else if(sl->spacetype==SPACE_IMASEL) {
1978 writestruct(wd, DATA, "SpaceImaSel", 1, sl);
1980 else if(sl->spacetype==SPACE_TEXT) {
1981 writestruct(wd, DATA, "SpaceText", 1, sl);
1983 else if(sl->spacetype==SPACE_SCRIPT) {
1984 SpaceScript *sc = (SpaceScript*)sl;
1985 sc->but_refs = NULL;
1986 writestruct(wd, DATA, "SpaceScript", 1, sl);
1988 else if(sl->spacetype==SPACE_ACTION) {
1989 writestruct(wd, DATA, "SpaceAction", 1, sl);
1991 else if(sl->spacetype==SPACE_SOUND) {
1992 writestruct(wd, DATA, "SpaceSound", 1, sl);
1994 else if(sl->spacetype==SPACE_NLA){
1995 SpaceNla *snla= (SpaceNla *)sl;
1997 writestruct(wd, DATA, "SpaceNla", 1, snla);
1998 if(snla->ads) writestruct(wd, DATA, "bDopeSheet", 1, snla->ads);
2000 else if(sl->spacetype==SPACE_TIME){
2001 writestruct(wd, DATA, "SpaceTime", 1, sl);
2003 else if(sl->spacetype==SPACE_NODE){
2004 writestruct(wd, DATA, "SpaceNode", 1, sl);
2006 else if(sl->spacetype==SPACE_LOGIC){
2007 writestruct(wd, DATA, "SpaceLogic", 1, sl);
2009 else if(sl->spacetype==SPACE_CONSOLE) {
2010 writestruct(wd, DATA, "SpaceConsole", 1, sl);
2020 static void write_libraries(WriteData *wd, Main *main)
2022 ListBase *lbarray[30];
2024 int a, tot, foundone;
2026 for(; main; main= main->next) {
2028 a=tot= set_listbasepointers(main, lbarray);
2030 /* test: is lib being used */
2033 for(id= lbarray[tot]->first; id; id= id->next) {
2034 if(id->us>0 && (id->flag & LIB_EXTERN)) {
2043 writestruct(wd, ID_LI, "Library", 1, main->curlib);
2046 for(id= lbarray[a]->first; id; id= id->next) {
2047 if(id->us>0 && (id->flag & LIB_EXTERN)) {
2048 writestruct(wd, ID_ID, "ID", 1, id);
2056 static void write_bone(WriteData *wd, Bone* bone)
2060 // PATCH for upward compatibility after 2.37+ armature recode
2061 bone->size[0]= bone->size[1]= bone->size[2]= 1.0f;
2064 writestruct(wd, DATA, "Bone", 1, bone);
2067 cbone= bone->childbase.first;
2069 write_bone(wd, cbone);
2074 static void write_armatures(WriteData *wd, ListBase *idbase)
2081 if (arm->id.us>0 || wd->current) {
2082 writestruct(wd, ID_AR, "bArmature", 1, arm);
2083 if (arm->id.properties) IDP_WriteProperty(arm->id.properties, wd);
2086 bone= arm->bonebase.first;
2088 write_bone(wd, bone);
2095 /* flush helps the compression for undo-save */
2096 mywrite(wd, MYWRITE_FLUSH, 0);
2099 static void write_texts(WriteData *wd, ListBase *idbase)
2105 text= idbase->first;
2107 if ( (text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) text->flags &= ~TXT_ISEXT;
2110 writestruct(wd, ID_TXT, "Text", 1, text);
2111 if(text->name) writedata(wd, DATA, strlen(text->name)+1, text->name);
2112 if (text->id.properties) IDP_WriteProperty(text->id.properties, wd);
2114 if(!(text->flags & TXT_ISEXT)) {
2115 /* now write the text data, in two steps for optimization in the readfunction */
2116 tmp= text->lines.first;
2118 writestruct(wd, DATA, "TextLine", 1, tmp);
2122 tmp= text->lines.first;
2124 writedata(wd, DATA, tmp->len+1, tmp->line);
2129 mrk= text->markers.first;
2131 writestruct(wd, DATA, "TextMarker", 1, mrk);
2137 text= text->id.next;
2140 /* flush helps the compression for undo-save */
2141 mywrite(wd, MYWRITE_FLUSH, 0);
2144 static void write_sounds(WriteData *wd, ListBase *idbase)
2151 // set all samples to unsaved status
2153 sample = samples->first; // samples is a global defined in sound.c
2155 sample->flags |= SAMPLE_NEEDS_SAVE;
2156 sample = sample->id.next;
2159 sound= idbase->first;
2161 if(sound->id.us>0 || wd->current) {
2162 // do we need to save the packedfile as well ?
2163 sample = sound->sample;
2165 if (sample->flags & SAMPLE_NEEDS_SAVE) {
2166 sound->newpackedfile = sample->packedfile;
2167 sample->flags &= ~SAMPLE_NEEDS_SAVE;
2169 sound->newpackedfile = NULL;
2174 writestruct(wd, ID_SO, "bSound", 1, sound);
2175 if (sound->id.properties) IDP_WriteProperty(sound->id.properties, wd);
2177 if (sound->newpackedfile) {
2178 pf = sound->newpackedfile;
2179 writestruct(wd, DATA, "PackedFile", 1, pf);
2180 writedata(wd, DATA, pf->size, pf->data);
2184 sound->newpackedfile = sample->packedfile;
2187 sound= sound->id.next;
2190 /* flush helps the compression for undo-save */
2191 mywrite(wd, MYWRITE_FLUSH, 0);
2194 static void write_groups(WriteData *wd, ListBase *idbase)
2199 for(group= idbase->first; group; group= group->id.next) {
2200 if(group->id.us>0 || wd->current) {
2202 writestruct(wd, ID_GR, "Group", 1, group);
2203 if (group->id.properties) IDP_WriteProperty(group->id.properties, wd);
2205 go= group->gobject.first;
2207 writestruct(wd, DATA, "GroupObject", 1, go);
2214 static void write_nodetrees(WriteData *wd, ListBase *idbase)
2218 for(ntree=idbase->first; ntree; ntree= ntree->id.next) {
2219 if (ntree->id.us>0 || wd->current) {
2220 writestruct(wd, ID_NT, "bNodeTree", 1, ntree);
2221 write_nodetree(wd, ntree);
2223 if (ntree->id.properties) IDP_WriteProperty(ntree->id.properties, wd);
2225 if (ntree->adt) write_animdata(wd, ntree->adt);
2230 static void write_brushes(WriteData *wd, ListBase *idbase)
2235 for(brush=idbase->first; brush; brush= brush->id.next) {
2236 if(brush->id.us>0 || wd->current) {
2237 writestruct(wd, ID_BR, "Brush", 1, brush);
2238 if (brush->id.properties) IDP_WriteProperty(brush->id.properties, wd);
2239 for(a=0; a<MAX_MTEX; a++)
2241 writestruct(wd, DATA, "MTex", 1, brush->mtex[a]);
2244 write_curvemapping(wd, brush->curve);
2249 static void write_scripts(WriteData *wd, ListBase *idbase)
2253 for(script=idbase->first; script; script= script->id.next) {
2254 if(script->id.us>0 || wd->current) {
2255 writestruct(wd, ID_SCRIPT, "Script", 1, script);
2256 if (script->id.properties) IDP_WriteProperty(script->id.properties, wd);
2261 /* context is usually defined by WM, two cases where no WM is available:
2262 * - for forward compatibility, curscreen has to be saved
2263 * - for undofile, curscene needs to be saved */
2264 static void write_global(WriteData *wd, Main *mainvar)
2270 current_screen_compat(mainvar, &screen);
2272 /* XXX still remap G */
2273 fg.curscreen= screen;
2274 fg.curscene= screen->scene;
2275 fg.displaymode= G.displaymode;
2276 fg.winpos= G.winpos;
2277 fg.fileflags= (G.fileflags & ~G_FILE_NO_UI); // prevent to save this, is not good convention, and feature with concerns...
2280 sprintf(subvstr, "%4d", BLENDER_SUBVERSION);
2281 memcpy(fg.subvstr, subvstr, 4);
2283 fg.subversion= BLENDER_SUBVERSION;
2284 fg.minversion= BLENDER_MINVERSION;
2285 fg.minsubversion= BLENDER_MINSUBVERSION;
2286 fg.pads= 0; /* prevent mem checkers from complaining */
2287 writestruct(wd, GLOB, "FileGlobal", 1, &fg);
2290 /* if MemFile * there's filesave to memory */
2291 static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFile *current,
2292 int write_user_block, int write_flags)
2299 blo_split_main(&mainlist, mainvar);
2301 wd= bgnwrite(handle, compare, current, write_flags);
2303 sprintf(buf, "BLENDER%c%c%.3d", (sizeof(void*)==8)?'-':'_', (ENDIAN_ORDER==B_ENDIAN)?'V':'v', BLENDER_VERSION);
2304 mywrite(wd, buf, 12);
2306 write_renderinfo(wd, mainvar);
2307 write_global(wd, mainvar);
2309 /* no UI save in undo */
2311 write_windowmanagers(wd, &mainvar->wm);
2312 write_screens (wd, &mainvar->screen);
2314 write_scenes (wd, &mainvar->scene);
2315 write_curves (wd, &mainvar->curve);
2316 write_mballs (wd, &mainvar->mball);
2317 write_images (wd, &mainvar->image);
2318 write_cameras (wd, &mainvar->camera);
2319 write_lamps (wd, &mainvar->lamp);
2320 write_lattices (wd, &mainvar->latt);
2321 write_vfonts (wd, &mainvar->vfont);
2322 write_keys (wd, &mainvar->key);
2323 write_worlds (wd, &mainvar->world);
2324 write_texts (wd, &mainvar->text);
2325 write_sounds (wd, &mainvar->sound);
2326 write_groups (wd, &mainvar->group);
2327 write_armatures(wd, &mainvar->armature);
2328 write_actions (wd, &mainvar->action);
2329 write_objects (wd, &mainvar->object, (current != NULL));
2330 write_materials(wd, &mainvar->mat);
2331 write_textures (wd, &mainvar->tex);
2332 write_meshs (wd, &mainvar->mesh);
2333 write_particlesettings(wd, &mainvar->particle);
2334 write_nodetrees(wd, &mainvar->nodetree);
2335 write_brushes (wd, &mainvar->brush);
2336 write_scripts (wd, &mainvar->script);
2337 write_gpencils (wd, &mainvar->gpencil);
2339 write_libraries(wd, mainvar->next); /* no library save in undo */
2341 if (write_user_block) {
2345 /* dna as last, because (to be implemented) test for which structs are written */
2346 writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data);
2349 memset(&bhead, 0, sizeof(BHead));
2351 mywrite(wd, &bhead, sizeof(BHead));
2353 blo_join_main(&mainlist);
2355 return endwrite(wd);
2358 /* return: success (1) */
2359 int BLO_write_file(Main *mainvar, char *dir, int write_flags, ReportList *reports)
2361 char userfilename[FILE_MAXDIR+FILE_MAXFILE];
2362 char tempname[FILE_MAXDIR+FILE_MAXFILE];
2363 int file, err, write_user_block;
2365 sprintf(tempname, "%s@", dir);
2367 file = open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
2369 BKE_report(reports, RPT_ERROR, "Unable to open file for writing.");
2373 BLI_make_file_string(G.sce, userfilename, BLI_gethome(), ".B25.blend");
2374 write_user_block= BLI_streq(dir, userfilename);
2376 err= write_file_handle(mainvar, file, NULL,NULL, write_user_block, write_flags);
2380 if(write_flags & G_FILE_COMPRESS)
2382 // compressed files have the same ending as regular files... only from 2.4!!!
2384 int ret = BLI_gzip(tempname, dir);
2387 BKE_report(reports, RPT_ERROR, "Failed opening .gz file.");
2391 BKE_report(reports, RPT_ERROR, "Failed opening .blend file for compression.");
2396 if(BLI_rename(tempname, dir) != 0) {
2397 BKE_report(reports, RPT_ERROR, "Can't change old file. File saved with @");
2403 BKE_report(reports, RPT_ERROR, strerror(errno));
2412 /* return: success (1) */
2413 int BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags, ReportList *reports)
2417 err= write_file_handle(mainvar, 0, compare, current, 0, write_flags);
2419 if(err==0) return 1;
2424 /* Runtime writing */
2427 #define PATHSEPERATOR "\\"
2429 #define PATHSEPERATOR "/"
2432 static char *get_runtime_path(char *exename) {
2433 char *installpath= get_install_dir();
2438 char *path= MEM_mallocN(strlen(installpath)+strlen(PATHSEPERATOR)+strlen(exename)+1, "runtimepath");
2441 MEM_freeN(installpath);
2445 strcpy(path, installpath);
2446 strcat(path, PATHSEPERATOR);
2447 strcat(path, exename);
2449 MEM_freeN(installpath);
2457 static int recursive_copy_runtime(char *outname, char *exename, ReportList *reports)
2459 char *runtime = get_runtime_path(exename);
2460 char command[2 * (FILE_MAXDIR+FILE_MAXFILE) + 32];
2461 int progfd = -1, error= 0;
2464 BKE_report(reports, RPT_ERROR, "Unable to find runtime");
2468 //printf("runtimepath %s\n", runtime);
2470 progfd= open(runtime, O_BINARY|O_RDONLY, 0);
2472 BKE_report(reports, RPT_ERROR, "Unable to find runtime");
2477 sprintf(command, "/bin/cp -R \"%s\" \"%s\"", runtime, outname);
2478 //printf("command %s\n", command);
2479 if (system(command) == -1) {
2480 BKE_report(reports, RPT_ERROR, "Couldn't copy runtime");
2493 int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports)
2495 char gamename[FILE_MAXDIR+FILE_MAXFILE];
2496 int outfd = -1, error= 0;
2498 // remove existing file / bundle
2499 //printf("Delete file %s\n", file);
2500 BLI_delete(file, 0, TRUE);
2502 if (!recursive_copy_runtime(file, exename, reports)) {
2507 strcpy(gamename, file);
2508 strcat(gamename, "/Contents/Resources/game.blend");
2509 //printf("gamename %s\n", gamename);
2510 outfd= open(gamename, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777);
2513 write_file_handle(mainvar, outfd, NULL,NULL, 0, G.fileflags);
2515 if (write(outfd, " ", 1) != 1) {
2516 BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
2521 BKE_report(reports, RPT_ERROR, "Unable to open blenderfile.");
2529 BKE_reports_prepend(reports, "Unable to make runtime: ");
2533 #else /* !__APPLE__ */
2535 static int handle_append_runtime(int handle, char *exename, ReportList *reports)
2537 char *runtime= get_runtime_path(exename);
2538 unsigned char buf[1024];
2539 int count, progfd= -1, error= 0;
2541 if (!BLI_exists(runtime)) {
2542 BKE_report(reports, RPT_ERROR, "Unable to find runtime.");
2547 progfd= open(runtime, O_BINARY|O_RDONLY, 0);
2549 BKE_report(reports, RPT_ERROR, "Unable to find runtime.@");
2554 while ((count= read(progfd, buf, sizeof(buf)))>0) {
2555 if (write(handle, buf, count)!=count) {
2556 BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
2571 static int handle_write_msb_int(int handle, int i)
2573 unsigned char buf[4];
2574 buf[0]= (i>>24)&0xFF;
2575 buf[1]= (i>>16)&0xFF;
2576 buf[2]= (i>>8)&0xFF;
2577 buf[3]= (i>>0)&0xFF;
2579 return (write(handle, buf, 4)==4);
2582 int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports)
2584 int outfd= open(file, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777);
2585 int datastart, error= 0;
2588 BKE_report(reports, RPT_ERROR, "Unable to open output file.");
2592 if (!handle_append_runtime(outfd, exename, reports)) {
2597 datastart= lseek(outfd, 0, SEEK_CUR);
2599 write_file_handle(mainvar, outfd, NULL,NULL, 0, G.fileflags);
2601 if (!handle_write_msb_int(outfd, datastart) || (write(outfd, "BRUNTIME", 8)!=8)) {
2602 BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
2611 BKE_reports_prepend(reports, "Unable to make runtime: ");
2615 #endif /* !__APPLE__ */