Ejemplo n.º 1
0
static bool delete_recursive(const char *dir)
{
	struct direntry *filelist, *fl;
	bool err = false;
	unsigned int nbr, i;

	i = nbr = BLI_dir_contents(dir, &filelist);
	fl = filelist;
	while (i--) {
		char file[8];
		BLI_split_file_part(fl->path, file, sizeof(file));
		if (STREQ(file, ".") || STREQ(file, "..")) {
			/* Skip! */
		}
		else if (S_ISDIR(fl->type)) {
			if (delete_recursive(fl->path)) {
				err = true;
			}
		}
		else {
			if (delete_unique(fl->path, false)) {
				err = true;
			}
		}
		++fl;
	}

	if (!err && delete_unique(dir, true)) {
		err = true;
	}

	BLI_free_filelist(filelist, nbr);

	return err;
}
Ejemplo n.º 2
0
static void filelist_read_dir(struct FileList* filelist)
{
	char wdir[FILE_MAX]= "";
	if (!filelist) return;

	filelist->fidx = NULL;
	filelist->filelist = NULL;

	BLI_current_working_dir(wdir, sizeof(wdir));	 /* backup cwd to restore after */

	BLI_cleanup_dir(G.main->name, filelist->dir);
	filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist));

	if (!chdir(wdir)) {} /* fix warning about not checking return value */
	filelist_setfiletypes(filelist);
	filelist_filter(filelist);
}
Ejemplo n.º 3
0
static void init_iconfile_list(struct ListBase *list)
{
	IconFile *ifile;
	struct direntry *dir;
	int totfile, i, index = 1;
	const char *icondir;

	BLI_listbase_clear(list);
	icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");

	if (icondir == NULL)
		return;
	
	totfile = BLI_dir_contents(icondir, &dir);

	for (i = 0; i < totfile; i++) {
		if ((dir[i].type & S_IFREG)) {
			const char *filename = dir[i].relname;
			
			if (BLI_testextensie(filename, ".png")) {
				/* loading all icons on file start is overkill & slows startup
				 * its possible they change size after blender load anyway. */
#if 0
				int ifilex, ifiley;
				char iconfilestr[FILE_MAX + 16]; /* allow 256 chars for file+dir */
				ImBuf *bbuf = NULL;
				/* check to see if the image is the right size, continue if not */
				/* copying strings here should go ok, assuming that we never get back
				 * a complete path to file longer than 256 chars */
				BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename);
				bbuf = IMB_loadiffname(iconfilestr, IB_rect);

				if (bbuf) {
					ifilex = bbuf->x;
					ifiley = bbuf->y;
					IMB_freeImBuf(bbuf);
				}
				else {
					ifilex = ifiley = 0;
				}
				
				/* bad size or failed to load */
				if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) {
					printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley);
					continue;
				}
#endif          /* removed */

				/* found a potential icon file, so make an entry for it in the cache list */
				ifile = MEM_callocN(sizeof(IconFile), "IconFile");
				
				BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename));
				ifile->index = index;

				BLI_addtail(list, ifile);
				
				index++;
			}
		}
	}

	BLI_free_filelist(dir, totfile);
	dir = NULL;
}
Ejemplo n.º 4
0
static void init_iconfile_list(struct ListBase *list)
{
	IconFile *ifile;
	struct direntry *dir;
	int restoredir = 1; /* restore to current directory */
	int totfile, i, index=1;
	const char *icondir;
	char olddir[FILE_MAX];

	list->first = list->last = NULL;
	icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");

	if(icondir==NULL)
		return;
	
	/* since BLI_dir_contents changes the current working directory, restore it 
	   back to old value afterwards */
	if(!BLI_current_working_dir(olddir, sizeof(olddir))) 
		restoredir = 0;
	totfile = BLI_dir_contents(icondir, &dir);
	if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */

	for(i=0; i<totfile; i++) {
		if( (dir[i].type & S_IFREG) ) {
			char *filename = dir[i].relname;
			
			if(BLI_testextensie(filename, ".png")) {
				/* loading all icons on file start is overkill & slows startup
				 * its possible they change size after blender load anyway. */
#if 0
				int ifilex, ifiley;
				char iconfilestr[FILE_MAX+16]; /* allow 256 chars for file+dir */
				ImBuf *bbuf= NULL;
				/* check to see if the image is the right size, continue if not */
				/* copying strings here should go ok, assuming that we never get back
				   a complete path to file longer than 256 chars */
				BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename);
				bbuf= IMB_loadiffname(iconfilestr, IB_rect);

				if(bbuf) {
					ifilex = bbuf->x;
					ifiley = bbuf->y;
					IMB_freeImBuf(bbuf);
				}
				else {
					ifilex= ifiley= 0;
				}
				
				/* bad size or failed to load */
				if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) {
					printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley);
					continue;
				}
#endif			/* removed */

				/* found a potential icon file, so make an entry for it in the cache list */
				ifile = MEM_callocN(sizeof(IconFile), "IconFile");
				
				BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename));
				ifile->index = index;

				BLI_addtail(list, ifile);
				
				index++;
			}
		}
	}
	
	/* free temporary direntry structure that's been created by BLI_dir_contents() */
	i= totfile-1;
	
	for(; i>=0; i--){
		MEM_freeN(dir[i].relname);
		MEM_freeN(dir[i].path);
		if (dir[i].string) {
			MEM_freeN(dir[i].string);
		}
	}
	free(dir);
	dir= NULL;
}