- remove bpath iterator and replace all uses with visitor.
- added flag to optionally receive all paths as absolute.
This commit is contained in:
@@ -160,22 +160,19 @@ static void clear_global(void)
|
||||
G.main= NULL;
|
||||
}
|
||||
|
||||
static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src)
|
||||
{
|
||||
strcpy(path_dst, path_src);
|
||||
BLI_clean(path_dst);
|
||||
return (strcmp(path_dst, path_src) == 0) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/* make sure path names are correct for OS */
|
||||
static void clean_paths(Main *main)
|
||||
{
|
||||
struct BPathIterator *bpi;
|
||||
char filepath_expanded[1024];
|
||||
Scene *scene;
|
||||
|
||||
for(BLI_bpathIterator_init(&bpi, main, main->name, BPATH_USE_PACKED); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
|
||||
BLI_bpathIterator_getPath(bpi, filepath_expanded);
|
||||
|
||||
BLI_clean(filepath_expanded);
|
||||
|
||||
BLI_bpathIterator_setPath(bpi, filepath_expanded);
|
||||
}
|
||||
|
||||
BLI_bpathIterator_free(bpi);
|
||||
bpath_traverse_main(main, clean_paths_visit_cb, 0, NULL);
|
||||
|
||||
for(scene= main->scene.first; scene; scene= scene->id.next) {
|
||||
BLI_clean(scene->r.pic);
|
||||
|
@@ -391,7 +391,7 @@ void make_local_image(struct Image *ima)
|
||||
iman->id.us= 0;
|
||||
|
||||
/* Remap paths of new ID using old library as base. */
|
||||
bpath_traverse_id(&iman->id, bpath_relocate_visitor, user_data);
|
||||
bpath_traverse_id(bmain, &iman->id, bpath_relocate_visitor, 0, user_data);
|
||||
|
||||
tex= bmain->tex.first;
|
||||
while(tex) {
|
||||
|
@@ -1253,7 +1253,7 @@ int new_id(ListBase *lb, ID *id, const char *tname)
|
||||
void id_clear_lib_data(Main *bmain, ID *id)
|
||||
{
|
||||
char *user_data[2]= {bmain->name, id->lib->filepath};
|
||||
bpath_traverse_id(id, bpath_relocate_visitor, user_data);
|
||||
bpath_traverse_id(bmain, id, bpath_relocate_visitor, 0, user_data);
|
||||
id->lib= NULL;
|
||||
id->flag= LIB_LOCAL;
|
||||
new_id(which_libbase(bmain, GS(id->name)), id, NULL);
|
||||
|
@@ -34,38 +34,28 @@
|
||||
#ifndef BLI_BPATH_H
|
||||
#define BLI_BPATH_H
|
||||
|
||||
struct BPathIterator;
|
||||
struct ReportList;
|
||||
struct Main;
|
||||
struct ID;
|
||||
|
||||
void BLI_bpathIterator_init (struct BPathIterator **bpi, struct Main *bmain, const char *basedir, const int flag);
|
||||
void BLI_bpathIterator_free (struct BPathIterator *bpi);
|
||||
const char* BLI_bpathIterator_getLib (struct BPathIterator *bpi);
|
||||
const char* BLI_bpathIterator_getName (struct BPathIterator *bpi);
|
||||
int BLI_bpathIterator_getType (struct BPathIterator *bpi);
|
||||
unsigned int BLI_bpathIterator_getPathMaxLen (struct BPathIterator *bpi);
|
||||
const char* BLI_bpathIterator_getBasePath (struct BPathIterator *bpi);
|
||||
void BLI_bpathIterator_step (struct BPathIterator *bpi);
|
||||
int BLI_bpathIterator_isDone (struct BPathIterator *bpi);
|
||||
void BLI_bpathIterator_getPath (struct BPathIterator *bpi, char *path);
|
||||
void BLI_bpathIterator_getPathExpanded (struct BPathIterator *bpi, char *path_expanded);
|
||||
void BLI_bpathIterator_setPath (struct BPathIterator *bpi, const char *path);
|
||||
|
||||
/* Function that does something with an ID's file path. Should return 1 if the
|
||||
path has changed, and in that case, should write the result to pathOut. */
|
||||
typedef int (*BPathVisitor)(void *userdata, char *path_dst, const char *path_src);
|
||||
/* Executes 'visit' for each path associated with 'id'. */
|
||||
void bpath_traverse_id(struct ID *id, BPathVisitor visit, void *userdata);
|
||||
void bpath_traverse_id(struct Main *bmain, struct ID *id, BPathVisitor visit_cb, int flag, void *userdata);
|
||||
void bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, BPathVisitor visit_cb, int flag, void *userdata);
|
||||
void bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, int flag, void *userdata);
|
||||
int bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char *path_src);
|
||||
|
||||
#define BPATH_TRAVERSE_ABS 1 /* convert paths to absolute */
|
||||
|
||||
/* high level funcs */
|
||||
|
||||
/* creates a text file with missing files if there are any */
|
||||
void checkMissingFiles(struct Main *bmain, struct ReportList *reports);
|
||||
void makeFilesRelative(struct Main *bmain, const char *basedir, struct ReportList *reports);
|
||||
void makeFilesAbsolute(struct Main *bmain, const char *basedir, struct ReportList *reports);
|
||||
void findMissingFiles(struct Main *bmain, const char *str);
|
||||
void findMissingFiles(struct Main *bmain, const char *searchpath, struct ReportList *reports);
|
||||
|
||||
#define BPATH_USE_PACKED 1
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -253,10 +253,12 @@ void FILE_OT_make_paths_absolute(wmOperatorType *ot)
|
||||
|
||||
/********************* report missing files operator *********************/
|
||||
|
||||
static int report_missing_files_exec(bContext *UNUSED(C), wmOperator *op)
|
||||
static int report_missing_files_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain= CTX_data_main(C);
|
||||
|
||||
/* run the missing file check */
|
||||
checkMissingFiles(G.main, op->reports);
|
||||
checkMissingFiles(bmain, op->reports);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
@@ -276,13 +278,12 @@ void FILE_OT_report_missing_files(wmOperatorType *ot)
|
||||
|
||||
/********************* find missing files operator *********************/
|
||||
|
||||
static int find_missing_files_exec(bContext *UNUSED(C), wmOperator *op)
|
||||
static int find_missing_files_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
char *path;
|
||||
|
||||
path= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
|
||||
findMissingFiles(G.main, path);
|
||||
MEM_freeN(path);
|
||||
Main *bmain= CTX_data_main(C);
|
||||
const char *searchpath= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
|
||||
findMissingFiles(bmain, searchpath, op->reports);
|
||||
MEM_freeN((void *)searchpath);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
@@ -81,6 +81,15 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
|
||||
{
|
||||
PyObject *list= (PyObject *)userdata;
|
||||
PyObject *item= PyUnicode_DecodeFSDefault(path_src);
|
||||
PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
return FALSE; /* never edits the path */
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpy_blend_paths_doc,
|
||||
".. function:: blend_paths(absolute=False)\n"
|
||||
"\n"
|
||||
@@ -93,11 +102,8 @@ PyDoc_STRVAR(bpy_blend_paths_doc,
|
||||
);
|
||||
static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
struct BPathIterator *bpi;
|
||||
PyObject *list, *st; /* stupidly big string to be safe */
|
||||
/* be sure there is low chance of the path being too short */
|
||||
char filepath_expanded[1024];
|
||||
const char *lib;
|
||||
int flag= 0;
|
||||
PyObject *list;
|
||||
|
||||
int absolute= 0;
|
||||
static const char *kwlist[]= {"absolute", NULL};
|
||||
@@ -105,29 +111,13 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|i:blend_paths", (char **)kwlist, &absolute))
|
||||
return NULL;
|
||||
|
||||
list= PyList_New(0);
|
||||
|
||||
for (BLI_bpathIterator_init(&bpi, G.main, G.main->name, 0); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
|
||||
/* build the list */
|
||||
if (absolute) {
|
||||
BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
|
||||
}
|
||||
else {
|
||||
lib= BLI_bpathIterator_getLib(bpi);
|
||||
if (lib && (BLI_path_cmp(lib, BLI_bpathIterator_getBasePath(bpi)))) { /* relative path to the library is NOT the same as our blendfile path, return an absolute path */
|
||||
BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
|
||||
}
|
||||
else {
|
||||
BLI_bpathIterator_getPath(bpi, filepath_expanded);
|
||||
}
|
||||
}
|
||||
st= PyUnicode_DecodeFSDefault(filepath_expanded);
|
||||
|
||||
PyList_Append(list, st);
|
||||
Py_DECREF(st);
|
||||
if (absolute) {
|
||||
flag |= BPATH_TRAVERSE_ABS;
|
||||
}
|
||||
|
||||
BLI_bpathIterator_free(bpi);
|
||||
list= PyList_New(0);
|
||||
|
||||
bpath_traverse_main(G.main, bpy_blend_paths_visit_cb, flag, (void *)list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
Reference in New Issue
Block a user