Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenloader/intern/readfile.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 1,183 Lines • ▼ Show 20 Lines | |||||
| /* ************ DIV ****************** */ | /* ************ DIV ****************** */ | ||||
| bool BLO_has_bfile_extension(const char *str) | bool BLO_has_bfile_extension(const char *str) | ||||
| { | { | ||||
| const char *ext_test[4] = {".blend", ".ble", ".blend.gz", NULL}; | const char *ext_test[4] = {".blend", ".ble", ".blend.gz", NULL}; | ||||
| return BLI_testextensie_array(str, ext_test); | return BLI_testextensie_array(str, ext_test); | ||||
| } | } | ||||
| bool BLO_is_a_library(const char *path, char *dir, char *group) | bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name) | ||||
| { | { | ||||
| /* return ok when a blenderfile, in dir is the filename, | /* We might get some data names with slashes, so we have to go up in path until we find blend file itself, | ||||
| * in group the type of libdata | * then we now next path item is group, and everything else is data name. */ | ||||
| */ | char *slash = NULL, *prev_slash = NULL, c = '\0'; | ||||
| int len; | |||||
| char *fd; | |||||
| /* if path leads to a directory we can be sure we're not in a library */ | r_dir[0] = '\0'; | ||||
| if (BLI_is_dir(path)) return 0; | if (r_group) { | ||||
| *r_group = NULL; | |||||
| } | |||||
| if (r_name) { | |||||
| *r_name = NULL; | |||||
| } | |||||
| strcpy(dir, path); | /* if path leads to an existing directory, we can be sure we're not (in) a library */ | ||||
| len = strlen(dir); | if (BLI_is_dir(path)) { | ||||
| if (len < 7) return 0; | return false; | ||||
| if ((dir[len - 1] != '/') && (dir[len - 1] != '\\')) return 0; | } | ||||
| group[0] = '\0'; | strcpy(r_dir, path); | ||||
| dir[len - 1] = '\0'; | |||||
| /* Find the last slash */ | while ((slash = (char *)BLI_last_slash(r_dir))) { | ||||
| fd = (char *)BLI_last_slash(dir); | char tc = *slash; | ||||
| *slash = '\0'; | |||||
| if (BLO_has_bfile_extension(r_dir)) { | |||||
| break; | |||||
| } | |||||
| if (fd == NULL) return 0; | if (prev_slash) { | ||||
| *fd = 0; | *prev_slash = c; | ||||
| if (BLO_has_bfile_extension(fd+1)) { | } | ||||
| /* the last part of the dir is a .blend file, no group follows */ | prev_slash = slash; | ||||
| *fd = '/'; /* put back the removed slash separating the dir and the .blend file name */ | c = tc; | ||||
| } | } | ||||
| else { | |||||
| const char * const gp = fd + 1; // in case we have a .blend file, gp points to the group | |||||
| /* Find the last slash */ | if (!slash) { | ||||
| fd = (char *)BLI_last_slash(dir); | return false; | ||||
| if (!fd || !BLO_has_bfile_extension(fd+1)) return 0; | } | ||||
| /* now we know that we are in a blend file and it is safe to | if (slash[1] != '\0') { | ||||
| * assume that gp actually points to a group */ | BLI_assert(strlen(slash + 1) < BLO_GROUP_MAX); | ||||
| if (!STREQ("Screen", gp)) | if (r_group) { | ||||
| BLI_strncpy(group, gp, BLO_GROUP_MAX); | *r_group = slash + 1; | ||||
| } | |||||
| } | |||||
| if (prev_slash && (prev_slash[1] != '\0')) { | |||||
| BLI_assert(strlen(prev_slash + 1) < MAX_ID_NAME - 2); | |||||
| if (r_name) { | |||||
| *r_name = prev_slash + 1; | |||||
| } | } | ||||
| return 1; | } | ||||
| return true; | |||||
| } | } | ||||
| /* ************** OLD POINTERS ******************* */ | /* ************** OLD POINTERS ******************* */ | ||||
| static void *newdataadr(FileData *fd, void *adr) /* only direct databocks */ | static void *newdataadr(FileData *fd, void *adr) /* only direct databocks */ | ||||
| { | { | ||||
| return oldnewmap_lookup_and_inc(fd->datamap, adr, true); | return oldnewmap_lookup_and_inc(fd->datamap, adr, true); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 636 Lines • ▼ Show 20 Lines | static void _IDP_DirectLinkGroup_OrFree(IDProperty **prop, int switch_endian, FileData *fd, | ||||
| } | } | ||||
| } | } | ||||
| /* stub function */ | /* stub function */ | ||||
| static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endian), FileData *UNUSED(fd)) | static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endian), FileData *UNUSED(fd)) | ||||
| { | { | ||||
| } | } | ||||
| /* ************ READ IMAGE PREVIEW *************** */ | |||||
| static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_prv) | |||||
| { | |||||
| PreviewImage *prv = newdataadr(fd, old_prv); | |||||
| if (prv) { | |||||
| int i; | |||||
| for (i = 0; i < NUM_ICON_SIZES; ++i) { | |||||
| if (prv->rect[i]) { | |||||
| prv->rect[i] = newdataadr(fd, prv->rect[i]); | |||||
| } | |||||
| prv->gputexture[i] = NULL; | |||||
| } | |||||
| } | |||||
| return prv; | |||||
| } | |||||
| /* ************ READ ID *************** */ | /* ************ READ ID *************** */ | ||||
| static void direct_link_id(FileData *fd, ID *id) | static void direct_link_id(FileData *fd, ID *id) | ||||
| { | { | ||||
| /*link direct data of ID properties*/ | /*link direct data of ID properties*/ | ||||
| if (id->properties) { | if (id->properties) { | ||||
| id->properties = newdataadr(fd, id->properties); | id->properties = newdataadr(fd, id->properties); | ||||
| /* this case means the data was written incorrectly, it should not happen */ | /* this case means the data was written incorrectly, it should not happen */ | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static void direct_link_brush(FileData *fd, Brush *brush) | ||||
| brush->curve = newdataadr(fd, brush->curve); | brush->curve = newdataadr(fd, brush->curve); | ||||
| brush->gradient = newdataadr(fd, brush->gradient); | brush->gradient = newdataadr(fd, brush->gradient); | ||||
| if (brush->curve) | if (brush->curve) | ||||
| direct_link_curvemapping(fd, brush->curve); | direct_link_curvemapping(fd, brush->curve); | ||||
| else | else | ||||
| BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); | BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); | ||||
| brush->preview = NULL; | brush->preview = direct_link_preview_image(fd, brush->preview); | ||||
| brush->icon_imbuf = NULL; | brush->icon_imbuf = NULL; | ||||
| } | } | ||||
| /* ************ READ Palette *************** */ | /* ************ READ Palette *************** */ | ||||
| static void lib_link_palette(FileData *UNUSED(fd), Main *main) | static void lib_link_palette(FileData *UNUSED(fd), Main *main) | ||||
| { | { | ||||
| Palette *palette; | Palette *palette; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf) | ||||
| if (pf) { | if (pf) { | ||||
| pf->data = newpackedadr(fd, pf->data); | pf->data = newpackedadr(fd, pf->data); | ||||
| } | } | ||||
| return pf; | return pf; | ||||
| } | } | ||||
| /* ************ READ IMAGE PREVIEW *************** */ | |||||
| static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_prv) | |||||
| { | |||||
| PreviewImage *prv = newdataadr(fd, old_prv); | |||||
| if (prv) { | |||||
| int i; | |||||
| for (i = 0; i < NUM_ICON_SIZES; ++i) { | |||||
| if (prv->rect[i]) { | |||||
| prv->rect[i] = newdataadr(fd, prv->rect[i]); | |||||
| } | |||||
| prv->gputexture[i] = NULL; | |||||
| } | |||||
| } | |||||
| return prv; | |||||
| } | |||||
| /* ************ READ ANIMATION STUFF ***************** */ | /* ************ READ ANIMATION STUFF ***************** */ | ||||
| /* Legacy Data Support (for Version Patching) ----------------------------- */ | /* Legacy Data Support (for Version Patching) ----------------------------- */ | ||||
| // XXX deprecated - old animation system | // XXX deprecated - old animation system | ||||
| static void lib_link_ipo(FileData *fd, Main *main) | static void lib_link_ipo(FileData *fd, Main *main) | ||||
| { | { | ||||
| Ipo *ipo; | Ipo *ipo; | ||||
| ▲ Show 20 Lines • Show All 3,198 Lines • ▼ Show 20 Lines | // >>> XXX deprecated - old animation system | ||||
| CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); | CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX); | ||||
| if (ob->sculpt) { | if (ob->sculpt) { | ||||
| ob->sculpt = MEM_callocN(sizeof(SculptSession), "reload sculpt session"); | ob->sculpt = MEM_callocN(sizeof(SculptSession), "reload sculpt session"); | ||||
| } | } | ||||
| link_list(fd, &ob->lodlevels); | link_list(fd, &ob->lodlevels); | ||||
| ob->currentlod = ob->lodlevels.first; | ob->currentlod = ob->lodlevels.first; | ||||
| ob->preview = direct_link_preview_image(fd, ob->preview); | |||||
| } | } | ||||
| /* ************ READ SCENE ***************** */ | /* ************ READ SCENE ***************** */ | ||||
| /* patch for missing scene IDs, can't be in do-versions */ | /* patch for missing scene IDs, can't be in do-versions */ | ||||
| static void composite_patch(bNodeTree *ntree, Scene *scene) | static void composite_patch(bNodeTree *ntree, Scene *scene) | ||||
| { | { | ||||
| bNode *node; | bNode *node; | ||||
| ▲ Show 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | if (rbw) { | ||||
| /* link cache */ | /* link cache */ | ||||
| direct_link_pointcache_list(fd, &rbw->ptcaches, &rbw->pointcache, false); | direct_link_pointcache_list(fd, &rbw->ptcaches, &rbw->pointcache, false); | ||||
| /* make sure simulation starts from the beginning after loading file */ | /* make sure simulation starts from the beginning after loading file */ | ||||
| if (rbw->pointcache) { | if (rbw->pointcache) { | ||||
| rbw->ltime = (float)rbw->pointcache->startframe; | rbw->ltime = (float)rbw->pointcache->startframe; | ||||
| } | } | ||||
| } | } | ||||
| sce->preview = direct_link_preview_image(fd, sce->preview); | |||||
| } | } | ||||
| /* ************ READ WM ***************** */ | /* ************ READ WM ***************** */ | ||||
| static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) | static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) | ||||
| { | { | ||||
| wmWindow *win; | wmWindow *win; | ||||
| ▲ Show 20 Lines • Show All 1,226 Lines • ▼ Show 20 Lines | for (sound = main->sound.first; sound; sound = sound->id.next) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ***************** READ GROUP *************** */ | /* ***************** READ GROUP *************** */ | ||||
| static void direct_link_group(FileData *fd, Group *group) | static void direct_link_group(FileData *fd, Group *group) | ||||
| { | { | ||||
| link_list(fd, &group->gobject); | link_list(fd, &group->gobject); | ||||
| group->preview = direct_link_preview_image(fd, group->preview); | |||||
| } | } | ||||
| static void lib_link_group(FileData *fd, Main *main) | static void lib_link_group(FileData *fd, Main *main) | ||||
| { | { | ||||
| Group *group; | Group *group; | ||||
| GroupObject *go; | GroupObject *go; | ||||
| int add_us; | int add_us; | ||||
| ▲ Show 20 Lines • Show All 2,696 Lines • Show Last 20 Lines | |||||