bool BKE_cachefile_filepath_get( const Main *bmain, const CacheFile *cache_file, float frame, char r_filepath[FILE_MAX]) { BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX); BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id)); int fframe; int frame_len; if (cache_file->is_sequence && BLI_path_frame_get(r_filepath, &fframe, &frame_len)) { char ext[32]; BLI_path_frame_strip(r_filepath, true, ext); BLI_path_frame(r_filepath, frame, frame_len); BLI_ensure_extension(r_filepath, FILE_MAX, ext); /* TODO(kevin): store sequence range? */ return BLI_exists(r_filepath); } return true; }
static int get_sequence_len(char *filename, int *ofs) { int frame; int numdigit; if (!BLI_path_frame_get(filename, &frame, &numdigit)) { return 1; } char path[FILE_MAX]; BLI_path_abs(filename, G.main->name); BLI_split_dir_part(filename, path, FILE_MAX); if (path[0] == '\0') { /* The filename had no path, so just use the blend file path. */ BLI_split_dir_part(G.main->name, path, FILE_MAX); } DIR *dir = opendir(path); if (dir == NULL) { fprintf(stderr, "Error opening directory '%s': %s\n", path, errno ? strerror(errno) : "unknown error"); return -1; } const char *ext = ".abc"; const char *basename = BLI_path_basename(filename); const int len = strlen(basename) - (numdigit + strlen(ext)); ListBase frames; BLI_listbase_clear(&frames); struct dirent *fname; while ((fname = readdir(dir)) != NULL) { /* do we have the right extension? */ if (!strstr(fname->d_name, ext)) { continue; } if (!STREQLEN(basename, fname->d_name, len)) { continue; } CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame"); BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit); BLI_addtail(&frames, cache_frame); } closedir(dir); BLI_listbase_sort(&frames, cmp_frame); CacheFrame *cache_frame = frames.first; if (cache_frame) { int frame_curr = cache_frame->framenr; (*ofs) = frame_curr; while (cache_frame && (cache_frame->framenr == frame_curr)) { ++frame_curr; cache_frame = cache_frame->next; } BLI_freelistN(&frames); return frame_curr - (*ofs); } return 1; }
static int get_sequence_len(char *filename, int *ofs) { int frame; int numdigit; if (!BLI_path_frame_get(filename, &frame, &numdigit)) { return 1; } char path[FILE_MAX]; BLI_split_dir_part(filename, path, FILE_MAX); DIR *dir = opendir(path); const char *ext = ".abc"; const char *basename = BLI_path_basename(filename); const int len = strlen(basename) - (numdigit + strlen(ext)); ListBase frames; BLI_listbase_clear(&frames); struct dirent *fname; while ((fname = readdir(dir)) != NULL) { /* do we have the right extension? */ if (!strstr(fname->d_name, ext)) { continue; } if (!STREQLEN(basename, fname->d_name, len)) { continue; } CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame"); BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit); BLI_addtail(&frames, cache_frame); } closedir(dir); BLI_listbase_sort(&frames, cmp_frame); CacheFrame *cache_frame = frames.first; if (cache_frame) { int frame_curr = cache_frame->framenr; (*ofs) = frame_curr; while (cache_frame && (cache_frame->framenr == frame_curr)) { ++frame_curr; cache_frame = cache_frame->next; } BLI_freelistN(&frames); return frame_curr - (*ofs); } return 1; }