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

	i = nbr = BLI_filelist_dir_contents(dir, &filelist);
	fl = filelist;
	while (i--) {
		char file[8];
		BLI_split_file_part(fl->path, file, sizeof(file));
		if (FILENAME_IS_CURRPAR(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_filelist_free(filelist, nbr, NULL);

	return err;
}
Esempio n. 2
0
void filelist_free(struct FileList *filelist)
{
	if (!filelist) {
		printf("Attempting to delete empty filelist.\n");
		return;
	}
	
	MEM_SAFE_FREE(filelist->fidx);
	filelist->numfiltered = 0;
	memset(&filelist->filter_data, 0, sizeof(filelist->filter_data));

	filelist->need_sorting = false;
	filelist->sort = FILE_SORT_NONE;

	BLI_filelist_free(filelist->filelist, filelist->numfiles, NULL);
	filelist->numfiles = 0;
	filelist->filelist = NULL;
}
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 = BKE_appdir_folder_id(BLENDER_DATAFILES, "icons");

	if (icondir == NULL)
		return;
	
	totfile = BLI_filelist_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_filelist_free(dir, totfile, NULL);
	dir = NULL;
}