Ejemplo n.º 1
0
char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how)
{
    char *newname = NULL;
    const char *temp = NULL;

    // char newabs[FILE_MAX];
    // char newlocal[FILE_MAX];

    if (pf != NULL) {
        switch (how) {
        case -1:
        case PF_KEEP:
            break;
        case PF_REMOVE:
            temp = abs_name;
            break;
        case PF_USE_LOCAL:
            /* if file exists use it */
            if (BLI_exists(local_name)) {
                temp = local_name;
                break;
            }
        /* else create it */
        /* fall-through */
        case PF_WRITE_LOCAL:
            if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
                temp = local_name;
            }
            break;
        case PF_USE_ORIGINAL:
            /* if file exists use it */
            if (BLI_exists(abs_name)) {
                BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name);
                temp = abs_name;
                break;
            }
        /* else create it */
        /* fall-through */
        case PF_WRITE_ORIGINAL:
            if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
                temp = abs_name;
            }
            break;
        default:
            printf("unpackFile: unknown return_value %d\n", how);
            break;
        }

        if (temp) {
            newname = BLI_strdup(temp);
        }
    }

    return newname;
}
Ejemplo n.º 2
0
char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFile *pf, int how)
{
	char *newname = NULL, *temp = NULL;
	
	// char newabs[FILE_MAXDIR + FILE_MAXFILE];
	// char newlocal[FILE_MAXDIR + FILE_MAXFILE];
	
	if (pf != NULL) {
		switch (how) {
			case -1:
			case PF_KEEP:
				break;
			case PF_REMOVE:
				temp= abs_name;
				break;
			case PF_USE_LOCAL:
				// if file exists use it
				if (BLI_exists(local_name)) {
					temp = local_name;
					break;
				}
				// else fall through and create it
			case PF_WRITE_LOCAL:
				if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
					temp = local_name;
				}
				break;
			case PF_USE_ORIGINAL:
				// if file exists use it
				if (BLI_exists(abs_name)) {
					temp = abs_name;
					break;
				}
				// else fall through and create it
			case PF_WRITE_ORIGINAL:
				if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
					temp = abs_name;
				}
				break;
			default:
				printf("unpackFile: unknown return_value %d\n", how);
				break;
		}
		
		if (temp) {
			newname = MEM_mallocN(strlen(temp) + 1, "unpack_file newname");
			strcpy(newname, temp);
		}
	}
	
	return (newname);
}
Ejemplo n.º 3
0
static void rna_Image_save(Image *image, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, G.main->name);

		if (image->packedfile) {
			if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
				BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", image->id.name + 2, image->name);
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
}
Ejemplo n.º 4
0
static void rna_Image_save(Image *image, ReportList *reports)
{
	ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
	if(ibuf) {
		char filename[FILE_MAXDIR + FILE_MAXFILE];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, G.main->name);

		if(image->packedfile) {
			if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
				BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could saved packed file to \"%s\"", image->id.name+2, image->name);
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type= IMA_TYPE_IMAGE;

			if(image->source==IMA_SRC_GENERATED)
				image->source= IMA_SRC_FILE;

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could not be saved to \"%s\"", image->id.name+2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
	}
}
Ejemplo n.º 5
0
static void rna_ImagePackedFile_save(ImagePackedFile *imapf, ReportList *reports)
{
	if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) {
		BKE_reportf(reports, RPT_ERROR, "Image could not save packed file to '%s'",
		            imapf->filepath);
	}
}
Ejemplo n.º 6
0
static void rna_ImagePackedFile_save(ImagePackedFile *imapf, Main *bmain, ReportList *reports)
{
	if (writePackedFile(reports, BKE_main_blendfile_path(bmain), imapf->filepath, imapf->packedfile, 0) != RET_OK) {
		BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'",
		            imapf->filepath);
	}
}
Ejemplo n.º 7
0
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		if (BKE_image_has_packedfile(image)) {
			ImagePackedFile *imapf;

			for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) {
				if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) {
					BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'",
					            image->id.name + 2, imapf->filepath);
				}
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
Ejemplo n.º 8
0
/**
 * unpackFile() 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
 * there was an error or when the user decides to cancel the operation.
 *
 * \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 *ref_file_name,
        const char *abs_name, const char *local_name, PackedFile *pf, int how)
{
	char *newname = NULL;
	const char *temp = NULL;

	if (pf != NULL) {
		switch (how) {
			case -1:
			case PF_KEEP:
				break;
			case PF_REMOVE:
				temp = abs_name;
				break;
			case PF_USE_LOCAL:
			{
				char temp_abs[FILE_MAX];

				BLI_strncpy(temp_abs, local_name, sizeof(temp_abs));
				BLI_path_abs(temp_abs, ref_file_name);

				/* if file exists use it */
				if (BLI_exists(temp_abs)) {
					temp = local_name;
					break;
				}
				/* else create it */
				ATTR_FALLTHROUGH;
			}
			case PF_WRITE_LOCAL:
				if (writePackedFile(reports, ref_file_name, local_name, pf, 1) == RET_OK) {
					temp = local_name;
				}
				break;
			case PF_USE_ORIGINAL:
			{
				char temp_abs[FILE_MAX];

				BLI_strncpy(temp_abs, abs_name, sizeof(temp_abs));
				BLI_path_abs(temp_abs, ref_file_name);

				/* if file exists use it */
				if (BLI_exists(temp_abs)) {
					BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name);
					temp = abs_name;
					break;
				}
				/* else create it */
				ATTR_FALLTHROUGH;
			}
			case PF_WRITE_ORIGINAL:
				if (writePackedFile(reports, ref_file_name, abs_name, pf, 1) == RET_OK) {
					temp = abs_name;
				}
				break;
			default:
				printf("unpackFile: unknown return_value %d\n", how);
				break;
		}

		if (temp) {
			newname = BLI_strdup(temp);
		}
	}

	return newname;
}