static void filelist_read_dir(struct FileList* filelist) { char wdir[FILE_MAX]= ""; if (!filelist) return; filelist->fidx = NULL; filelist->filelist = NULL; BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */ BLI_cleanup_dir(G.main->name, filelist->dir); filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist)); if(!chdir(wdir)) {} /* fix warning about not checking return value */ filelist_setfiletypes(filelist); filelist_filter(filelist); }
/* * Should only be done with command line paths. * this is NOT somthing blenders internal paths support like the // prefix */ int BLI_path_cwd(char *path) { int wasrelative = 1; int filelen = strlen(path); #ifdef WIN32 if (filelen >= 3 && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) wasrelative = 0; #else if (filelen >= 2 && path[0] == '/') wasrelative = 0; #endif if (wasrelative==1) { char cwd[FILE_MAXDIR + FILE_MAXFILE]= ""; BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */ if (cwd[0] == '\0') { printf( "Could not get the current working directory - $PWD for an unknown reason."); } else { /* uses the blend path relative to cwd important for loading relative linked files. * * cwd should contain c:\ etc on win32 so the relbase can be NULL * relbase being NULL also prevents // being misunderstood as relative to the current * blend file which isnt a feature we want to use in this case since were dealing * with a path from the command line, rather than from inside Blender */ char origpath[FILE_MAXDIR + FILE_MAXFILE]; BLI_strncpy(origpath, path, FILE_MAXDIR + FILE_MAXFILE); BLI_make_file_string(NULL, path, cwd, origpath); } } return wasrelative; }
static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver) { char system_path[FILE_MAX]; const char *system_base_path; /* first allow developer only overrides to the system path * these are only used when running blender from source */ char cwd[FILE_MAX]; char relfolder[FILE_MAX]; char bprogdir[FILE_MAX]; /* use argv[0] (bprogname) to get the path to the executable */ BLI_split_dirfile(bprogname, bprogdir, NULL); if(folder_name) { if (subfolder_name) { BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name); } else { BLI_strncpy(relfolder, folder_name, sizeof(relfolder)); } } else { relfolder[0]= '\0'; } /* try CWD/release/folder_name */ if(BLI_getwdN(cwd, sizeof(cwd))) { if(test_path(targetpath, cwd, "release", relfolder)) { return 1; } } /* try EXECUTABLE_DIR/release/folder_name */ if(test_path(targetpath, bprogdir, "release", relfolder)) return 1; /* end developer overrides */ system_path[0] = '\0'; if (test_env_path(system_path, envvar)) { if (subfolder_name) { return test_path(targetpath, system_path, NULL, subfolder_name); } else { BLI_strncpy(targetpath, system_path, FILE_MAX); return 1; } } system_base_path = (const char *)GHOST_getSystemDir(); if (system_base_path) { BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal(ver)); } if(!system_path[0]) return 0; #ifdef PATH_DEBUG2 printf("get_path_system: %s\n", system_path); #endif if (subfolder_name) { /* try $BLENDERPATH/folder_name/subfolder_name */ return test_path(targetpath, system_path, folder_name, subfolder_name); } else { /* try $BLENDERPATH/folder_name */ return test_path(targetpath, system_path, NULL, folder_name); } }
/* filename must be FILE_MAX length minimum */ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name) { char filename[FILE_MAXDIR+FILE_MAXFILE]; const char *path = NULL, *temp; #ifdef _WIN32 const char *separator = ";"; #else const char *separator = ":"; #endif #ifdef WITH_BINRELOC /* linux uses binreloc since argv[0] is not relyable, call br_init( NULL ) first */ path = br_find_exe( NULL ); if (path) { BLI_strncpy(fullname, path, maxlen); free((void *)path); return; } #endif #ifdef _WIN32 if(GetModuleFileName(0, fullname, maxlen)) { if(!BLI_exists(fullname)) { printf("path can't be found: \"%.*s\"\n", maxlen, fullname); MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } return; } #endif /* unix and non linux */ if (name && name[0]) { BLI_strncpy(fullname, name, maxlen); if (name[0] == '.') { char wdir[FILE_MAX]= ""; BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name if(name[1]==SEP) BLI_join_dirfile(fullname, maxlen, wdir, name+2); else BLI_join_dirfile(fullname, maxlen, wdir, name); add_win32_extension(fullname); /* XXX, doesnt respect length */ } else if (BLI_last_slash(name)) { // full path BLI_strncpy(fullname, name, maxlen); add_win32_extension(fullname); } else { // search for binary in $PATH path = getenv("PATH"); if (path) { do { temp = strstr(path, separator); if (temp) { strncpy(filename, path, temp - path); filename[temp - path] = 0; path = temp + 1; } else { strncpy(filename, path, sizeof(filename)); } BLI_join_dirfile(fullname, maxlen, fullname, name); if (add_win32_extension(filename)) { BLI_strncpy(fullname, filename, maxlen); break; } } while (temp); } } #if defined(DEBUG) if (strcmp(name, fullname)) { printf("guessing '%s' == '%s'\n", name, fullname); } #endif } }