static void file_expand_directory(bContext *C) { SpaceFile *sfile= CTX_wm_space_file(C); if(sfile->params) { if ( sfile->params->dir[0] == '~' ) { char tmpstr[sizeof(sfile->params->dir)-1]; BLI_strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr)); BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BLI_getDefaultDocumentFolder(), tmpstr); } #ifdef WIN32 if (sfile->params->dir[0] == '\0') { get_default_root(sfile->params->dir); } /* change "C:" --> "C:\", [#28102] */ else if ( (isalpha(sfile->params->dir[0]) && (sfile->params->dir[1] == ':')) && (sfile->params->dir[2] == '\0') ) { sfile->params->dir[2]= '\\'; sfile->params->dir[3]= '\0'; } #endif } }
static void file_expand_directory(bContext *C) { SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { /* TODO, what about // when relbase isn't valid? */ if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) { BLI_path_abs(sfile->params->dir, G.main->name); } else if (sfile->params->dir[0] == '~') { char tmpstr[sizeof(sfile->params->dir) - 1]; BLI_strncpy(tmpstr, sfile->params->dir + 1, sizeof(tmpstr)); BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BLI_getDefaultDocumentFolder(), tmpstr); } else if (sfile->params->dir[0] == '\0') #ifndef WIN32 { sfile->params->dir[0] = '/'; sfile->params->dir[1] = '\0'; } #else { get_default_root(sfile->params->dir); } /* change "C:" --> "C:\", [#28102] */ else if ((isalpha(sfile->params->dir[0]) && (sfile->params->dir[1] == ':')) && (sfile->params->dir[2] == '\0')) { sfile->params->dir[2] = '\\'; sfile->params->dir[3] = '\0'; } #endif }
/* 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_menutype_init(); WM_uilisttype_init(); set_free_windowmanager_cb(wm_close_and_free); /* library.c */ set_free_notifier_reference_cb(WM_main_remove_notifier_reference); /* library.c */ set_blender_test_break_cb(wm_window_testbreak); /* blender.c */ DAG_editors_update_cb(ED_render_id_flush_update, ED_render_scene_update); /* depsgraph.c */ ED_spacetypes_init(); /* editors/space_api/spacetype.c */ ED_file_init(); /* for fsmenu */ ED_node_init_butfuncs(); BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */ BLF_lang_init(); /* get the default database, plus a wm */ wm_homefile_read(C, NULL, G.factory_startup); BLF_lang_set(NULL); /* 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); wm_init_reports(C); /* reports cant be initialized before the wm */ if (!G.background) { GPU_extensions_init(); GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP)); GPU_set_anisotropic(U.anisotropic_filter); GPU_set_gpu_mipmapping(U.use_gpu_mipmap); UI_init(); } clear_matcopybuf(); ED_render_clear_mtex_copybuf(); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ED_preview_init_dbase(); wm_read_history(); /* allow a path of "", this is what happens when making a new file */ #if 0 if (G.main->name[0] == 0) BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend"); #endif BLI_strncpy(G.lib, G.main->name, FILE_MAX); #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 { /* 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. */ BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); } }
/* 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(); wm_operatortype_init(); WM_menutype_init(); set_free_windowmanager_cb(wm_close_and_free); /* library.c */ set_blender_test_break_cb(wm_window_testbreak); /* blender.c */ DAG_editors_update_cb(ED_render_id_flush_update, ED_render_scene_update); /* depsgraph.c */ ED_spacetypes_init(); /* editors/space_api/spacetype.c */ ED_file_init(); /* for fsmenu */ ED_init_node_butfuncs(); BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */ BLF_lang_init(); /* get the default database, plus a wm */ WM_read_homefile(C, NULL, G.factory_startup); BLF_lang_set(NULL); /* 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_read_homefile() 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_driver_reset(); BPY_app_handlers_reset(FALSE); /* causes addon callbacks to be freed [#28068], * but this is actually what we want. */ BPY_modules_load_user(C); #else (void)argc; /* unused */ (void)argv; /* unused */ #endif if (!G.background && !wm_start_with_console) GHOST_toggleConsole(3); wm_init_reports(C); /* reports cant be initialized before the wm */ if (!G.background) { GPU_extensions_init(); GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP)); GPU_set_anisotropic(U.anisotropic_filter); GPU_set_gpu_mipmapping(U.use_gpu_mipmap); UI_init(); } clear_matcopybuf(); ED_render_clear_mtex_copybuf(); // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); ED_preview_init_dbase(); WM_read_history(); /* allow a path of "", this is what happens when making a new file */ #if 0 if (G.main->name[0] == 0) BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend"); #endif BLI_strncpy(G.lib, G.main->name, FILE_MAX); #ifdef WITH_COMPOSITOR if (1) { extern void *COM_linker_hack; extern void *COM_execute; COM_linker_hack = COM_execute; } #endif }
/** * \note RNA_struct_property_is_set_ex is used here because we want * the previously used settings to be used here rather then overriding them */ short ED_fileselect_set_params(SpaceFile *sfile) { FileSelectParams *params; wmOperator *op = sfile->op; /* create new parameters if necessary */ if (!sfile->params) { sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams"); /* set path to most recently opened .blend */ BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; } params = sfile->params; /* set the parameters from the operator, if it exists */ if (op) { PropertyRNA *prop; const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL); const bool is_filepath = (RNA_struct_find_property(op->ptr, "filepath") != NULL); const bool is_filename = (RNA_struct_find_property(op->ptr, "filename") != NULL); const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL); const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL); BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title)); if (RNA_struct_find_property(op->ptr, "filemode")) params->type = RNA_int_get(op->ptr, "filemode"); else params->type = FILE_SPECIAL; if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { char name[FILE_MAX]; RNA_string_get(op->ptr, "filepath", name); if (params->type == FILE_LOADLIB) { BLI_strncpy(params->dir, name, sizeof(params->dir)); sfile->params->file[0] = '\0'; } else { BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); } } else { if (is_directory && RNA_struct_property_is_set_ex(op->ptr, "directory", false)) { RNA_string_get(op->ptr, "directory", params->dir); sfile->params->file[0] = '\0'; } if (is_filename && RNA_struct_property_is_set_ex(op->ptr, "filename", false)) { RNA_string_get(op->ptr, "filename", params->file); } } if (params->dir[0]) { BLI_cleanup_dir(G.main->name, params->dir); BLI_path_abs(params->dir, G.main->name); } if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) { params->flag |= FILE_DIRSEL_ONLY; } else { params->flag &= ~FILE_DIRSEL_ONLY; } params->filter = 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? BLENDERFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? BLENDERFILE_BACKUP : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_image"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? IMAGEFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_movie"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? MOVIEFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_python"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? PYSCRIPTFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_font"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FTFONTFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_sound"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? SOUNDFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_text"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? TEXTFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_folder"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FOLDERFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_btx"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? BTXFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_collada"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? COLLADAFILE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) { RNA_property_string_get(op->ptr, prop, params->filter_glob); params->filter |= (OPERATORFILE | FOLDERFILE); } else { params->filter_glob[0] = '\0'; } if (params->filter != 0) { if (U.uiflag & USER_FILTERFILEEXTS) { params->flag |= FILE_FILTER; } else { params->flag &= ~FILE_FILTER; } } if (U.uiflag & USER_HIDE_DOT) { params->flag |= FILE_HIDE_DOT; } else { params->flag &= ~FILE_HIDE_DOT; } if (params->type == FILE_LOADLIB) { params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0; params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0; params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0; } if (RNA_struct_find_property(op->ptr, "display_type")) params->display = RNA_enum_get(op->ptr, "display_type"); if (params->display == FILE_DEFAULTDISPLAY) { if (U.uiflag & USER_SHOW_THUMBNAILS) { if (params->filter & (IMAGEFILE | MOVIEFILE)) params->display = FILE_IMGDISPLAY; else params->display = FILE_SHORTDISPLAY; } else { params->display = FILE_SHORTDISPLAY; } } if (is_relative_path) { if (!RNA_struct_property_is_set_ex(op->ptr, "relative_path", false)) { RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS); } } } else { /* default values, if no operator */ params->type = FILE_UNIX; params->flag |= FILE_HIDE_DOT; params->flag &= ~FILE_DIRSEL_ONLY; params->display = FILE_SHORTDISPLAY; params->filter = 0; params->filter_glob[0] = '\0'; } /* operator has no setting for this */ params->sort = FILE_SORT_ALPHA; /* initialize the list with previous folders */ if (!sfile->folders_prev) sfile->folders_prev = folderlist_new(); if (!sfile->params->dir[0]) { if (G.main->name[0]) { BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir)); } else { const char *doc_path = BLI_getDefaultDocumentFolder(); if (doc_path) { BLI_strncpy(sfile->params->dir, doc_path, sizeof(sfile->params->dir)); } } } folderlist_pushdir(sfile->folders_prev, sfile->params->dir); /* switching thumbnails needs to recalc layout [#28809] */ if (sfile->layout) { sfile->layout->dirty = true; } return 1; }