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, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(string); if (rd->scemode & R_EXTENSION) { if (!BLI_path_extension_check(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, ""); }
ImBuf *get_brush_icon(Brush *brush) { static const int flags = IB_rect | IB_multilayer | IB_metadata; char path[FILE_MAX]; const char *folder; if (!(brush->icon_imbuf)) { if (brush->flag & BRUSH_CUSTOM_ICON) { if (brush->icon_filepath[0]) { // first use the path directly to try and load the file BLI_strncpy(path, brush->icon_filepath, sizeof(brush->icon_filepath)); BLI_path_abs(path, BKE_main_blendfile_path_from_global()); /* use default colorspaces for brushes */ brush->icon_imbuf = IMB_loadiffname(path, flags, NULL); // otherwise lets try to find it in other directories if (!(brush->icon_imbuf)) { folder = BKE_appdir_folder_id(BLENDER_DATAFILES, "brushicons"); BLI_make_file_string( BKE_main_blendfile_path_from_global(), path, folder, brush->icon_filepath); if (path[0]) { /* use fefault color spaces */ brush->icon_imbuf = IMB_loadiffname(path, flags, NULL); } } if (brush->icon_imbuf) { BKE_icon_changed(BKE_icon_id_ensure(&brush->id)); } } } } if (!(brush->icon_imbuf)) { brush->id.icon_id = 0; } return brush->icon_imbuf; }
static int screenshot_exec(bContext *C, wmOperator *op) { ScreenshotData *scd = op->customdata; bool ok = false; if (scd == NULL) { /* when running exec directly */ screenshot_data_create(C, op); scd = op->customdata; } if (scd) { if (scd->dumprect) { ImBuf *ibuf; char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); BLI_path_abs(path, BKE_main_blendfile_path_from_global()); /* operator ensures the extension */ ibuf = IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0); ibuf->rect = scd->dumprect; /* crop to show only single editor */ if (!RNA_boolean_get(op->ptr, "full")) { screenshot_crop(ibuf, scd->crop); } if (scd->im_format.planes == R_IMF_PLANES_BW) { /* bw screenshot? - users will notice if it fails! */ IMB_color_to_bw(ibuf); } if (BKE_imbuf_write(ibuf, path, &scd->im_format)) { ok = true; } else { BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); } IMB_freeImBuf(ibuf); } } screenshot_data_free(op); return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; }
static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { if (screenshot_data_create(C, op)) { if (RNA_struct_property_is_set(op->ptr, "filepath")) { return screenshot_exec(C, op); } /* extension is added by 'screenshot_check' after */ char filepath[FILE_MAX] = "//screen"; if (G.relbase_valid) { BLI_strncpy(filepath, BKE_main_blendfile_path_from_global(), sizeof(filepath)); BLI_path_extension_replace(filepath, sizeof(filepath), ""); /* strip '.blend' */ } RNA_string_set(op->ptr, "filepath", filepath); WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; } return OPERATOR_CANCELLED; }
/* only called once, for startup */ void WM_init(bContext *C, int argc, const char **argv) { if (!G.background) { wm_ghost_init(C); /* note: it assigns C to ghost! */ wm_init_cursor_data(); } GHOST_CreateSystemPaths(); BKE_addon_pref_type_init(); wm_operatortype_init(); wm_operatortypes_register(); WM_menutype_init(); WM_uilisttype_init(); ED_undosys_type_init(); BKE_library_callback_free_window_manager_set(wm_close_and_free); /* library.c */ BKE_library_callback_free_notifier_reference_set(WM_main_remove_notifier_reference); /* library.c */ BKE_library_callback_remap_editor_id_reference_set(WM_main_remap_editor_id_reference); /* library.c */ BKE_blender_callback_test_break_set(wm_window_testbreak); /* blender.c */ BKE_spacedata_callback_id_remap_set(ED_spacedata_id_remap); /* screen.c */ DAG_editors_update_cb(ED_render_id_flush_update, ED_render_scene_update, ED_render_scene_update_pre); /* depsgraph.c */ ED_spacetypes_init(); /* editors/space_api/spacetype.c */ ED_file_init(); /* for fsmenu */ ED_node_init_butfuncs(); BLF_init(); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */ BLT_lang_init(); /* Must call first before doing any .blend file reading, since versionning code may create new IDs... See T57066. */ BLT_lang_set(NULL); /* reports cant be initialized before the wm, * but keep before file reading, since that may report errors */ wm_init_reports(C); /* get the default database, plus a wm */ wm_homefile_read(C, NULL, G.factory_startup, false, true, NULL, WM_init_state_app_template_get()); /* Call again to set from userpreferences... */ BLT_lang_set(NULL); if (!G.background) { #ifdef WITH_INPUT_NDOF /* sets 3D mouse deadzone */ WM_ndof_deadzone_set(U.ndof_deadzone); #endif GPU_init(); GPU_set_mipmap(G_MAIN, !(U.gameflags & USER_DISABLE_MIPMAP)); GPU_set_linear_mipmap(true); GPU_set_anisotropic(G_MAIN, U.anisotropic_filter); GPU_set_gpu_mipmapping(G_MAIN, U.use_gpu_mipmap); #ifdef WITH_OPENSUBDIV BKE_subsurf_osd_init(); #endif UI_init(); } else { /* Note: Currently only inits icons, which we now want in background mode too * (scripts could use those in background processing...). * In case we do more later, we may need to pass a 'background' flag. * Called from 'UI_init' above */ BKE_icons_init(1); } ED_spacemacros_init(); /* note: there is a bug where python needs initializing before loading the * startup.blend because it may contain PyDrivers. It also needs to be after * initializing space types and other internal data. * * However cant redo this at the moment. Solution is to load python * before wm_homefile_read() or make py-drivers check if python is running. * Will try fix when the crash can be repeated. - campbell. */ #ifdef WITH_PYTHON BPY_context_set(C); /* necessary evil */ BPY_python_start(argc, argv); BPY_python_reset(C); #else (void)argc; /* unused */ (void)argv; /* unused */ #endif if (!G.background && !wm_start_with_console) GHOST_toggleConsole(3); clear_matcopybuf(); ED_render_clear_mtex_copybuf(); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); wm_history_file_read(); /* allow a path of "", this is what happens when making a new file */ #if 0 if (BKE_main_blendfile_path_from_global()[0] == '\0') BLI_make_file_string("/", G_MAIN->name, BKE_appdir_folder_default(), "untitled.blend"); #endif BLI_strncpy(G.lib, BKE_main_blendfile_path_from_global(), sizeof(G.lib)); #ifdef WITH_COMPOSITOR if (1) { extern void *COM_linker_hack; COM_linker_hack = COM_execute; } #endif /* load last session, uses regular file reading so it has to be in end (after init py etc) */ if (U.uiflag2 & USER_KEEP_SESSION) { /* calling WM_recover_last_session(C, NULL) has been moved to creator.c */ /* that prevents loading both the kept session, and the file on the command line */ } else { Main *bmain = CTX_data_main(C); /* note, logic here is from wm_file_read_post, * call functions that depend on Python being initialized. */ /* normally 'wm_homefile_read' will do this, * however python is not initialized when called from this function. * * unlikely any handlers are set but its possible, * note that recovering the last session does its own callbacks. */ CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first); BLI_callback_exec(bmain, NULL, BLI_CB_EVT_VERSION_UPDATE); BLI_callback_exec(bmain, NULL, BLI_CB_EVT_LOAD_POST); wm_file_read_report(C, bmain); if (!G.background) { CTX_wm_window_set(C, NULL); } } }
static int get_sequence_len(char *filename, int *ofs) { int frame; int numdigit; if (!BLI_path_frame_get(filename, &frame, &numdigit)) { return 1; } char path[FILE_MAX]; BLI_path_abs(filename, BKE_main_blendfile_path_from_global()); BLI_split_dir_part(filename, path, FILE_MAX); if (path[0] == '\0') { /* The filename had no path, so just use the blend file path. */ BLI_split_dir_part(BKE_main_blendfile_path_from_global(), path, FILE_MAX); } DIR *dir = opendir(path); if (dir == NULL) { fprintf(stderr, "Error opening directory '%s': %s\n", path, errno ? strerror(errno) : "unknown error"); return -1; } const char *ext = ".abc"; const char *basename = BLI_path_basename(filename); const int len = strlen(basename) - (numdigit + strlen(ext)); ListBase frames; BLI_listbase_clear(&frames); struct dirent *fname; while ((fname = readdir(dir)) != NULL) { /* do we have the right extension? */ if (!strstr(fname->d_name, ext)) { continue; } if (!STREQLEN(basename, fname->d_name, len)) { continue; } CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame"); BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit); BLI_addtail(&frames, cache_frame); } closedir(dir); BLI_listbase_sort(&frames, cmp_frame); CacheFrame *cache_frame = frames.first; if (cache_frame) { int frame_curr = cache_frame->framenr; (*ofs) = frame_curr; while (cache_frame && (cache_frame->framenr == frame_curr)) { ++frame_curr; cache_frame = cache_frame->next; } BLI_freelistN(&frames); return frame_curr - (*ofs); } return 1; }