Blender  V2.93
preferences.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 
23 #include <string.h>
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_listbase.h"
28 #include "BLI_path_util.h"
29 #include "BLI_string.h"
30 #include "BLI_string_utf8.h"
31 #include "BLI_string_utils.h"
32 
33 #include "BKE_appdir.h"
34 #include "BKE_preferences.h"
35 
36 #include "BLT_translation.h"
37 
38 #include "DNA_userdef_types.h"
39 
40 #define U BLI_STATIC_ASSERT(false, "Global 'U' not allowed, only use arguments passed in!")
41 
42 /* -------------------------------------------------------------------- */
47  const char *name,
48  const char *path)
49 {
50  bUserAssetLibrary *library = MEM_callocN(sizeof(*library), "bUserAssetLibrary");
51 
53 
54  if (name) {
56  }
57  if (path) {
58  BLI_strncpy(library->path, path, sizeof(library->path));
59  }
60 
61  return library;
62 }
63 
66  const char *name)
67 {
68  BLI_strncpy_utf8(library->name, name, sizeof(library->name));
70  library,
71  name,
72  '.',
73  offsetof(bUserAssetLibrary, name),
74  sizeof(library->name));
75 }
76 
82 {
84 }
85 
87 {
88  return BLI_findlink(&userdef->asset_libraries, index);
89 }
90 
92  const char *name)
93 {
94  return BLI_findstring(&userdef->asset_libraries, name, offsetof(bUserAssetLibrary, name));
95 }
96 
99 {
100  return BLI_findindex(&userdef->asset_libraries, library);
101 }
102 
104 {
105  char documents_path[FILE_MAXDIR];
106 
107  /* No home or documents path found, not much we can do. */
108  if (!BKE_appdir_folder_documents(documents_path) || !documents_path[0]) {
109  return;
110  }
111 
113 
114  /* Add new "Default" library under '[doc_path]/Blender/Assets'. */
116  library->path, sizeof(library->path), documents_path, N_("Blender"), N_("Assets"), NULL);
117 }
118 
bool BKE_appdir_folder_documents(char *dir)
Definition: appdir.c:190
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:281
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first,...) ATTR_NONNULL(1
#define FILE_MAXDIR
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string_utf8.c:258
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t len)
Definition: string_utils.c:381
#define N_(msgid)
#define DATA_(msgid)
Read Guarded memory(de)allocation.
static FT_Library library
Definition: freetypefont.c:51
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void BKE_preferences_asset_library_default_add(UserDef *userdef)
Definition: preferences.c:103
bUserAssetLibrary * BKE_preferences_asset_library_find_from_name(const UserDef *userdef, const char *name)
Definition: preferences.c:91
bUserAssetLibrary * BKE_preferences_asset_library_find_from_index(const UserDef *userdef, int index)
Definition: preferences.c:86
int BKE_preferences_asset_library_get_index(const UserDef *userdef, const bUserAssetLibrary *library)
Definition: preferences.c:97
void BKE_preferences_asset_library_name_set(UserDef *userdef, bUserAssetLibrary *library, const char *name)
Definition: preferences.c:64
void BKE_preferences_asset_library_remove(UserDef *userdef, bUserAssetLibrary *library)
Definition: preferences.c:81
bUserAssetLibrary * BKE_preferences_asset_library_add(UserDef *userdef, const char *name, const char *path)
Definition: preferences.c:46
struct ListBase asset_libraries