static void filepath_avi(char *string, RenderData *rd, bool preview, const char *suffix) { int sfra, efra; if (string == NULL) return; if (preview) { sfra = rd->psfra; efra = rd->pefra; } else { sfra = rd->sfra; efra = rd->efra; } strcpy(string, rd->pic); BLI_path_abs(string, G.main->name); BLI_make_existing_file(string); if (rd->scemode & R_EXTENSION) { if (!BLI_testextensie(string, ".avi")) { BLI_path_frame_range(string, sfra, efra, 4); strcat(string, ".avi"); } } else { if (BLI_path_frame_check_chars(string)) { BLI_path_frame_range(string, sfra, efra, 4); } } BLI_path_suffix(string, FILE_MAX, suffix, ""); }
static int path_extension_type(const char *path) { if (BLO_has_bfile_extension(path)) { return FILE_TYPE_BLENDER; } else if (file_is_blend_backup(path)) { return FILE_TYPE_BLENDER_BACKUP; } else if (BLI_testextensie(path, ".app")) { return FILE_TYPE_APPLICATIONBUNDLE; } else if (BLI_testextensie(path, ".py")) { return FILE_TYPE_PYSCRIPT; } else if (BLI_testextensie_n(path, ".txt", ".glsl", ".osl", ".data", NULL)) { return FILE_TYPE_TEXT; } else if (BLI_testextensie_n(path, ".ttf", ".ttc", ".pfb", ".otf", ".otc", NULL)) { return FILE_TYPE_FTFONT; } else if (BLI_testextensie(path, ".btx")) { return FILE_TYPE_BTX; } else if (BLI_testextensie(path, ".dae")) { return FILE_TYPE_COLLADA; } else if (BLI_testextensie_array(path, imb_ext_image) || (G.have_quicktime && BLI_testextensie_array(path, imb_ext_image_qt))) { return FILE_TYPE_IMAGE; } else if (BLI_testextensie(path, ".ogg")) { if (IMB_isanim(path)) { return FILE_TYPE_MOVIE; } else { return FILE_TYPE_SOUND; } } else if (BLI_testextensie_array(path, imb_ext_movie)) { return FILE_TYPE_MOVIE; } else if (BLI_testextensie_array(path, imb_ext_audio)) { return FILE_TYPE_SOUND; } return 0; }
void Controller::InsertStyleModule(unsigned index, const char *iFileName) { if (!BLI_testextensie(iFileName, ".py")) { cerr << "Error: Cannot load \"" << string(iFileName) << "\", unknown extension" << endl; return; } StyleModule *sm = new StyleModule(iFileName, _inter); _Canvas->InsertStyleModule(index, sm); }
int BLI_testextensie_array(const char *str, const char **ext_array) { int i = 0; while (ext_array[i]) { if (BLI_testextensie(str, ext_array[i])) { return 1; } i++; } return 0; }
static bool wm_collada_export_check(bContext *UNUSED(C), wmOperator *op) { char filepath[FILE_MAX]; RNA_string_get(op->ptr, "filepath", filepath); if (!BLI_testextensie(filepath, ".dae")) { BLI_ensure_extension(filepath, FILE_MAX, ".dae"); RNA_string_set(op->ptr, "filepath", filepath); return true; } return false; }
TextFormatType *ED_text_format_get(Text *text) { /* NOTE: once more types are added we'll need to return some type based on 'text' * for now this function is more of a placeholder */ /* XXX, wrong, but OK for testing */ if (text && BLI_testextensie(text->id.name + 2, ".osl")) { return tft_lb.last; } else { return tft_lb.first; } }
static void filepath_avi (char *string, RenderData *rd) { if (string==NULL) return; strcpy(string, rd->pic); BLI_path_abs(string, G.main->name); BLI_make_existing_file(string); if (!BLI_testextensie(string, ".avi")) { BLI_path_frame_range(string, rd->sfra, rd->efra, 4); strcat(string, ".avi"); } }
void BPY_modules_load_user(bContext *C) { PyGILState_STATE gilstate; Main *bmain = CTX_data_main(C); Text *text; /* can happen on file load */ if (bmain == NULL) return; /* update pointers since this can run from a nested script * on file load */ if (py_call_level) { BPY_context_update(C); } bpy_context_set(C, &gilstate); for (text = bmain->text.first; text; text = text->id.next) { if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) { if (!(G.f & G_SCRIPT_AUTOEXEC)) { if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) { G.f |= G_SCRIPT_AUTOEXEC_FAIL; BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Text '%s'", text->id.name + 2); printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2); } } else { PyObject *module = bpy_text_import(text); if (module == NULL) { PyErr_Print(); PyErr_Clear(); } else { Py_DECREF(module); } /* check if the script loaded a new file */ if (bmain != CTX_data_main(C)) { break; } } } } bpy_context_clear(C, &gilstate); }
int BLI_parent_dir(char *path) { static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */ char tmp[FILE_MAXDIR+FILE_MAXFILE+4]; BLI_strncpy(tmp, path, sizeof(tmp)-4); BLI_add_slash(tmp); strcat(tmp, parent_dir); BLI_cleanup_dir(NULL, tmp); if (!BLI_testextensie(tmp, parent_dir)) { BLI_strncpy(path, tmp, sizeof(tmp)); return 1; } else { return 0; } }
static int file_extension_type(const char *relname) { if (BLO_has_bfile_extension(relname)) { return BLENDERFILE; } else if (file_is_blend_backup(relname)) { return BLENDERFILE_BACKUP; } else if (BLI_testextensie(relname, ".py")) { return PYSCRIPTFILE; } else if (BLI_testextensie(relname, ".txt") || BLI_testextensie(relname, ".glsl") || BLI_testextensie(relname, ".data")) { return TEXTFILE; } else if (BLI_testextensie(relname, ".ttf") || BLI_testextensie(relname, ".ttc") || BLI_testextensie(relname, ".pfb") || BLI_testextensie(relname, ".otf") || BLI_testextensie(relname, ".otc")) { return FTFONTFILE; } else if (BLI_testextensie(relname, ".btx")) { return BTXFILE; } else if (BLI_testextensie(relname, ".dae")) { return COLLADAFILE; } else if (BLI_testextensie_array(relname, imb_ext_image) || (G.have_quicktime && BLI_testextensie_array(relname, imb_ext_image_qt))) { return IMAGEFILE; } else if (BLI_testextensie_array(relname, imb_ext_movie)) { return MOVIEFILE; } else if (BLI_testextensie_array(relname, imb_ext_audio)) { return SOUNDFILE; } return 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 = 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; }
int IMB_isanim(const char *filename) { int type; if(U.uiflag & USER_FILTERFILEEXTS) { if (G.have_quicktime){ if( BLI_testextensie(filename, ".avi") || BLI_testextensie(filename, ".flc") || BLI_testextensie(filename, ".dv") || BLI_testextensie(filename, ".r3d") || BLI_testextensie(filename, ".mov") || BLI_testextensie(filename, ".movie") || BLI_testextensie(filename, ".mv")) { type = imb_get_anim_type(filename); } else { return(FALSE); } } else { // no quicktime if( BLI_testextensie(filename, ".avi") || BLI_testextensie(filename, ".dv") || BLI_testextensie(filename, ".r3d") || BLI_testextensie(filename, ".mv")) { type = imb_get_anim_type(filename); } else { return(FALSE); } } } else { // no FILTERFILEEXTS type = imb_get_anim_type(filename); } return (type && type!=ANIM_SEQUENCE); }
static int isffmpeg (const char *filename) { AVFormatContext *pFormatCtx; unsigned int i; int videoStream; AVCodec *pCodec; AVCodecContext *pCodecCtx; do_init_ffmpeg(); if( BLI_testextensie(filename, ".swf") || BLI_testextensie(filename, ".jpg") || BLI_testextensie(filename, ".png") || BLI_testextensie(filename, ".dds") || BLI_testextensie(filename, ".tga") || BLI_testextensie(filename, ".bmp") || BLI_testextensie(filename, ".exr") || BLI_testextensie(filename, ".cin") || BLI_testextensie(filename, ".wav")) return 0; if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) { if(UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n"); return 0; } if(av_find_stream_info(pFormatCtx)<0) { if(UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n"); av_close_input_file(pFormatCtx); return 0; } if(UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0); /* Find the first video stream */ videoStream=-1; for(i=0; i<pFormatCtx->nb_streams; i++) if(pFormatCtx->streams[i] && pFormatCtx->streams[i]->codec && (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)) { videoStream=i; break; } if(videoStream==-1) { av_close_input_file(pFormatCtx); return 0; } pCodecCtx = pFormatCtx->streams[videoStream]->codec; /* Find the decoder for the video stream */ pCodec=avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec==NULL) { av_close_input_file(pFormatCtx); return 0; } if(avcodec_open(pCodecCtx, pCodec)<0) { av_close_input_file(pFormatCtx); return 0; } avcodec_close(pCodecCtx); av_close_input_file(pFormatCtx); return 1; }
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; }