2003-05-24 16:53:40 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
*/
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2003-05-24 16:53:40 +00:00
|
|
|
/**
|
2011-05-11 19:29:23 +00:00
|
|
|
* \file runtime.c
|
|
|
|
* \brief This file handles the loading of .blend files embedded in runtimes
|
|
|
|
* \ingroup blenloader
|
2003-05-24 16:53:40 +00:00
|
|
|
*/
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2010-07-04 23:26:55 +00:00
|
|
|
#include <errno.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-05-27 19:40:36 +00:00
|
|
|
# include <io.h> // read, open
|
2012-04-15 07:54:07 +00:00
|
|
|
# include "BLI_winstuff.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#else // ! WIN32
|
2012-05-27 19:40:36 +00:00
|
|
|
# include <unistd.h> // read
|
2002-10-12 11:37:38 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-10 16:37:48 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2013-04-05 17:56:54 +00:00
|
|
|
#include "BLO_readfile.h"
|
|
|
|
#include "BLO_runtime.h"
|
|
|
|
|
2008-12-19 00:50:21 +00:00
|
|
|
#include "BKE_report.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
This commit removes the glue from Blender, and with it
the directories decrypt, deflate, encrypt, inflate, readstreamglue,
sign, writeblenfile and writestreamglue.
Sirdude was so kind to modify the makefiles, so SCons and
Make are ready to build with the new Blender.
Visual Studio workspaces, solutions and projectfiles still need
to be updated (I'll do the .vcprojs and .sln myself after this commit).
Runtimes created with the Blender Publisher are not anymore
recognised - if you want these available, you'll have to convert
them first to .blends with the Publisher.
2004-04-16 15:55:16 +00:00
|
|
|
/* Runtime reading */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-05-11 19:29:23 +00:00
|
|
|
static int handle_read_msb_int(int handle)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned char buf[4];
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (read(handle, buf, 4) != 4)
|
2002-10-12 11:37:38 +00:00
|
|
|
return -1;
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 23:10:54 +00:00
|
|
|
int BLO_is_a_runtime(const char *path)
|
2011-05-11 19:29:23 +00:00
|
|
|
{
|
2012-05-27 19:40:36 +00:00
|
|
|
int res = 0, fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
int datastart;
|
|
|
|
char buf[8];
|
|
|
|
|
2014-04-22 16:40:17 +10:00
|
|
|
if (fd == -1)
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
lseek(fd, -12, SEEK_END);
|
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
datastart = handle_read_msb_int(fd);
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
if (datastart == -1)
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
2012-05-27 19:40:36 +00:00
|
|
|
else if (read(fd, buf, 8) != 8)
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
2012-05-27 19:40:36 +00:00
|
|
|
else if (memcmp(buf, "BRUNTIME", 8) != 0)
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
else
|
2012-05-27 19:40:36 +00:00
|
|
|
res = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
cleanup:
|
2012-05-27 19:40:36 +00:00
|
|
|
if (fd != -1)
|
2002-10-12 11:37:38 +00:00
|
|
|
close(fd);
|
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
return res;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 23:10:54 +00:00
|
|
|
BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-27 19:40:36 +00:00
|
|
|
BlendFileData *bfd = NULL;
|
2010-09-15 06:43:36 +00:00
|
|
|
size_t actualsize;
|
|
|
|
int fd, datastart;
|
2002-10-12 11:37:38 +00:00
|
|
|
char buf[8];
|
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2014-04-22 16:40:17 +10:00
|
|
|
if (fd == -1) {
|
2012-10-19 16:43:10 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
This commit removes the glue from Blender, and with it
the directories decrypt, deflate, encrypt, inflate, readstreamglue,
sign, writeblenfile and writestreamglue.
Sirdude was so kind to modify the makefiles, so SCons and
Make are ready to build with the new Blender.
Visual Studio workspaces, solutions and projectfiles still need
to be updated (I'll do the .vcprojs and .sln myself after this commit).
Runtimes created with the Blender Publisher are not anymore
recognised - if you want these available, you'll have to convert
them first to .blends with the Publisher.
2004-04-16 15:55:16 +00:00
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
actualsize = BLI_file_descriptor_size(fd);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
lseek(fd, -12, SEEK_END);
|
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
datastart = handle_read_msb_int(fd);
|
2011-05-11 19:29:23 +00:00
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
if (datastart == -1) {
|
2012-10-19 16:43:10 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (problem seeking)", path);
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
2011-05-11 19:29:23 +00:00
|
|
|
}
|
2012-05-27 19:40:36 +00:00
|
|
|
else if (read(fd, buf, 8) != 8) {
|
2012-10-19 16:43:10 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (truncated header)", path);
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
2011-05-11 19:29:23 +00:00
|
|
|
}
|
2012-05-27 19:40:36 +00:00
|
|
|
else if (memcmp(buf, "BRUNTIME", 8) != 0) {
|
2012-10-19 16:43:10 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (not a blend file)", path);
|
2002-10-12 11:37:38 +00:00
|
|
|
goto cleanup;
|
2011-05-11 19:29:23 +00:00
|
|
|
}
|
2012-10-21 05:46:41 +00:00
|
|
|
else {
|
2004-04-24 06:29:51 +00:00
|
|
|
//printf("starting to read runtime from %s at datastart %d\n", path, datastart);
|
2002-10-12 11:37:38 +00:00
|
|
|
lseek(fd, datastart, SEEK_SET);
|
2012-05-27 19:40:36 +00:00
|
|
|
bfd = blo_read_blendafterruntime(fd, path, actualsize - datastart, reports);
|
|
|
|
fd = -1; // file was closed in blo_read_blendafterruntime()
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2012-05-27 19:40:36 +00:00
|
|
|
if (fd != -1)
|
2002-10-12 11:37:38 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|