Example #1
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
	int ret_value = RET_ERROR;

	if (ima != NULL) {
		while (ima->packedfiles.last) {
			char localname[FILE_MAX], absname[FILE_MAX];
			char *newname;
			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);

			if (newname != NULL) {
				ImageView *iv;

				ret_value = ret_value == RET_ERROR ? RET_ERROR : RET_OK;
				freePackedFile(imapf->packedfile);
				imapf->packedfile = NULL;

				/* update the new corresponding view filepath */
				iv = BLI_findstring(&ima->views, imapf->filepath, offsetof(ImageView, filepath));
				if (iv) {
					BLI_strncpy(iv->filepath, newname, sizeof(imapf->filepath));
				}

				/* keep the new name in the image for non-pack specific reasons */
				if (how != PF_REMOVE) {
					BLI_strncpy(ima->name, newname, sizeof(imapf->filepath));
				}
				MEM_freeN(newname);
			}
			else {
				ret_value = RET_ERROR;
			}

			BLI_remlink(&ima->packedfiles, imapf);
			MEM_freeN(imapf);
		}
	}

	if (ret_value == RET_OK) {
		BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
	}

	return(ret_value);
}
void ExtractCine::unpackAllResourceFiles(const Common::Filename &filename) {
	Common::File f(filename, "rb");

	uint32 unpackedSize, packedSize;
	{
		char header[8];
		f.read_throwsOnError(header, 8);
		if (memcmp(header, "ABASECP", 7) == 0) {
			unpackedSize = f.readUint32BE();
			packedSize = f.readUint32BE();
		} else {
			unpackedSize = packedSize = f.pos(); /* Get file size */
			f.seek(0, SEEK_SET);
		}
	}

	assert(unpackedSize >= packedSize);
	uint8 *buf = (uint8 *)calloc(unpackedSize, 1);
	assert(buf);
	f.read_throwsOnError(buf, packedSize);

	if (packedSize != unpackedSize) {
		CineUnpacker cineUnpacker;
		if (!cineUnpacker.unpack(buf, packedSize, buf, unpackedSize)) {
			error("Failed to unpack 'vol.cnf' data");
		}
	}

	unsigned int resourceFilesCount = READ_BE_UINT16(&buf[0]);
	unsigned int entrySize = READ_BE_UINT16(&buf[2]);
	print("--- Unpacking all %d resource files from 'vol.cnf' (entrySize = %d):", resourceFilesCount, entrySize);
	char resourceFileName[9];
	for (unsigned int i = 0; i < resourceFilesCount; ++i) {
		memcpy(resourceFileName, &buf[4 + i * entrySize], 8);
		resourceFileName[8] = 0;

		Common::File fpResFile(resourceFileName, "rb");
		print("--- Unpacking resource file %s:", resourceFileName);
		unpackFile(fpResFile);
	}

	free(buf);
}
Example #3
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (vfont != NULL) {
		unpack_generate_paths(vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, vfont->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(vfont->packedfile);
			vfont->packedfile = NULL;
			BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
			MEM_freeN(newname);
		}
	}
	
	return (ret_value);
}
Example #4
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
    char localname[FILE_MAX], fi[FILE_MAXFILE];
    char *newname;
    int ret_value = RET_ERROR;

    if (vfont != NULL) {
        BLI_split_file_part(vfont->name, fi, sizeof(fi));
        BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
        newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
        if (newname != NULL) {
            ret_value = RET_OK;
            freePackedFile(vfont->packedfile);
            vfont->packedfile = NULL;
            BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
            MEM_freeN(newname);
        }
    }

    return (ret_value);
}
Example #5
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (ima != NULL && ima->name[0]) {
		unpack_generate_paths(ima->name, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, ima->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(ima->packedfile);
			ima->packedfile = NULL;
			BLI_strncpy(ima->name, newname, sizeof(ima->name));
			MEM_freeN(newname);
			BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
		}
	}
	
	return(ret_value);
}
Example #6
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
    char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
    char *newname;
    int ret_value = RET_ERROR;

    if (ima != NULL && ima->name[0]) {
        BLI_split_file_part(ima->name, fi, sizeof(fi));
        BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
        newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
        if (newname != NULL) {
            ret_value = RET_OK;
            freePackedFile(ima->packedfile);
            ima->packedfile = NULL;
            BLI_strncpy(ima->name, newname, sizeof(ima->name));
            MEM_freeN(newname);
            BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
        }
    }

    return(ret_value);
}
Example #7
0
int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;

	if (sound != NULL) {
		unpack_generate_paths(sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, sound->packedfile, how);
		if (newname != NULL) {
			BLI_strncpy(sound->name, newname, sizeof(sound->name));
			MEM_freeN(newname);

			freePackedFile(sound->packedfile);
			sound->packedfile = NULL;

			BKE_sound_load(bmain, sound);

			ret_value = RET_OK;
		}
	}
	
	return(ret_value);
}
Example #8
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
	char localname[FILE_MAXDIR + FILE_MAXFILE], fi[FILE_MAXFILE];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (vfont != NULL) {
		strcpy(localname, vfont->name);
		BLI_splitdirstring(localname, fi);
		
		sprintf(localname, "//fonts/%s", fi);
		
		newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(vfont->packedfile);
			vfont->packedfile = NULL;
			strcpy(vfont->name, newname);
			MEM_freeN(newname);
		}
	}
	
	return (ret_value);
}