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 *****
27 #ifndef __BLO_READFILE_H__
28 #define __BLO_READFILE_H__
30 /** \file BLO_readfile.h
32 * \brief external readfile function prototypes.
52 typedef struct BlendHandle BlendHandle;
54 typedef enum BlenFileType {
55 BLENFILETYPE_BLEND= 1,
57 BLENFILETYPE_RUNTIME= 3
60 typedef struct BlendFileData {
68 char filename[1024]; /* 1024 = FILE_MAX */
70 struct bScreen* curscreen;
71 struct Scene* curscene;
77 * Open a blender file from a pathname. The function
78 * returns NULL and sets a report in the list if
79 * it cannot open the file.
81 * \param filepath The path of the file to open.
82 * \param reports If the return value is NULL, errors
83 * indicating the cause of the failure.
84 * \return The data of the file.
86 BlendFileData* BLO_read_from_file(const char *filepath, struct ReportList *reports);
89 * Open a blender file from memory. The function
90 * returns NULL and sets a report in the list if
91 * it cannot open the file.
93 * \param mem The file data.
94 * \param memsize The length of \a mem.
95 * \param reports If the return value is NULL, errors
96 * indicating the cause of the failure.
97 * \return The data of the file.
99 BlendFileData* BLO_read_from_memory(void *mem, int memsize, struct ReportList *reports);
102 * oldmain is old main, from which we will keep libraries, images, ..
103 * file name is current file, only for retrieving library data */
105 BlendFileData *BLO_read_from_memfile(struct Main *oldmain, const char *filename, struct MemFile *memfile, struct ReportList *reports);
108 * Free's a BlendFileData structure and _all_ the
109 * data associated with it (the userdef data, and
110 * the main libblock data).
112 * \param bfd The structure to free.
115 BLO_blendfiledata_free(
119 * Open a blendhandle from a file path.
121 * \param file The file path to open.
122 * \param reports Report errors in opening the file (can be NULL).
123 * \return A handle on success, or NULL on failure.
126 BLO_blendhandle_from_file(
128 struct ReportList *reports);
131 * Open a blendhandle from memory.
133 * \param mem The data to load from.
134 * \param memsize The size of the data.
135 * \return A handle on success, or NULL on failure.
139 BLO_blendhandle_from_memory(
144 * Gets the names of all the datablocks in a file
145 * of a certain type (ie. All the scene names in
148 * \param bh The blendhandle to access.
149 * \param ofblocktype The type of names to get.
150 * \param tot_names The length of the returned list.
151 * \return A BLI_linklist of strings. The string links
152 * should be freed with malloc.
155 BLO_blendhandle_get_datablock_names(
161 * Gets the previews of all the datablocks in a file
162 * of a certain type (ie. All the scene names in
165 * \param bh The blendhandle to access.
166 * \param ofblocktype The type of names to get.
167 * \param tot_prev The length of the returned list.
168 * \return A BLI_linklist of PreviewImage. The PreviewImage links
169 * should be freed with malloc.
172 BLO_blendhandle_get_previews(
178 * Gets the names of all the datablock groups in a
179 * file. (ie. file contains Scene, Mesh, and Lamp
182 * \param bh The blendhandle to access.
183 * \return A BLI_linklist of strings. The string links
184 * should be freed with malloc.
187 BLO_blendhandle_get_linkable_groups(
191 * Close and free a blendhandle. The handle
192 * becomes invalid after this call.
194 * \param bh The handle to close.
197 BLO_blendhandle_close(
204 int BLO_has_bfile_extension(const char *str);
206 /* return ok when a blenderfile, in dir is the filename,
207 * in group the type of libdata
209 int BLO_is_a_library(const char *path, char *dir, char *group);
213 * Initialize the BlendHandle for appending or linking library data.
215 * \param mainvar The current main database eg G.main or CTX_data_main(C).
216 * \param bh A blender file handle as returned by BLO_blendhandle_from_file or BLO_blendhandle_from_memory.
217 * \param filepath Used for relative linking, copied to the lib->name
218 * \return the library Main, to be passed to BLO_library_append_named_part as mainl.
220 struct Main* BLO_library_append_begin(struct Main *mainvar, BlendHandle** bh, const char *filepath);
224 * Link/Append a named datablock from an external blend file.
226 * \param mainl The main database to link from (not the active one).
227 * \param bh The blender file handle.
228 * \param idname The name of the datablock (without the 2 char ID prefix)
229 * \param idcode The kind of datablock to link.
230 * \return the appended ID when found.
232 struct ID *BLO_library_append_named_part(struct Main *mainl, BlendHandle** bh, const char *idname, const int idcode);
235 * Link/Append a named datablock from an external blend file.
236 * optionally instance the object in the scene when the flags are set.
238 * \param C The context, when NULL instancing object in the scene isn't done.
239 * \param mainl The main database to link from (not the active one).
240 * \param bh The blender file handle.
241 * \param idname The name of the datablock (without the 2 char ID prefix)
242 * \param idcode The kind of datablock to link.
243 * \param flag Options for linking, used for instancing.
244 * \return the appended ID when found.
246 struct ID *BLO_library_append_named_part_ex(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, const int idcode, const short flag);
248 void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag);
250 void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);
252 BlendFileData* blo_read_blendafterruntime(int file, const char *name, int actualsize, struct ReportList *reports);