Esempio n. 1
0
static void movieclip_calc_length(MovieClip *clip)
{
    if (clip->source == MCLIP_SRC_MOVIE) {
        movieclip_open_anim_file(clip);

        if (clip->anim) {
            clip->len = IMB_anim_get_duration(clip->anim, clip->proxy.tc);
        }
    }
    else if (clip->source == MCLIP_SRC_SEQUENCE) {
        int framenr = 1;
        unsigned short numlen;
        char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];

        BLI_stringdec(clip->name, head, tail, &numlen);

        if (numlen == 0) {
            /* there's no number group in file name, assume it's single framed sequence */
            clip->len = framenr + 1;
        }
        else {
            for (;; ) {
                get_sequence_fname(clip, framenr, name);

                if (!BLI_exists(name)) {
                    clip->len = framenr + 1;
                    break;
                }

                framenr++;
            }
        }
    }
}
Esempio n. 2
0
void wm_autosave_location(char *filepath)
{
	char pidstr[32];
#ifdef WIN32
	const char *savedir;
#endif

	BLI_snprintf(pidstr, sizeof(pidstr), "%d.blend", abs(getpid()));

#ifdef WIN32
	/* XXX Need to investigate how to handle default location of '/tmp/'
	 * This is a relative directory on Windows, and it may be
	 * found. Example:
	 * Blender installed on D:\ drive, D:\ drive has D:\tmp\
	 * Now, BLI_exists() will find '/tmp/' exists, but
	 * BLI_make_file_string will create string that has it most likely on C:\
	 * through get_default_root().
	 * If there is no C:\tmp autosave fails. */
	if (!BLI_exists(BLI_temporary_dir())) {
		savedir = BLI_get_folder_create(BLENDER_USER_AUTOSAVE, NULL);
		BLI_make_file_string("/", filepath, savedir, pidstr);
		return;
	}
#endif

	BLI_make_file_string("/", filepath, BLI_temporary_dir(), pidstr);
}
Esempio n. 3
0
void wm_read_history(void)
{
	char name[FILE_MAX];
	LinkNode *l, *lines;
	struct RecentFile *recent;
	char *line;
	int num;
	const char * const cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);

	if (!cfgdir) return;

	BLI_make_file_string("/", name, cfgdir, BLENDER_HISTORY_FILE);

	lines = BLI_file_read_as_lines(name);

	G.recent_files.first = G.recent_files.last = NULL;

	/* read list of recent opened files from recent-files.txt to memory */
	for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) {
		line = l->link;
		if (line[0] && BLI_exists(line)) {
			recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile");
			BLI_addtail(&(G.recent_files), recent);
			recent->filepath = BLI_strdup(line);
			num++;
		}
	}
	
	BLI_file_free_lines(lines);
}
Esempio n. 4
0
void BLI_recurdir_fileops(char *dirname) {
	char *lslash;
	char tmp[MAXPATHLEN];
	
	// First remove possible slash at the end of the dirname.
	// This routine otherwise tries to create
	// blah1/blah2/ (with slash) after creating
	// blah1/blah2 (without slash)

	strcpy(tmp, dirname);
	lslash= BLI_last_slash(tmp);

	if (lslash == tmp + strlen(tmp) - 1) {
		*lslash = 0;
	}
	
	if (BLI_exists(tmp)) return;
		
	lslash= BLI_last_slash(tmp);
	if (lslash) {
			/* Split about the last slash and recurse */	
		*lslash = 0;
		BLI_recurdir_fileops(tmp);
	}
	
	if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */
		if (!CreateDirectory(dirname, NULL))
			callLocalErrorCallBack("Unable to create directory\n");
}
Esempio n. 5
0
void BLI_dir_create_recursive(const char *dirname)
{
	char *lslash;
	size_t size;
#ifdef MAXPATHLEN
	char static_buf[MAXPATHLEN];
#endif
	char *tmp;

	if (BLI_exists(dirname)) return;

#ifdef MAXPATHLEN
	size = MAXPATHLEN;
	tmp = static_buf;
#else
	size = strlen(dirname) + 1;
	tmp = MEM_callocN(size, __func__);
#endif

	BLI_strncpy(tmp, dirname, size);
		
	lslash = (char *)BLI_last_slash(tmp);
	if (lslash) {
		/* Split about the last slash and recurse */
		*lslash = 0;
		BLI_dir_create_recursive(tmp);
	}

#ifndef MAXPATHLEN
	MEM_freeN(tmp);
#endif

	mkdir(dirname, 0777);
}
Esempio n. 6
0
void wm_autosave_location(char *filepath)
{
	const int pid = abs(getpid());
	char path[1024];
#ifdef WIN32
	const char *savedir;
#endif

	if (G.main && G.relbase_valid) {
		const char *basename = BLI_path_basename(G.main->name);
		int len = strlen(basename) - 6;
		BLI_snprintf(path, sizeof(path), "%.*s.blend", len, basename);
	}
	else {
		BLI_snprintf(path, sizeof(path), "%d.blend", pid);
	}

#ifdef WIN32
	/* XXX Need to investigate how to handle default location of '/tmp/'
	 * This is a relative directory on Windows, and it may be
	 * found. Example:
	 * Blender installed on D:\ drive, D:\ drive has D:\tmp\
	 * Now, BLI_exists() will find '/tmp/' exists, but
	 * BLI_make_file_string will create string that has it most likely on C:\
	 * through get_default_root().
	 * If there is no C:\tmp autosave fails. */
	if (!BLI_exists(BKE_tempdir_base())) {
		savedir = BKE_appdir_folder_id_create(BLENDER_USER_AUTOSAVE, NULL);
		BLI_make_file_string("/", filepath, savedir, path);
		return;
	}
#endif

	BLI_make_file_string("/", filepath, BKE_tempdir_base(), path);
}
Esempio n. 7
0
static void get_filename(int argc, char **argv, char *filename)
{
#ifdef __APPLE__
    /* On Mac we park the game file (called game.blend) in the application bundle.
     * The executable is located in the bundle as well.
     * Therefore, we can locate the game relative to the executable.
     */
    int srclen = ::strlen(argv[0]);
    int len = 0;
    char *gamefile = NULL;

    filename[0] = '\0';

    if (argc > 1) {
        if (BLI_exists(argv[argc-1])) {
            BLI_strncpy(filename, argv[argc-1], FILE_MAX);
        }
        if (::strncmp(argv[argc-1], "-psn_", 5)==0) {
            static char firstfilebuf[512];
            if (GHOST_HACK_getFirstFile(firstfilebuf)) {
                BLI_strncpy(filename, firstfilebuf, FILE_MAX);
            }
        }
    }

    srclen -= ::strlen("MacOS/blenderplayer");
    if (srclen > 0) {
        len = srclen + ::strlen("Resources/game.blend");
        gamefile = new char [len + 1];
        ::strcpy(gamefile, argv[0]);
        ::strcpy(gamefile + srclen, "Resources/game.blend");
        //::printf("looking for file: %s\n", filename);

        if (BLI_exists(gamefile))
            BLI_strncpy(filename, gamefile, FILE_MAX);

        delete [] gamefile;
    }

#else
    filename[0] = '\0';

    if (argc > 1)
        BLI_strncpy(filename, argv[argc-1], FILE_MAX);
#endif // !_APPLE
}
Esempio n. 8
0
/* op can be NULL */
int WM_read_homefile(bContext *C, wmOperator *op)
{
	ListBase wmbase;
	char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
	char *home= BLI_gethome();
	int from_memory= op?RNA_boolean_get(op->ptr, "factory"):0;
	int success;
		
	BLI_clean(home);
	
	free_ttfont(); /* still weird... what does it here? */
		
	G.relbase_valid = 0;
	if (!from_memory) {
		BLI_make_file_string(G.sce, tstr, home, ".B25.blend");
	}
	strcpy(scestr, G.sce);	/* temporary store */
	
	/* prevent loading no UI */
	G.fileflags &= ~G_FILE_NO_UI;
	
	/* put aside screens to match with persistant windows later */
	wm_window_match_init(C, &wmbase); 
	
	if (!from_memory && BLI_exists(tstr)) {
		success = BKE_read_file(C, tstr, NULL, NULL);
	} else {
		success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL, NULL);
		if (wmbase.first == NULL) wm_clear_default_size(C);
	}
	
	/* match the read WM with current WM */
	wm_window_match_do(C, &wmbase); 
	wm_check(C); /* opens window(s), checks keymaps */

	strcpy(G.sce, scestr); /* restore */
	
	wm_init_userdef();
	
	/* When loading factory settings, the reset solid OpenGL lights need to be applied. */
	GPU_default_lights();
	
	/* XXX */
	G.save_over = 0;	// start with save preference untitled.blend
	G.fileflags &= ~G_FILE_AUTOPLAY;	/*  disable autoplay in .B.blend... */
//	mainwindow_set_filename_to_title("");	// empty string re-initializes title to "Blender"
	
//	refresh_interface_font();
	
//	undo_editmode_clear();
	BKE_reset_undo();
	BKE_write_undo(C, "original");	/* save current state */
	
	WM_event_add_notifier(C, NC_WM|ND_FILEREAD, NULL);
	CTX_wm_window_set(C, NULL); /* exits queues */

	return OPERATOR_FINISHED;
}
Esempio n. 9
0
int file_directory_new_exec(bContext *C, wmOperator *op)
{
	char name[FILE_MAXFILE];
	char path[FILE_MAX];
	int generate_name = 1;

	wmWindowManager *wm = CTX_wm_manager(C);
	SpaceFile *sfile = CTX_wm_space_file(C);
	
	if (!sfile->params) {
		BKE_report(op->reports, RPT_WARNING, "No parent directory given");
		return OPERATOR_CANCELLED;
	}
	
	path[0] = '\0';

	if (RNA_struct_find_property(op->ptr, "directory")) {
		RNA_string_get(op->ptr, "directory", path);
		if (path[0] != '\0') generate_name = 0;
	}

	if (generate_name) {
		/* create a new, non-existing folder name */
		if (!new_folder_path(sfile->params->dir, path, name)) {
			BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
			return OPERATOR_CANCELLED;
		}
	}

	/* create the file */
	BLI_dir_create_recursive(path);

	if (!BLI_exists(path)) {
		BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
		return OPERATOR_CANCELLED;
	}

	/* now remember file to jump into editing */
	BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);

	/* set timer to smoothly view newly generated file */
	sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0);  /* max 30 frs/sec */
	sfile->scroll_offset = 0;

	/* reload dir to make sure we're seeing what's in the directory */
	ED_fileselect_clear(wm, sfile);

	if (RNA_boolean_get(op->ptr, "open")) {
		BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir));
		file_change_dir(C, 1);
	}

	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);

	return OPERATOR_FINISHED;
}
Esempio n. 10
0
static int add_win32_extension(char *name)
{
	int retval = 0;
	int type;

	type = BLI_exists(name);
	if ((type == 0) || S_ISDIR(type)) {
#ifdef _WIN32
		char filename[FILE_MAX];
		char ext[FILE_MAX];
		const char *extensions = getenv("PATHEXT");
		if (extensions) {
			char *temp;
			do {
				strcpy(filename, name);
				temp = strstr(extensions, ";");
				if (temp) {
					strncpy(ext, extensions, temp - extensions);
					ext[temp - extensions] = 0;
					extensions = temp + 1;
					strcat(filename, ext);
				}
				else {
					strcat(filename, extensions);
				}

				type = BLI_exists(filename);
				if (type && (!S_ISDIR(type))) {
					retval = 1;
					strcpy(name, filename);
					break;
				}
			} while (temp);
		}
#endif
	}
	else {
		retval = 1;
	}

	return (retval);
}
Esempio n. 11
0
static WorkspaceConfigFileData *workspace_config_file_read(const char *app_template)
{
  const char *cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, app_template);
  char startup_file_path[FILE_MAX] = {0};

  if (cfgdir) {
    BLI_join_dirfile(startup_file_path, sizeof(startup_file_path), cfgdir, BLENDER_STARTUP_FILE);
  }

  bool has_path = BLI_exists(startup_file_path);
  return (has_path) ? BKE_blendfile_workspace_config_read(startup_file_path, NULL, 0, NULL) : NULL;
}
Esempio n. 12
0
void BLI_make_existing_file(const char *name)
{
	char di[FILE_MAX], fi[FILE_MAXFILE];

	BLI_strncpy(di, name, sizeof(di));
	BLI_splitdirstring(di, fi);
	
	/* test exist */
	if (BLI_exists(di) == 0) {
		BLI_dir_create_recursive(di);
	}
}
Esempio n. 13
0
char *blf_dir_search(const char *file)
{
	DirBLF *dir;
	char full_path[FILE_MAX];
	char *s = NULL;

	for (dir = global_font_dir.first; dir; dir = dir->next) {
		BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file);
		if (BLI_exists(full_path)) {
			s = BLI_strdup(full_path);
			break;
		}
	}

	if (!s) {
		/* check the current directory, why not ? */
		if (BLI_exists(file))
			s = BLI_strdup(file);
	}

	return s;
}
Esempio n. 14
0
void wm_autosave_delete(void)
{
	char filename[FILE_MAX];
	
	wm_autosave_location(filename);

	if (BLI_exists(filename)) {
		char str[FILE_MAX];
		BLI_make_file_string("/", str, BKE_tempdir_base(), BLENDER_QUIT_FILE);

		/* if global undo; remove tempsave, otherwise rename */
		if (U.uiflag & USER_GLOBALUNDO) BLI_delete(filename, false, false);
		else BLI_rename(filename, str);
	}
}
Esempio n. 15
0
void wm_autosave_delete(void)
{
	char filename[FILE_MAX];
	
	wm_autosave_location(filename);

	if(BLI_exists(filename)) {
		char str[FILE_MAXDIR+FILE_MAXFILE];
		BLI_make_file_string("/", str, U.tempdir, "quit.blend");

		/* if global undo; remove tempsave, otherwise rename */
		if(U.uiflag & USER_GLOBALUNDO) BLI_delete(filename, 0, 0);
		else BLI_rename(filename, str);
	}
}
Esempio n. 16
0
IMB_Proxy_Size IMB_anim_proxy_get_existing(struct anim *anim)
{
	const int num_proxy_sizes = IMB_PROXY_MAX_SLOT;
	IMB_Proxy_Size existing = 0;
	int i;
	for (i = 0; i < num_proxy_sizes; ++i) {
		IMB_Proxy_Size proxy_size = proxy_sizes[i];
		char filename[FILE_MAX];
		get_proxy_filename(anim, proxy_size, filename, false);
		if (BLI_exists(filename)) {
			existing |= proxy_size;
		}
	}
	return existing;
}
Esempio n. 17
0
static int file_directory_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
	SpaceFile *sfile= CTX_wm_space_file(C);

	if(sfile->params) {
		file_expand_directory(C);
		
		if (!BLI_exists(sfile->params->dir)) {
			return WM_operator_confirm_message(C, op, "Create new directory?");
		} 

		return file_directory_exec(C, op);
	}

	return OPERATOR_CANCELLED;
}
Esempio n. 18
0
int file_draw_check_exists(SpaceFile *sfile)
{
	if(sfile->op) { /* fails on reload */
		if(RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
			if(RNA_boolean_get(sfile->op->ptr, "check_existing")) {
				char filepath[FILE_MAX];
				BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
				if(BLI_exists(filepath) && !BLI_is_dir(filepath)) {
					return TRUE;
				}
			}
		}
	}

	return FALSE;
}
Esempio n. 19
0
static int fluidsim_find_lastframe(Object *ob, FluidsimSettings *fss)
{
	char targetFileTest[FILE_MAX];
	char targetFile[FILE_MAX];
	int curFrame = 1;

	BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME);
	BLI_path_abs(targetFile, modifier_path_relbase(ob));

	do {
		BLI_strncpy(targetFileTest, targetFile, sizeof(targetFileTest));
		BLI_path_frame(targetFileTest, curFrame++, 0);
	} while (BLI_exists(targetFileTest));

	return curFrame - 1;
}
Esempio n. 20
0
void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
{
	SpaceFile *sfile = CTX_wm_space_file(C);

	/* search if str matches the beginning of name */
	if (str[0] && sfile->files) {
		char dirname[FILE_MAX];

		DIR *dir;
		struct dirent *de;
		
		BLI_split_dir_part(str, dirname, sizeof(dirname));

		dir = opendir(dirname);

		if (dir) {
			AutoComplete *autocpl = autocomplete_begin(str, FILE_MAX);

			while ((de = readdir(dir)) != NULL) {
				if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0) {
					/* pass */
				}
				else {
					char path[FILE_MAX];
					struct stat status;
					
					BLI_join_dirfile(path, sizeof(path), dirname, de->d_name);

					if (stat(path, &status) == 0) {
						if (S_ISDIR(status.st_mode)) { /* is subdir */
							autocomplete_do_name(autocpl, path);
						}
					}
				}
			}
			closedir(dir);

			autocomplete_end(autocpl, str);
			if (BLI_exists(str)) {
				BLI_add_slash(str);
			}
			else {
				BLI_strncpy(sfile->params->dir, str, sizeof(sfile->params->dir));
			}
		}
	}
}
Esempio n. 21
0
void BLI_recurdir_fileops(char *dirname) {
	char *lslash;
	char tmp[MAXPATHLEN];
		
	if (BLI_exists(dirname)) return;

	strcpy(tmp, dirname);
		
	lslash= BLI_last_slash(tmp);
	if (lslash) {
			/* Split about the last slash and recurse */	
		*lslash = 0;
		BLI_recurdir_fileops(tmp);
	}

	mkdir(dirname, 0777);
}
Esempio n. 22
0
void BLI_dir_create_recursive(const char *dirname)
{
	char *lslash;
	char tmp[MAXPATHLEN];
		
	if (BLI_exists(dirname)) return;

	BLI_strncpy(tmp, dirname, sizeof(tmp));
		
	lslash= BLI_last_slash(tmp);
	if (lslash) {
			/* Split about the last slash and recurse */	
		*lslash = 0;
		BLI_dir_create_recursive(tmp);
	}

	mkdir(dirname, 0777);
}
Esempio n. 23
0
/* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created.
 * The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
 */
static int new_folder_path(const char *parent, char *folder, char *name)
{
	int i = 1;
	int len = 0;

	BLI_strncpy(name, "New Folder", FILE_MAXFILE);
	BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
	/* check whether folder with the name already exists, in this case
	 * add number to the name. Check length of generated name to avoid
	 * crazy case of huge number of folders each named 'New Folder (x)' */
	while (BLI_exists(folder) && (len < FILE_MAXFILE)) {
		len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
		BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
		i++;
	}

	return (len < FILE_MAXFILE);
}
Esempio n. 24
0
static WorkspaceConfigFileData *workspace_system_file_read(const char *app_template)
{
  if (app_template == NULL) {
    return BKE_blendfile_workspace_config_read(
        NULL, datatoc_startup_blend, datatoc_startup_blend_size, NULL);
  }

  char template_dir[FILE_MAX];
  if (!BKE_appdir_app_template_id_search(app_template, template_dir, sizeof(template_dir))) {
    return NULL;
  }

  char startup_file_path[FILE_MAX];
  BLI_join_dirfile(
      startup_file_path, sizeof(startup_file_path), template_dir, BLENDER_STARTUP_FILE);

  bool has_path = BLI_exists(startup_file_path);
  return (has_path) ? BKE_blendfile_workspace_config_read(startup_file_path, NULL, 0, NULL) : NULL;
}
Esempio n. 25
0
/* sends events now, so things get handled on windowqueue level */
int file_exec(bContext *C, wmOperator *exec_op)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	SpaceFile *sfile = CTX_wm_space_file(C);
	char filepath[FILE_MAX];
	
	if (sfile->op) {
		wmOperator *op = sfile->op;
	
		/* when used as a macro, for doubleclick, 
		 * to prevent closing when doubleclicking on .. item */
		if (RNA_boolean_get(exec_op->ptr, "need_active")) {
			int i, active = 0;
			
			for (i = 0; i < filelist_numfiles(sfile->files); i++) {
				if (filelist_is_selected(sfile->files, i, CHECK_ALL)) {
					active = 1;
					break;
				}
			}
			if (active == 0)
				return OPERATOR_CANCELLED;
		}
		
		sfile->op = NULL;

		file_sfile_to_operator(op, sfile, filepath);

		if (BLI_exists(sfile->params->dir)) {
			fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE | FS_INSERT_FIRST);
		}

		BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
		fsmenu_write_file(fsmenu_get(), filepath);
		WM_event_fileselect_event(wm, op, EVT_FILESELECT_EXEC);

	}
				
	return OPERATOR_FINISHED;
}
Esempio n. 26
0
bool BKE_cachefile_filepath_get(
        const Main *bmain, const CacheFile *cache_file, float frame,
        char r_filepath[FILE_MAX])
{
	BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX);
	BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id));

	int fframe;
	int frame_len;

	if (cache_file->is_sequence && BLI_path_frame_get(r_filepath, &fframe, &frame_len)) {
		char ext[32];
		BLI_path_frame_strip(r_filepath, true, ext);
		BLI_path_frame(r_filepath, frame, frame_len);
		BLI_ensure_extension(r_filepath, FILE_MAX, ext);

		/* TODO(kevin): store sequence range? */
		return BLI_exists(r_filepath);
	}

	return true;
}
Esempio n. 27
0
static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
{
	char newname[FILE_MAX + 12];
	char orgname[FILE_MAX + 12];
	char filename[FILE_MAX + 12];
	SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
	ARegion *ar = CTX_wm_region(C);

	BLI_make_file_string(G.main->name, orgname, sfile->params->dir, oldname);
	BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename));
	BLI_make_file_string(G.main->name, newname, sfile->params->dir, filename);

	if (strcmp(orgname, newname) != 0) {
		if (!BLI_exists(newname)) {
			BLI_rename(orgname, newname);
			/* to make sure we show what is on disk */
			ED_fileselect_clear(C, sfile);
		}

		ED_region_tag_redraw(ar);
	}
}
Esempio n. 28
0
	int collada_export(Scene *sce, const char *filepath, int selected, int apply_modifiers, int second_life)
	{
		ExportSettings export_settings;
		
		export_settings.selected        = selected != 0;
		export_settings.apply_modifiers = apply_modifiers != 0;
		export_settings.second_life     = second_life != 0;
		export_settings.filepath        = (char *)filepath;

		/* annoying, collada crashes if file cant be created! [#27162] */
		if (!BLI_exists(filepath)) {
			BLI_make_existing_file(filepath); /* makes the dir if its not there */
			if (BLI_file_touch(filepath) == 0) {
				return 0;
			}
		}
		/* end! */

		DocumentExporter exporter(&export_settings);
		exporter.exportCurrentScene(sce);

		return 1;
	}
Esempio n. 29
0
void BLI_dir_create_recursive(const char *dirname)
{
	char *lslash;
	char tmp[MAXPATHLEN];

	/* First remove possible slash at the end of the dirname.
	 * This routine otherwise tries to create
	 * blah1/blah2/ (with slash) after creating
	 * blah1/blah2 (without slash) */

	BLI_strncpy(tmp, dirname, sizeof(tmp));
	lslash = (char *)BLI_last_slash(tmp);

	if (lslash && (*(lslash + 1) == '\0')) {
		*lslash = '\0';
	}

	/* check special case "c:\foo", don't try create "c:", harmless but prints an error below */
	if (isalpha(tmp[0]) && (tmp[1] == ':') && tmp[2] == '\0') return;

	if (BLI_exists(tmp)) return;

	lslash = (char *)BLI_last_slash(tmp);

	if (lslash) {
		/* Split about the last slash and recurse */
		*lslash = 0;
		BLI_dir_create_recursive(tmp);
	}

	if (dirname[0]) {  /* patch, this recursive loop tries to create a nameless directory */
		if (umkdir(dirname) == -1) {
			printf("Unable to create directory %s\n", dirname);
		}
	}
}
Esempio n. 30
0
/**
 * called on startup,  (context entirely filled with NULLs)
 * or called for 'New File'
 * both startup.blend and userpref.blend are checked
 * the optional parameter custom_file points to an alternative startup page
 * custom_file can be NULL
 */
int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const char *custom_file)
{
	ListBase wmbase;
	char startstr[FILE_MAX];
	char prefstr[FILE_MAX];
	int success = 0;

	/* Indicates whether user preferences were really load from memory.
	 *
	 * This is used for versioning code, and for this we can not rely on from_memory
	 * passed via argument. This is because there might be configuration folder
	 * exists but it might not have userpref.blend and in this case we fallback to
	 * reading home file from memory.
	 *
	 * And in this case versioning code is to be run.
	 */
	bool read_userdef_from_memory = true;

	/* options exclude eachother */
	BLI_assert((from_memory && custom_file) == 0);

	if ((G.f & G_SCRIPT_OVERRIDE_PREF) == 0) {
		BKE_BIT_TEST_SET(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_SCRIPT_AUTOEXEC);
	}

	BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE);

	UI_view2d_zoom_cache_reset();

	G.relbase_valid = 0;
	if (!from_memory) {
		const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
		if (custom_file) {
			BLI_strncpy(startstr, custom_file, FILE_MAX);

			if (cfgdir) {
				BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE);
			}
			else {
				prefstr[0] = '\0';
			}
		}
		else if (cfgdir) {
			BLI_make_file_string(G.main->name, startstr, cfgdir, BLENDER_STARTUP_FILE);
			BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE);
		}
		else {
			startstr[0] = '\0';
			prefstr[0] = '\0';
			from_memory = 1;
		}
	}
	
	/* put aside screens to match with persistent windows later */
	wm_window_match_init(C, &wmbase);
	
	if (!from_memory) {
		if (BLI_access(startstr, R_OK) == 0) {
			success = (BKE_read_file(C, startstr, NULL) != BKE_READ_FILE_FAIL);
		}
		if (BLI_listbase_is_empty(&U.themes)) {
			if (G.debug & G_DEBUG)
				printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n", startstr);
			success = 0;
		}
	}

	if (success == 0 && custom_file && reports) {
		BKE_reportf(reports, RPT_ERROR, "Could not read '%s'", custom_file);
		/*We can not return from here because wm is already reset*/
	}

	if (success == 0) {
		success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true);
		if (BLI_listbase_is_empty(&wmbase)) {
			wm_clear_default_size(C);
		}
		BKE_tempdir_init(U.tempdir);

#ifdef WITH_PYTHON_SECURITY
		/* use alternative setting for security nuts
		 * otherwise we'd need to patch the binary blob - startup.blend.c */
		U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
#endif
	}
	
	/* check new prefs only after startup.blend was finished */
	if (!from_memory && BLI_exists(prefstr)) {
		int done = BKE_read_file_userdef(prefstr, NULL);
		if (done != BKE_READ_FILE_FAIL) {
			read_userdef_from_memory = false;
			printf("Read new prefs: %s\n", prefstr);
		}
	}
	
	/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
	 * can remove this eventually, only in a 2.53 and older, now its not written */
	G.fileflags &= ~G_FILE_RELATIVE_REMAP;
	
	/* check userdef before open window, keymaps etc */
	wm_init_userdef(C, read_userdef_from_memory);
	
	/* match the read WM with current WM */
	wm_window_match_do(C, &wmbase); 
	WM_check(C); /* opens window(s), checks keymaps */

	G.main->name[0] = '\0';

	/* When loading factory settings, the reset solid OpenGL lights need to be applied. */
	if (!G.background) GPU_default_lights();
	
	/* XXX */
	G.save_over = 0;    // start with save preference untitled.blend
	G.fileflags &= ~G_FILE_AUTOPLAY;    /*  disable autoplay in startup.blend... */

	wm_file_read_post(C, true);

	return true;
}