Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/packedFile.c
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_font.h" | #include "BKE_font.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_packedFile.h" | #include "BKE_packedFile.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_sound.h" | #include "BKE_sound.h" | ||||
| #include "BKE_volume.h" | #include "BKE_volume.h" | ||||
| #include "IMB_imbuf.h" | |||||
| #include "IMB_imbuf_types.h" | |||||
| #include "BLO_read_write.h" | #include "BLO_read_write.h" | ||||
| int BKE_packedfile_seek(PackedFile *pf, int offset, int whence) | int BKE_packedfile_seek(PackedFile *pf, int offset, int whence) | ||||
| { | { | ||||
| int oldseek = -1, seek = 0; | int oldseek = -1, seek = 0; | ||||
| if (pf) { | if (pf) { | ||||
| oldseek = pf->seek; | oldseek = pf->seek; | ||||
| ▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | static void unpack_generate_paths(const char *name, | ||||
| size_t relpathlen) | size_t relpathlen) | ||||
| { | { | ||||
| char tempname[FILE_MAX]; | char tempname[FILE_MAX]; | ||||
| char tempdir[FILE_MAXDIR]; | char tempdir[FILE_MAXDIR]; | ||||
| BLI_split_dirfile(name, tempdir, tempname, sizeof(tempdir), sizeof(tempname)); | BLI_split_dirfile(name, tempdir, tempname, sizeof(tempdir), sizeof(tempname)); | ||||
| if (tempname[0] == '\0') { | if (tempname[0] == '\0') { | ||||
| /* Note: we do not have any real way to re-create extension out of data... */ | /* Note: We generally do not have any real way to re-create extension out of data... */ | ||||
| BLI_strncpy(tempname, id->name + 2, sizeof(tempname)); | BLI_strncpy(tempname, id->name + 2, sizeof(tempname)); | ||||
| printf("%s\n", tempname); | printf("%s\n", tempname); | ||||
| if (GS(id->name) == ID_IM) { | |||||
| /* For images we can add the file extension based on the file header */ | |||||
| ImagePackedFile *imapf = ((Image *)id)->packedfiles.last; | |||||
| if (imapf != NULL && imapf->packedfile != NULL) { | |||||
| int ftype = IMB_ispic_type_from_memory((unsigned char *)imapf->packedfile->data, | |||||
| imapf->packedfile->size); | |||||
| int imtype = BKE_image_ftype_to_imtype(ftype, NULL); | |||||
| BKE_image_path_ensure_ext_from_imtype(tempname, imtype); | |||||
| } | |||||
| } | |||||
| BLI_filename_make_safe(tempname); | BLI_filename_make_safe(tempname); | ||||
| printf("%s\n", tempname); | printf("%s\n", tempname); | ||||
| } | } | ||||
| if (tempdir[0] == '\0') { | if (tempdir[0] == '\0') { | ||||
| /* Fallback to relative dir. */ | /* Fallback to relative dir. */ | ||||
| BLI_strncpy(tempdir, "//", sizeof(tempdir)); | BLI_strncpy(tempdir, "//", sizeof(tempdir)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | int BKE_packedfile_unpack_image(Main *bmain, | ||||
| int ret_value = RET_ERROR; | int ret_value = RET_ERROR; | ||||
| if (ima != NULL) { | if (ima != NULL) { | ||||
| while (ima->packedfiles.last) { | while (ima->packedfiles.last) { | ||||
| char localname[FILE_MAX], absname[FILE_MAX]; | char localname[FILE_MAX], absname[FILE_MAX]; | ||||
| char *newname; | char *newname; | ||||
| ImagePackedFile *imapf = ima->packedfiles.last; | ImagePackedFile *imapf = ima->packedfiles.last; | ||||
| unpack_generate_paths( | unpack_generate_paths( | ||||
| imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname)); | imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname)); | ||||
| newname = BKE_packedfile_unpack_to_file( | newname = BKE_packedfile_unpack_to_file( | ||||
| reports, BKE_main_blendfile_path(bmain), absname, localname, imapf->packedfile, how); | reports, BKE_main_blendfile_path(bmain), absname, localname, imapf->packedfile, how); | ||||
| if (newname != NULL) { | if (newname != NULL) { | ||||
| ImageView *iv; | ImageView *iv; | ||||
| ret_value = ret_value == RET_ERROR ? RET_ERROR : RET_OK; | ret_value = ret_value == RET_ERROR ? RET_ERROR : RET_OK; | ||||
| BKE_packedfile_free(imapf->packedfile); | BKE_packedfile_free(imapf->packedfile); | ||||
campbellbarton: This could be moved into `unpack_generate_paths` at the end of the block containing the comment… | |||||
Done Inline Actionsunpack_generate_paths is used for more than just images, hence I didn't put the implementation there. It's also used in BKE_packedfile_unpack_vfont, BKE_packedfile_unpack_sound, BKE_packedfile_unpack_volume. I don't think this would be a good idea, since we would have to give image input a special treatment in this function. The note is still correct, the function cannot generally retrieve the extension from the data, which is why we supply it as part of the name argument to this function. This is already the case in the current implementation in master, when imapf->filepath is set. rjg: `unpack_generate_paths` is used for more than just images, hence I didn't put the… | |||||
| imapf->packedfile = NULL; | imapf->packedfile = NULL; | ||||
| /* update the new corresponding view filepath */ | /* update the new corresponding view filepath */ | ||||
| iv = BLI_findstring(&ima->views, imapf->filepath, offsetof(ImageView, filepath)); | iv = BLI_findstring(&ima->views, imapf->filepath, offsetof(ImageView, filepath)); | ||||
| if (iv) { | if (iv) { | ||||
| BLI_strncpy(iv->filepath, newname, sizeof(imapf->filepath)); | BLI_strncpy(iv->filepath, newname, sizeof(imapf->filepath)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines | |||||
This could be moved into unpack_generate_paths at the end of the block containing the comment:
Otherwise anyone someone reading this function may assume extensions aren't being handled when in fact they are handled outside of the function.