From 3a34dcde680ca55ce054c9f5f216d73ff33edf68 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 11 May 2011 19:29:23 +0000 Subject: Code cleanup: remove readblenfile module, only contained some utility functions to read .blend files from runtimes, folded those into blenloader. --- source/blender/blenloader/BLO_runtime.h | 53 +++++++++ source/blender/blenloader/CMakeLists.txt | 3 +- source/blender/blenloader/SConscript | 2 +- source/blender/blenloader/intern/readblenentry.c | 2 - source/blender/blenloader/intern/readfile.c | 1 - source/blender/blenloader/intern/runtime.c | 145 +++++++++++++++++++++++ 6 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 source/blender/blenloader/BLO_runtime.h create mode 100644 source/blender/blenloader/intern/runtime.c (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/BLO_runtime.h b/source/blender/blenloader/BLO_runtime.h new file mode 100644 index 00000000000..920b14e92fa --- /dev/null +++ b/source/blender/blenloader/BLO_runtime.h @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +#ifndef BLO_RUNTIME_H +#define BLO_RUNTIME_H + +/** \file BLO_runtime.h + * \ingroup blenloader + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct BlendFileData; +struct ReportList; + +int BLO_is_a_runtime(char *file); +struct BlendFileData *BLO_read_runtime(char *file, struct ReportList *reports); + +#ifdef __cplusplus +} +#endif + +#endif /* BLO_RUNTIME_H */ + diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 4d8ac9bc4b6..888cf3148e3 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -29,7 +29,6 @@ set(INC ../blenlib ../blenkernel ../makesdna - ../readblenfile ../makesrna ../render/extern/include ../../../intern/guardedalloc @@ -39,10 +38,12 @@ set(INC set(SRC intern/readblenentry.c intern/readfile.c + intern/runtime.c intern/undofile.c intern/writefile.c BLO_readfile.h + BLO_runtime.h BLO_soundfile.h BLO_sys_types.h BLO_undofile.h diff --git a/source/blender/blenloader/SConscript b/source/blender/blenloader/SConscript index 695d17f0638..be9908d84e6 100644 --- a/source/blender/blenloader/SConscript +++ b/source/blender/blenloader/SConscript @@ -4,7 +4,7 @@ Import ('env') sources = env.Glob('intern/*.c') incs = '. #/intern/guardedalloc ../blenlib ../blenkernel' -incs += ' ../makesdna ../readblenfile ../editors/include' +incs += ' ../makesdna ../editors/include' incs += ' ../render/extern/include ../makesrna' incs += ' ' + env['BF_ZLIB_INC'] diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 39fab1929da..214f637ea6c 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -62,8 +62,6 @@ #include "readfile.h" -#include "BLO_readblenfile.h" - #include "BLO_sys_types.h" // needed for intptr_t #ifdef _WIN32 diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e1b13e0ee50..afa571769ab 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -137,7 +137,6 @@ //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo #include "BLO_readfile.h" #include "BLO_undofile.h" -#include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory #include "readfile.h" diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c new file mode 100644 index 00000000000..f5308b5ea5c --- /dev/null +++ b/source/blender/blenloader/intern/runtime.c @@ -0,0 +1,145 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** + * \file runtime.c + * \brief This file handles the loading of .blend files embedded in runtimes + * \ingroup blenloader + */ + +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include // read, open +#include "BLI_winstuff.h" +#else // ! WIN32 +#include // read +#endif + +#include "BLO_readfile.h" +#include "BLO_runtime.h" + +#include "BKE_blender.h" +#include "BKE_report.h" +#include "BKE_utildefines.h" + +#include "BLI_blenlib.h" + +/* Runtime reading */ + +static int handle_read_msb_int(int handle) +{ + unsigned char buf[4]; + + if(read(handle, buf, 4) != 4) + return -1; + + return (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + (buf[3]<<0); +} + +int BLO_is_a_runtime(char *path) +{ + int res= 0, fd= open(path, O_BINARY|O_RDONLY, 0); + int datastart; + char buf[8]; + + if(fd==-1) + goto cleanup; + + lseek(fd, -12, SEEK_END); + + datastart= handle_read_msb_int(fd); + + if(datastart==-1) + goto cleanup; + else if(read(fd, buf, 8)!=8) + goto cleanup; + else if(memcmp(buf, "BRUNTIME", 8)!=0) + goto cleanup; + else + res= 1; + +cleanup: + if(fd!=-1) + close(fd); + + return res; +} + +BlendFileData *BLO_read_runtime(char *path, ReportList *reports) +{ + BlendFileData *bfd= NULL; + size_t actualsize; + int fd, datastart; + char buf[8]; + + fd= open(path, O_BINARY|O_RDONLY, 0); + + if(fd==-1) { + BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", path, strerror(errno)); + goto cleanup; + } + + actualsize= BLI_filesize(fd); + + lseek(fd, -12, SEEK_END); + + datastart= handle_read_msb_int(fd); + + if(datastart==-1) { + BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (problem seeking)", path); + goto cleanup; + } + else if(read(fd, buf, 8)!=8) { + BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (truncated header)", path); + goto cleanup; + } + else if(memcmp(buf, "BRUNTIME", 8)!=0) { + BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (not a blend file)", path); + goto cleanup; + } + else { + //printf("starting to read runtime from %s at datastart %d\n", path, datastart); + lseek(fd, datastart, SEEK_SET); + bfd = blo_read_blendafterruntime(fd, path, actualsize-datastart, reports); + fd= -1; // file was closed in blo_read_blendafterruntime() + } + +cleanup: + if(fd!=-1) + close(fd); + + return bfd; +} + -- cgit v1.2.3