This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenkernel/intern/packedFile.c

668 lines
15 KiB
C
Raw Normal View History

/*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*/
2011-02-27 20:40:57 +00:00
/** \file blender/blenkernel/intern/packedFile.c
* \ingroup bke
*/
2002-10-12 11:37:38 +00:00
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
2002-10-12 11:37:38 +00:00
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_image_types.h"
#include "DNA_ID.h"
#include "DNA_packedFile_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_sound_types.h"
#include "DNA_vfont_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
2002-10-12 11:37:38 +00:00
#include "BKE_font.h"
2002-10-12 11:37:38 +00:00
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
2002-10-12 11:37:38 +00:00
#include "BKE_packedFile.h"
#include "BKE_report.h"
#include "BKE_sound.h"
2002-10-12 11:37:38 +00:00
#ifdef _WIN32
#define open _open
#define close _close
#define read _read
#define write _write
#endif
int seekPackedFile(PackedFile *pf, int offset, int whence)
2002-10-12 11:37:38 +00:00
{
int oldseek = -1, seek = 0;
if (pf) {
oldseek = pf->seek;
switch (whence) {
2012-05-06 17:22:54 +00:00
case SEEK_CUR:
seek = oldseek + offset;
break;
case SEEK_END:
seek = pf->size + offset;
break;
case SEEK_SET:
seek = offset;
break;
default:
oldseek = -1;
break;
2002-10-12 11:37:38 +00:00
}
if (seek < 0) {
seek = 0;
}
else if (seek > pf->size) {
2002-10-12 11:37:38 +00:00
seek = pf->size;
}
pf->seek = seek;
}
return(oldseek);
}
void rewindPackedFile(PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
seekPackedFile(pf, 0, SEEK_SET);
}
int readPackedFile(PackedFile *pf, void *data, int size)
2002-10-12 11:37:38 +00:00
{
if ((pf != NULL) && (size >= 0) && (data != NULL)) {
if (size + pf->seek > pf->size) {
size = pf->size - pf->seek;
}
if (size > 0) {
memcpy(data, ((char *) pf->data) + pf->seek, size);
}
else {
2002-10-12 11:37:38 +00:00
size = 0;
}
pf->seek += size;
}
else {
2002-10-12 11:37:38 +00:00
size = -1;
}
return(size);
}
int countPackedFiles(Main *bmain)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vf;
bSound *sound;
int count = 0;
2002-10-12 11:37:38 +00:00
2012-07-07 22:51:57 +00:00
/* let's check if there are packed files... */
2012-05-06 17:22:54 +00:00
for (ima = bmain->image.first; ima; ima = ima->id.next)
if (ima->packedfile)
2002-10-12 11:37:38 +00:00
count++;
2012-05-06 17:22:54 +00:00
for (vf = bmain->vfont.first; vf; vf = vf->id.next)
if (vf->packedfile)
2002-10-12 11:37:38 +00:00
count++;
2012-05-06 17:22:54 +00:00
for (sound = bmain->sound.first; sound; sound = sound->id.next)
if (sound->packedfile)
count++;
2002-10-12 11:37:38 +00:00
return count;
2002-10-12 11:37:38 +00:00
}
void freePackedFile(PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
if (pf) {
2002-10-12 11:37:38 +00:00
MEM_freeN(pf->data);
MEM_freeN(pf);
}
else
printf("freePackedFile: Trying to free a NULL pointer\n");
2002-10-12 11:37:38 +00:00
}
PackedFile *dupPackedFile(const PackedFile *pf_src)
{
PackedFile *pf_dst;
pf_dst = MEM_dupallocN(pf_src);
pf_dst->data = MEM_dupallocN(pf_src->data);
return pf_dst;
}
PackedFile *newPackedFileMemory(void *mem, int memlen)
2002-10-12 11:37:38 +00:00
{
PackedFile *pf = MEM_callocN(sizeof(*pf), "PackedFile");
2002-10-12 11:37:38 +00:00
pf->data = mem;
pf->size = memlen;
return pf;
}
PackedFile *newPackedFile(ReportList *reports, const char *filename, const char *basepath)
2002-10-12 11:37:38 +00:00
{
PackedFile *pf = NULL;
2002-10-12 11:37:38 +00:00
int file, filelen;
char name[FILE_MAX];
void *data;
2002-10-12 11:37:38 +00:00
/* render result has no filename and can be ignored
* any other files with no name can be ignored too */
2012-05-06 17:22:54 +00:00
if (filename[0] == '\0')
return NULL;
//XXX waitcursor(1);
2002-10-12 11:37:38 +00:00
2012-07-07 22:51:57 +00:00
/* convert relative filenames to absolute filenames */
BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, basepath);
2012-07-07 22:51:57 +00:00
/* open the file
* and create a PackedFile structure */
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
if (file < 0) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", name);
}
else {
filelen = BLI_file_descriptor_size(file);
2002-10-12 11:37:38 +00:00
if (filelen == 0) {
2012-07-07 22:51:57 +00:00
/* MEM_mallocN complains about MEM_mallocN(0, "bla");
* we don't care.... */
2002-10-12 11:37:38 +00:00
data = MEM_mallocN(1, "packFile");
}
else {
2002-10-12 11:37:38 +00:00
data = MEM_mallocN(filelen, "packFile");
}
if (read(file, data, filelen) == filelen) {
pf = newPackedFileMemory(data, filelen);
}
close(file);
}
//XXX waitcursor(0);
2002-10-12 11:37:38 +00:00
return (pf);
}
/* no libraries for now */
void packAll(Main *bmain, ReportList *reports)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vfont;
bSound *sound;
int tot = 0;
2012-05-06 17:22:54 +00:00
for (ima = bmain->image.first; ima; ima = ima->id.next) {
if (ima->packedfile == NULL && ima->id.lib == NULL) {
if (ima->source == IMA_SRC_FILE) {
ima->packedfile = newPackedFile(reports, ima->name, ID_BLEND_PATH(bmain, &ima->id));
tot ++;
}
else if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported",
ima->id.name + 2);
}
}
}
2002-10-12 11:37:38 +00:00
for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == FALSE) {
vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
tot ++;
}
}
2002-10-12 11:37:38 +00:00
for (sound = bmain->sound.first; sound; sound = sound->id.next) {
if (sound->packedfile == NULL && sound->id.lib == NULL) {
sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
tot++;
}
}
if (tot == 0)
BKE_report(reports, RPT_INFO, "No new files have been packed");
else
BKE_reportf(reports, RPT_INFO, "Packed %d files", tot);
2002-10-12 11:37:38 +00:00
}
#if 0
2002-10-12 11:37:38 +00:00
// attempt to create a function that generates an unique filename
// this will work when all funtions in fileops.c understand relative filenames...
static char *find_new_name(char *name)
2002-10-12 11:37:38 +00:00
{
char tempname[FILE_MAX];
char *newname;
size_t len;
2002-10-12 11:37:38 +00:00
if (fop_exists(name)) {
for (number = 1; number <= 999; number++) {
BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", name, number);
2012-05-06 17:22:54 +00:00
if (!fop_exists(tempname)) {
2002-10-12 11:37:38 +00:00
break;
}
}
}
2012-05-06 17:22:54 +00:00
len = strlen(tempname) + 1;
newname = MEM_mallocN(len, "find_new_name");
memcpy(newname, tempname, len * sizeof(char));
return newname;
2002-10-12 11:37:38 +00:00
}
#endif
2002-10-12 11:37:38 +00:00
int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, int guimode)
2002-10-12 11:37:38 +00:00
{
int file, number, remove_tmp = FALSE;
int ret_value = RET_OK;
char name[FILE_MAX];
char tempname[FILE_MAX];
2012-05-06 17:22:54 +00:00
/* void *data; */
2002-10-12 11:37:38 +00:00
if (guimode) {} //XXX waitcursor(1);
2002-10-12 11:37:38 +00:00
BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, G.main->name);
2002-10-12 11:37:38 +00:00
if (BLI_exists(name)) {
for (number = 1; number <= 999; number++) {
BLI_snprintf(tempname, sizeof(tempname), "%s.%03d_", name, number);
2012-05-06 17:22:54 +00:00
if (!BLI_exists(tempname)) {
if (BLI_copy(name, tempname) == RET_OK) {
2002-10-12 11:37:38 +00:00
remove_tmp = TRUE;
}
break;
}
}
}
2012-07-07 22:51:57 +00:00
/* make sure the path to the file exists... */
Giant commit! A full detailed description of this will be done later... is several days of work. Here's a summary: Render: - Full cleanup of render code, removing *all* globals and bad level calls all over blender. Render module is now not called abusive anymore - API-fied calls to rendering - Full recode of internal render pipeline. Is now rendering tiles by default, prepared for much smarter 'bucket' render later. - Each thread now can render a full part - Renders were tested with 4 threads, goes fine, apart from some lookup tables in softshadow and AO still - Rendering is prepared to do multiple layers and passes - No single 32 bits trick in render code anymore, all 100% floats now. Writing images/movies - moved writing images to blender kernel (bye bye 'schrijfplaatje'!) - made a new Movie handle system, also in kernel. This will enable much easier use of movies in Blender PreviewRender: - Using new render API, previewrender (in buttons) now uses regular render code to generate images. - new datafile 'preview.blend.c' has the preview scenes in it - previews get rendered in exact displayed size (1 pixel = 1 pixel) 3D Preview render - new; press Pkey in 3d window, for a panel that continuously renders (pkey is for games, i know... but we dont do that in orange now!) - this render works nearly identical to buttons-preview render, so it stops rendering on any event (mouse, keyboard, etc) - on moving/scaling the panel, the render code doesn't recreate all geometry - same for shifting/panning view - all other operations (now) regenerate the full render database still. - this is WIP... but big fun, especially for simple scenes! Compositor - Using same node system as now in use for shaders, you can composit images - works pretty straightforward... needs much more options/tools and integration with rendering still - is not threaded yet, nor is so smart to only recalculate changes... will be done soon! - the "Render Result" node will get all layers/passes as output sockets - The "Output" node renders to a builtin image, which you can view in the Image window. (yes, output nodes to render-result, and to files, is on the list!) The Bad News - "Unified Render" is removed. It might come back in some stage, but this system should be built from scratch. I can't really understand this code... I expect it is not much needed, especially with advanced layer/passes control - Panorama render, Field render, Motion blur, is not coded yet... (I had to recode every single feature in render, so...!) - Lens Flare is also not back... needs total revision, might become composit effect though (using zbuffer for visibility) - Part render is gone! (well, thats obvious, its default now). - The render window is only restored with limited functionality... I am going to check first the option to render to a Image window, so Blender can become a true single-window application. :) For example, the 'Spare render buffer' (jkey) doesnt work. - Render with border, now default creates a smaller image - No zbuffers are written yet... on the todo! - Scons files and MSVC will need work to get compiling again OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
BLI_make_existing_file(name);
2002-10-12 11:37:38 +00:00
file = BLI_open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file < 0) {
BKE_reportf(reports, RPT_ERROR, "Error creating file '%s'", name);
ret_value = RET_ERROR;
}
else {
2002-10-12 11:37:38 +00:00
if (write(file, pf->data, pf->size) != pf->size) {
BKE_reportf(reports, RPT_ERROR, "Error writing file '%s'", name);
2002-10-12 11:37:38 +00:00
ret_value = RET_ERROR;
}
else {
BKE_reportf(reports, RPT_INFO, "Saved packed file to: %s", name);
}
2002-10-12 11:37:38 +00:00
close(file);
}
2002-10-12 11:37:38 +00:00
if (remove_tmp) {
if (ret_value == RET_ERROR) {
if (BLI_rename(tempname, name) != 0) {
BKE_reportf(reports, RPT_ERROR, "Error restoring temp file (check files '%s' '%s')", tempname, name);
2002-10-12 11:37:38 +00:00
}
}
else {
if (BLI_delete(tempname, false, false) != 0) {
BKE_reportf(reports, RPT_ERROR, "Error deleting '%s' (ignored)", tempname);
2002-10-12 11:37:38 +00:00
}
}
}
if (guimode) {} //XXX waitcursor(0);
2002-10-12 11:37:38 +00:00
return (ret_value);
}
/*
* This function compares a packed file to a 'real' file.
* It returns an integer indicating if:
*
* PF_EQUAL - the packed file and original file are identical
* PF_DIFFERENT - the packed file and original file differ
* PF_NOFILE - the original file doens't exist
*/
2002-10-12 11:37:38 +00:00
int checkPackedFile(const char *filename, PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
struct stat st;
int ret_val, i, len, file;
char buf[4096];
char name[FILE_MAX];
2002-10-12 11:37:38 +00:00
BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, G.main->name);
2002-10-12 11:37:38 +00:00
if (BLI_stat(name, &st)) {
2002-10-12 11:37:38 +00:00
ret_val = PF_NOFILE;
}
else if (st.st_size != pf->size) {
2002-10-12 11:37:38 +00:00
ret_val = PF_DIFFERS;
}
else {
2012-07-07 22:51:57 +00:00
/* we'll have to compare the two... */
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
2002-10-12 11:37:38 +00:00
if (file < 0) {
ret_val = PF_NOFILE;
}
else {
2002-10-12 11:37:38 +00:00
ret_val = PF_EQUAL;
2012-07-07 22:51:57 +00:00
2002-10-12 11:37:38 +00:00
for (i = 0; i < pf->size; i += sizeof(buf)) {
len = pf->size - i;
if (len > sizeof(buf)) {
len = sizeof(buf);
}
2012-07-07 22:51:57 +00:00
2002-10-12 11:37:38 +00:00
if (read(file, buf, len) != len) {
2012-07-07 22:51:57 +00:00
/* read error ... */
2002-10-12 11:37:38 +00:00
ret_val = PF_DIFFERS;
break;
}
else {
2002-10-12 11:37:38 +00:00
if (memcmp(buf, ((char *)pf->data) + i, len)) {
ret_val = PF_DIFFERS;
break;
}
}
}
close(file);
2002-10-12 11:37:38 +00:00
}
}
return(ret_val);
}
/* 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.
*/
2002-10-12 11:37:38 +00:00
char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how)
2002-10-12 11:37:38 +00:00
{
char *newname = NULL;
const char *temp = NULL;
2002-10-12 11:37:38 +00:00
// char newabs[FILE_MAX];
// char newlocal[FILE_MAX];
2002-10-12 11:37:38 +00:00
if (pf != NULL) {
switch (how) {
case -1:
case PF_KEEP:
break;
case PF_REMOVE:
2012-05-06 17:22:54 +00:00
temp = abs_name;
break;
2002-10-12 11:37:38 +00:00
case PF_USE_LOCAL:
2012-07-07 22:51:57 +00:00
/* if file exists use it */
2002-10-12 11:37:38 +00:00
if (BLI_exists(local_name)) {
temp = local_name;
break;
}
/* else create it */
/* fall-through */
2002-10-12 11:37:38 +00:00
case PF_WRITE_LOCAL:
if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
2002-10-12 11:37:38 +00:00
temp = local_name;
}
break;
case PF_USE_ORIGINAL:
2012-07-07 22:51:57 +00:00
/* if file exists use it */
2002-10-12 11:37:38 +00:00
if (BLI_exists(abs_name)) {
BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name);
2002-10-12 11:37:38 +00:00
temp = abs_name;
break;
}
/* else create it */
/* fall-through */
2002-10-12 11:37:38 +00:00
case PF_WRITE_ORIGINAL:
if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
2002-10-12 11:37:38 +00:00
temp = abs_name;
}
break;
default:
printf("unpackFile: unknown return_value %d\n", how);
break;
}
if (temp) {
2012-05-06 17:22:54 +00:00
newname = BLI_strdup(temp);
2002-10-12 11:37:38 +00:00
}
}
return newname;
2002-10-12 11:37:38 +00:00
}
int unpackVFont(ReportList *reports, VFont *vfont, int how)
2002-10-12 11:37:38 +00:00
{
char localname[FILE_MAX], fi[FILE_MAXFILE];
char *newname;
2002-10-12 11:37:38 +00:00
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);
2002-10-12 11:37:38 +00:00
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(vfont->packedfile);
vfont->packedfile = NULL;
BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
2002-10-12 11:37:38 +00:00
MEM_freeN(newname);
}
}
return (ret_value);
}
int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
2002-10-12 11:37:38 +00:00
{
char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
char *newname;
2002-10-12 11:37:38 +00:00
int ret_value = RET_ERROR;
if (sound != NULL) {
BLI_split_file_part(sound->name, fi, sizeof(fi));
BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);
newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
2002-10-12 11:37:38 +00:00
if (newname != NULL) {
BLI_strncpy(sound->name, newname, sizeof(sound->name));
2002-10-12 11:37:38 +00:00
MEM_freeN(newname);
freePackedFile(sound->packedfile);
sound->packedfile = NULL;
sound_load(bmain, sound);
2002-10-12 11:37:38 +00:00
ret_value = RET_OK;
}
}
return(ret_value);
}
int unpackImage(ReportList *reports, Image *ima, int how)
2002-10-12 11:37:38 +00:00
{
char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
char *newname;
2002-10-12 11:37:38 +00:00
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);
2002-10-12 11:37:38 +00:00
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(ima->packedfile);
ima->packedfile = NULL;
BLI_strncpy(ima->name, newname, sizeof(ima->name));
2002-10-12 11:37:38 +00:00
MEM_freeN(newname);
BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
2002-10-12 11:37:38 +00:00
}
}
return(ret_value);
}
int unpackLibraries(Main *bmain, ReportList *reports)
{
Library *lib;
char *newname;
int ret_value = RET_ERROR;
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);
if (newname != NULL) {
ret_value = RET_OK;
printf("Unpacked .blend library: %s\n", newname);
freePackedFile(lib->packedfile);
lib->packedfile = NULL;
MEM_freeN(newname);
}
}
}
return(ret_value);
}
void packLibraries(Main *bmain, ReportList *reports)
{
Library *lib;
/* test for relativenss */
for (lib = bmain->library.first; lib; lib = lib->id.next)
if (!BLI_path_is_rel(lib->name))
break;
if (lib) {
BKE_reportf(reports, RPT_ERROR, "Cannot pack absolute file: '%s'", lib->name);
return;
}
for (lib = bmain->library.first; lib; lib = lib->id.next)
if (lib->packedfile == NULL)
lib->packedfile = newPackedFile(reports, lib->name, bmain->name);
}
void unpackAll(Main *bmain, ReportList *reports, int how)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vf;
bSound *sound;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
for (ima = bmain->image.first; ima; ima = ima->id.next)
if (ima->packedfile)
unpackImage(reports, ima, how);
2012-05-06 17:22:54 +00:00
for (vf = bmain->vfont.first; vf; vf = vf->id.next)
if (vf->packedfile)
unpackVFont(reports, vf, how);
2012-05-06 17:22:54 +00:00
for (sound = bmain->sound.first; sound; sound = sound->id.next)
if (sound->packedfile)
unpackSound(bmain, reports, sound, how);
2002-10-12 11:37:38 +00:00
}
/* ID should be not NULL, return 1 if there's a packed file */
2013-03-09 05:35:49 +00:00
bool BKE_pack_check(ID *id)
{
if (GS(id->name) == ID_IM) {
Image *ima = (Image *)id;
return ima->packedfile != NULL;
}
if (GS(id->name) == ID_VF) {
VFont *vf = (VFont *)id;
return vf->packedfile != NULL;
}
if (GS(id->name) == ID_SO) {
bSound *snd = (bSound *)id;
return snd->packedfile != NULL;
}
if (GS(id->name) == ID_LI) {
Library *li = (Library *)id;
return li->packedfile != NULL;
}
2013-03-09 05:35:49 +00:00
return false;
}
/* ID should be not NULL */
void BKE_unpack_id(Main *bmain, ID *id, ReportList *reports, int how)
{
if (GS(id->name) == ID_IM) {
Image *ima = (Image *)id;
if (ima->packedfile)
unpackImage(reports, ima, how);
}
if (GS(id->name) == ID_VF) {
VFont *vf = (VFont *)id;
if (vf->packedfile)
unpackVFont(reports, vf, how);
}
if (GS(id->name) == ID_SO) {
bSound *snd = (bSound *)id;
if (snd->packedfile)
unpackSound(bmain, reports, snd, how);
}
if (GS(id->name) == ID_LI) {
Library *li = (Library *)id;
BKE_reportf(reports, RPT_ERROR, "Cannot unpack individual Library file, '%s'", li->name);
}
}