Blender  V2.93
library.c
Go to the documentation of this file.
1 /*
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.
6  *
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.
11  *
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.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
26 #include "CLG_log.h"
27 
28 #include "MEM_guardedalloc.h"
29 
30 /* all types are needed here, in order to do memory operations */
31 #include "DNA_ID.h"
32 
33 #include "BLI_utildefines.h"
34 
35 #include "BLI_blenlib.h"
36 
37 #include "BLT_translation.h"
38 
39 #include "BKE_idtype.h"
40 #include "BKE_lib_id.h"
41 #include "BKE_lib_query.h"
42 #include "BKE_library.h"
43 #include "BKE_main.h"
44 #include "BKE_packedFile.h"
45 
46 /* Unused currently. */
47 // static CLG_LogRef LOG = {.identifier = "bke.library"};
48 
49 static void library_free_data(ID *id)
50 {
51  Library *library = (Library *)id;
52  if (library->packedfile) {
53  BKE_packedfile_free(library->packedfile);
54  }
55 }
56 
58 {
59  Library *lib = (Library *)id;
61 }
62 
64  .id_code = ID_LI,
65  .id_filter = 0,
66  .main_listbase_index = INDEX_ID_LI,
67  .struct_size = sizeof(Library),
68  .name = "Library",
69  .name_plural = "libraries",
70  .translation_context = BLT_I18NCONTEXT_ID_LIBRARY,
73 
74  .init_data = NULL,
75  .copy_data = NULL,
76  .free_data = library_free_data,
77  .make_local = NULL,
78  .foreach_id = library_foreach_id,
79  .foreach_cache = NULL,
80  .owner_get = NULL,
81 
82  .blend_write = NULL,
83  .blend_read_data = NULL,
84  .blend_read_lib = NULL,
85  .blend_read_expand = NULL,
86 
87  .blend_read_undo_preserve = NULL,
88 
89  .lib_override_apply_post = NULL,
90 };
91 
92 void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
93 {
94  /* in some cases this is used to update the absolute path from the
95  * relative */
96  if (lib->filepath != filepath) {
97  BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
98  }
99 
100  BLI_strncpy(lib->filepath_abs, filepath, sizeof(lib->filepath_abs));
101 
102  /* Not essential but set `filepath_abs` is an absolute copy of value which
103  * is more useful if its kept in sync. */
104  if (BLI_path_is_rel(lib->filepath_abs)) {
105  /* note that the file may be unsaved, in this case, setting the
106  * `filepath_abs` on an indirectly linked path is not allowed from the
107  * outliner, and its not really supported but allow from here for now
108  * since making local could cause this to be directly linked - campbell
109  */
110  /* Never make paths relative to parent lib - reading code (blenloader) always set *all*
111  * `lib->filepath` relative to current main, not to their parent for indirectly linked ones. */
112  const char *basepath = BKE_main_blendfile_path(bmain);
113  BLI_path_abs(lib->filepath_abs, basepath);
114  }
115 }
@ IDTYPE_FLAGS_NO_MAKELOCAL
Definition: BKE_idtype.h:49
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition: BKE_idtype.h:51
@ IDTYPE_FLAGS_NO_COPY
Definition: BKE_idtype.h:45
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition: BKE_idtype.h:47
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
@ IDWALK_CB_NEVER_SELF
Definition: BKE_lib_query.h:49
const char * BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL()
void BKE_packedfile_free(struct PackedFile *pf)
Definition: packedFile.c:155
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:411
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
Definition: path_util.c:1016
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define BLT_I18NCONTEXT_ID_LIBRARY
ID and Library types, which are fundamental for sdna.
struct Library Library
@ INDEX_ID_LI
Definition: DNA_ID.h:781
@ ID_LI
Definition: DNA_ID_enums.h:58
Read Guarded memory(de)allocation.
static void init_data(ModifierData *md)
DRWShaderLibrary * lib
static FT_Library library
Definition: freetypefont.c:51
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
Definition: library.c:92
static void library_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: library.c:57
IDTypeInfo IDType_ID_LI
Definition: library.c:63
static void library_free_data(ID *id)
Definition: library.c:49
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
Definition: BKE_main.h:116