diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-05-04 13:41:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-05-04 13:41:15 +0400 |
commit | 110f927c636778fedddccb041553fc6040f4ffd8 (patch) | |
tree | 350e9e82b6406ab8e633286faade5e0af5be9272 /source/blender/blenlib | |
parent | f95c1141db077ea9323dd4f1d8852e365aadb2b1 (diff) |
Changed frame numbering to only alter hashes if they are in the filename (not the directory name) to fix bug [#10566] File Open Dialog replaces '#' with '0' in directory names.
removed frame numbering from BLI_convertstringcode into its own function (BLI_convertstringframe), many uses of BLI_convertstringcode were passing dummy frames values anyway.
in cases where adding the current frame number to a filename is needed run BLI_convertstringframe(...) after BLI_convertstringcode(...)
There are some cases Im not sure BLI_convertstringframe is needed, these have been commented as todo, but at least have the same functionality they used to.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_blenlib.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/util.c | 122 |
3 files changed, 76 insertions, 53 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 33567d92c99..e24ccad12fb 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -150,7 +150,8 @@ void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds * @a framenum The framenumber to replace the frame code with. * @retval Returns true if the path was relative (started with "//"). */ -int BLI_convertstringcode(char *path, const char *basepath, int framenum); +int BLI_convertstringcode(char *path, const char *basepath); +int BLI_convertstringframe(char *path, int frame); void BLI_makestringcode(const char *relfile, char *file); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 66eb63c8dfd..79d3e487712 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -130,9 +130,9 @@ void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_ex libpath = BLI_bpathIterator_getLib(bpi); if (libpath) { /* check the files location relative to its library path */ - BLI_convertstringcode(path_expanded, libpath, G.scene->r.cfra); + BLI_convertstringcode(path_expanded, libpath); } else { /* local data, use the blend files path */ - BLI_convertstringcode(path_expanded, G.sce, G.scene->r.cfra); + BLI_convertstringcode(path_expanded, G.sce); } } char* BLI_bpathIterator_getLib( struct BPathIterator *bpi) { diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index cdac1ba7061..c85849b5ed4 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -877,7 +877,7 @@ void BLI_cleanup_file(const char *relabase, char *dir) short a; char *start, *eind; if (relabase) { - BLI_convertstringcode(dir, relabase, 0); + BLI_convertstringcode(dir, relabase); } #ifdef WIN32 if(dir[0]=='.') { /* happens for example in FILE_MAIN */ @@ -1037,10 +1037,78 @@ void BLI_makestringcode(const char *relfile, char *file) } } -int BLI_convertstringcode(char *path, const char *basepath, int framenum) + +int BLI_convertstringframe(char *path, int frame) +{ + int ch_sta, ch_end, i; + /* Insert current frame: file### -> file001 */ + ch_sta = ch_end = 0; + for (i = 0; path[i] != '\0'; i++) { + if (path[i] == '\\' || path[i] == '/') { + ch_end = 0; /* this is a directory name, dont use any hashes we found */ + } else if (path[i] == '#') { + ch_sta = i; + ch_end = ch_sta+1; + while (path[ch_end] == '#') { + ch_end++; + } + i = ch_end-1; /* keep searching */ + + /* dont break, there may be a slash after this that invalidates the previous #'s */ + } + } + if (ch_end) { /* warning, ch_end is the last # +1 */ + /* Add the frame number? */ + short numlen, hashlen; + char tmp[FILE_MAX]; + + char format[16]; /* 6 is realistically the maxframe (300000), so 8 should be enough, but 16 to be safe. */ + if (((ch_end-1)-ch_sta) >= 16) { + ch_end = ch_sta+15; /* disallow values longer then 'format' can hold */ + } + + strcpy(tmp, path); + + numlen = 1 + (int)log10((double)frame); /* this is the number of chars in the number */ + hashlen = ch_end - ch_sta; + + sprintf(format, "%d", frame); + + if (numlen==hashlen) { /* simple case */ + memcpy(tmp+ch_sta, format, numlen); + } else if (numlen < hashlen) { + memcpy(tmp+ch_sta + (hashlen-numlen), format, numlen); /*dont copy the string terminator */ + memset(tmp+ch_sta, '0', hashlen-numlen); + } else { + /* number is longer then number of #'s */ + if (tmp[ch_end] == '\0') { /* hashes are last, no need to move any string*/ + /* bad juju - not testing string length here :/ */ + memcpy(tmp+ch_sta, format, numlen+1); /* add 1 to get the string terminator \0 */ + } else { + /* we need to move the end characters, reuse i */ + int j; + + i = strlen(tmp); /* +1 to copy the string terminator */ + j = i + (numlen-hashlen); /* from/to */ + + while (i >= ch_end) { + tmp[j] = tmp[i]; + i--; + j--; + } + memcpy(tmp + ch_sta, format, numlen); + } + } + strcpy(path, tmp); + return 1; + } + return 0; +} + + +int BLI_convertstringcode(char *path, const char *basepath) { int wasrelative; - int ch_sta, ch_end; char tmp[FILE_MAX]; char base[FILE_MAX]; char vol[3] = {'\0', '\0', '\0'}; @@ -1098,54 +1166,8 @@ int BLI_convertstringcode(char *path, const char *basepath, int framenum) MEM_freeN(filepart); } - - /* Insert current frame: file### -> file001 */ - ch_end = 0; - for (ch_sta = 0; tmp[ch_sta] != '\0'; ch_sta++) { - if (tmp[ch_sta] == '#') { - ch_end = ch_sta+1; - while (tmp[ch_end] == '#') { - ch_end++; - } - break; - } - } - if (ch_end) { /* warning, ch_end is the last # +1 */ - /* Add the frame number? */ - short numlen, hashlen; - char format[16]; /* 6 is realistically the maxframe (300000), so 8 should be enough, but 16 to be safe. */ - - numlen = 1 + (int)log10((double)framenum); /* this is the number of chars in the number */ - hashlen = ch_end - ch_sta; - - sprintf(format, "%d", framenum); - - if (numlen==hashlen) { /* simple case */ - memcpy(tmp+ch_sta, format, numlen); - } else if (numlen < hashlen) { - memcpy(tmp+ch_sta + (hashlen-numlen), format, numlen); /*dont copy the string terminator */ - memset(tmp+ch_sta, '0', hashlen-numlen); - } else { - /* number is longer then number of #'s */ - if (tmp[ch_end] == '\0') { /* hashes are last, no need to move any string*/ - /* bad juju - not testing string length here :/ */ - memcpy(tmp+ch_sta, format, numlen+1); /* add 1 to get the string terminator \0 */ - } else { - /* we need to move the end characters */ - int i = strlen(tmp); /* +1 to copy the string terminator */ - int j = i + (numlen-hashlen); /* from/to */ - while (i >= ch_end) { - tmp[j] = tmp[i]; - i--; - j--; - } - memcpy(tmp + ch_sta, format, numlen); - } - } - } - /* done with file### stuff */ - strcpy(path, tmp); + #ifdef WIN32 /* skip first two chars, which in case of absolute path will be drive:/blabla and |