Fix: Dont unpack resources that are packed in linked files (next round)

These remain linked, so data remains to be read/loaded from the packed
version from the library (making this a useless and wasteful
duplication, also changes could be perceived as lost)

Continuation of !122092 which came up in #122033 -- but spread to more
operators / API so it is consistent everywhere

For operators, first intuition was to do it in a poll function, but that
isnt possible because the actual ID might depend on a given (to the
operator) ID name.

NOTE: Still not 100% in which scenarios linked data could still be
editable, but using ID_IS_EDITABLE for this now.

c6aa1fec2b / 918d34a9ed are related

Pull Request: https://projects.blender.org/blender/blender/pulls/122204
This commit is contained in:
Philipp Oeser
2024-05-26 11:32:06 +02:00
committed by Philipp Oeser
parent 9c534cda00
commit a65df02031
5 changed files with 47 additions and 11 deletions

View File

@@ -810,6 +810,11 @@ static int sound_unpack_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
if (!ID_IS_EDITABLE(&sound->id)) {
BKE_report(op->reports, RPT_ERROR, "Sound is not editable");
return OPERATOR_CANCELLED;
}
if (G.fileflags & G_FILE_AUTOPACK) {
BKE_report(op->reports,
RPT_WARNING,
@@ -840,6 +845,11 @@ static int sound_unpack_invoke(bContext *C, wmOperator *op, const wmEvent * /*ev
return OPERATOR_CANCELLED;
}
if (!ID_IS_EDITABLE(&sound->id)) {
BKE_report(op->reports, RPT_ERROR, "Sound is not editable");
return OPERATOR_CANCELLED;
}
if (G.fileflags & G_FILE_AUTOPACK) {
BKE_report(op->reports,
RPT_WARNING,

View File

@@ -3352,6 +3352,11 @@ static int image_unpack_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
if (!ID_IS_EDITABLE(&ima->id)) {
BKE_report(op->reports, RPT_ERROR, "Image is not editable");
return OPERATOR_CANCELLED;
}
if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
return OPERATOR_CANCELLED;
@@ -3385,6 +3390,11 @@ static int image_unpack_invoke(bContext *C, wmOperator *op, const wmEvent * /*ev
return OPERATOR_CANCELLED;
}
if (!ID_IS_EDITABLE(&ima->id)) {
BKE_report(op->reports, RPT_ERROR, "Image is not editable");
return OPERATOR_CANCELLED;
}
if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
return OPERATOR_CANCELLED;

View File

@@ -144,15 +144,21 @@ static void rna_Image_unpack(Image *image, Main *bmain, ReportList *reports, int
{
if (!BKE_image_has_packedfile(image)) {
BKE_report(reports, RPT_ERROR, "Image not packed");
return;
}
else if (ELEM(image->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
if (!ID_IS_EDITABLE(&image->id)) {
BKE_report(reports, RPT_ERROR, "Image is not editable");
return;
}
if (ELEM(image->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
BKE_report(reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
return;
}
else {
/* reports its own error on failure */
BKE_packedfile_unpack_image(bmain, reports, image, ePF_FileStatus(method));
}
/* reports its own error on failure */
BKE_packedfile_unpack_image(bmain, reports, image, ePF_FileStatus(method));
}
static void rna_Image_reload(Image *image, Main *bmain)

View File

@@ -27,11 +27,16 @@ static void rna_Sound_unpack(bSound *sound, Main *bmain, ReportList *reports, in
{
if (!sound->packedfile) {
BKE_report(reports, RPT_ERROR, "Sound not packed");
return;
}
else {
/* reports its own error on failure */
BKE_packedfile_unpack_sound(bmain, reports, sound, ePF_FileStatus(method));
if (!ID_IS_EDITABLE(&sound->id)) {
BKE_report(reports, RPT_ERROR, "Sound is not editable");
return;
}
/* reports its own error on failure */
BKE_packedfile_unpack_sound(bmain, reports, sound, ePF_FileStatus(method));
}
#else

View File

@@ -27,11 +27,16 @@ static void rna_VectorFont_unpack(VFont *vfont, Main *bmain, ReportList *reports
{
if (!vfont->packedfile) {
BKE_report(reports, RPT_ERROR, "Font not packed");
return;
}
else {
/* reports its own error on failure */
BKE_packedfile_unpack_vfont(bmain, reports, vfont, ePF_FileStatus(method));
if (!ID_IS_EDITABLE(&vfont->id)) {
BKE_report(reports, RPT_ERROR, "Font is not editable");
return;
}
/* reports its own error on failure */
BKE_packedfile_unpack_vfont(bmain, reports, vfont, ePF_FileStatus(method));
}
#else