2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17 * All rights reserved.
19 #ifndef __BLO_READFILE_H__
20 #define __BLO_READFILE_H__
22 #include "BLI_sys_types.h"
26 * \brief external readfile function prototypes.
34 struct BlendThumbnail;
47 struct wmWindowManager;
49 typedef struct BlendHandle BlendHandle;
51 typedef enum eBlenFileType {
52 BLENFILETYPE_BLEND = 1,
53 /* BLENFILETYPE_PUB = 2, */ /* UNUSED */
54 /* BLENFILETYPE_RUNTIME = 3, */ /* UNUSED */
57 typedef struct BlendFileData {
63 char filename[1024]; /* 1024 = FILE_MAX */
65 struct bScreen *curscreen; /* TODO think this isn't needed anymore? */
66 struct Scene *curscene;
67 struct ViewLayer *cur_view_layer; /* layer to activate in workspaces when reading without UI */
72 typedef struct WorkspaceConfigFileData {
73 struct Main *main; /* has to be freed when done reading file data */
75 struct ListBase workspaces;
76 } WorkspaceConfigFileData;
78 struct BlendFileReadParams {
79 uint skip_flags : 3; /* eBLOReadSkip */
82 /** Whether we are reading the memfile for an undo (< 0) or a redo (> 0). */
83 int undo_direction : 2;
86 /* skip reading some data-block types (may want to skip screen data too). */
87 typedef enum eBLOReadSkip {
88 BLO_READ_SKIP_NONE = 0,
89 BLO_READ_SKIP_USERDEF = (1 << 0),
90 BLO_READ_SKIP_DATA = (1 << 1),
91 /** Do not attempt to re-use IDs from old bmain for unchanged ones in case of undo. */
92 BLO_READ_SKIP_UNDO_OLD_MAIN = (1 << 2),
94 #define BLO_READ_SKIP_ALL (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA)
96 BlendFileData *BLO_read_from_file(const char *filepath,
97 eBLOReadSkip skip_flags,
98 struct ReportList *reports);
99 BlendFileData *BLO_read_from_memory(const void *mem,
101 eBLOReadSkip skip_flags,
102 struct ReportList *reports);
103 BlendFileData *BLO_read_from_memfile(struct Main *oldmain,
104 const char *filename,
105 struct MemFile *memfile,
106 const struct BlendFileReadParams *params,
107 struct ReportList *reports);
109 void BLO_blendfiledata_free(BlendFileData *bfd);
111 BlendHandle *BLO_blendhandle_from_file(const char *filepath, struct ReportList *reports);
112 BlendHandle *BLO_blendhandle_from_memory(const void *mem, int memsize);
114 struct LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
117 struct LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *tot_prev);
118 struct LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh);
120 void BLO_blendhandle_close(BlendHandle *bh);
124 #define BLO_GROUP_MAX 32
125 #define BLO_EMBEDDED_STARTUP_BLEND "<startup.blend>"
127 bool BLO_has_bfile_extension(const char *str);
128 bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name);
130 /* Options controlling behavior of append/link code.
131 * Note: merged with 'user-level' options from operators etc. in 16 lower bits
132 * (see eFileSel_Params_Flag in DNA_space_types.h). */
133 typedef enum BLO_LibLinkFlags {
134 /* Generate a placeholder (empty ID) if not found in current lib file. */
135 BLO_LIBLINK_USE_PLACEHOLDERS = 1 << 16,
136 /* Force loaded ID to be tagged as LIB_TAG_INDIRECT (used in reload context only). */
137 BLO_LIBLINK_FORCE_INDIRECT = 1 << 17,
140 struct Main *BLO_library_link_begin(struct Main *mainvar, BlendHandle **bh, const char *filepath);
141 struct ID *BLO_library_link_named_part(struct Main *mainl,
145 struct ID *BLO_library_link_named_part_ex(
146 struct Main *mainl, BlendHandle **bh, const short idcode, const char *name, const int flag);
147 void BLO_library_link_end(struct Main *mainl,
152 struct ViewLayer *view_layer,
153 const struct View3D *v3d);
155 int BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh, const uint64_t id_types_mask);
157 void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);
159 /* internal function but we need to expose it */
160 void blo_lib_link_restore(struct Main *oldmain,
161 struct Main *newmain,
162 struct wmWindowManager *curwm,
163 struct Scene *curscene,
164 struct ViewLayer *cur_render_layer);
166 typedef void (*BLOExpandDoitCallback)(void *fdhandle, struct Main *mainvar, void *idv);
168 void BLO_main_expander(BLOExpandDoitCallback expand_doit_func);
169 void BLO_expand_main(void *fdhandle, struct Main *mainvar);
171 /* Update defaults in startup.blend & userprefs.blend, without having to save and embed it */
172 void BLO_update_defaults_startup_blend(struct Main *mainvar, const char *app_template);
173 void BLO_update_defaults_workspace(struct WorkSpace *workspace, const char *app_template);
175 /* Version patch user preferences. */
176 void BLO_version_defaults_userpref_blend(struct Main *mainvar, struct UserDef *userdef);
178 struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
180 /* datafiles (generated theme) */
181 extern const struct bTheme U_theme_default;
182 extern const struct UserDef U_default;
188 #endif /* __BLO_READFILE_H__ */