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.
23 * Contributor(s): Blender Foundation 2007
25 * ***** END GPL LICENSE BLOCK *****
28 /* placed up here because of crappy
35 #include <windows.h> /* need to include windows.h so _WIN32_IE is defined */
37 #define _WIN32_IE 0x0400 /* minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already */
39 #include <shlobj.h> /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff because 'near' is disabled through BLI_windstuff */
40 #include "BLI_winstuff.h"
41 #include <process.h> /* getpid */
43 #include <unistd.h> /* getpid */
46 #include "MEM_guardedalloc.h"
47 #include "MEM_CacheLimiterC-Api.h"
49 #include "BLI_blenlib.h"
50 #include "BLI_linklist.h"
52 #include "DNA_object_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_userdef_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_screen_types.h"
57 #include "DNA_windowmanager_types.h"
59 #include "BKE_blender.h"
60 #include "BKE_DerivedMesh.h"
61 #include "BKE_exotic.h"
63 #include "BKE_global.h"
64 #include "BKE_library.h"
66 #include "BKE_packedFile.h"
67 #include "BKE_texture.h"
68 #include "BKE_utildefines.h"
71 #include "BKE_verse.h"
74 #include "BLO_readfile.h"
75 #include "BLO_writefile.h"
77 // XXX #include "BPY_extern.h"
79 //XXX #include "datatoc.h"
87 /* define for setting colors in theme below */
88 #define SETCOL(col, r, g, b, a) col[0]=r; col[1]=g; col[2]= b; col[3]= a;
90 /* patching UserDef struct and Themes */
91 static void init_userdef_themes(void)
94 // XXX BIF_InitTheme(); // sets default again
98 /* the UserDef struct is not corrected with do_versions() .... ugh! */
99 if(U.wheellinescroll == 0) U.wheellinescroll = 3;
100 if(U.menuthreshold1==0) {
104 if(U.tb_leftmouse==0) {
108 if(U.mixbufsize==0) U.mixbufsize= 2048;
109 if (BLI_streq(U.tempdir, "/")) {
110 char *tmp= getenv("TEMP");
112 strcpy(U.tempdir, tmp?tmp:"/tmp/");
114 if (U.savetime <= 0) {
116 // XXX error(".B.blend is buggy, please consider removing it.\n");
118 /* transform widget settings */
119 if(U.tw_hotspot==0) {
121 U.tw_size= 20; // percentage of window size
122 U.tw_handlesize= 16; // percentage of widget radius
124 if(U.pad_rot_angle==0)
127 if(U.flag & USER_CUSTOM_RANGE)
128 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
130 if (G.main->versionfile <= 191) {
131 strcpy(U.plugtexdir, U.textudir);
132 strcpy(U.sounddir, "/");
135 /* patch to set Dupli Armature */
136 if (G.main->versionfile < 220) {
137 U.dupflag |= USER_DUP_ARM;
140 /* userdef new option */
141 if (G.main->versionfile <= 222) {
142 U.vrmlflag= USER_VRML_LAYERS;
145 /* added seam, normal color, undo */
146 if (G.main->versionfile <= 234) {
149 U.uiflag |= USER_GLOBALUNDO;
150 if (U.undosteps==0) U.undosteps=32;
152 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
153 /* check for alpha==0 is safe, then color was never set */
154 if(btheme->tv3d.edge_seam[3]==0) {
155 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
157 if(btheme->tv3d.normal[3]==0) {
158 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
160 if(btheme->tv3d.face_dot[3]==0) {
161 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
162 btheme->tv3d.facedot_size= 4;
166 if (G.main->versionfile <= 235) {
167 /* illegal combo... */
168 if (U.flag & USER_LMOUSESELECT)
169 U.flag &= ~USER_TWOBUTTONMOUSE;
171 if (G.main->versionfile <= 236) {
174 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
175 /* check for alpha==0 is safe, then color was never set */
176 if(btheme->ttime.back[3]==0) {
177 btheme->ttime = btheme->tsnd; // copy from sound
179 if(btheme->text.syntaxn[3]==0) {
180 SETCOL(btheme->text.syntaxn, 0, 0, 200, 255); /* Numbers Blue*/
181 SETCOL(btheme->text.syntaxl, 100, 0, 0, 255); /* Strings red */
182 SETCOL(btheme->text.syntaxc, 0, 100, 50, 255); /* Comments greenish */
183 SETCOL(btheme->text.syntaxv, 95, 95, 0, 255); /* Special */
184 SETCOL(btheme->text.syntaxb, 128, 0, 80, 255); /* Builtin, red-purple */
188 if (G.main->versionfile <= 237) {
191 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
192 /* check for alpha==0 is safe, then color was never set */
193 if(btheme->tv3d.bone_solid[3]==0) {
194 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
195 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
199 if (G.main->versionfile <= 238) {
202 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
203 /* check for alpha==0 is safe, then color was never set */
204 if(btheme->tnla.strip[3]==0) {
205 SETCOL(btheme->tnla.strip_select, 0xff, 0xff, 0xaa, 255);
206 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
210 if (G.main->versionfile <= 239) {
213 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
214 /* Lamp theme, check for alpha==0 is safe, then color was never set */
215 if(btheme->tv3d.lamp[3]==0) {
216 SETCOL(btheme->tv3d.lamp, 0, 0, 0, 40);
217 /* TEMPORAL, remove me! (ton) */
218 U.uiflag |= USER_PLAINMENUS;
221 /* check for text field selection highlight, set it to text editor highlight by default */
222 if(btheme->tui.textfield_hi[3]==0) {
223 SETCOL(btheme->tui.textfield_hi,
224 btheme->text.shade2[0],
225 btheme->text.shade2[1],
226 btheme->text.shade2[2],
230 if(U.obcenter_dia==0) U.obcenter_dia= 6;
232 if (G.main->versionfile <= 241) {
234 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
235 /* Node editor theme, check for alpha==0 is safe, then color was never set */
236 if(btheme->tnode.syntaxn[3]==0) {
237 /* re-uses syntax color storage */
238 btheme->tnode= btheme->tv3d;
239 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
240 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255); /* TH_NODE, backdrop */
241 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255); /* in/output */
242 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255); /* operator */
243 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255); /* generator */
244 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255); /* group */
246 /* Group theme colors */
247 if(btheme->tv3d.group[3]==0) {
248 SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
249 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
251 /* Sequence editor theme*/
252 if(btheme->tseq.movie[3]==0) {
253 SETCOL(btheme->tseq.movie, 81, 105, 135, 255);
254 SETCOL(btheme->tseq.image, 109, 88, 129, 255);
255 SETCOL(btheme->tseq.scene, 78, 152, 62, 255);
256 SETCOL(btheme->tseq.audio, 46, 143, 143, 255);
257 SETCOL(btheme->tseq.effect, 169, 84, 124, 255);
258 SETCOL(btheme->tseq.plugin, 126, 126, 80, 255);
259 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
260 SETCOL(btheme->tseq.meta, 109, 145, 131, 255);
262 if(!(btheme->tui.iconfile)) {
263 BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
267 /* set defaults for 3D View rotating axis indicator */
268 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
269 if (U.rvisize == 0) {
272 U.uiflag |= USER_SHOW_ROTVIEWICON;
276 if (G.main->versionfile <= 242) {
279 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
280 /* long keyframe color */
281 /* check for alpha==0 is safe, then color was never set */
282 if(btheme->tact.strip[3]==0) {
283 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
284 SETCOL(btheme->tact.strip_select, 0xff, 0xff, 0xaa, 204);
285 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
288 /* IPO-Editor - Vertex Size*/
289 if(btheme->tipo.vertex_size == 0) {
290 btheme->tipo.vertex_size= 3;
294 if (G.main->versionfile <= 243) {
295 /* set default number of recently-used files (if not set) */
296 if (U.recent_files == 0) U.recent_files = 10;
298 if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
300 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
301 SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
303 if(U.coba_weight.tot==0)
304 init_colorband(&U.coba_weight, 1);
306 if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
308 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
309 /* these should all use the same colour */
310 SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
311 SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
312 SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
313 SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
314 SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
315 SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
316 SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
320 /* GL Texture Garbage Collection (variable abused above!) */
321 if (U.textimeout == 0) {
322 U.texcollectrate = 60;
325 if (U.memcachelimit <= 0) {
326 U.memcachelimit = 32;
328 if (U.frameserverport == 0) {
329 U.frameserverport = 8080;
332 MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
334 /* funny name, but it is GE stuff, moves userdef stuff to engine */
335 // XXX space_set_commmandline_options();
336 /* this timer uses U */
337 // XXX reset_autosave();
340 if(strlen(U.versemaster)<1) {
341 strcpy(U.versemaster, "master.uni-verse.org");
343 if(strlen(U.verseuser)<1) {
344 // XXX char *name = verse_client_name();
345 // XXX strcpy(U.verseuser, name);
346 // XXX MEM_freeN(name);
352 /* To be able to read files without windows closing, opening, moving
353 we try to prepare for worst case:
354 - active window gets active screen from file
355 - restoring the screens from non-active windows
356 Best case is all screens match, in that case they get assigned to proper window
358 static void wm_window_match_init(bContext *C, ListBase *wmlist)
360 wmWindowManager *wm= G.main->wm.first;
364 G.main->wm.first= G.main->wm.last= NULL;
368 if(G.fileflags & G_FILE_NO_UI) return;
370 /* we take apart the used screens from non-active window */
371 for(win= wm->windows.first; win; win= win->next) {
372 BLI_strncpy(win->screenname, win->screen->id.name, MAX_ID_NAME);
374 BLI_remlink(&G.main->screen, win->screen);
375 //BLI_addtail(screenbase, win->screen);
380 /* match old WM with new, 4 cases:
381 1- no current wm, no read wm: make new default
382 2- no current wm, but read wm: that's OK, do nothing
383 3- current wm, but not in file: try match screen names
384 4- current wm, and wm in file: try match ghostwin
387 static void wm_window_match_do(bContext *C, ListBase *wmlist)
389 wmWindowManager *oldwm, *wm;
390 wmWindow *oldwin, *win;
393 if(wmlist->first==NULL) {
394 if(G.main->wm.first); /* nothing todo */
401 /* we've read file without wm... */
402 if(G.main->wm.first==NULL) {
403 /* match oldwm to new dbase, only old files */
405 for(wm= wmlist->first; wm; wm= wm->id.next) {
406 for(win= wm->windows.first; win; win= win->next) {
407 win->screen= (bScreen *)find_id("SR", win->screenname);
408 if(win->screen->winid==0) {
409 if(win->screen==NULL)
410 win->screen= C->screen; /* active screen */
412 win->screen->winid= win->winid;
416 /* XXX still solve, case where multiple windows open */
421 /* what if old was 3, and loaded 1? */
422 /* this code could move to setup_appdata */
423 oldwm= wmlist->first;
424 wm= G.main->wm.first;
425 /* only first wm in list has ghostwins */
426 for(win= wm->windows.first; win; win= win->next) {
427 for(oldwin= oldwm->windows.first; oldwin; oldwin= oldwin->next) {
429 if(oldwin->winid == win->winid ) {
430 win->ghostwin= oldwin->ghostwin;
431 oldwin->ghostwin= NULL;
435 wm_close_and_free_all(C, wmlist);
441 static void verse_unsub(void)
443 extern ListBase session_list;
444 struct VerseSession *session;
447 session = session_list.first;
449 vnode = session->nodes.lb.first;
451 switch(vnode->type) {
453 //XXX unsubscribe_from_obj_node(vnode);
456 //XXX unsubscribe_from_geom_node(vnode);
459 //XXX unsubscribe_from_bitmap_node(vnode);
464 session = session->next;
469 void WM_read_file(bContext *C, char *name)
474 verse_unsub(); /* bad call here (ton) */
477 /* first try to append data from exotic file formats... */
478 /* it throws error box when file doesnt exist and returns -1 */
479 retval= BKE_read_exotic(name);
481 /* we didn't succeed, now try to read Blender file */
485 /* put aside screens to match with persistant windows later */
486 wm_window_match_init(C, &wmbase);
488 retval= BKE_read_file(C, name, NULL);
490 /* match the read WM with current WM */
491 wm_window_match_do(C, &wmbase);
493 // XXX mainwindow_set_filename_to_title(G.main->name);
494 // countall(); <-- will be listener
495 // XXX sound_initialize_sounds();
497 // winqueue_break= 1; /* leave queues everywhere */
499 // XXX if(retval==2) init_userdef_themes(); // in case a userdef is read from regular .blend
501 if (retval!=0) G.relbase_valid = 1;
503 // XXX undo_editmode_clear();
505 BKE_write_undo(C, "original"); /* save current state */
507 // refresh_interface_font();
509 // else if(retval==1)
510 // XXX BIF_undo_push("Import file");
513 static void outliner_242_patch(void)
518 if(G.curscreen==NULL) return;
519 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
520 SpaceLink *sl= sa->spacedata.first;
521 for(; sl; sl= sl->next) {
522 if(sl->spacetype==SPACE_OOPS) {
523 SpaceOops *soops= (SpaceOops *)sl;
524 if(soops->type!=SO_OUTLINER) {
525 soops->type= SO_OUTLINER;
526 // XXX init_v2d_oops(sa, soops);
531 G.fileflags |= G_FILE_GAME_MAT;
534 /* called on startup, (context entirely filled with NULLs) */
535 /* or called for 'Erase All' */
536 int WM_read_homefile(bContext *C, int from_memory)
539 char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
540 char *home= BLI_gethome();
545 free_ttfont(); /* still weird... what does it here? */
548 if (!from_memory) BLI_make_file_string(G.sce, tstr, home, ".B.blend");
549 strcpy(scestr, G.sce); /* temporary store */
551 /* prevent loading no UI */
552 G.fileflags &= ~G_FILE_NO_UI;
554 /* put aside screens to match with persistant windows later */
555 wm_window_match_init(C, &wmbase);
557 if (!from_memory && BLI_exists(tstr)) {
558 success = BKE_read_file(C, tstr, NULL);
560 extern int datatoc_B_blend_size;
561 extern char datatoc_B_blend[];
562 success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL);
563 /* outliner patch for 2.42 .b.blend */
564 outliner_242_patch();
567 /* match the read WM with current WM */
568 wm_window_match_do(C, &wmbase);
570 strcpy(G.sce, scestr); /* restore */
572 init_userdef_themes();
575 G.save_over = 0; // start with save preference untitled.blend
576 G.fileflags &= ~G_FILE_AUTOPLAY; /* disable autoplay in .B.blend... */
577 // mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender"
580 // XXX read_languagefile();
583 // refresh_interface_font();
585 // undo_editmode_clear();
587 BKE_write_undo(C, "original"); /* save current state */
593 static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
598 char savedir[FILE_MAXDIR];
601 sprintf(pidstr, "%d.blend", abs(getpid()));
604 if (!BLI_exists(U.tempdir)) {
605 BLI_strncpy(subdir, "autosave", sizeof(subdir));
606 BLI_make_file_string("/", savedir, BLI_gethome(), subdir);
608 /* create a new autosave dir
609 * function already checks for existence or not */
610 BLI_recurdir_fileops(savedir);
612 BLI_make_file_string("/", buf, savedir, pidstr);
617 BLI_make_file_string("/", buf, U.tempdir, pidstr);
620 void WM_read_autosavefile(bContext *C)
622 char tstr[FILE_MAX], scestr[FILE_MAX];
625 BLI_strncpy(scestr, G.sce, FILE_MAX); /* temporal store */
627 get_autosave_location(tstr);
629 save_over = G.save_over;
630 BKE_read_file(C, tstr, NULL);
631 G.save_over = save_over;
632 BLI_strncpy(G.sce, scestr, FILE_MAX);
638 char name[FILE_MAX], filename[FILE_MAX];
640 struct RecentFile *recent;
644 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
645 lines= BLI_read_file_as_lines(name);
647 G.recent_files.first = G.recent_files.last = NULL;
649 /* read list of recent opend files from .Blog to memory */
650 for (l= lines, num= 0; l && (num<U.recent_files); l= l->next, num++) {
652 if (!BLI_streq(line, "")) {
656 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
657 BLI_addtail(&(G.recent_files), recent);
658 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(line)+1), "name of file");
659 recent->filename[0] = '\0';
661 strcpy(recent->filename, line);
666 BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
668 BLI_free_file_lines(lines);
671 /* Add the drive names to the listing */
674 char folder[MAX_PATH];
678 tmp= GetLogicalDrives();
680 for (i=2; i < 26; i++) {
687 // XX fsmenu_insert_entry(tmps, 0, 0);
691 /* Adding Desktop and My Documents */
692 // XXX fsmenu_append_separator();
694 SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0);
695 // XXX fsmenu_insert_entry(folder, 0, 0);
696 SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0);
697 // XXX fsmenu_insert_entry(folder, 0, 0);
699 // XXX fsmenu_append_separator();
703 BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
704 lines= BLI_read_file_as_lines(name);
706 for (l= lines; l; l= l->next) {
709 if (!BLI_streq(line, "")) {
710 // XXX fsmenu_insert_entry(line, 0, 1);
714 // XXX fsmenu_append_separator();
716 /* add last saved file */
717 BLI_split_dirfile(G.sce, name, filename); /* G.sce shouldn't be relative */
719 // XXX fsmenu_insert_entry(name, 0, 0);
721 BLI_free_file_lines(lines);
724 static void writeBlog(void)
726 struct RecentFile *recent, *next_recent;
727 char name[FILE_MAXDIR+FILE_MAXFILE];
731 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
733 recent = G.recent_files.first;
734 /* refresh .Blog of recent opened files, when current file was changed */
735 if(!(recent) || (strcmp(recent->filename, G.sce)!=0)) {
736 fp= fopen(name, "w");
738 /* add current file to the beginning of list */
739 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
740 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(G.sce)+1), "name of file");
741 recent->filename[0] = '\0';
742 strcpy(recent->filename, G.sce);
743 BLI_addhead(&(G.recent_files), recent);
744 /* write current file to .Blog */
745 fprintf(fp, "%s\n", recent->filename);
746 recent = recent->next;
748 /* write rest of recent opened files to .Blog */
749 while((i<U.recent_files) && (recent)){
750 /* this prevents to have duplicities in list */
751 if (strcmp(recent->filename, G.sce)!=0) {
752 fprintf(fp, "%s\n", recent->filename);
753 recent = recent->next;
756 next_recent = recent->next;
757 MEM_freeN(recent->filename);
758 BLI_freelinkN(&(G.recent_files), recent);
759 recent = next_recent;
768 static void do_history(char *name)
770 char tempname1[FILE_MAXDIR+FILE_MAXFILE], tempname2[FILE_MAXDIR+FILE_MAXFILE];
771 int hisnr= U.versions;
773 if(U.versions==0) return;
774 if(strlen(name)<2) return;
777 sprintf(tempname1, "%s%d", name, hisnr-1);
778 sprintf(tempname2, "%s%d", name, hisnr);
780 // if(BLI_rename(tempname1, tempname2))
781 // XXX error("Unable to make version backup");
786 /* is needed when hisnr==1 */
787 sprintf(tempname1, "%s%d", name, hisnr);
789 // if(BLI_rename(name, tempname1))
790 // XXX error("Unable to make version backup");
793 void WM_write_file(bContext *C, char *target)
800 len = strlen(target);
802 if (len == 0) return;
803 if (len >= FILE_MAX) {
804 // XXX error("Path too long, cannot save");
808 /* send the OnSave event */
809 // XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&C->scene->id, SCRIPT_ONSAVE);
811 for (li= G.main->library.first; li; li= li->id.next) {
812 if (BLI_streq(li->name, target)) {
813 // XXX error("Cannot overwrite used library");
818 if (!BLO_has_bfile_extension(target) && (len+6 < FILE_MAX)) {
819 sprintf(di, "%s.blend", target);
824 if (BLI_exists(di)) {
825 // XXX if(!saveover(di))
830 // XXX exit_editmode(0); /* 0 = no free data */
832 if (G.fileflags & G_AUTOPACK) {
836 // XXX waitcursor(1); // exit_editmode sets cursor too
840 /* we use the UserDef to define compression flag */
841 writeflags= G.fileflags & ~G_FILE_COMPRESS;
842 if(U.flag & USER_FILECOMPRESS)
843 writeflags |= G_FILE_COMPRESS;
845 if (BLO_write_file(C, di, writeflags, &err)) {
848 strcpy(G.main->name, di); /* is guaranteed current file */
850 // XXX mainwindow_set_filename_to_title(G.main->name);
856 // XXX error("%s", err);
859 // XXX waitcursor(0);
863 int WM_write_homefile(bContext *C, wmOperator *op)
865 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
868 BLI_make_file_string("/", tstr, BLI_gethome(), ".B.blend");
870 /* force save as regular blend file */
871 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
872 BLO_write_file(C, tstr, write_flags, &err);
877 void WM_write_autosave(bContext *C)
879 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
882 get_autosave_location(tstr);
884 /* force save as regular blend file */
885 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
886 BLO_write_file(C, tstr, write_flags, &err);
889 /* if global undo; remove tempsave, otherwise rename */
890 void delete_autosave(void)
892 char tstr[FILE_MAXDIR+FILE_MAXFILE];
894 get_autosave_location(tstr);
896 if (BLI_exists(tstr)) {
897 char str[FILE_MAXDIR+FILE_MAXFILE];
898 BLI_make_file_string("/", str, U.tempdir, "quit.blend");
900 if(U.uiflag & USER_GLOBALUNDO) BLI_delete(tstr, 0, 0);
901 else BLI_rename(tstr, str);