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 //XXX success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL);
561 /* outliner patch for 2.42 .b.blend */
562 outliner_242_patch();
565 /* match the read WM with current WM */
566 wm_window_match_do(C, &wmbase);
568 strcpy(G.sce, scestr); /* restore */
570 init_userdef_themes();
573 G.save_over = 0; // start with save preference untitled.blend
574 G.fileflags &= ~G_FILE_AUTOPLAY; /* disable autoplay in .B.blend... */
575 // mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender"
578 // XXX read_languagefile();
581 // refresh_interface_font();
583 // undo_editmode_clear();
585 BKE_write_undo(C, "original"); /* save current state */
591 static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
596 char savedir[FILE_MAXDIR];
599 sprintf(pidstr, "%d.blend", abs(getpid()));
602 if (!BLI_exists(U.tempdir)) {
603 BLI_strncpy(subdir, "autosave", sizeof(subdir));
604 BLI_make_file_string("/", savedir, BLI_gethome(), subdir);
606 /* create a new autosave dir
607 * function already checks for existence or not */
608 BLI_recurdir_fileops(savedir);
610 BLI_make_file_string("/", buf, savedir, pidstr);
615 BLI_make_file_string("/", buf, U.tempdir, pidstr);
618 void WM_read_autosavefile(bContext *C)
620 char tstr[FILE_MAX], scestr[FILE_MAX];
623 BLI_strncpy(scestr, G.sce, FILE_MAX); /* temporal store */
625 get_autosave_location(tstr);
627 save_over = G.save_over;
628 BKE_read_file(C, tstr, NULL);
629 G.save_over = save_over;
630 BLI_strncpy(G.sce, scestr, FILE_MAX);
636 char name[FILE_MAX], filename[FILE_MAX];
638 struct RecentFile *recent;
642 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
643 lines= BLI_read_file_as_lines(name);
645 G.recent_files.first = G.recent_files.last = NULL;
647 /* read list of recent opend files from .Blog to memory */
648 for (l= lines, num= 0; l && (num<U.recent_files); l= l->next, num++) {
650 if (!BLI_streq(line, "")) {
654 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
655 BLI_addtail(&(G.recent_files), recent);
656 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(line)+1), "name of file");
657 recent->filename[0] = '\0';
659 strcpy(recent->filename, line);
664 BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
666 BLI_free_file_lines(lines);
669 /* Add the drive names to the listing */
672 char folder[MAX_PATH];
676 tmp= GetLogicalDrives();
678 for (i=2; i < 26; i++) {
685 // XX fsmenu_insert_entry(tmps, 0, 0);
689 /* Adding Desktop and My Documents */
690 // XXX fsmenu_append_separator();
692 SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0);
693 // XXX fsmenu_insert_entry(folder, 0, 0);
694 SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0);
695 // XXX fsmenu_insert_entry(folder, 0, 0);
697 // XXX fsmenu_append_separator();
701 BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
702 lines= BLI_read_file_as_lines(name);
704 for (l= lines; l; l= l->next) {
707 if (!BLI_streq(line, "")) {
708 // XXX fsmenu_insert_entry(line, 0, 1);
712 // XXX fsmenu_append_separator();
714 /* add last saved file */
715 BLI_split_dirfile(G.sce, name, filename); /* G.sce shouldn't be relative */
717 // XXX fsmenu_insert_entry(name, 0, 0);
719 BLI_free_file_lines(lines);
722 static void writeBlog(void)
724 struct RecentFile *recent, *next_recent;
725 char name[FILE_MAXDIR+FILE_MAXFILE];
729 BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
731 recent = G.recent_files.first;
732 /* refresh .Blog of recent opened files, when current file was changed */
733 if(!(recent) || (strcmp(recent->filename, G.sce)!=0)) {
734 fp= fopen(name, "w");
736 /* add current file to the beginning of list */
737 recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
738 recent->filename = (char*)MEM_mallocN(sizeof(char)*(strlen(G.sce)+1), "name of file");
739 recent->filename[0] = '\0';
740 strcpy(recent->filename, G.sce);
741 BLI_addhead(&(G.recent_files), recent);
742 /* write current file to .Blog */
743 fprintf(fp, "%s\n", recent->filename);
744 recent = recent->next;
746 /* write rest of recent opened files to .Blog */
747 while((i<U.recent_files) && (recent)){
748 /* this prevents to have duplicities in list */
749 if (strcmp(recent->filename, G.sce)!=0) {
750 fprintf(fp, "%s\n", recent->filename);
751 recent = recent->next;
754 next_recent = recent->next;
755 MEM_freeN(recent->filename);
756 BLI_freelinkN(&(G.recent_files), recent);
757 recent = next_recent;
766 static void do_history(char *name)
768 char tempname1[FILE_MAXDIR+FILE_MAXFILE], tempname2[FILE_MAXDIR+FILE_MAXFILE];
769 int hisnr= U.versions;
771 if(U.versions==0) return;
772 if(strlen(name)<2) return;
775 sprintf(tempname1, "%s%d", name, hisnr-1);
776 sprintf(tempname2, "%s%d", name, hisnr);
778 // if(BLI_rename(tempname1, tempname2))
779 // XXX error("Unable to make version backup");
784 /* is needed when hisnr==1 */
785 sprintf(tempname1, "%s%d", name, hisnr);
787 // if(BLI_rename(name, tempname1))
788 // XXX error("Unable to make version backup");
791 void WM_write_file(bContext *C, char *target)
798 len = strlen(target);
800 if (len == 0) return;
801 if (len >= FILE_MAX) {
802 // XXX error("Path too long, cannot save");
806 /* send the OnSave event */
807 // XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&C->scene->id, SCRIPT_ONSAVE);
809 for (li= G.main->library.first; li; li= li->id.next) {
810 if (BLI_streq(li->name, target)) {
811 // XXX error("Cannot overwrite used library");
816 if (!BLO_has_bfile_extension(target) && (len+6 < FILE_MAX)) {
817 sprintf(di, "%s.blend", target);
822 if (BLI_exists(di)) {
823 // XXX if(!saveover(di))
828 // XXX exit_editmode(0); /* 0 = no free data */
830 if (G.fileflags & G_AUTOPACK) {
834 // XXX waitcursor(1); // exit_editmode sets cursor too
838 /* we use the UserDef to define compression flag */
839 writeflags= G.fileflags & ~G_FILE_COMPRESS;
840 if(U.flag & USER_FILECOMPRESS)
841 writeflags |= G_FILE_COMPRESS;
843 if (BLO_write_file(C, di, writeflags, &err)) {
846 strcpy(G.main->name, di); /* is guaranteed current file */
848 // XXX mainwindow_set_filename_to_title(G.main->name);
854 // XXX error("%s", err);
857 // XXX waitcursor(0);
861 int WM_write_homefile(bContext *C, wmOperator *op)
863 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
866 BLI_make_file_string("/", tstr, BLI_gethome(), ".B.blend");
868 /* force save as regular blend file */
869 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
870 BLO_write_file(C, tstr, write_flags, &err);
875 void WM_write_autosave(bContext *C)
877 char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
880 get_autosave_location(tstr);
882 /* force save as regular blend file */
883 write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
884 BLO_write_file(C, tstr, write_flags, &err);
887 /* if global undo; remove tempsave, otherwise rename */
888 void delete_autosave(void)
890 char tstr[FILE_MAXDIR+FILE_MAXFILE];
892 get_autosave_location(tstr);
894 if (BLI_exists(tstr)) {
895 char str[FILE_MAXDIR+FILE_MAXFILE];
896 BLI_make_file_string("/", str, U.tempdir, "quit.blend");
898 if(U.uiflag & USER_GLOBALUNDO) BLI_delete(tstr, 0, 0);
899 else BLI_rename(tstr, str);