Cleanup: use BKE_packedfile prefix for function names

Avoid ambiguity with terms check & compare.
This commit is contained in:
2019-07-07 23:57:35 +10:00
parent 28057d54de
commit 084d545202
15 changed files with 154 additions and 136 deletions

View File

@@ -34,49 +34,63 @@ struct VFont;
struct bSound; struct bSound;
/* pack */ /* pack */
struct PackedFile *dupPackedFile(const struct PackedFile *pf_src); struct PackedFile *BKE_packedfile_duplicate(const struct PackedFile *pf_src);
struct PackedFile *newPackedFile(struct ReportList *reports, struct PackedFile *BKE_packedfile_new(struct ReportList *reports,
const char *filename, const char *filename,
const char *relabase); const char *relabase);
struct PackedFile *newPackedFileMemory(void *mem, int memlen); struct PackedFile *BKE_packedfile_new_from_memory(void *mem, int memlen);
void packAll(struct Main *bmain, struct ReportList *reports, bool verbose); void BKE_packedfile_pack_all(struct Main *bmain, struct ReportList *reports, bool verbose);
void packLibraries(struct Main *bmain, struct ReportList *reports); void BKE_packedfile_pack_all_libraries(struct Main *bmain, struct ReportList *reports);
/* unpack */ /* unpack */
char *unpackFile(struct ReportList *reports, char *BKE_packedfile_unpack_to_file(struct ReportList *reports,
const char *ref_file_name, const char *ref_file_name,
const char *abs_name, const char *abs_name,
const char *local_name, const char *local_name,
struct PackedFile *pf, struct PackedFile *pf,
int how); int how);
int unpackVFont(struct Main *bmain, struct ReportList *reports, struct VFont *vfont, int how); int BKE_packedfile_unpack_vfont(struct Main *bmain,
int unpackSound(struct Main *bmain, struct ReportList *reports, struct bSound *sound, int how); struct ReportList *reports,
int unpackImage(struct Main *bmain, struct ReportList *reports, struct Image *ima, int how); struct VFont *vfont,
void unpackAll(struct Main *bmain, struct ReportList *reports, int how); int how);
int unpackLibraries(struct Main *bmain, struct ReportList *reports); int BKE_packedfile_unpack_sound(struct Main *bmain,
struct ReportList *reports,
struct bSound *sound,
int how);
int BKE_packedfile_unpack_image(struct Main *bmain,
struct ReportList *reports,
struct Image *ima,
int how);
void BKE_packedfile_unpack_all(struct Main *bmain, struct ReportList *reports, int how);
int BKE_packedfile_unpack_all_libraries(struct Main *bmain, struct ReportList *reports);
int writePackedFile(struct ReportList *reports, int BKE_packedfile_write_to_file(struct ReportList *reports,
const char *ref_file_name, const char *ref_file_name,
const char *filename, const char *filename,
struct PackedFile *pf, struct PackedFile *pf,
const bool guimode); const bool guimode);
/* free */ /* free */
void freePackedFile(struct PackedFile *pf); void BKE_packedfile_free(struct PackedFile *pf);
/* info */ /* info */
int countPackedFiles(struct Main *bmain); int BKE_packedfile_count_all(struct Main *bmain);
int checkPackedFile(const char *ref_file_name, const char *filename, struct PackedFile *pf); int BKE_packedfile_compare_to_file(const char *ref_file_name,
const char *filename,
struct PackedFile *pf);
/* read */ /* read */
int seekPackedFile(struct PackedFile *pf, int offset, int whence); int BKE_packedfile_seek(struct PackedFile *pf, int offset, int whence);
void rewindPackedFile(struct PackedFile *pf); void BKE_packedfile_rewind(struct PackedFile *pf);
int readPackedFile(struct PackedFile *pf, void *data, int size); int BKE_packedfile_read(struct PackedFile *pf, void *data, int size);
/* ID should be not NULL, return 1 if there's a packed file */ /* ID should be not NULL, return 1 if there's a packed file */
bool BKE_pack_check(struct ID *id); bool BKE_packedfile_id_check(struct ID *id);
/* ID should be not NULL, throws error when ID is Library */ /* ID should be not NULL, throws error when ID is Library */
void BKE_unpack_id(struct Main *bmain, struct ID *id, struct ReportList *reports, int how); void BKE_packedfile_id_unpack(struct Main *bmain,
struct ID *id,
struct ReportList *reports,
int how);
#endif #endif

View File

@@ -86,7 +86,7 @@ void BKE_vfont_free_data(struct VFont *vfont)
} }
if (vfont->temp_pf) { if (vfont->temp_pf) {
freePackedFile(vfont->temp_pf); /* NULL when the font file can't be found on disk */ BKE_packedfile_free(vfont->temp_pf); /* NULL when the font file can't be found on disk */
vfont->temp_pf = NULL; vfont->temp_pf = NULL;
} }
} }
@@ -97,7 +97,7 @@ void BKE_vfont_free(struct VFont *vf)
BKE_vfont_free_data(vf); BKE_vfont_free_data(vf);
if (vf->packedfile) { if (vf->packedfile) {
freePackedFile(vf->packedfile); BKE_packedfile_free(vf->packedfile);
vf->packedfile = NULL; vf->packedfile = NULL;
} }
} }
@@ -114,7 +114,7 @@ void BKE_vfont_copy_data(Main *UNUSED(bmain),
vfont_dst->temp_pf = NULL; vfont_dst->temp_pf = NULL;
if (vfont_dst->packedfile) { if (vfont_dst->packedfile) {
vfont_dst->packedfile = dupPackedFile(vfont_dst->packedfile); vfont_dst->packedfile = BKE_packedfile_duplicate(vfont_dst->packedfile);
} }
if (vfont_dst->data) { if (vfont_dst->data) {
@@ -148,7 +148,7 @@ static PackedFile *get_builtin_packedfile(void)
memcpy(mem, builtin_font_data, builtin_font_size); memcpy(mem, builtin_font_data, builtin_font_size);
return newPackedFileMemory(mem, builtin_font_size); return BKE_packedfile_new_from_memory(mem, builtin_font_size);
} }
} }
@@ -183,14 +183,15 @@ static VFontData *vfont_get_data(VFont *vfont)
/* We need to copy a tmp font to memory unless it is already there */ /* We need to copy a tmp font to memory unless it is already there */
if (vfont->temp_pf == NULL) { if (vfont->temp_pf == NULL) {
vfont->temp_pf = dupPackedFile(pf); vfont->temp_pf = BKE_packedfile_duplicate(pf);
} }
} }
else { else {
pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); pf = BKE_packedfile_new(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id));
if (vfont->temp_pf == NULL) { if (vfont->temp_pf == NULL) {
vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); vfont->temp_pf = BKE_packedfile_new(
NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id));
} }
} }
if (!pf) { if (!pf) {
@@ -208,7 +209,7 @@ static VFontData *vfont_get_data(VFont *vfont)
if (pf) { if (pf) {
vfont->data = BLI_vfontdata_from_freetypefont(pf); vfont->data = BLI_vfontdata_from_freetypefont(pf);
if (pf != vfont->packedfile) { if (pf != vfont->packedfile) {
freePackedFile(pf); BKE_packedfile_free(pf);
} }
} }
@@ -234,7 +235,7 @@ void BKE_vfont_init(VFont *vfont)
} }
/* Free the packed file */ /* Free the packed file */
freePackedFile(pf); BKE_packedfile_free(pf);
} }
} }
@@ -253,7 +254,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath)
} }
else { else {
BLI_split_file_part(filepath, filename, sizeof(filename)); BLI_split_file_part(filepath, filename, sizeof(filename));
pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); pf = BKE_packedfile_new(NULL, filepath, BKE_main_blendfile_path(bmain));
is_builtin = false; is_builtin = false;
} }
@@ -279,13 +280,13 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath)
/* Do not add FO_BUILTIN_NAME to temporary listbase */ /* Do not add FO_BUILTIN_NAME to temporary listbase */
if (!STREQ(filename, FO_BUILTIN_NAME)) { if (!STREQ(filename, FO_BUILTIN_NAME)) {
vfont->temp_pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); vfont->temp_pf = BKE_packedfile_new(NULL, filepath, BKE_main_blendfile_path(bmain));
} }
} }
/* Free the packed file */ /* Free the packed file */
if (!vfont || vfont->packedfile != pf) { if (!vfont || vfont->packedfile != pf) {
freePackedFile(pf); BKE_packedfile_free(pf);
} }
} }

View File

@@ -198,7 +198,7 @@ static void image_free_packedfiles(Image *ima)
while (ima->packedfiles.last) { while (ima->packedfiles.last) {
ImagePackedFile *imapf = ima->packedfiles.last; ImagePackedFile *imapf = ima->packedfiles.last;
if (imapf->packedfile) { if (imapf->packedfile) {
freePackedFile(imapf->packedfile); BKE_packedfile_free(imapf->packedfile);
} }
BLI_remlink(&ima->packedfiles, imapf); BLI_remlink(&ima->packedfiles, imapf);
MEM_freeN(imapf); MEM_freeN(imapf);
@@ -377,7 +377,7 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src)
STRNCPY(imapf_dst->filepath, imapf_src->filepath); STRNCPY(imapf_dst->filepath, imapf_src->filepath);
if (imapf_src->packedfile) { if (imapf_src->packedfile) {
imapf_dst->packedfile = dupPackedFile(imapf_src->packedfile); imapf_dst->packedfile = BKE_packedfile_duplicate(imapf_src->packedfile);
} }
BLI_addtail(lb_dst, imapf_dst); BLI_addtail(lb_dst, imapf_dst);
@@ -838,7 +838,7 @@ void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath)
if (totfiles == 1) { if (totfiles == 1) {
ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image packed file"); ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image packed file");
BLI_addtail(&ima->packedfiles, imapf); BLI_addtail(&ima->packedfiles, imapf);
imapf->packedfile = newPackedFile(reports, ima->name, basepath); imapf->packedfile = BKE_packedfile_new(reports, ima->name, basepath);
if (imapf->packedfile) { if (imapf->packedfile) {
STRNCPY(imapf->filepath, ima->name); STRNCPY(imapf->filepath, ima->name);
} }
@@ -852,7 +852,7 @@ void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath)
ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image packed file"); ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image packed file");
BLI_addtail(&ima->packedfiles, imapf); BLI_addtail(&ima->packedfiles, imapf);
imapf->packedfile = newPackedFile(reports, iv->filepath, basepath); imapf->packedfile = BKE_packedfile_new(reports, iv->filepath, basepath);
if (imapf->packedfile) { if (imapf->packedfile) {
STRNCPY(imapf->filepath, iv->filepath); STRNCPY(imapf->filepath, iv->filepath);
} }
@@ -876,7 +876,7 @@ void BKE_image_packfiles_from_mem(ReportList *reports,
else { else {
ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), __func__); ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), __func__);
BLI_addtail(&ima->packedfiles, imapf); BLI_addtail(&ima->packedfiles, imapf);
imapf->packedfile = newPackedFileMemory(data, data_len); imapf->packedfile = BKE_packedfile_new_from_memory(data, data_len);
STRNCPY(imapf->filepath, ima->name); STRNCPY(imapf->filepath, ima->name);
} }
} }
@@ -3241,9 +3241,9 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
ImagePackedFile *imapf; ImagePackedFile *imapf;
for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
PackedFile *pf; PackedFile *pf;
pf = newPackedFile(NULL, imapf->filepath, ID_BLEND_PATH(bmain, &ima->id)); pf = BKE_packedfile_new(NULL, imapf->filepath, ID_BLEND_PATH(bmain, &ima->id));
if (pf) { if (pf) {
freePackedFile(imapf->packedfile); BKE_packedfile_free(imapf->packedfile);
imapf->packedfile = pf; imapf->packedfile = pf;
} }
else { else {
@@ -4014,7 +4014,8 @@ static ImBuf *load_image_single(Image *ima,
BLI_addtail(&ima->packedfiles, imapf); BLI_addtail(&ima->packedfiles, imapf);
STRNCPY(imapf->filepath, filepath); STRNCPY(imapf->filepath, filepath);
imapf->packedfile = newPackedFile(NULL, filepath, ID_BLEND_PATH_FROM_GLOBAL(&ima->id)); imapf->packedfile = BKE_packedfile_new(
NULL, filepath, ID_BLEND_PATH_FROM_GLOBAL(&ima->id));
} }
} }
} }

View File

@@ -1502,7 +1502,7 @@ void *BKE_libblock_copy_for_localize(const ID *id)
void BKE_library_free(Library *lib) void BKE_library_free(Library *lib)
{ {
if (lib->packedfile) { if (lib->packedfile) {
freePackedFile(lib->packedfile); BKE_packedfile_free(lib->packedfile);
} }
} }

View File

@@ -49,7 +49,7 @@
#include "BKE_report.h" #include "BKE_report.h"
#include "BKE_sound.h" #include "BKE_sound.h"
int seekPackedFile(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;
@@ -81,12 +81,12 @@ int seekPackedFile(PackedFile *pf, int offset, int whence)
return (oldseek); return (oldseek);
} }
void rewindPackedFile(PackedFile *pf) void BKE_packedfile_rewind(PackedFile *pf)
{ {
seekPackedFile(pf, 0, SEEK_SET); BKE_packedfile_seek(pf, 0, SEEK_SET);
} }
int readPackedFile(PackedFile *pf, void *data, int size) int BKE_packedfile_read(PackedFile *pf, void *data, int size)
{ {
if ((pf != NULL) && (size >= 0) && (data != NULL)) { if ((pf != NULL) && (size >= 0) && (data != NULL)) {
if (size + pf->seek > pf->size) { if (size + pf->seek > pf->size) {
@@ -109,7 +109,7 @@ int readPackedFile(PackedFile *pf, void *data, int size)
return (size); return (size);
} }
int countPackedFiles(Main *bmain) int BKE_packedfile_count_all(Main *bmain)
{ {
Image *ima; Image *ima;
VFont *vf; VFont *vf;
@@ -138,18 +138,18 @@ int countPackedFiles(Main *bmain)
return count; return count;
} }
void freePackedFile(PackedFile *pf) void BKE_packedfile_free(PackedFile *pf)
{ {
if (pf) { if (pf) {
MEM_freeN(pf->data); MEM_freeN(pf->data);
MEM_freeN(pf); MEM_freeN(pf);
} }
else { else {
printf("freePackedFile: Trying to free a NULL pointer\n"); printf("BKE_packedfile_free: Trying to free a NULL pointer\n");
} }
} }
PackedFile *dupPackedFile(const PackedFile *pf_src) PackedFile *BKE_packedfile_duplicate(const PackedFile *pf_src)
{ {
PackedFile *pf_dst; PackedFile *pf_dst;
@@ -159,7 +159,7 @@ PackedFile *dupPackedFile(const PackedFile *pf_src)
return pf_dst; return pf_dst;
} }
PackedFile *newPackedFileMemory(void *mem, int memlen) PackedFile *BKE_packedfile_new_from_memory(void *mem, int memlen)
{ {
PackedFile *pf = MEM_callocN(sizeof(*pf), "PackedFile"); PackedFile *pf = MEM_callocN(sizeof(*pf), "PackedFile");
pf->data = mem; pf->data = mem;
@@ -168,7 +168,7 @@ PackedFile *newPackedFileMemory(void *mem, int memlen)
return pf; return pf;
} }
PackedFile *newPackedFile(ReportList *reports, const char *filename, const char *basepath) PackedFile *BKE_packedfile_new(ReportList *reports, const char *filename, const char *basepath)
{ {
PackedFile *pf = NULL; PackedFile *pf = NULL;
int file, filelen; int file, filelen;
@@ -207,7 +207,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
data = MEM_mallocN(filelen, "packFile"); data = MEM_mallocN(filelen, "packFile");
} }
if (read(file, data, filelen) == filelen) { if (read(file, data, filelen) == filelen) {
pf = newPackedFileMemory(data, filelen); pf = BKE_packedfile_new_from_memory(data, filelen);
} }
else { else {
MEM_freeN(data); MEM_freeN(data);
@@ -222,7 +222,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
} }
/* no libraries for now */ /* no libraries for now */
void packAll(Main *bmain, ReportList *reports, bool verbose) void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
{ {
Image *ima; Image *ima;
VFont *vfont; VFont *vfont;
@@ -247,14 +247,14 @@ void packAll(Main *bmain, ReportList *reports, bool verbose)
for (vfont = bmain->fonts.first; vfont; vfont = vfont->id.next) { for (vfont = bmain->fonts.first; vfont; vfont = vfont->id.next) {
if (vfont->packedfile == NULL && !ID_IS_LINKED(vfont) && if (vfont->packedfile == NULL && !ID_IS_LINKED(vfont) &&
BKE_vfont_is_builtin(vfont) == false) { BKE_vfont_is_builtin(vfont) == false) {
vfont->packedfile = newPackedFile(reports, vfont->name, BKE_main_blendfile_path(bmain)); vfont->packedfile = BKE_packedfile_new(reports, vfont->name, BKE_main_blendfile_path(bmain));
tot++; tot++;
} }
} }
for (sound = bmain->sounds.first; sound; sound = sound->id.next) { for (sound = bmain->sounds.first; sound; sound = sound->id.next) {
if (sound->packedfile == NULL && !ID_IS_LINKED(sound)) { if (sound->packedfile == NULL && !ID_IS_LINKED(sound)) {
sound->packedfile = newPackedFile(reports, sound->name, BKE_main_blendfile_path(bmain)); sound->packedfile = BKE_packedfile_new(reports, sound->name, BKE_main_blendfile_path(bmain));
tot++; tot++;
} }
} }
@@ -267,11 +267,11 @@ void packAll(Main *bmain, ReportList *reports, bool verbose)
} }
} }
int writePackedFile(ReportList *reports, int BKE_packedfile_write_to_file(ReportList *reports,
const char *ref_file_name, const char *ref_file_name,
const char *filename, const char *filename,
PackedFile *pf, PackedFile *pf,
const bool guimode) const bool guimode)
{ {
int file, number; int file, number;
int ret_value = RET_OK; int ret_value = RET_OK;
@@ -349,7 +349,7 @@ int writePackedFile(ReportList *reports,
* - PF_DIFFERENT: the packed file and original file differ * - PF_DIFFERENT: the packed file and original file differ
* - PF_NOFILE: the original file doesn't exist * - PF_NOFILE: the original file doesn't exist
*/ */
int checkPackedFile(const char *ref_file_name, const char *filename, PackedFile *pf) int BKE_packedfile_compare_to_file(const char *ref_file_name, const char *filename, PackedFile *pf)
{ {
BLI_stat_t st; BLI_stat_t st;
int ret_val, i, len, file; int ret_val, i, len, file;
@@ -402,7 +402,8 @@ int checkPackedFile(const char *ref_file_name, const char *filename, PackedFile
} }
/** /**
* unpackFile() looks at the existing files (abs_name, local_name) and a packed file. * #BKE_packedfile_unpack_to_file() looks at the existing files (abs_name, local_name)
* and a packed file.
* *
* It returns a char *to the existing file name / new file name or NULL when * It returns a char *to the existing file name / new file name or NULL when
* there was an error or when the user decides to cancel the operation. * there was an error or when the user decides to cancel the operation.
@@ -410,12 +411,12 @@ int checkPackedFile(const char *ref_file_name, const char *filename, PackedFile
* \warning 'abs_name' may be relative still! (use a "//" prefix) * \warning 'abs_name' may be relative still! (use a "//" prefix)
* be sure to run #BLI_path_abs on it first. * be sure to run #BLI_path_abs on it first.
*/ */
char *unpackFile(ReportList *reports, char *BKE_packedfile_unpack_to_file(ReportList *reports,
const char *ref_file_name, const char *ref_file_name,
const char *abs_name, const char *abs_name,
const char *local_name, const char *local_name,
PackedFile *pf, PackedFile *pf,
int how) int how)
{ {
char *newname = NULL; char *newname = NULL;
const char *temp = NULL; const char *temp = NULL;
@@ -443,7 +444,7 @@ char *unpackFile(ReportList *reports,
ATTR_FALLTHROUGH; ATTR_FALLTHROUGH;
} }
case PF_WRITE_LOCAL: case PF_WRITE_LOCAL:
if (writePackedFile(reports, ref_file_name, local_name, pf, 1) == RET_OK) { if (BKE_packedfile_write_to_file(reports, ref_file_name, local_name, pf, 1) == RET_OK) {
temp = local_name; temp = local_name;
} }
break; break;
@@ -463,12 +464,12 @@ char *unpackFile(ReportList *reports,
ATTR_FALLTHROUGH; ATTR_FALLTHROUGH;
} }
case PF_WRITE_ORIGINAL: case PF_WRITE_ORIGINAL:
if (writePackedFile(reports, ref_file_name, abs_name, pf, 1) == RET_OK) { if (BKE_packedfile_write_to_file(reports, ref_file_name, abs_name, pf, 1) == RET_OK) {
temp = abs_name; temp = abs_name;
} }
break; break;
default: default:
printf("unpackFile: unknown return_value %d\n", how); printf("BKE_packedfile_unpack_to_file: unknown return_value %d\n", how);
break; break;
} }
@@ -525,7 +526,7 @@ static void unpack_generate_paths(const char *name,
} }
} }
int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how) int BKE_packedfile_unpack_vfont(Main *bmain, ReportList *reports, VFont *vfont, int how)
{ {
char localname[FILE_MAX], absname[FILE_MAX]; char localname[FILE_MAX], absname[FILE_MAX];
char *newname; char *newname;
@@ -534,11 +535,11 @@ int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how)
if (vfont != NULL) { if (vfont != NULL) {
unpack_generate_paths( unpack_generate_paths(
vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname)); vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname));
newname = unpackFile( newname = BKE_packedfile_unpack_to_file(
reports, BKE_main_blendfile_path(bmain), absname, localname, vfont->packedfile, how); reports, BKE_main_blendfile_path(bmain), absname, localname, vfont->packedfile, how);
if (newname != NULL) { if (newname != NULL) {
ret_value = RET_OK; ret_value = RET_OK;
freePackedFile(vfont->packedfile); BKE_packedfile_free(vfont->packedfile);
vfont->packedfile = NULL; vfont->packedfile = NULL;
BLI_strncpy(vfont->name, newname, sizeof(vfont->name)); BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
MEM_freeN(newname); MEM_freeN(newname);
@@ -548,7 +549,7 @@ int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how)
return (ret_value); return (ret_value);
} }
int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) int BKE_packedfile_unpack_sound(Main *bmain, ReportList *reports, bSound *sound, int how)
{ {
char localname[FILE_MAX], absname[FILE_MAX]; char localname[FILE_MAX], absname[FILE_MAX];
char *newname; char *newname;
@@ -557,13 +558,13 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
if (sound != NULL) { if (sound != NULL) {
unpack_generate_paths( unpack_generate_paths(
sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname)); sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname));
newname = unpackFile( newname = BKE_packedfile_unpack_to_file(
reports, BKE_main_blendfile_path(bmain), absname, localname, sound->packedfile, how); reports, BKE_main_blendfile_path(bmain), absname, localname, sound->packedfile, how);
if (newname != NULL) { if (newname != NULL) {
BLI_strncpy(sound->name, newname, sizeof(sound->name)); BLI_strncpy(sound->name, newname, sizeof(sound->name));
MEM_freeN(newname); MEM_freeN(newname);
freePackedFile(sound->packedfile); BKE_packedfile_free(sound->packedfile);
sound->packedfile = NULL; sound->packedfile = NULL;
BKE_sound_load(bmain, sound); BKE_sound_load(bmain, sound);
@@ -575,7 +576,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
return (ret_value); return (ret_value);
} }
int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how) int BKE_packedfile_unpack_image(Main *bmain, ReportList *reports, Image *ima, int how)
{ {
int ret_value = RET_ERROR; int ret_value = RET_ERROR;
@@ -587,14 +588,14 @@ int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how)
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 = unpackFile( 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;
freePackedFile(imapf->packedfile); BKE_packedfile_free(imapf->packedfile);
imapf->packedfile = NULL; imapf->packedfile = NULL;
/* update the new corresponding view filepath */ /* update the new corresponding view filepath */
@@ -625,7 +626,7 @@ int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how)
return (ret_value); return (ret_value);
} }
int unpackLibraries(Main *bmain, ReportList *reports) int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
{ {
Library *lib; Library *lib;
char *newname; char *newname;
@@ -634,18 +635,18 @@ int unpackLibraries(Main *bmain, ReportList *reports)
for (lib = bmain->libraries.first; lib; lib = lib->id.next) { for (lib = bmain->libraries.first; lib; lib = lib->id.next) {
if (lib->packedfile && lib->name[0]) { if (lib->packedfile && lib->name[0]) {
newname = unpackFile(reports, newname = BKE_packedfile_unpack_to_file(reports,
BKE_main_blendfile_path(bmain), BKE_main_blendfile_path(bmain),
lib->filepath, lib->filepath,
lib->filepath, lib->filepath,
lib->packedfile, lib->packedfile,
PF_WRITE_ORIGINAL); PF_WRITE_ORIGINAL);
if (newname != NULL) { if (newname != NULL) {
ret_value = RET_OK; ret_value = RET_OK;
printf("Unpacked .blend library: %s\n", newname); printf("Unpacked .blend library: %s\n", newname);
freePackedFile(lib->packedfile); BKE_packedfile_free(lib->packedfile);
lib->packedfile = NULL; lib->packedfile = NULL;
MEM_freeN(newname); MEM_freeN(newname);
@@ -656,7 +657,7 @@ int unpackLibraries(Main *bmain, ReportList *reports)
return (ret_value); return (ret_value);
} }
void packLibraries(Main *bmain, ReportList *reports) void BKE_packedfile_pack_all_libraries(Main *bmain, ReportList *reports)
{ {
Library *lib; Library *lib;
@@ -674,12 +675,12 @@ void packLibraries(Main *bmain, ReportList *reports)
for (lib = bmain->libraries.first; lib; lib = lib->id.next) { for (lib = bmain->libraries.first; lib; lib = lib->id.next) {
if (lib->packedfile == NULL) { if (lib->packedfile == NULL) {
lib->packedfile = newPackedFile(reports, lib->name, BKE_main_blendfile_path(bmain)); lib->packedfile = BKE_packedfile_new(reports, lib->name, BKE_main_blendfile_path(bmain));
} }
} }
} }
void unpackAll(Main *bmain, ReportList *reports, int how) void BKE_packedfile_unpack_all(Main *bmain, ReportList *reports, int how)
{ {
Image *ima; Image *ima;
VFont *vf; VFont *vf;
@@ -687,25 +688,25 @@ void unpackAll(Main *bmain, ReportList *reports, int how)
for (ima = bmain->images.first; ima; ima = ima->id.next) { for (ima = bmain->images.first; ima; ima = ima->id.next) {
if (BKE_image_has_packedfile(ima)) { if (BKE_image_has_packedfile(ima)) {
unpackImage(bmain, reports, ima, how); BKE_packedfile_unpack_image(bmain, reports, ima, how);
} }
} }
for (vf = bmain->fonts.first; vf; vf = vf->id.next) { for (vf = bmain->fonts.first; vf; vf = vf->id.next) {
if (vf->packedfile) { if (vf->packedfile) {
unpackVFont(bmain, reports, vf, how); BKE_packedfile_unpack_vfont(bmain, reports, vf, how);
} }
} }
for (sound = bmain->sounds.first; sound; sound = sound->id.next) { for (sound = bmain->sounds.first; sound; sound = sound->id.next) {
if (sound->packedfile) { if (sound->packedfile) {
unpackSound(bmain, reports, sound, how); BKE_packedfile_unpack_sound(bmain, reports, sound, how);
} }
} }
} }
/* ID should be not NULL, return 1 if there's a packed file */ /* ID should be not NULL, return 1 if there's a packed file */
bool BKE_pack_check(ID *id) bool BKE_packedfile_id_check(ID *id)
{ {
switch (GS(id->name)) { switch (GS(id->name)) {
case ID_IM: { case ID_IM: {
@@ -731,27 +732,27 @@ bool BKE_pack_check(ID *id)
} }
/* ID should be not NULL */ /* ID should be not NULL */
void BKE_unpack_id(Main *bmain, ID *id, ReportList *reports, int how) void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, int how)
{ {
switch (GS(id->name)) { switch (GS(id->name)) {
case ID_IM: { case ID_IM: {
Image *ima = (Image *)id; Image *ima = (Image *)id;
if (BKE_image_has_packedfile(ima)) { if (BKE_image_has_packedfile(ima)) {
unpackImage(bmain, reports, ima, how); BKE_packedfile_unpack_image(bmain, reports, ima, how);
} }
break; break;
} }
case ID_VF: { case ID_VF: {
VFont *vf = (VFont *)id; VFont *vf = (VFont *)id;
if (vf->packedfile) { if (vf->packedfile) {
unpackVFont(bmain, reports, vf, how); BKE_packedfile_unpack_vfont(bmain, reports, vf, how);
} }
break; break;
} }
case ID_SO: { case ID_SO: {
bSound *snd = (bSound *)id; bSound *snd = (bSound *)id;
if (snd->packedfile) { if (snd->packedfile) {
unpackSound(bmain, reports, snd, how); BKE_packedfile_unpack_sound(bmain, reports, snd, how);
} }
break; break;
} }

View File

@@ -170,7 +170,7 @@ void BKE_sound_free(bSound *sound)
/* No animdata here. */ /* No animdata here. */
if (sound->packedfile) { if (sound->packedfile) {
freePackedFile(sound->packedfile); BKE_packedfile_free(sound->packedfile);
sound->packedfile = NULL; sound->packedfile = NULL;
} }
@@ -211,7 +211,7 @@ void BKE_sound_copy_data(Main *UNUSED(bmain),
sound_dst->newpackedfile = NULL; sound_dst->newpackedfile = NULL;
if (sound_dst->packedfile) { if (sound_dst->packedfile) {
sound_dst->packedfile = dupPackedFile(sound_dst->packedfile); sound_dst->packedfile = BKE_packedfile_duplicate(sound_dst->packedfile);
} }
BKE_sound_reset_runtime(sound_dst); BKE_sound_reset_runtime(sound_dst);

View File

@@ -952,7 +952,7 @@ static void template_ID(bContext *C,
/* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack. /* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
* Only for images, sound and fonts */ * Only for images, sound and fonts */
if (id && BKE_pack_check(id)) { if (id && BKE_packedfile_id_check(id)) {
but = uiDefIconButO(block, but = uiDefIconButO(block,
UI_BTYPE_BUT, UI_BTYPE_BUT,
"FILE_OT_unpack_item", "FILE_OT_unpack_item",

View File

@@ -765,7 +765,8 @@ static int sound_pack_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
sound->packedfile = newPackedFile(op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id)); sound->packedfile = BKE_packedfile_new(
op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id));
BKE_sound_load(bmain, sound); BKE_sound_load(bmain, sound);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
@@ -811,7 +812,7 @@ static int sound_unpack_exec(bContext *C, wmOperator *op)
"AutoPack is enabled, so image will be packed again on file save"); "AutoPack is enabled, so image will be packed again on file save");
} }
unpackSound(bmain, op->reports, sound, method); BKE_packedfile_unpack_sound(bmain, op->reports, sound, method);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }

View File

@@ -1391,7 +1391,7 @@ static int image_open_exec(bContext *C, wmOperator *op)
BKE_image_init_imageuser(ima, iuser); BKE_image_init_imageuser(ima, iuser);
} }
/* XXX unpackImage frees image buffers */ /* XXX BKE_packedfile_unpack_image frees image buffers */
ED_preview_kill_jobs(CTX_wm_manager(C), bmain); ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD); BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
@@ -1601,7 +1601,7 @@ static int image_replace_exec(bContext *C, wmOperator *op)
sima->image->source = IMA_SRC_FILE; sima->image->source = IMA_SRC_FILE;
} }
/* XXX unpackImage frees image buffers */ /* XXX BKE_packedfile_unpack_image frees image buffers */
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
BKE_icon_changed(BKE_icon_id_ensure(&sima->image->id)); BKE_icon_changed(BKE_icon_id_ensure(&sima->image->id));
@@ -2401,7 +2401,7 @@ static int image_reload_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
/* XXX unpackImage frees image buffers */ /* XXX BKE_packedfile_unpack_image frees image buffers */
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD); BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
@@ -2859,10 +2859,10 @@ static int image_unpack_exec(bContext *C, wmOperator *op)
"AutoPack is enabled, so image will be packed again on file save"); "AutoPack is enabled, so image will be packed again on file save");
} }
/* XXX unpackImage frees image buffers */ /* XXX BKE_packedfile_unpack_image frees image buffers */
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
unpackImage(CTX_data_main(C), op->reports, ima, method); BKE_packedfile_unpack_image(CTX_data_main(C), op->reports, ima, method);
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);

View File

@@ -65,7 +65,7 @@ static int pack_libraries_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
packLibraries(bmain, op->reports); BKE_packedfile_pack_all_libraries(bmain, op->reports);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
@@ -88,7 +88,7 @@ static int unpack_libraries_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
unpackLibraries(bmain, op->reports); BKE_packedfile_unpack_all_libraries(bmain, op->reports);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
@@ -124,7 +124,7 @@ static int autopack_toggle_exec(bContext *C, wmOperator *op)
G.fileflags &= ~G_FILE_AUTOPACK; G.fileflags &= ~G_FILE_AUTOPACK;
} }
else { else {
packAll(bmain, op->reports, true); BKE_packedfile_pack_all(bmain, op->reports, true);
G.fileflags |= G_FILE_AUTOPACK; G.fileflags |= G_FILE_AUTOPACK;
} }
@@ -151,7 +151,7 @@ static int pack_all_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
packAll(bmain, op->reports, true); BKE_packedfile_pack_all(bmain, op->reports, true);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
@@ -221,7 +221,7 @@ static int unpack_all_exec(bContext *C, wmOperator *op)
int method = RNA_enum_get(op->ptr, "method"); int method = RNA_enum_get(op->ptr, "method");
if (method != PF_KEEP) { if (method != PF_KEEP) {
unpackAll(bmain, op->reports, method); /* XXX PF_ASK can't work here */ BKE_packedfile_unpack_all(bmain, op->reports, method); /* XXX PF_ASK can't work here */
} }
G.fileflags &= ~G_FILE_AUTOPACK; G.fileflags &= ~G_FILE_AUTOPACK;
@@ -236,7 +236,7 @@ static int unpack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
char title[64]; char title[64];
int count = 0; int count = 0;
count = countPackedFiles(bmain); count = BKE_packedfile_count_all(bmain);
if (!count) { if (!count) {
BKE_report(op->reports, RPT_WARNING, "No packed files to unpack"); BKE_report(op->reports, RPT_WARNING, "No packed files to unpack");
@@ -321,7 +321,7 @@ static int unpack_item_exec(bContext *C, wmOperator *op)
} }
if (method != PF_KEEP) { if (method != PF_KEEP) {
BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */ BKE_packedfile_id_unpack(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */
} }
G.fileflags &= ~G_FILE_AUTOPACK; G.fileflags &= ~G_FILE_AUTOPACK;

View File

@@ -326,7 +326,7 @@ void unpack_menu(bContext *C,
BLI_split_file_part(abs_name, fi, sizeof(fi)); BLI_split_file_part(abs_name, fi, sizeof(fi));
BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
if (!STREQ(abs_name, local_name)) { if (!STREQ(abs_name, local_name)) {
switch (checkPackedFile(BKE_main_blendfile_path(bmain), local_name, pf)) { switch (BKE_packedfile_compare_to_file(BKE_main_blendfile_path(bmain), local_name, pf)) {
case PF_NOFILE: case PF_NOFILE:
BLI_snprintf(line, sizeof(line), TIP_("Create %s"), local_name); BLI_snprintf(line, sizeof(line), TIP_("Create %s"), local_name);
uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr);
@@ -359,7 +359,7 @@ void unpack_menu(bContext *C,
} }
} }
switch (checkPackedFile(BKE_main_blendfile_path(bmain), abs_name, pf)) { switch (BKE_packedfile_compare_to_file(BKE_main_blendfile_path(bmain), abs_name, pf)) {
case PF_NOFILE: case PF_NOFILE:
BLI_snprintf(line, sizeof(line), TIP_("Create %s"), abs_name); BLI_snprintf(line, sizeof(line), TIP_("Create %s"), abs_name);
// uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL);

View File

@@ -55,7 +55,7 @@
static void rna_ImagePackedFile_save(ImagePackedFile *imapf, Main *bmain, ReportList *reports) static void rna_ImagePackedFile_save(ImagePackedFile *imapf, Main *bmain, ReportList *reports)
{ {
if (writePackedFile( if (BKE_packedfile_write_to_file(
reports, BKE_main_blendfile_path(bmain), imapf->filepath, imapf->packedfile, 0) != reports, BKE_main_blendfile_path(bmain), imapf->filepath, imapf->packedfile, 0) !=
RET_OK) { RET_OK) {
BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'", imapf->filepath); BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'", imapf->filepath);
@@ -179,7 +179,7 @@ static void rna_Image_unpack(Image *image, Main *bmain, ReportList *reports, int
} }
else { else {
/* reports its own error on failure */ /* reports its own error on failure */
unpackImage(bmain, reports, image, method); BKE_packedfile_unpack_image(bmain, reports, image, method);
} }
} }

View File

@@ -34,7 +34,7 @@
static void rna_Sound_pack(bSound *sound, Main *bmain, ReportList *reports) static void rna_Sound_pack(bSound *sound, Main *bmain, ReportList *reports)
{ {
sound->packedfile = newPackedFile(reports, sound->name, ID_BLEND_PATH(bmain, &sound->id)); sound->packedfile = BKE_packedfile_new(reports, sound->name, ID_BLEND_PATH(bmain, &sound->id));
} }
static void rna_Sound_unpack(bSound *sound, Main *bmain, ReportList *reports, int method) static void rna_Sound_unpack(bSound *sound, Main *bmain, ReportList *reports, int method)
@@ -44,7 +44,7 @@ static void rna_Sound_unpack(bSound *sound, Main *bmain, ReportList *reports, in
} }
else { else {
/* reports its own error on failure */ /* reports its own error on failure */
unpackSound(bmain, reports, sound, method); BKE_packedfile_unpack_sound(bmain, reports, sound, method);
} }
} }

View File

@@ -34,7 +34,7 @@
static void rna_VectorFont_pack(VFont *vfont, Main *bmain, ReportList *reports) static void rna_VectorFont_pack(VFont *vfont, Main *bmain, ReportList *reports)
{ {
vfont->packedfile = newPackedFile(reports, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); vfont->packedfile = BKE_packedfile_new(reports, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
} }
static void rna_VectorFont_unpack(VFont *vfont, Main *bmain, ReportList *reports, int method) static void rna_VectorFont_unpack(VFont *vfont, Main *bmain, ReportList *reports, int method)
@@ -44,7 +44,7 @@ static void rna_VectorFont_unpack(VFont *vfont, Main *bmain, ReportList *reports
} }
else { else {
/* reports its own error on failure */ /* reports its own error on failure */
unpackVFont(bmain, reports, vfont, method); BKE_packedfile_unpack_vfont(bmain, reports, vfont, method);
} }
} }

View File

@@ -1376,7 +1376,7 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
/* operator now handles overwrite checks */ /* operator now handles overwrite checks */
if (G.fileflags & G_FILE_AUTOPACK) { if (G.fileflags & G_FILE_AUTOPACK) {
packAll(bmain, reports, false); BKE_packedfile_pack_all(bmain, reports, false);
} }
/* don't forget not to return without! */ /* don't forget not to return without! */