2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
31 * \brief This file handles the loading of .blend files embedded in runtimes
42 # include <io.h> // read, open
43 # include "BLI_winstuff.h"
45 # include <unistd.h> // read
48 #include "BLO_readfile.h"
49 #include "BLO_runtime.h"
51 #include "BLI_blenlib.h"
52 #include "BLI_utildefines.h"
54 #include "BKE_blender.h"
55 #include "BKE_report.h"
59 static int handle_read_msb_int(int handle)
63 if (read(handle, buf, 4) != 4)
66 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0);
69 int BLO_is_a_runtime(const char *path)
71 int res = 0, fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
78 lseek(fd, -12, SEEK_END);
80 datastart = handle_read_msb_int(fd);
84 else if (read(fd, buf, 8) != 8)
86 else if (memcmp(buf, "BRUNTIME", 8) != 0)
98 BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
100 BlendFileData *bfd = NULL;
105 fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
108 BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
112 actualsize = BLI_file_descriptor_size(fd);
114 lseek(fd, -12, SEEK_END);
116 datastart = handle_read_msb_int(fd);
118 if (datastart == -1) {
119 BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (problem seeking)", path);
122 else if (read(fd, buf, 8) != 8) {
123 BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (truncated header)", path);
126 else if (memcmp(buf, "BRUNTIME", 8) != 0) {
127 BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (not a blend file)", path);
131 //printf("starting to read runtime from %s at datastart %d\n", path, datastart);
132 lseek(fd, datastart, SEEK_SET);
133 bfd = blo_read_blendafterruntime(fd, path, actualsize - datastart, reports);
134 fd = -1; // file was closed in blo_read_blendafterruntime()