forked from bartvdbraak/blender
- add convenience functions BLI_split_dir_part / BLI_split_file_part, which just call BLI_split_dirfile().
- add a fixed value for bprogdir (the dir of bprogname), since it was being used for resource lookups.
This commit is contained in:
parent
9ec0ea91f0
commit
ef218c75ed
@ -910,7 +910,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
|
||||
else if (G.relbase_valid || lib) {
|
||||
char file[MAX_PTCACHE_PATH]; /* we dont want the dir, only the file */
|
||||
|
||||
BLI_split_dirfile(blendfilename, NULL, file, 0, sizeof(file));
|
||||
BLI_split_file_part(blendfilename, file, sizeof(file));
|
||||
i = strlen(file);
|
||||
|
||||
/* remove .blend */
|
||||
|
@ -104,6 +104,8 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir,
|
||||
void BLI_make_exist(char *dir);
|
||||
void BLI_make_existing_file(const char *name);
|
||||
void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
|
||||
void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen);
|
||||
void BLI_split_file_part(const char *string, char *file, const size_t filelen);
|
||||
void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file);
|
||||
char *BLI_path_basename(char *path);
|
||||
int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir);
|
||||
|
@ -903,7 +903,7 @@ void findMissingFiles(Main *bmain, const char *str)
|
||||
|
||||
//XXX waitcursor( 1 );
|
||||
|
||||
BLI_split_dirfile(str, dirname, NULL, sizeof(dirname), 0);
|
||||
BLI_split_dir_part(str, dirname, sizeof(dirname));
|
||||
|
||||
BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
|
||||
|
||||
|
@ -88,6 +88,7 @@
|
||||
#define UNIQUE_NAME_MAX 128
|
||||
|
||||
extern char bprogname[];
|
||||
extern char bprogdir[];
|
||||
|
||||
static int add_win32_extension(char *name);
|
||||
static char *blender_version_decimal(const int ver);
|
||||
@ -875,7 +876,6 @@ static int test_env_path(char *path, const char *envvar)
|
||||
|
||||
static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name, const int ver)
|
||||
{
|
||||
char bprogdir[FILE_MAX];
|
||||
char relfolder[FILE_MAX];
|
||||
|
||||
#ifdef PATH_DEBUG2
|
||||
@ -892,10 +892,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char
|
||||
else {
|
||||
relfolder[0]= '\0';
|
||||
}
|
||||
|
||||
/* use argv[0] (bprogname) to get the path to the executable */
|
||||
BLI_split_dirfile(bprogname, bprogdir, NULL, sizeof(bprogdir), 0);
|
||||
|
||||
|
||||
/* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */
|
||||
if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder))
|
||||
return 1;
|
||||
@ -963,10 +960,6 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
|
||||
* 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, sizeof(bprogdir), 0);
|
||||
|
||||
if(folder_name) {
|
||||
if (subfolder_name) {
|
||||
@ -1430,6 +1423,16 @@ void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t d
|
||||
}
|
||||
}
|
||||
|
||||
void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen)
|
||||
{
|
||||
BLI_split_dirfile(string, dir, NULL, dirlen, 0);
|
||||
}
|
||||
|
||||
void BLI_split_file_part(const char *string, char *file, const size_t filelen)
|
||||
{
|
||||
BLI_split_dirfile(string, NULL, file, 0, filelen);
|
||||
}
|
||||
|
||||
/* simple appending of filename to dir, does not check for valid path! */
|
||||
void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const char *file)
|
||||
{
|
||||
@ -1516,7 +1519,7 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const
|
||||
if (rel)
|
||||
rel[0]= 0;
|
||||
|
||||
BLI_split_dirfile(base_dir, blend_dir, NULL, sizeof(blend_dir), 0);
|
||||
BLI_split_dir_part(base_dir, blend_dir, sizeof(blend_dir));
|
||||
|
||||
if (src_dir[0]=='\0')
|
||||
return 0;
|
||||
|
@ -56,7 +56,7 @@ int BLI_getInstallationDir( char * str ) {
|
||||
int a;
|
||||
|
||||
GetModuleFileName(NULL,str,FILE_MAXDIR+FILE_MAXFILE);
|
||||
BLI_split_dirfile(str, dir, NULL, sizeof(dir), 0); /* shouldn't be relative */
|
||||
BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */
|
||||
a = strlen(dir);
|
||||
if(dir[a-1] == '\\') dir[a-1]=0;
|
||||
|
||||
|
@ -2678,8 +2678,8 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
|
||||
if(write_flags & G_FILE_RELATIVE_REMAP) {
|
||||
char dir1[FILE_MAXDIR+FILE_MAXFILE];
|
||||
char dir2[FILE_MAXDIR+FILE_MAXFILE];
|
||||
BLI_split_dirfile(filepath, dir1, NULL, sizeof(dir1), 0);
|
||||
BLI_split_dirfile(mainvar->name, dir2, NULL, sizeof(dir2), 0);
|
||||
BLI_split_dir_part(filepath, dir1, sizeof(dir1));
|
||||
BLI_split_dir_part(mainvar->name, dir2, sizeof(dir2));
|
||||
|
||||
/* just incase there is some subtle difference */
|
||||
BLI_cleanup_dir(mainvar->name, dir1);
|
||||
|
@ -884,7 +884,7 @@ bool DocumentImporter::writeImage( const COLLADAFW::Image* image )
|
||||
char dir[FILE_MAX];
|
||||
char full_path[FILE_MAX];
|
||||
|
||||
BLI_split_dirfile(filename, dir, NULL, sizeof(dir), 0);
|
||||
BLI_split_dir_part(filename, dir, sizeof(dir));
|
||||
BLI_join_dirfile(full_path, sizeof(full_path), dir, filepath.c_str());
|
||||
Image *ima = BKE_add_image_file(full_path);
|
||||
if (!ima) {
|
||||
|
@ -97,7 +97,7 @@ void ImagesExporter::operator()(Material *ma, Object *ob)
|
||||
char src[FILE_MAX];
|
||||
char dir[FILE_MAX];
|
||||
|
||||
BLI_split_dirfile(this->export_settings->filepath, dir, NULL, sizeof(dir), 0);
|
||||
BLI_split_dir_part(this->export_settings->filepath, dir, sizeof(dir));
|
||||
|
||||
BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.main->name, image->name, dir);
|
||||
|
||||
|
@ -613,7 +613,7 @@ void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
|
||||
BLI_split_dirfile(str, dirname, NULL, sizeof(dirname), 0);
|
||||
BLI_split_dir_part(str, dirname, sizeof(dirname));
|
||||
|
||||
dir = opendir(dirname);
|
||||
|
||||
|
@ -321,7 +321,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad
|
||||
char dir_only[FILE_MAX];
|
||||
char file_only[FILE_MAX];
|
||||
|
||||
BLI_split_dirfile(seq_load.path, dir_only, NULL, sizeof(dir_only), 0);
|
||||
BLI_split_dir_part(seq_load.path, dir_only, sizeof(dir_only));
|
||||
|
||||
RNA_BEGIN(op->ptr, itemptr, "files") {
|
||||
RNA_string_get(&itemptr, "name", file_only);
|
||||
|
@ -540,7 +540,7 @@ static int rna_Sequence_input_count_get(PointerRNA *ptr)
|
||||
static void rna_SequenceElement_filename_set(PointerRNA *ptr, const char *value)
|
||||
{
|
||||
StripElem *elem= (StripElem*)(ptr->data);
|
||||
BLI_split_dirfile(value, NULL, elem->name, 0, sizeof(elem->name));
|
||||
BLI_split_file_part(value, elem->name, sizeof(elem->name));
|
||||
}*/
|
||||
|
||||
static void rna_Sequence_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
|
||||
|
@ -141,7 +141,8 @@ static int print_version(int argc, const char **argv, void *data);
|
||||
|
||||
extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
|
||||
|
||||
char bprogname[FILE_MAX]; /* from blenpluginapi:pluginapi.c */
|
||||
char bprogname[FILE_MAX];
|
||||
char bprogdir[FILE_MAX];
|
||||
char btempdir[FILE_MAX];
|
||||
|
||||
#define BLEND_VERSION_STRING_FMT "Blender %d.%02d (sub %d)\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION
|
||||
@ -1157,6 +1158,7 @@ int main(int argc, const char **argv)
|
||||
// need this.
|
||||
|
||||
BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
|
||||
BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
|
||||
|
||||
BLI_threadapi_init();
|
||||
|
||||
|
@ -117,6 +117,7 @@ const int kMinWindowWidth = 100;
|
||||
const int kMinWindowHeight = 100;
|
||||
|
||||
char bprogname[FILE_MAX];
|
||||
char bprogdir[FILE_MAX];
|
||||
|
||||
static void mem_error_cb(const char *errorStr)
|
||||
{
|
||||
@ -380,6 +381,7 @@ int main(int argc, char** argv)
|
||||
#endif /* __alpha__ */
|
||||
#endif /* __linux__ */
|
||||
BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
|
||||
BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
|
||||
#ifdef __APPLE__
|
||||
// Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
|
||||
/*
|
||||
|
@ -502,7 +502,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
|
||||
BLI_path_abs(cpath, gp_GamePythonPath);
|
||||
} else {
|
||||
/* Get the dir only */
|
||||
BLI_split_dirfile(gp_GamePythonPath, cpath, NULL, sizeof(cpath), 0);
|
||||
BLI_split_dir_part(gp_GamePythonPath, cpath, sizeof(cpath));
|
||||
}
|
||||
|
||||
if((dp = opendir(cpath)) == NULL) {
|
||||
@ -1732,7 +1732,7 @@ static void initPySysObjects__append(PyObject *sys_path, char *filename)
|
||||
PyObject *item;
|
||||
char expanded[FILE_MAXDIR + FILE_MAXFILE];
|
||||
|
||||
BLI_split_dirfile(filename, expanded, NULL, sizeof(expanded), 0); /* get the dir part of filename only */
|
||||
BLI_split_dir_part(filename, expanded, sizeof(expanded)); /* get the dir part of filename only */
|
||||
BLI_path_abs(expanded, gp_GamePythonPath); /* filename from lib->filename is (always?) absolute, so this may not be needed but it wont hurt */
|
||||
BLI_cleanup_file(gp_GamePythonPath, expanded); /* Dont use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */
|
||||
item= PyUnicode_DecodeFSDefault(expanded);
|
||||
|
Loading…
Reference in New Issue
Block a user