forked from bartvdbraak/blender
BLI_split_dirfile was being used in cases it should not have been,
Added BLI_split_dirfile_basic, that only splits the path into directory and file. without checking the dir exists or creating it, without changing the original string that is passed to it.
This commit is contained in:
parent
19985ae918
commit
c8376869b1
@ -177,7 +177,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
|
|||||||
|
|
||||||
blendfilename= (lib)? lib->filename: G.sce;
|
blendfilename= (lib)? lib->filename: G.sce;
|
||||||
|
|
||||||
BLI_split_dirfile(blendfilename, dir, file);
|
BLI_split_dirfile_basic(blendfilename, NULL, file);
|
||||||
i = strlen(file);
|
i = strlen(file);
|
||||||
|
|
||||||
/* remove .blend */
|
/* remove .blend */
|
||||||
|
@ -212,7 +212,6 @@ int reopen_text(Text *text)
|
|||||||
int i, llen, len;
|
int i, llen, len;
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
TextLine *tmp;
|
TextLine *tmp;
|
||||||
char sdir[FILE_MAXDIR];
|
|
||||||
char sfile[FILE_MAXFILE];
|
char sfile[FILE_MAXFILE];
|
||||||
char str[FILE_MAXDIR+FILE_MAXFILE];
|
char str[FILE_MAXDIR+FILE_MAXFILE];
|
||||||
|
|
||||||
@ -220,7 +219,7 @@ int reopen_text(Text *text)
|
|||||||
|
|
||||||
BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE);
|
BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE);
|
||||||
BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
|
BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
|
||||||
BLI_split_dirfile(str, sdir, sfile);
|
BLI_split_dirfile_basic(str, NULL, sfile);
|
||||||
|
|
||||||
fp= fopen(str, "r");
|
fp= fopen(str, "r");
|
||||||
if(fp==NULL) return 0;
|
if(fp==NULL) return 0;
|
||||||
@ -312,14 +311,13 @@ Text *add_text(char *file)
|
|||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
TextLine *tmp;
|
TextLine *tmp;
|
||||||
Text *ta;
|
Text *ta;
|
||||||
char sdir[FILE_MAXDIR];
|
|
||||||
char sfile[FILE_MAXFILE];
|
char sfile[FILE_MAXFILE];
|
||||||
char str[FILE_MAXDIR+FILE_MAXFILE];
|
char str[FILE_MAXDIR+FILE_MAXFILE];
|
||||||
|
|
||||||
BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE);
|
BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE);
|
||||||
if (G.scene) /* can be NULL (bg mode) */
|
if (G.scene) /* can be NULL (bg mode) */
|
||||||
BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
|
BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
|
||||||
BLI_split_dirfile(str, sdir, sfile);
|
BLI_split_dirfile_basic(str, NULL, sfile);
|
||||||
|
|
||||||
fp= fopen(str, "r");
|
fp= fopen(str, "r");
|
||||||
if(fp==NULL) return NULL;
|
if(fp==NULL) return NULL;
|
||||||
|
@ -96,6 +96,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir,
|
|||||||
void BLI_make_exist(char *dir);
|
void BLI_make_exist(char *dir);
|
||||||
void BLI_make_existing_file(char *name);
|
void BLI_make_existing_file(char *name);
|
||||||
void BLI_split_dirfile(char *string, char *dir, char *file);
|
void BLI_split_dirfile(char *string, char *dir, char *file);
|
||||||
|
void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
|
||||||
void BLI_join_dirfile(char *string, const char *dir, const char *file);
|
void BLI_join_dirfile(char *string, const char *dir, const char *file);
|
||||||
int BLI_testextensie(const char *str, const char *ext);
|
int BLI_testextensie(const char *str, const char *ext);
|
||||||
void addlisttolist(ListBase *list1, ListBase *list2);
|
void addlisttolist(ListBase *list1, ListBase *list2);
|
||||||
|
@ -259,22 +259,7 @@ void seq_setpath(struct BPathIterator *bpi, char *path) {
|
|||||||
|
|
||||||
if (SEQ_HAS_PATH(seq)) {
|
if (SEQ_HAS_PATH(seq)) {
|
||||||
if (seq->type == SEQ_IMAGE || seq->type == SEQ_MOVIE) {
|
if (seq->type == SEQ_IMAGE || seq->type == SEQ_MOVIE) {
|
||||||
|
BLI_split_dirfile_basic(path, seq->strip->dir, seq->strip->stripdata->name);
|
||||||
int lslash, i = 0;
|
|
||||||
for (i=0; path[i]!='\0'; i++) {
|
|
||||||
if (path[i]=='\\' || path[i]=='/')
|
|
||||||
lslash = i+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lslash) {
|
|
||||||
BLI_strncpy( seq->strip->dir, path, lslash+1); /* +1 to include the slash and the last char */
|
|
||||||
} else {
|
|
||||||
path[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seq->strip->stripdata) { /* should always be true! */
|
|
||||||
BLI_strncpy( seq->strip->stripdata->name, path+lslash, sizeof(seq->strip->stripdata->name));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* simple case */
|
/* simple case */
|
||||||
BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
|
BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
|
||||||
@ -657,7 +642,7 @@ void findMissingFiles(char *str) {
|
|||||||
|
|
||||||
waitcursor( 1 );
|
waitcursor( 1 );
|
||||||
|
|
||||||
BLI_split_dirfile(str, dirname, dummyname);
|
BLI_split_dirfile_basic(str, dirname, NULL);
|
||||||
|
|
||||||
BLI_bpathIterator_init(&bpi);
|
BLI_bpathIterator_init(&bpi);
|
||||||
|
|
||||||
@ -678,7 +663,7 @@ void findMissingFiles(char *str) {
|
|||||||
/* can the dir be opened? */
|
/* can the dir be opened? */
|
||||||
filesize = -1;
|
filesize = -1;
|
||||||
recur_depth = 0;
|
recur_depth = 0;
|
||||||
BLI_split_dirfile(filepath, dummyname, filename); /* the file to find */
|
BLI_split_dirfile_basic(filepath, NULL, filename); /* the file to find */
|
||||||
|
|
||||||
findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth);
|
findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth);
|
||||||
if (filesize == -1) { /* could not open dir */
|
if (filesize == -1) { /* could not open dir */
|
||||||
|
@ -1426,8 +1426,41 @@ int BLI_testextensie(const char *str, const char *ext)
|
|||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a simple version of BLI_split_dirfile that has the following advantages...
|
||||||
|
*
|
||||||
|
* Converts "/foo/bar.txt" to "/foo/" and "bar.txt"
|
||||||
|
* - wont change 'string'
|
||||||
|
* - wont create any directories
|
||||||
|
* - dosnt use CWD, or deal with relative paths.
|
||||||
|
* - Only fill's in *dir and *file when they are non NULL
|
||||||
|
* */
|
||||||
|
void BLI_split_dirfile_basic(const char *string, char *dir, char *file)
|
||||||
|
{
|
||||||
|
int lslash=0, i = 0;
|
||||||
|
for (i=0; string[i]!='\0'; i++) {
|
||||||
|
if (string[i]=='\\' || string[i]=='/')
|
||||||
|
lslash = i+1;
|
||||||
|
}
|
||||||
|
if (dir) {
|
||||||
|
if (lslash) {
|
||||||
|
BLI_strncpy( dir, string, lslash+1); /* +1 to include the slash and the last char */
|
||||||
|
} else {
|
||||||
|
dir[0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
strcpy( file, string+lslash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* warning, can modify 'string' */
|
|
||||||
|
/* Warning,
|
||||||
|
* - May modify 'string' variable
|
||||||
|
* - May create the directory if it dosnt exist
|
||||||
|
* if this is not needed use BLI_split_dirfile_basic(...)
|
||||||
|
*/
|
||||||
void BLI_split_dirfile(char *string, char *dir, char *file)
|
void BLI_split_dirfile(char *string, char *dir, char *file)
|
||||||
{
|
{
|
||||||
int a;
|
int a;
|
||||||
|
@ -796,7 +796,7 @@ int BPY_run_script(Script *script)
|
|||||||
|
|
||||||
if (bpyhome) {
|
if (bpyhome) {
|
||||||
BLI_strncpy(ftmp, script->scriptname, sizeof(ftmp));
|
BLI_strncpy(ftmp, script->scriptname, sizeof(ftmp));
|
||||||
BLI_split_dirfile(ftmp, fpath, fname); /* get the filename only - fname */
|
BLI_split_dirfile_basic(ftmp, NULL, fname); /* get the filename only - fname */
|
||||||
BLI_strncpy(fpath, bpy_gethome(1), sizeof(fpath));
|
BLI_strncpy(fpath, bpy_gethome(1), sizeof(fpath));
|
||||||
BLI_add_slash(fpath);
|
BLI_add_slash(fpath);
|
||||||
strcat(fpath, fname);
|
strcat(fpath, fname);
|
||||||
|
@ -1589,7 +1589,7 @@ void mainwindow_set_filename_to_title(char *filename)
|
|||||||
char dir[FILE_MAXDIR];
|
char dir[FILE_MAXDIR];
|
||||||
char file[FILE_MAXFILE];
|
char file[FILE_MAXFILE];
|
||||||
|
|
||||||
BLI_split_dirfile(filename, dir, file);
|
BLI_split_dirfile_basic(filename, dir, file);
|
||||||
|
|
||||||
if(BLI_streq(file, ".B.blend") || filename[0] =='\0')
|
if(BLI_streq(file, ".B.blend") || filename[0] =='\0')
|
||||||
sprintf(str, "Blender");
|
sprintf(str, "Blender");
|
||||||
|
@ -786,7 +786,7 @@ static void readBlog(void)
|
|||||||
fsmenu_append_separator();
|
fsmenu_append_separator();
|
||||||
|
|
||||||
/* add last saved file */
|
/* add last saved file */
|
||||||
BLI_split_dirfile(G.sce, name, filename); /* G.sce shouldn't be relative */
|
BLI_split_dirfile_basic(G.sce, name, filename); /* G.sce shouldn't be relative */
|
||||||
|
|
||||||
fsmenu_insert_entry(name, 0, 0);
|
fsmenu_insert_entry(name, 0, 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user