void BLI_dir_create_recursive(const char *dirname) { char *lslash; char tmp[MAXPATHLEN]; // First remove possible slash at the end of the dirname. // This routine otherwise tries to create // blah1/blah2/ (with slash) after creating // blah1/blah2 (without slash) BLI_strncpy(tmp, dirname, sizeof(tmp)); lslash= BLI_last_slash(tmp); if (lslash == tmp + strlen(tmp) - 1) { *lslash = 0; } if (BLI_exists(tmp)) return; lslash= BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ if (!CreateDirectory(dirname, NULL)) callLocalErrorCallBack("Unable to create directory\n"); }
void BLI_dir_create_recursive(const char *dirname) { char *lslash; size_t size; #ifdef MAXPATHLEN char static_buf[MAXPATHLEN]; #endif char *tmp; if (BLI_exists(dirname)) return; #ifdef MAXPATHLEN size = MAXPATHLEN; tmp = static_buf; #else size = strlen(dirname) + 1; tmp = MEM_callocN(size, __func__); #endif BLI_strncpy(tmp, dirname, size); lslash = (char *)BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } #ifndef MAXPATHLEN MEM_freeN(tmp); #endif mkdir(dirname, 0777); }
int file_directory_new_exec(bContext *C, wmOperator *op) { char name[FILE_MAXFILE]; char path[FILE_MAX]; int generate_name = 1; wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); if (!sfile->params) { BKE_report(op->reports, RPT_WARNING, "No parent directory given"); return OPERATOR_CANCELLED; } path[0] = '\0'; if (RNA_struct_find_property(op->ptr, "directory")) { RNA_string_get(op->ptr, "directory", path); if (path[0] != '\0') generate_name = 0; } if (generate_name) { /* create a new, non-existing folder name */ if (!new_folder_path(sfile->params->dir, path, name)) { BKE_report(op->reports, RPT_ERROR, "Could not create new folder name"); return OPERATOR_CANCELLED; } } /* create the file */ BLI_dir_create_recursive(path); if (!BLI_exists(path)) { BKE_report(op->reports, RPT_ERROR, "Could not create new folder"); return OPERATOR_CANCELLED; } /* now remember file to jump into editing */ BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE); /* set timer to smoothly view newly generated file */ sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0); /* max 30 frs/sec */ sfile->scroll_offset = 0; /* reload dir to make sure we're seeing what's in the directory */ ED_fileselect_clear(wm, sfile); if (RNA_boolean_get(op->ptr, "open")) { BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir)); file_change_dir(C, 1); } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; }
void BLI_make_existing_file(const char *name) { char di[FILE_MAX], fi[FILE_MAXFILE]; BLI_strncpy(di, name, sizeof(di)); BLI_splitdirstring(di, fi); /* test exist */ if (BLI_exists(di) == 0) { BLI_dir_create_recursive(di); } }
char *BLI_get_folder_create(int folder_id, const char *subfolder) { char *path; /* only for user folders */ if (!ELEM4(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_SCRIPTS, BLENDER_USER_AUTOSAVE)) return NULL; path = BLI_get_folder(folder_id, subfolder); if (!path) { path = BLI_get_user_folder_notest(folder_id, subfolder); if (path) BLI_dir_create_recursive(path); } return path; }
void BLI_dir_create_recursive(const char *dirname) { char *lslash; char tmp[MAXPATHLEN]; if (BLI_exists(dirname)) return; BLI_strncpy(tmp, dirname, sizeof(tmp)); lslash= BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } mkdir(dirname, 0777); }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_draw_mat_preview(uiBlock *block, Scene *scene, ARegion *ar, SpaceLDB *slivedb, ListBase *lb) { LiveDbTreeElement *te; char *file_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0); strcat(file_path, "/livedb/"); strcat(file_path, slivedb->server_address); strcat(file_path, "/previews/"); BLI_path_native_slash(file_path); BLI_dir_create_recursive(file_path); for (te = lb->first; te; te = te->next) { if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_MATERIAL && te->ys + 2 * MAT_LIVEDB_UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) { unsigned int width, height; char* buf = mat_livedb_get_mat_preview(slivedb->server_address, te->item->mat_item.id, &width, &height, file_path); if(buf) { if(width && height) { glEnable(GL_BLEND); glColor4f(0.0, 0.0, 0.0, 0.0); if (width != UI_UNIT_X || height != (MAT_LIVEDB_UI_UNIT_Y - 2)) { float facx = (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)width; float facy = (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)height; glPixelZoom(facx, facy); } glaDrawPixelsAuto((float)(ar->v2d.cur.xmax - MAT_LIVEDB_UI_UNIT_Y - 1), (float)te->ys + 1, width, height, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, buf); glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); } MEM_freeN(buf); } } else if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) mat_livedb_draw_mat_preview(block, scene, ar, slivedb, &te->subtree); } } /* mat_livedb_draw_mat_preview() */
void BLI_dir_create_recursive(const char *dirname) { char *lslash; char tmp[MAXPATHLEN]; /* First remove possible slash at the end of the dirname. * This routine otherwise tries to create * blah1/blah2/ (with slash) after creating * blah1/blah2 (without slash) */ BLI_strncpy(tmp, dirname, sizeof(tmp)); lslash = (char *)BLI_last_slash(tmp); if (lslash && (*(lslash + 1) == '\0')) { *lslash = '\0'; } /* check special case "c:\foo", don't try create "c:", harmless but prints an error below */ if (isalpha(tmp[0]) && (tmp[1] == ':') && tmp[2] == '\0') return; if (BLI_exists(tmp)) return; lslash = (char *)BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } if (dirname[0]) { /* patch, this recursive loop tries to create a nameless directory */ if (umkdir(dirname) == -1) { printf("Unable to create directory %s\n", dirname); } } }
/** * Gets the temp directory when blender first runs. * If the default path is not found, use try $TEMP * * Also make sure the temp dir has a trailing slash * * \param fullname The full path to the temporary temp directory * \param basename The full path to the persistent temp directory (may be NULL) * \param maxlen The size of the fullname buffer * \param userdir Directory specified in user preferences */ static void BLI_where_is_temp(char *fullname, char *basename, const size_t maxlen, char *userdir) { /* Clear existing temp dir, if needed. */ BKE_tempdir_session_purge(); fullname[0] = '\0'; if (basename) { basename[0] = '\0'; } if (userdir && BLI_is_dir(userdir)) { BLI_strncpy(fullname, userdir, maxlen); } #ifdef WIN32 if (fullname[0] == '\0') { const char *tmp = getenv("TEMP"); /* Windows */ if (tmp && BLI_is_dir(tmp)) { BLI_strncpy(fullname, tmp, maxlen); } } #else /* Other OS's - Try TMP and TMPDIR */ if (fullname[0] == '\0') { const char *tmp = getenv("TMP"); if (tmp && BLI_is_dir(tmp)) { BLI_strncpy(fullname, tmp, maxlen); } } if (fullname[0] == '\0') { const char *tmp = getenv("TMPDIR"); if (tmp && BLI_is_dir(tmp)) { BLI_strncpy(fullname, tmp, maxlen); } } #endif if (fullname[0] == '\0') { BLI_strncpy(fullname, "/tmp/", maxlen); } else { /* add a trailing slash if needed */ BLI_add_slash(fullname); #ifdef WIN32 if (userdir && userdir != fullname) { BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */ } #endif } /* Now that we have a valid temp dir, add system-generated unique sub-dir. */ if (basename) { /* 'XXXXXX' is kind of tag to be replaced by mktemp-familly by an uuid. */ char *tmp_name = BLI_strdupcat(fullname, "blender_XXXXXX"); const size_t ln = strlen(tmp_name) + 1; if (ln <= maxlen) { #ifdef WIN32 if (_mktemp_s(tmp_name, ln) == 0) { BLI_dir_create_recursive(tmp_name); } #else mkdtemp(tmp_name); #endif } if (BLI_is_dir(tmp_name)) { BLI_strncpy(basename, fullname, maxlen); BLI_strncpy(fullname, tmp_name, maxlen); BLI_add_slash(fullname); } else { printf("Warning! Could not generate a temp file name for '%s', falling back to '%s'\n", tmp_name, fullname); } MEM_freeN(tmp_name); } }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void get_material_startjob(void *customdata, short *stop, short *do_update, float *progress) { Main *bmain; bContext *C; bNodeTree *ntree; MatItem *items; uint32_t buf_size; GetMaterialJob *mj = customdata; mj->stop = stop; mj->do_update = do_update; mj->progress = progress; ntree = mj->ntree; bmain = mj->bmain; C = mj->C; *progress = 0.1f; items = mat_livedb_get_material(mj->address, mj->mat_id, &buf_size); *progress = 0.9f; if(items) { bNode *node, *next; MatItem *cur_item = items; bNode *node_to; bNodeSocket *sock_to; char file_path[FILE_MAX]; float cur_y_pos = 0; /* Remove all existing nodes */ ED_preview_kill_jobs(CTX_wm_manager(C), bmain); for (node = ntree->nodes.first; node; node = next) { next = node->next; /* check id user here, nodeFreeNode is called for free dbase too */ if (node->id) node->id->us--; nodeFreeNode(ntree, node); } ntreeUpdateTree(bmain, ntree); node_to = nodeAddNode(C, ntree, "ShaderNodeOutputMaterial"); node_to->locx = 0; node_to->locy = 0; for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { if(!sock_to || strcmp(sock_to->name, "Surface")) continue; break; } /* create file path */ if(!strlen(G.main->name)) { char *cur_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0); strcpy(file_path, cur_path); strcat(file_path, "/livedb/"); } else { BLI_strncpy(file_path, "//livedb/", sizeof(file_path)); BLI_path_abs(file_path, G.main->name); } strcat(file_path, mj->address); strcat(file_path, "/textures/"); BLI_path_native_slash(file_path); BLI_dir_create_recursive(file_path); mat_livedb_add_mat_element(bmain, C, ntree, node_to, sock_to, &cur_item, file_path, 0, &cur_y_pos); ED_node_tree_update(C); ED_node_tag_update_nodetree(bmain, ntree, 0); MEM_freeN(items); } *do_update = 1; *stop = 0; *progress = 1.0f; return; } /* get_material_job() */