From 24d1829243c6e41c639c1d0722a13599a7c1927c Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 31 May 2018 11:07:14 +0200 Subject: Cleanup: nuke G.main out of BKE PackedFile code. --- source/blender/blenkernel/BKE_packedFile.h | 14 +++++---- source/blender/blenkernel/intern/packedFile.c | 41 ++++++++++++++------------ source/blender/editors/space_image/image_ops.c | 2 +- source/blender/editors/util/ed_util.c | 5 ++-- source/blender/makesrna/intern/rna_image_api.c | 12 ++++---- source/blender/makesrna/intern/rna_vfont_api.c | 8 ++--- 6 files changed, 45 insertions(+), 37 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h index a2397922061..ed6d66906d1 100644 --- a/source/blender/blenkernel/BKE_packedFile.h +++ b/source/blender/blenkernel/BKE_packedFile.h @@ -52,21 +52,25 @@ void packAll(struct Main *bmain, struct ReportList *reports, bool verbose); void packLibraries(struct Main *bmain, struct ReportList *reports); /* unpack */ -char *unpackFile(struct ReportList *reports, const char *abs_name, const char *local_name, struct PackedFile *pf, int how); -int unpackVFont(struct ReportList *reports, struct VFont *vfont, int how); +char *unpackFile( + struct ReportList *reports, const char *ref_file_name, + const char *abs_name, const char *local_name, struct PackedFile *pf, int how); +int unpackVFont(struct Main *bmain, struct ReportList *reports, struct VFont *vfont, int how); int unpackSound(struct Main *bmain, struct ReportList *reports, struct bSound *sound, int how); -int unpackImage(struct ReportList *reports, struct Image *ima, int how); +int unpackImage(struct Main *bmain, struct ReportList *reports, struct Image *ima, int how); void unpackAll(struct Main *bmain, struct ReportList *reports, int how); int unpackLibraries(struct Main *bmain, struct ReportList *reports); -int writePackedFile(struct ReportList *reports, const char *filename, struct PackedFile *pf, int guimode); +int writePackedFile( + struct ReportList *reports, const char *ref_file_name, + const char *filename, struct PackedFile *pf, const bool guimode); /* free */ void freePackedFile(struct PackedFile *pf); /* info */ int countPackedFiles(struct Main *bmain); -int checkPackedFile(const char *filename, struct PackedFile *pf); +int checkPackedFile(const char *ref_file_name, const char *filename, struct PackedFile *pf); /* read */ int seekPackedFile(struct PackedFile *pf, int offset, int whence); diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index f17c10765b8..afb155f7646 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -291,7 +291,8 @@ static char *find_new_name(char *name) } #endif -int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, int guimode) +int writePackedFile( + ReportList *reports, const char *ref_file_name, const char *filename, PackedFile *pf, const bool guimode) { int file, number; int ret_value = RET_OK; @@ -303,7 +304,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i if (guimode) {} //XXX waitcursor(1); BLI_strncpy(name, filename, sizeof(name)); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, ref_file_name); if (BLI_exists(name)) { for (number = 1; number <= 999; number++) { @@ -363,7 +364,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i * - PF_DIFFERENT: the packed file and original file differ * - PF_NOFILE: the original file doens't exist */ -int checkPackedFile(const char *filename, PackedFile *pf) +int checkPackedFile(const char *ref_file_name, const char *filename, PackedFile *pf) { BLI_stat_t st; int ret_val, i, len, file; @@ -371,7 +372,7 @@ int checkPackedFile(const char *filename, PackedFile *pf) char name[FILE_MAX]; BLI_strncpy(name, filename, sizeof(name)); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, ref_file_name); if (BLI_stat(name, &st) == -1) { ret_val = PF_NOFILE; @@ -423,7 +424,9 @@ int checkPackedFile(const char *filename, PackedFile *pf) * * \warning 'abs_name' may be relative still! (use a "//" prefix) be sure to run #BLI_path_abs on it first. */ -char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how) +char *unpackFile( + ReportList *reports, const char *ref_file_name, + const char *abs_name, const char *local_name, PackedFile *pf, int how) { char *newname = NULL; const char *temp = NULL; @@ -441,7 +444,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na char temp_abs[FILE_MAX]; BLI_strncpy(temp_abs, local_name, sizeof(temp_abs)); - BLI_path_abs(temp_abs, G.main->name); + BLI_path_abs(temp_abs, ref_file_name); /* if file exists use it */ if (BLI_exists(temp_abs)) { @@ -452,7 +455,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na ATTR_FALLTHROUGH; } case PF_WRITE_LOCAL: - if (writePackedFile(reports, local_name, pf, 1) == RET_OK) { + if (writePackedFile(reports, ref_file_name, local_name, pf, 1) == RET_OK) { temp = local_name; } break; @@ -461,7 +464,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na char temp_abs[FILE_MAX]; BLI_strncpy(temp_abs, abs_name, sizeof(temp_abs)); - BLI_path_abs(temp_abs, G.main->name); + BLI_path_abs(temp_abs, ref_file_name); /* if file exists use it */ if (BLI_exists(temp_abs)) { @@ -473,7 +476,7 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na ATTR_FALLTHROUGH; } case PF_WRITE_ORIGINAL: - if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) { + if (writePackedFile(reports, ref_file_name, abs_name, pf, 1) == RET_OK) { temp = abs_name; } break; @@ -531,7 +534,7 @@ static void unpack_generate_paths( } } -int unpackVFont(ReportList *reports, VFont *vfont, int how) +int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how) { char localname[FILE_MAX], absname[FILE_MAX]; char *newname; @@ -539,7 +542,7 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how) if (vfont != NULL) { unpack_generate_paths(vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, absname, localname, vfont->packedfile, how); + newname = unpackFile(reports, bmain->name, absname, localname, vfont->packedfile, how); if (newname != NULL) { ret_value = RET_OK; freePackedFile(vfont->packedfile); @@ -560,7 +563,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) if (sound != NULL) { unpack_generate_paths(sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, absname, localname, sound->packedfile, how); + newname = unpackFile(reports, bmain->name, absname, localname, sound->packedfile, how); if (newname != NULL) { BLI_strncpy(sound->name, newname, sizeof(sound->name)); MEM_freeN(newname); @@ -577,7 +580,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) return(ret_value); } -int unpackImage(ReportList *reports, Image *ima, int how) +int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how) { int ret_value = RET_ERROR; @@ -588,7 +591,7 @@ int unpackImage(ReportList *reports, Image *ima, int how) ImagePackedFile *imapf = ima->packedfiles.last; unpack_generate_paths(imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, absname, localname, imapf->packedfile, how); + newname = unpackFile(reports, bmain->name, absname, localname, imapf->packedfile, how); if (newname != NULL) { ImageView *iv; @@ -634,7 +637,7 @@ int unpackLibraries(Main *bmain, ReportList *reports) for (lib = bmain->library.first; lib; lib = lib->id.next) { if (lib->packedfile && lib->name[0]) { - newname = unpackFile(reports, lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); + newname = unpackFile(reports, bmain->name, lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); if (newname != NULL) { ret_value = RET_OK; @@ -678,11 +681,11 @@ void unpackAll(Main *bmain, ReportList *reports, int how) for (ima = bmain->image.first; ima; ima = ima->id.next) if (BKE_image_has_packedfile(ima)) - unpackImage(reports, ima, how); + unpackImage(bmain, reports, ima, how); for (vf = bmain->vfont.first; vf; vf = vf->id.next) if (vf->packedfile) - unpackVFont(reports, vf, how); + unpackVFont(bmain, reports, vf, how); for (sound = bmain->sound.first; sound; sound = sound->id.next) if (sound->packedfile) @@ -727,7 +730,7 @@ void BKE_unpack_id(Main *bmain, ID *id, ReportList *reports, int how) { Image *ima = (Image *)id; if (BKE_image_has_packedfile(ima)) { - unpackImage(reports, ima, how); + unpackImage(bmain, reports, ima, how); } break; } @@ -735,7 +738,7 @@ void BKE_unpack_id(Main *bmain, ID *id, ReportList *reports, int how) { VFont *vf = (VFont *)id; if (vf->packedfile) { - unpackVFont(reports, vf, how); + unpackVFont(bmain, reports, vf, how); } break; } diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index e14e7820403..308ee61a2b8 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -2823,7 +2823,7 @@ static int image_unpack_exec(bContext *C, wmOperator *op) /* XXX unpackImage frees image buffers */ ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - unpackImage(op->reports, ima, method); + unpackImage(CTX_data_main(C), op->reports, ima, method); WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 03d0b4a8d48..8569666c1d9 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -232,6 +232,7 @@ void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, fl void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf) { + Main *bmain = CTX_data_main(C); PointerRNA props_ptr; uiPopupMenu *pup; uiLayout *layout; @@ -253,7 +254,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha BLI_split_file_part(abs_name, fi, sizeof(fi)); BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); if (!STREQ(abs_name, local_name)) { - switch (checkPackedFile(local_name, pf)) { + switch (checkPackedFile(bmain->name, local_name, pf)) { case PF_NOFILE: BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), local_name); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); @@ -286,7 +287,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha } } - switch (checkPackedFile(abs_name, pf)) { + switch (checkPackedFile(bmain->name, abs_name, pf)) { case PF_NOFILE: BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), abs_name); //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 61f1edc0af5..f5f7ade6390 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -64,9 +64,9 @@ #include "MEM_guardedalloc.h" -static void rna_ImagePackedFile_save(ImagePackedFile *imapf, ReportList *reports) +static void rna_ImagePackedFile_save(ImagePackedFile *imapf, Main *bmain, ReportList *reports) { - if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) { + if (writePackedFile(reports, bmain->name, imapf->filepath, imapf->packedfile, 0) != RET_OK) { BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'", imapf->filepath); } @@ -177,7 +177,7 @@ static void rna_Image_pack( WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image); } -static void rna_Image_unpack(Image *image, ReportList *reports, int method) +static void rna_Image_unpack(Image *image, Main *bmain, ReportList *reports, int method) { if (!BKE_image_has_packedfile(image)) { BKE_report(reports, RPT_ERROR, "Image not packed"); @@ -188,7 +188,7 @@ static void rna_Image_unpack(Image *image, ReportList *reports, int method) } else { /* reports its own error on failure */ - unpackImage(reports, image, method); + unpackImage(bmain, reports, image, method); } } @@ -302,7 +302,7 @@ void RNA_api_image_packed_file(StructRNA *srna) func = RNA_def_function(srna, "save", "rna_ImagePackedFile_save"); RNA_def_function_ui_description(func, "Save the packed file to its filepath"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); } void RNA_api_image(StructRNA *srna) @@ -332,7 +332,7 @@ void RNA_api_image(StructRNA *srna) func = RNA_def_function(srna, "unpack", "rna_Image_unpack"); RNA_def_function_ui_description(func, "Save an image packed in the .blend file to disk"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); RNA_def_enum(func, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "method", "How to unpack"); func = RNA_def_function(srna, "reload", "rna_Image_reload"); diff --git a/source/blender/makesrna/intern/rna_vfont_api.c b/source/blender/makesrna/intern/rna_vfont_api.c index 6a2a7f3ffad..b93fc1a0053 100644 --- a/source/blender/makesrna/intern/rna_vfont_api.c +++ b/source/blender/makesrna/intern/rna_vfont_api.c @@ -43,14 +43,14 @@ static void rna_VectorFont_pack(VFont *vfont, Main *bmain, ReportList *reports) vfont->packedfile = newPackedFile(reports, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); } -static void rna_VectorFont_unpack(VFont *vfont, ReportList *reports, int method) +static void rna_VectorFont_unpack(VFont *vfont, Main *bmain, ReportList *reports, int method) { if (!vfont->packedfile) { BKE_report(reports, RPT_ERROR, "Font not packed"); } else { /* reports its own error on failure */ - unpackVFont(reports, vfont, method); + unpackVFont(bmain, reports, vfont, method); } } @@ -62,11 +62,11 @@ void RNA_api_vfont(StructRNA *srna) func = RNA_def_function(srna, "pack", "rna_VectorFont_pack"); RNA_def_function_ui_description(func, "Pack the font into the current blend file"); - RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_MAIN); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); func = RNA_def_function(srna, "unpack", "rna_VectorFont_unpack"); RNA_def_function_ui_description(func, "Unpack the font to the samples filename"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); RNA_def_enum(func, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "method", "How to unpack"); } -- cgit v1.2.3