4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
29 #ifndef BLI_PATH_UTIL_H
30 #define BLI_PATH_UTIL_H
32 /** \file BLI_path_util.h
43 const char *BLI_getDefaultDocumentFolder(void);
45 char *BLI_get_folder(int folder_id, const char *subfolder);
46 char *BLI_get_folder_create(int folder_id, const char *subfolder);
47 char *BLI_get_user_folder_notest(int folder_id, const char *subfolder);
48 char *BLI_get_folder_version(const int id, const int ver, const int do_check);
52 /* general, will find based on user/local/system priority */
53 #define BLENDER_DATAFILES 2
56 #define BLENDER_USER_CONFIG 31
57 #define BLENDER_USER_DATAFILES 32
58 #define BLENDER_USER_SCRIPTS 33
59 #define BLENDER_USER_PLUGINS 34
60 #define BLENDER_USER_AUTOSAVE 35
63 #define BLENDER_SYSTEM_DATAFILES 52
64 #define BLENDER_SYSTEM_SCRIPTS 53
65 #define BLENDER_SYSTEM_PLUGINS 54
66 #define BLENDER_SYSTEM_PYTHON 54
68 #define BLENDER_TEMP 80
70 #define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
72 /* for BLI_get_folder_version only */
73 #define BLENDER_RESOURCE_PATH_USER 0
74 #define BLENDER_RESOURCE_PATH_LOCAL 1
75 #define BLENDER_RESOURCE_PATH_SYSTEM 2
77 #define BLENDER_STARTUP_FILE "startup.blend"
78 #define BLENDER_BOOKMARK_FILE "bookmarks.txt"
79 #define BLENDER_HISTORY_FILE "recent-files.txt"
82 #define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s"
83 #define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s"
84 #elif defined(__APPLE__)
85 #define BLENDER_USER_FORMAT "%s/Blender/%s"
86 #define BLENDER_SYSTEM_FORMAT "%s/Blender/%s"
88 #define BLENDER_USER_FORMAT "%s/.blender/%s"
89 #define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
100 void BLI_setenv(const char *env, const char *val);
101 void BLI_setenv_if_new(const char *env, const char* val);
103 void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
104 void BLI_make_exist(char *dir);
105 void BLI_make_existing_file(const char *name);
106 void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
107 void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen);
108 void BLI_split_file_part(const char *string, char *file, const size_t filelen);
109 void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file);
110 char *BLI_path_basename(char *path);
111 int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir);
112 char *BLI_last_slash(const char *string);
113 int BLI_add_slash(char *string);
114 void BLI_del_slash(char *string);
115 char *BLI_first_slash(char *string);
117 void BLI_getlastdir(const char* dir, char *last, const size_t maxlen);
118 int BLI_testextensie(const char *str, const char *ext);
119 int BLI_testextensie_array(const char *str, const char **ext_array);
120 int BLI_testextensie_glob(const char *str, const char *ext_fnmatch);
121 int BLI_replace_extension(char *path, size_t maxlen, const char *ext);
122 void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
123 int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len);
124 void BLI_newname(char * name, int add);
125 int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen);
126 void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic);
127 int BLI_split_name_num(char *left, int *nr, const char *name, const char delim);
128 void BLI_splitdirstring(char *di,char *fi);
130 /* make sure path separators conform to system one */
131 void BLI_clean(char *path);
134 * dir can be any input, like from buttons, and this function
135 * converts it to a regular full path.
136 * Also removes garbage from directory paths, like /../ or double slashes etc
138 void BLI_cleanup_file(const char *relabase, char *dir); /* removes trailing slash */
139 void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */
140 void BLI_cleanup_path(const char *relabase, char *dir); /* doesn't touch trailing slash */
142 /* go back one directory */
143 int BLI_parent_dir(char *path);
145 /* return whether directory is root and thus has no parent dir */
146 int BLI_has_parent(char *path);
149 * Blender's path code replacement function.
150 * Bases @a path strings leading with "//" by the
151 * directory @a basepath, and replaces instances of
152 * '#' with the @a framenum. Results are written
155 * @a path The path to convert
156 * @a basepath The directory to base relative paths with.
157 * @a framenum The framenumber to replace the frame code with.
158 * @retval Returns true if the path was relative (started with "//").
160 int BLI_path_abs(char *path, const char *basepath);
161 int BLI_path_frame(char *path, int frame, int digits);
162 int BLI_path_frame_range(char *path, int sta, int end, int digits);
163 int BLI_path_cwd(char *path);
164 void BLI_path_rel(char *file, const char *relfile);
167 # define BLI_path_cmp BLI_strcasecmp
168 # define BLI_path_ncmp BLI_strncasecmp
170 # define BLI_path_cmp strcmp
171 # define BLI_path_ncmp strncmp
175 * Change every @a from in @a string into @a to. The
176 * result will be in @a string
178 * @a string The string to work on
179 * @a from The character to replace
180 * @a to The character to replace with
182 void BLI_char_switch(char *string, char from, char to);
185 * Checks if name is a fully qualified filename to an executable.
186 * If not it searches $PATH for the file. On Windows it also
187 * adds the correct extension (.com .exe etc) from
188 * $PATHEXT if necessary. Also on Windows it translates
189 * the name to its 8.3 version to prevent problems with
190 * spaces and stuff. Final result is returned in fullname.
192 * @param fullname The full path and full name of the executable
193 * @param name The name of the executable (usually argv[0]) to be checked
195 void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name);
198 * Gets the temp directory when blender first runs.
199 * If the default path is not found, use try $TEMP
201 * Also make sure the temp dir has a trailing slash
203 * @param fullname The full path to the temp directory
205 void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp);
209 void BLI_string_to_utf8(char *original, char *utf_8, const char *code);