From ef218c75edf975b2f3946bd16194cc9679dd2d31 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Oct 2011 02:13:36 +0000 Subject: - 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. --- source/blender/blenkernel/intern/pointcache.c | 2 +- source/blender/blenlib/BLI_path_util.h | 2 ++ source/blender/blenlib/intern/bpath.c | 2 +- source/blender/blenlib/intern/path_util.c | 23 ++++++++++++---------- source/blender/blenlib/intern/winstuff.c | 2 +- source/blender/blenloader/intern/writefile.c | 4 ++-- source/blender/collada/DocumentImporter.cpp | 2 +- source/blender/collada/ImageExporter.cpp | 2 +- source/blender/editors/space_file/filesel.c | 2 +- .../editors/space_sequencer/sequencer_add.c | 2 +- source/blender/makesrna/intern/rna_sequencer.c | 2 +- source/creator/creator.c | 4 +++- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 2 ++ source/gameengine/Ketsji/KX_PythonInit.cpp | 4 ++-- 14 files changed, 32 insertions(+), 23 deletions(-) diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 8e5452e2704..bd5e5dc6049 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -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 */ diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 4f7f7b482b5..9ccdc37c353 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -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); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 4e4f8b3cade..293f824c5fd 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -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); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 21f91ce8f14..b338bfcbc50 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -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; diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 9594197ef90..21ad0ff7253 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -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; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 6e9e3da3b42..c4f6e25f40b 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -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); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 056d74aabfb..c06867ca107 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -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) { diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index 53c43677c18..6c7251016c3 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -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); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index f36145aaba0..149d84b86cd 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -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); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 7e4d02036ef..2b78bc3c190 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 9d72eeacf3e..3c2b771ae86 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -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) diff --git a/source/creator/creator.c b/source/creator/creator.c index f6b99a9f73c..24f2d22a029 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -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(); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index ea17b9adcfd..78ea2aac8ce 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -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) /* diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index e86831b9323..c7da650f988 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -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); -- cgit v1.2.3