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 #include "ED_datafiles.h"
78 #include "ED_screen.h"
80 #include "UI_interface.h"
82 // XXX #include "BPY_extern.h"
90 /* define for setting colors in theme below */
91 #define SETCOL(col, r, g, b, a) col[0]=r; col[1]=g; col[2]= b; col[3]= a;
93 /* patching UserDef struct and Themes */
94 static void init_userdef_themes(void)
96 // sets themes, fonts, .. from userdef
101 /* the UserDef struct is not corrected with do_versions() .... ugh! */
102 if(U.wheellinescroll == 0) U.wheellinescroll = 3;
103 if(U.menuthreshold1==0) {
107 if(U.tb_leftmouse==0) {
111 if(U.mixbufsize==0) U.mixbufsize= 2048;
112 if (BLI_streq(U.tempdir, "/")) {
113 char *tmp= getenv("TEMP");
115 strcpy(U.tempdir, tmp?tmp:"/tmp/");
117 if (U.savetime <= 0) {
119 // XXX error(".B.blend is buggy, please consider removing it.\n");
121 /* transform widget settings */
122 if(U.tw_hotspot==0) {
124 U.tw_size= 20; // percentage of window size
125 U.tw_handlesize= 16; // percentage of widget radius
127 if(U.pad_rot_angle==0)
130 if(U.flag & USER_CUSTOM_RANGE)
131 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
133 if (G.main->versionfile <= 191) {
134 strcpy(U.plugtexdir, U.textudir);
135 strcpy(U.sounddir, "/");
138 /* patch to set Dupli Armature */
139 if (G.main->versionfile < 220) {
140 U.dupflag |= USER_DUP_ARM;
143 /* userdef new option */
144 if (G.main->versionfile <= 222) {
145 U.vrmlflag= USER_VRML_LAYERS;
148 /* added seam, normal color, undo */
149 if (G.main->versionfile <= 234) {
152 U.uiflag |= USER_GLOBALUNDO;
153 if (U.undosteps==0) U.undosteps=32;
155 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
156 /* check for alpha==0 is safe, then color was never set */
157 if(btheme->tv3d.edge_seam[3]==0) {
158 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
160 if(btheme->tv3d.normal[3]==0) {
161 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
163 if(btheme->tv3d.face_dot[3]==0) {
164 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
165 btheme->tv3d.facedot_size= 4;
169 if (G.main->versionfile <= 235) {
170 /* illegal combo... */
171 if (U.flag & USER_LMOUSESELECT)
172 U.flag &= ~USER_TWOBUTTONMOUSE;
174 if (G.main->versionfile <= 236) {
177 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
178 /* check for alpha==0 is safe, then color was never set */
179 if(btheme->ttime.back[3]==0) {
180 btheme->ttime = btheme->tsnd; // copy from sound
182 if(btheme->text.syntaxn[3]==0) {
183 SETCOL(btheme->text.syntaxn, 0, 0, 200, 255); /* Numbers Blue*/
184 SETCOL(btheme->text.syntaxl, 100, 0, 0, 255); /* Strings red */
185 SETCOL(btheme->text.syntaxc, 0, 100, 50, 255); /* Comments greenish */
186 SETCOL(btheme->text.syntaxv, 95, 95, 0, 255); /* Special */
187 SETCOL(btheme->text.syntaxb, 128, 0, 80, 255); /* Builtin, red-purple */
191 if (G.main->versionfile <= 237) {
194 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
195 /* check for alpha==0 is safe, then color was never set */
196 if(btheme->tv3d.bone_solid[3]==0) {
197 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
198 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
202 if (G.main->versionfile <= 238) {
205 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
206 /* check for alpha==0 is safe, then color was never set */
207 if(btheme->tnla.strip[3]==0) {
208 SETCOL(btheme->tnla.strip_select, 0xff, 0xff, 0xaa, 255);
209 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
213 if (G.main->versionfile <= 239) {
216 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
217 /* Lamp theme, check for alpha==0 is safe, then color was never set */
218 if(btheme->tv3d.lamp[3]==0) {
219 SETCOL(btheme->tv3d.lamp, 0, 0, 0, 40);
220 /* TEMPORAL, remove me! (ton) */
221 U.uiflag |= USER_PLAINMENUS;
224 /* check for text field selection highlight, set it to text editor highlight by default */
225 if(btheme->tui.textfield_hi[3]==0) {
226 SETCOL(btheme->tui.textfield_hi,
227 btheme->text.shade2[0],
228 btheme->text.shade2[1],
229 btheme->text.shade2[2],
233 if(U.obcenter_dia==0) U.obcenter_dia= 6;
235 if (G.main->versionfile <= 241) {
237 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
238 /* Node editor theme, check for alpha==0 is safe, then color was never set */
239 if(btheme->tnode.syntaxn[3]==0) {
240 /* re-uses syntax color storage */
241 btheme->tnode= btheme->tv3d;
242 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
243 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255); /* TH_NODE, backdrop */
244 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255); /* in/output */
245 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255); /* operator */
246 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255); /* generator */
247 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255); /* group */
249 /* Group theme colors */
250 if(btheme->tv3d.group[3]==0) {
251 SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
252 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
254 /* Sequence editor theme*/
255 if(btheme->tseq.movie[3]==0) {
256 SETCOL(btheme->tseq.movie, 81, 105, 135, 255);
257 SETCOL(btheme->tseq.image, 109, 88, 129, 255);
258 SETCOL(btheme->tseq.scene, 78, 152, 62, 255);
259 SETCOL(btheme->tseq.audio, 46, 143, 143, 255);
260 SETCOL(btheme->tseq.effect, 169, 84, 124, 255);
261 SETCOL(btheme->tseq.plugin, 126, 126, 80, 255);
262 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
263 SETCOL(btheme->tseq.meta, 109, 145, 131, 255);
265 if(!(btheme->tui.iconfile)) {
266 BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
270 /* set defaults for 3D View rotating axis indicator */
271 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
272 if (U.rvisize == 0) {
275 U.uiflag |= USER_SHOW_ROTVIEWICON;
279 if (G.main->versionfile <= 242) {
282 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
283 /* long keyframe color */
284 /* check for alpha==0 is safe, then color was never set */
285 if(btheme->tact.strip[3]==0) {
286 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
287 SETCOL(btheme->tact.strip_select, 0xff, 0xff, 0xaa, 204);
288 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
291 /* IPO-Editor - Vertex Size*/
292 if(btheme->tipo.vertex_size == 0) {
293 btheme->tipo.vertex_size= 3;
297 if (G.main->versionfile <= 243) {
298 /* set default number of recently-used files (if not set) */
299 if (U.recent_files == 0) U.recent_files = 10;
301 if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
303 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
304 SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
306 if(U.coba_weight.tot==0)
307 init_colorband(&U.coba_weight, 1);
309 if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
311 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
312 /* these should all use the same colour */
313 SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
314 SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
315 SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
316 SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
317 SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
318 SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
319 SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
323 /* GL Texture Garbage Collection (variable abused above!) */
324 if (U.textimeout == 0) {
325 U.texcollectrate = 60;
328 if (U.memcachelimit <= 0) {
329 U.memcachelimit = 32;
331 if (U.frameserverport == 0) {
332 U.frameserverport = 8080;
335 MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
337 /* funny name, but it is GE stuff, moves userdef stuff to engine */
338 // XXX space_set_commmandline_options();
339 /* this timer uses U */
340 // XXX reset_autosave();
343 if(strlen(U.versemaster)<1) {
344 strcpy(U.versemaster, "master.uni-verse.org");
346 if(strlen(U.verseuser)<1) {
347 // XXX char *name = verse_client_name();
348 // XXX strcpy(U.verseuser, name);
349 // XXX MEM_freeN(name);
355 /* To be able to read files without windows closing, opening, moving
356 we try to prepare for worst case:
357 - active window gets active screen from file
358 - restoring the screens from non-active windows
359 Best case is all screens match, in that case they get assigned to proper window
361 static void wm_window_match_init(bContext *C, ListBase *wmlist)
363 wmWindowManager *wm= G.main->wm.first;
367 G.main->wm.first= G.main->wm.last= NULL;
371 if(G.fileflags & G_FILE_NO_UI) return;
373 /* we take apart the used screens from non-active window */
374 for(win= wm->windows.first; win; win= win->next) {
375 BLI_strncpy(win->screenname, win->screen->id.name, MAX_ID_NAME);
376 if(win!=C->wm->winactive) {
377 BLI_remlink(&G.main->screen, win->screen);
378 //BLI_addtail(screenbase, win->screen);
383 /* match old WM with new, 4 cases:
384 1- no current wm, no read wm: make new default
385 2- no current wm, but read wm: that's OK, do nothing
386 3- current wm, but not in file: try match screen names
387 4- current wm, and wm in file: try match ghostwin
390 static void wm_window_match_do(bContext *C, ListBase *wmlist)
392 wmWindowManager *oldwm, *wm;
393 wmWindow *oldwin, *win;
396 if(wmlist->first==NULL) {
397 if(G.main->wm.first); /* nothing todo */
404 /* we've read file without wm... */
405 if(G.main->wm.first==NULL) {
406 /* match oldwm to new dbase, only old files */
408 for(wm= wmlist->first; wm; wm= wm->id.next) {
409 for(win= wm->windows.first; win; win= win->next) {
410 win->screen= (bScreen *)find_id("SR", win->screenname);
412 if(win->screen==NULL)
413 win->screen= ED_screen_duplicate(win, C->screen); /* active screen */
415 if(win->screen->winid==0)
416 win->screen->winid= win->winid;
419 /* XXX still solve, case where multiple windows open */
424 /* what if old was 3, and loaded 1? */
425 /* this code could move to setup_appdata */
426 oldwm= wmlist->first;
427 wm= G.main->wm.first;
428 /* only first wm in list has ghostwins */
429 for(win= wm->windows.first; win; win= win->next) {
430 for(oldwin= oldwm->windows.first; oldwin; oldwin= oldwin->next) {
432 if(oldwin->winid == win->winid ) {
433 win->ghostwin= oldwin->ghostwin;
434 oldwin->ghostwin= NULL;
438 wm_close_and_free_all(C, wmlist);
444 static void verse_unsub(void)
446 extern ListBase session_list;
447 struct VerseSession *session;
450 session = session_list.first;
452 vnode = session->nodes.lb.first;
454 switch(vnode->type) {
456 //XXX unsubscribe_from_obj_node(vnode);
459 //XXX unsubscribe_from_geom_node(vnode);
462 //XXX unsubscribe_from_bitmap_node(vnode);
467 session = session->next;
472 void WM_read_file(bContext *C, char *name)
477 verse_unsub(); /* bad call here (ton) */
480 /* first try to append data from exotic file formats... */
481 /* it throws error box when file doesnt exist and returns -1 */
482 retval= BKE_read_exotic(name);
484 /* we didn't succeed, now try to read Blender file */
488 /* put aside screens to match with persistant windows later */
489 wm_window_match_init(C, &wmbase);
491 retval= BKE_read_file(C, name, NULL);
493 /* match the read WM with current WM */
494 wm_window_match_do(C, &wmbase);
496 // XXX mainwindow_set_filename_to_title(G.main->name);
497 // countall(); <-- will be listener
498 // XXX sound_initialize_sounds();
500 // winqueue_break= 1; /* leave queues everywhere */
502 // XXX if(retval==2) init_userdef_themes(); // in case a userdef is read from regular .blend
504 if (retval!=0) G.relbase_valid = 1;
506 // XXX undo_editmode_clear();
508 BKE_write_undo(C, "original"); /* save current state */
510 // refresh_interface_font();
512 // else if(retval==1)
513 // XXX BIF_undo_push("Import file");
516 static void outliner_242_patch(void)
521 if(G.curscreen==NULL) return;
522 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
523 SpaceLink *sl= sa->spacedata.first;
524 for(; sl; sl= sl->next) {
525 if(sl->spacetype==SPACE_OOPS) {
526 SpaceOops *soops= (SpaceOops *)sl;
527 if(soops->type!=SO_OUTLINER) {
528 soops->type= SO_OUTLINER;
529 // XXX init_v2d_oops(sa, soops);
534 G.fileflags |= G_FILE_GAME_MAT;
537 /* called on startup, (context entirely filled with NULLs) */
538 /* or called for 'Erase All' */
539 int WM_read_homefile(bContext *C, int from_memory)
542 char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
543 char *home= BLI_gethome();
548 free_ttfont(); /* still weird... what does it here? */
551 if (!from_memory) BLI_make_file_string(G.sce, tstr, home, ".B.blend");
552 strcpy(scestr, G.sce); /* temporary store */
554 /* prevent loading no UI */
555 G.fileflags &= ~G_FILE_NO_UI;
557 /* put aside screens to match with persistant windows later */
558 wm_window_match_init(C, &wmbase);
560 if (!from_memory && BLI_exists(tstr)) {
561 success = BKE_read_file(C, tstr, NULL);
563 success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL);
564 /* outliner patch for 2.42 .b.blend */
565 outliner_242_patch();
568 /* match the read WM with current WM */
569 wm_window_match_do(C, &wmbase);
571 strcpy(G.sce, scestr); /* restore */
573 init_userdef_themes();
576 G.save_over = 0; // start with save preference untitled.blend
577 G.fileflags &= ~G_FILE_AUTOPLAY; /* disable autoplay in .B.blend... */
578 // mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender"
581 // XXX read_languagefile();
584 // refresh_interface_font();
586 // undo_editmode_clear();
588 BKE_write_undo(C, "original"); /* save current state */
594 static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
599 char savedir[FILE_MAXDIR];
602 sprintf(pidstr, "%d.blend", abs(getpid()));
605 if (!BLI_exists(U.tempdir)) {
606 BLI_strncpy(subdir, "autosave", sizeof(subdir));
607 BLI_make_file_string("/", savedir, BLI_gethome(), subdir);
609 /* create a new autosave dir
610 * function already checks for existence or not */
611 BLI_recurdir_fileops(savedir);
613 BLI_make_file_string("/", buf, savedir, pidstr);
618 BLI_make_file_string("/", buf, U.tempdir, pidstr);
621 void WM_read_autosavefile(bContext *C)
623 char tstr[FILE_MAX], scestr[FILE_MAX];
626 BLI_strncpy(scestr, G.sce, FILE_MAX); /* temporal store */
628 get_autosave_location(tstr);
630 save_over = G.save_over;
631 BKE_read_file(C, tstr, NULL);
632 G.save_over = save_over;
633 BLI_strncpy(G.sce, scestr, FILE_MAX);
639 char name[FILE_MAX], filename[FILE_MAX];
641 struct RecentFile *recent;
645 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
646 lines= BLI_read_file_as_lines(name);
648 G.recent_files.first = G.recent_files.last = NULL;
650 /* read list of recent opend files from .Blog to memory */
651 for (l= lines, num= 0; l && (num<U.recent_files); l= l->next, num++) {
653 if (!BLI_streq(line, "")) {
657 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
658 BLI_addtail(&(G.recent_files), recent);
659 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(line)+1), "name of file");
660 recent->filename[0] = '\0';
662 strcpy(recent->filename, line);
667 BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
669 BLI_free_file_lines(lines);
672 /* Add the drive names to the listing */
675 char folder[MAX_PATH];
679 tmp= GetLogicalDrives();
681 for (i=2; i < 26; i++) {
688 // XX fsmenu_insert_entry(tmps, 0, 0);
692 /* Adding Desktop and My Documents */
693 // XXX fsmenu_append_separator();
695 SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0);
696 // XXX fsmenu_insert_entry(folder, 0, 0);
697 SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0);
698 // XXX fsmenu_insert_entry(folder, 0, 0);
700 // XXX fsmenu_append_separator();
704 BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
705 lines= BLI_read_file_as_lines(name);
707 for (l= lines; l; l= l->next) {
710 if (!BLI_streq(line, "")) {
711 // XXX fsmenu_insert_entry(line, 0, 1);
715 // XXX fsmenu_append_separator();
717 /* add last saved file */
718 BLI_split_dirfile(G.sce, name, filename); /* G.sce shouldn't be relative */
720 // XXX fsmenu_insert_entry(name, 0, 0);
722 BLI_free_file_lines(lines);
725 static void writeBlog(void)
727 struct RecentFile *recent, *next_recent;
728 char name[FILE_MAXDIR+FILE_MAXFILE];
732 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
734 recent = G.recent_files.first;
735 /* refresh .Blog of recent opened files, when current file was changed */
736 if(!(recent) || (strcmp(recent->filename, G.sce)!=0)) {
737 fp= fopen(name, "w");
739 /* add current file to the beginning of list */
740 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
741 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(G.sce)+1), "name of file");
742 recent->filename[0] = '\0';
743 strcpy(recent->filename, G.sce);
744 BLI_addhead(&(G.recent_files), recent);
745 /* write current file to .Blog */
746 fprintf(fp, "%s\n", recent->filename);
747 recent = recent->next;
749 /* write rest of recent opened files to .Blog */
750 while((i<U.recent_files) && (recent)){
751 /* this prevents to have duplicities in list */
752 if (strcmp(recent->filename, G.sce)!=0) {
753 fprintf(fp, "%s\n", recent->filename);
754 recent = recent->next;
757 next_recent = recent->next;
758 MEM_freeN(recent->filename);
759 BLI_freelinkN(&(G.recent_files), recent);
760 recent = next_recent;
769 static void do_history(char *name)
771 char tempname1[FILE_MAXDIR+FILE_MAXFILE], tempname2[FILE_MAXDIR+FILE_MAXFILE];
772 int hisnr= U.versions;
774 if(U.versions==0) return;
775 if(strlen(name)<2) return;
778 sprintf(tempname1, "%s%d", name, hisnr-1);
779 sprintf(tempname2, "%s%d", name, hisnr);
781 // if(BLI_rename(tempname1, tempname2))
782 // XXX error("Unable to make version backup");
787 /* is needed when hisnr==1 */
788 sprintf(tempname1, "%s%d", name, hisnr);
790 // if(BLI_rename(name, tempname1))
791 // XXX error("Unable to make version backup");
794 void WM_write_file(bContext *C, char *target)
801 len = strlen(target);
803 if (len == 0) return;
804 if (len >= FILE_MAX) {
805 // XXX error("Path too long, cannot save");
809 /* send the OnSave event */
810 // XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&C->scene->id, SCRIPT_ONSAVE);
812 for (li= G.main->library.first; li; li= li->id.next) {
813 if (BLI_streq(li->name, target)) {
814 // XXX error("Cannot overwrite used library");
819 if (!BLO_has_bfile_extension(target) && (len+6 < FILE_MAX)) {
820 sprintf(di, "%s.blend", target);
825 if (BLI_exists(di)) {
826 // XXX if(!saveover(di))
831 // XXX exit_editmode(0); /* 0 = no free data */
833 if (G.fileflags & G_AUTOPACK) {
837 // XXX waitcursor(1); // exit_editmode sets cursor too
841 /* we use the UserDef to define compression flag */
842 writeflags= G.fileflags & ~G_FILE_COMPRESS;
843 if(U.flag & USER_FILECOMPRESS)
844 writeflags |= G_FILE_COMPRESS;
846 if (BLO_write_file(C, di, writeflags, &err)) {
849 strcpy(G.main->name, di); /* is guaranteed current file */
851 // XXX mainwindow_set_filename_to_title(G.main->name);
857 // XXX error("%s", err);
860 // XXX waitcursor(0);
864 int WM_write_homefile(bContext *C, wmOperator *op)
866 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
869 BLI_make_file_string("/", tstr, BLI_gethome(), ".B.blend");
871 /* force save as regular blend file */
872 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
873 BLO_write_file(C, tstr, write_flags, &err);
875 return OPERATOR_FINISHED;
878 void WM_write_autosave(bContext *C)
880 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
883 get_autosave_location(tstr);
885 /* force save as regular blend file */
886 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
887 BLO_write_file(C, tstr, write_flags, &err);
890 /* if global undo; remove tempsave, otherwise rename */
891 void delete_autosave(void)
893 char tstr[FILE_MAXDIR+FILE_MAXFILE];
895 get_autosave_location(tstr);
897 if (BLI_exists(tstr)) {
898 char str[FILE_MAXDIR+FILE_MAXFILE];
899 BLI_make_file_string("/", str, U.tempdir, "quit.blend");
901 if(U.uiflag & USER_GLOBALUNDO) BLI_delete(tstr, 0, 0);
902 else BLI_rename(tstr, str);