Cleanup: rename Library.filepath to filepath_abs
Make it clear that this is the absolute path, allow the 'name' to be renamed to 'filepath'. Rename is safe since this is only for run-time.
This commit is contained in:
parent
58f3fabb97
commit
a573d7e8a1
@ -100,7 +100,7 @@ bool BKE_copybuffer_read(Main *bmain_dst,
|
||||
BKE_main_lib_objects_recalc_all(bmain_dst);
|
||||
IMB_colormanagement_check_file_config(bmain_dst);
|
||||
/* Append, rather than linking. */
|
||||
Library *lib = BLI_findstring(&bmain_dst->libraries, libname, offsetof(Library, filepath));
|
||||
Library *lib = BLI_findstring(&bmain_dst->libraries, libname, offsetof(Library, filepath_abs));
|
||||
BKE_library_make_local(bmain_dst, lib, NULL, true, false);
|
||||
/* Important we unset, otherwise these object wont
|
||||
* link into other scenes from this blend file.
|
||||
@ -155,7 +155,7 @@ int BKE_copybuffer_paste(bContext *C,
|
||||
IMB_colormanagement_check_file_config(bmain);
|
||||
|
||||
/* append, rather than linking */
|
||||
lib = BLI_findstring(&bmain->libraries, libname, offsetof(Library, filepath));
|
||||
lib = BLI_findstring(&bmain->libraries, libname, offsetof(Library, filepath_abs));
|
||||
BKE_library_make_local(bmain, lib, NULL, true, false);
|
||||
|
||||
/* important we unset, otherwise these object wont
|
||||
|
@ -114,7 +114,7 @@ IDTypeInfo IDType_ID_LINK_PLACEHOLDER = {
|
||||
* Also note that the id _must_ have a library - campbell */
|
||||
static void lib_id_library_local_paths(Main *bmain, Library *lib, ID *id)
|
||||
{
|
||||
const char *bpath_user_data[2] = {BKE_main_blendfile_path(bmain), lib->filepath};
|
||||
const char *bpath_user_data[2] = {BKE_main_blendfile_path(bmain), lib->filepath_abs};
|
||||
|
||||
BKE_bpath_traverse_id(bmain,
|
||||
id,
|
||||
@ -225,7 +225,7 @@ void id_us_ensure_real(ID *id)
|
||||
CLOG_ERROR(&LOG,
|
||||
"ID user count error: %s (from '%s')",
|
||||
id->name,
|
||||
id->lib ? id->lib->filepath : "[Main]");
|
||||
id->lib ? id->lib->filepath_abs : "[Main]");
|
||||
BLI_assert(0);
|
||||
}
|
||||
id->us = limit + 1;
|
||||
@ -283,7 +283,7 @@ void id_us_min(ID *id)
|
||||
CLOG_ERROR(&LOG,
|
||||
"ID user decrement error: %s (from '%s'): %d <= %d",
|
||||
id->name,
|
||||
id->lib ? id->lib->filepath : "[Main]",
|
||||
id->lib ? id->lib->filepath_abs : "[Main]",
|
||||
id->us,
|
||||
limit);
|
||||
if (GS(id->name) != ID_IP) {
|
||||
|
@ -85,19 +85,19 @@ void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
|
||||
BLI_strncpy(lib->name, filepath, sizeof(lib->name));
|
||||
}
|
||||
|
||||
BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
|
||||
BLI_strncpy(lib->filepath_abs, filepath, sizeof(lib->filepath_abs));
|
||||
|
||||
/* not essential but set filepath is an absolute copy of value which
|
||||
* is more useful if its kept in sync */
|
||||
if (BLI_path_is_rel(lib->filepath)) {
|
||||
/* Not essential but set `filepath_abs` is an absolute copy of value which
|
||||
* is more useful if its kept in sync. */
|
||||
if (BLI_path_is_rel(lib->filepath_abs)) {
|
||||
/* note that the file may be unsaved, in this case, setting the
|
||||
* filepath on an indirectly linked path is not allowed from the
|
||||
* `filepath_abs` on an indirectly linked path is not allowed from the
|
||||
* outliner, and its not really supported but allow from here for now
|
||||
* since making local could cause this to be directly linked - campbell
|
||||
*/
|
||||
/* Never make paths relative to parent lib - reading code (blenloader) always set *all*
|
||||
* lib->name relative to current main, not to their parent for indirectly linked ones. */
|
||||
const char *basepath = BKE_main_blendfile_path(bmain);
|
||||
BLI_path_abs(lib->filepath, basepath);
|
||||
BLI_path_abs(lib->filepath_abs, basepath);
|
||||
}
|
||||
}
|
||||
|
@ -3216,7 +3216,7 @@ void BKE_node_clipboard_add_node(bNode *node)
|
||||
BLI_strncpy(node_info->id_name, node->id->name, sizeof(node_info->id_name));
|
||||
if (ID_IS_LINKED(node->id)) {
|
||||
BLI_strncpy(
|
||||
node_info->library_name, node->id->lib->filepath, sizeof(node_info->library_name));
|
||||
node_info->library_name, node->id->lib->filepath_abs, sizeof(node_info->library_name));
|
||||
}
|
||||
else {
|
||||
node_info->library_name[0] = '\0';
|
||||
|
@ -705,8 +705,8 @@ int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
|
||||
|
||||
newname = BKE_packedfile_unpack_to_file(reports,
|
||||
BKE_main_blendfile_path(bmain),
|
||||
lib->filepath,
|
||||
lib->filepath,
|
||||
lib->filepath_abs,
|
||||
lib->filepath_abs,
|
||||
lib->packedfile,
|
||||
PF_WRITE_ORIGINAL);
|
||||
if (newname != NULL) {
|
||||
|
@ -2190,7 +2190,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
|
||||
{
|
||||
Library *lib = (pid->ob) ? pid->ob->id.lib : NULL;
|
||||
const char *blendfilename = (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH) == 0) ?
|
||||
lib->filepath :
|
||||
lib->filepath_abs :
|
||||
BKE_main_blendfile_path_from_global();
|
||||
size_t i;
|
||||
|
||||
|
@ -83,14 +83,14 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
|
||||
}
|
||||
|
||||
BKE_library_filepath_set(bmain, curlib, curlib->name);
|
||||
BlendHandle *bh = BLO_blendhandle_from_file(curlib->filepath, reports);
|
||||
BlendHandle *bh = BLO_blendhandle_from_file(curlib->filepath_abs, reports);
|
||||
|
||||
if (bh == NULL) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"Library ID %s not found at expected path %s!",
|
||||
curlib->id.name,
|
||||
curlib->filepath);
|
||||
curlib->filepath_abs);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ void blo_reportf_wrap(ReportList *reports, ReportType type, const char *format,
|
||||
/* for reporting linking messages */
|
||||
static const char *library_parent_filepath(Library *lib)
|
||||
{
|
||||
return lib->parent ? lib->parent->filepath : "<direct>";
|
||||
return lib->parent ? lib->parent->filepath_abs : "<direct>";
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@ -673,7 +673,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
|
||||
// printf("blo_find_main: converted to %s\n", name1);
|
||||
|
||||
for (m = mainlist->first; m; m = m->next) {
|
||||
const char *libname = (m->curlib) ? m->curlib->filepath : m->name;
|
||||
const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->name;
|
||||
|
||||
if (BLI_path_cmp(name1, libname) == 0) {
|
||||
if (G.debug & G_DEBUG) {
|
||||
@ -697,7 +697,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
|
||||
id_us_ensure_real(&lib->id);
|
||||
|
||||
BLI_strncpy(lib->name, filepath, sizeof(lib->name));
|
||||
BLI_strncpy(lib->filepath, name1, sizeof(lib->filepath));
|
||||
BLI_strncpy(lib->filepath_abs, name1, sizeof(lib->filepath_abs));
|
||||
|
||||
m->curlib = lib;
|
||||
|
||||
@ -8356,12 +8356,12 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
|
||||
/* check if the library was already read */
|
||||
for (newmain = fd->mainlist->first; newmain; newmain = newmain->next) {
|
||||
if (newmain->curlib) {
|
||||
if (BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) {
|
||||
if (BLI_path_cmp(newmain->curlib->filepath_abs, lib->filepath_abs) == 0) {
|
||||
blo_reportf_wrap(fd->reports,
|
||||
RPT_WARNING,
|
||||
TIP_("Library '%s', '%s' had multiple instances, save and reload!"),
|
||||
lib->name,
|
||||
lib->filepath);
|
||||
lib->filepath_abs);
|
||||
|
||||
change_link_placeholder_to_real_ID_pointer(fd->mainlist, fd, lib, newmain->curlib);
|
||||
/* change_link_placeholder_to_real_ID_pointer_fd(fd, lib, newmain->curlib); */
|
||||
@ -8383,12 +8383,12 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
|
||||
}
|
||||
}
|
||||
|
||||
/* make sure we have full path in lib->filepath */
|
||||
BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name));
|
||||
BLI_path_normalize(fd->relabase, lib->filepath);
|
||||
/* Make sure we have full path in lib->filepath_abs */
|
||||
BLI_strncpy(lib->filepath_abs, lib->name, sizeof(lib->name));
|
||||
BLI_path_normalize(fd->relabase, lib->filepath_abs);
|
||||
|
||||
// printf("direct_link_library: name %s\n", lib->name);
|
||||
// printf("direct_link_library: filepath %s\n", lib->filepath);
|
||||
// printf("direct_link_library: filepath %s\n", lib->filepath_abs);
|
||||
|
||||
BlendDataReader reader = {fd};
|
||||
lib->packedfile = direct_link_packedfile(&reader, lib->packedfile);
|
||||
@ -8421,7 +8421,7 @@ static void fix_relpaths_library(const char *basepath, Main *main)
|
||||
* link into an unsaved blend file. See [#27405].
|
||||
* The remap relative option will make it relative again on save - campbell */
|
||||
if (BLI_path_is_rel(lib->name)) {
|
||||
BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
|
||||
BLI_strncpy(lib->name, lib->filepath_abs, sizeof(lib->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8431,7 +8431,7 @@ static void fix_relpaths_library(const char *basepath, Main *main)
|
||||
* relative to the blend file since indirectly linked libs will be
|
||||
* relative to their direct linked library. */
|
||||
if (BLI_path_is_rel(lib->name)) { /* if this is relative to begin with? */
|
||||
BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
|
||||
BLI_strncpy(lib->name, lib->filepath_abs, sizeof(lib->name));
|
||||
BLI_path_rel(lib->name, basepath);
|
||||
}
|
||||
}
|
||||
@ -10545,7 +10545,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
|
||||
RPT_WARNING,
|
||||
TIP_("LIB: Data refers to main .blend file: '%s' from %s"),
|
||||
idname,
|
||||
mainvar->curlib->filepath);
|
||||
mainvar->curlib->filepath_abs);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -12105,7 +12105,7 @@ static void library_link_end(Main *mainl,
|
||||
/* make the lib path relative if required */
|
||||
if (flag & FILE_RELPATH) {
|
||||
/* use the full path, this could have been read by other library even */
|
||||
BLI_strncpy(curlib->name, curlib->filepath, sizeof(curlib->name));
|
||||
BLI_strncpy(curlib->name, curlib->filepath_abs, sizeof(curlib->name));
|
||||
|
||||
/* uses current .blend file as reference */
|
||||
BLI_path_rel(curlib->name, BKE_main_blendfile_path_from_global());
|
||||
@ -12255,7 +12255,7 @@ static void read_library_linked_id(
|
||||
"non-linkable data type"),
|
||||
BKE_idtype_idcode_to_name(GS(id->name)),
|
||||
id->name + 2,
|
||||
mainvar->curlib->filepath,
|
||||
mainvar->curlib->filepath_abs,
|
||||
library_parent_filepath(mainvar->curlib));
|
||||
}
|
||||
|
||||
@ -12273,7 +12273,7 @@ static void read_library_linked_id(
|
||||
TIP_("LIB: %s: '%s' missing from '%s', parent '%s'"),
|
||||
BKE_idtype_idcode_to_name(GS(id->name)),
|
||||
id->name + 2,
|
||||
mainvar->curlib->filepath,
|
||||
mainvar->curlib->filepath_abs,
|
||||
library_parent_filepath(mainvar->curlib));
|
||||
|
||||
/* Generate a placeholder for this ID (simplified version of read_libblock actually...). */
|
||||
@ -12381,17 +12381,17 @@ static FileData *read_library_file_data(FileData *basefd,
|
||||
fd = blo_filedata_from_memory(pf->data, pf->size, basefd->reports);
|
||||
|
||||
/* Needed for library_append and read_libraries. */
|
||||
BLI_strncpy(fd->relabase, mainptr->curlib->filepath, sizeof(fd->relabase));
|
||||
BLI_strncpy(fd->relabase, mainptr->curlib->filepath_abs, sizeof(fd->relabase));
|
||||
}
|
||||
else {
|
||||
/* Read file on disk. */
|
||||
blo_reportf_wrap(basefd->reports,
|
||||
RPT_INFO,
|
||||
TIP_("Read library: '%s', '%s', parent '%s'"),
|
||||
mainptr->curlib->filepath,
|
||||
mainptr->curlib->filepath_abs,
|
||||
mainptr->curlib->name,
|
||||
library_parent_filepath(mainptr->curlib));
|
||||
fd = blo_filedata_from_file(mainptr->curlib->filepath, basefd->reports);
|
||||
fd = blo_filedata_from_file(mainptr->curlib->filepath_abs, basefd->reports);
|
||||
}
|
||||
|
||||
if (fd) {
|
||||
@ -12428,7 +12428,7 @@ static FileData *read_library_file_data(FileData *basefd,
|
||||
|
||||
if (fd == NULL) {
|
||||
blo_reportf_wrap(
|
||||
basefd->reports, RPT_WARNING, TIP_("Cannot find lib '%s'"), mainptr->curlib->filepath);
|
||||
basefd->reports, RPT_WARNING, TIP_("Cannot find lib '%s'"), mainptr->curlib->filepath_abs);
|
||||
}
|
||||
|
||||
return fd;
|
||||
|
@ -3989,7 +3989,7 @@ static void write_libraries(WriteData *wd, Main *main)
|
||||
"ERROR: write file: data-block '%s' from lib '%s' is not linkable "
|
||||
"but is flagged as directly linked",
|
||||
id->name,
|
||||
main->curlib->filepath);
|
||||
main->curlib->filepath_abs);
|
||||
BLI_assert(0);
|
||||
}
|
||||
writestruct(wd, ID_LINK_PLACEHOLDER, ID, 1, id);
|
||||
|
@ -545,7 +545,7 @@ static int outliner_id_delete_invoke_do(bContext *C,
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Cannot delete indirectly linked library '%s'",
|
||||
((Library *)tselem->id)->filepath);
|
||||
((Library *)tselem->id)->filepath_abs);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
id_delete(C, reports, te, tselem);
|
||||
@ -911,12 +911,12 @@ static int lib_relocate(
|
||||
Library *lib = (Library *)tselem->id;
|
||||
char dir[FILE_MAXDIR], filename[FILE_MAX];
|
||||
|
||||
BLI_split_dirfile(lib->filepath, dir, filename, sizeof(dir), sizeof(filename));
|
||||
BLI_split_dirfile(lib->filepath_abs, dir, filename, sizeof(dir), sizeof(filename));
|
||||
|
||||
printf("%s, %s\n", tselem->id->name, lib->filepath);
|
||||
printf("%s, %s\n", tselem->id->name, lib->filepath_abs);
|
||||
|
||||
/* We assume if both paths in lib are not the same then lib->name was relative... */
|
||||
RNA_boolean_set(&op_props, "relative_path", BLI_path_cmp(lib->filepath, lib->name) != 0);
|
||||
RNA_boolean_set(&op_props, "relative_path", BLI_path_cmp(lib->filepath_abs, lib->name) != 0);
|
||||
|
||||
RNA_string_set(&op_props, "directory", dir);
|
||||
RNA_string_set(&op_props, "filename", filename);
|
||||
@ -943,7 +943,7 @@ static int outliner_lib_relocate_invoke_do(
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Cannot relocate indirectly linked library '%s'",
|
||||
((Library *)tselem->id)->filepath);
|
||||
((Library *)tselem->id)->filepath_abs);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
|
@ -311,7 +311,7 @@ typedef struct Library {
|
||||
* This is set on file read.
|
||||
* Use BKE_library_filepath_set() rather than setting 'name'
|
||||
* directly and it will be kept in sync - campbell */
|
||||
char filepath[1024];
|
||||
char filepath_abs[1024];
|
||||
|
||||
/** Set for indirectly linked libs, used in the outliner and while reading. */
|
||||
struct Library *parent;
|
||||
@ -456,9 +456,9 @@ typedef enum ID_Type {
|
||||
((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM) && (GS((id)->name) != ID_WS))
|
||||
|
||||
#define ID_BLEND_PATH(_bmain, _id) \
|
||||
((_id)->lib ? (_id)->lib->filepath : BKE_main_blendfile_path((_bmain)))
|
||||
((_id)->lib ? (_id)->lib->filepath_abs : BKE_main_blendfile_path((_bmain)))
|
||||
#define ID_BLEND_PATH_FROM_GLOBAL(_id) \
|
||||
((_id)->lib ? (_id)->lib->filepath : BKE_main_blendfile_path_from_global())
|
||||
((_id)->lib ? (_id)->lib->filepath_abs : BKE_main_blendfile_path_from_global())
|
||||
|
||||
#define ID_MISSING(_id) ((((ID *)(_id))->tag & LIB_TAG_MISSING) != 0)
|
||||
|
||||
|
@ -1458,7 +1458,7 @@ static bool wm_file_write(bContext *C,
|
||||
|
||||
/* send the OnSave event */
|
||||
for (li = bmain->libraries.first; li; li = li->id.next) {
|
||||
if (BLI_path_cmp(li->filepath, filepath) == 0) {
|
||||
if (BLI_path_cmp(li->filepath_abs, filepath) == 0) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
|
||||
return ok;
|
||||
}
|
||||
|
@ -681,10 +681,10 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN
|
||||
BKE_reportf(op->reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Cannot relocate indirectly linked library '%s'",
|
||||
lib->filepath);
|
||||
lib->filepath_abs);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
RNA_string_set(op->ptr, "filepath", lib->filepath);
|
||||
RNA_string_set(op->ptr, "filepath", lib->filepath_abs);
|
||||
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
@ -913,24 +913,24 @@ static void lib_relocate_do(Main *bmain,
|
||||
|
||||
void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
|
||||
{
|
||||
if (!BLO_has_bfile_extension(lib->filepath)) {
|
||||
BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath);
|
||||
if (!BLO_has_bfile_extension(lib->filepath_abs)) {
|
||||
BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath_abs);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!BLI_exists(lib->filepath)) {
|
||||
if (!BLI_exists(lib->filepath_abs)) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"Trying to reload library '%s' from invalid path '%s'",
|
||||
lib->id.name,
|
||||
lib->filepath);
|
||||
lib->filepath_abs);
|
||||
return;
|
||||
}
|
||||
|
||||
WMLinkAppendData *lapp_data = wm_link_append_data_new(BLO_LIBLINK_USE_PLACEHOLDERS |
|
||||
BLO_LIBLINK_FORCE_INDIRECT);
|
||||
|
||||
wm_link_append_data_library_add(lapp_data, lib->filepath);
|
||||
wm_link_append_data_library_add(lapp_data, lib->filepath_abs);
|
||||
|
||||
lib_relocate_do(CTX_data_main(C), lib, lapp_data, reports, true);
|
||||
|
||||
@ -963,7 +963,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
|
||||
BKE_reportf(op->reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Cannot relocate indirectly linked library '%s'",
|
||||
lib->filepath);
|
||||
lib->filepath_abs);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
@ -986,7 +986,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if (BLI_path_cmp(lib->filepath, path) == 0) {
|
||||
if (BLI_path_cmp(lib->filepath_abs, path) == 0) {
|
||||
#ifdef PRINT_DEBUG
|
||||
printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
|
||||
#endif
|
||||
@ -1023,7 +1023,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
|
||||
|
||||
BLI_join_dirfile(path, sizeof(path), root, relname);
|
||||
|
||||
if (BLI_path_cmp(path, lib->filepath) == 0 || !BLO_has_bfile_extension(relname)) {
|
||||
if (BLI_path_cmp(path, lib->filepath_abs) == 0 || !BLO_has_bfile_extension(relname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user