65 const char *xdg_config_home = getenv(
"XDG_CONFIG_HOME");
66 if (xdg_config_home !=
nullptr) {
67 BLI_path_join(filepath,
sizeof(filepath), xdg_config_home,
"user-dirs.dirs");
70 BLI_path_join(filepath,
sizeof(filepath), home,
".config",
"user-dirs.dirs");
79 while (fgets(
l,
sizeof(
l), fp) !=
nullptr) {
83 char *l_value = strchr(
l,
'=');
84 if (l_value !=
nullptr) {
89 const uint l_value_len = strlen(l_value);
90 if ((l_value[0] ==
'"') && (l_value_len > 0) && (l_value[l_value_len - 1] ==
'"')) {
91 l_value[l_value_len - 1] =
'\0';
95 char *l_value_final = l_value;
101 BLI_path_join(l_value_expanded,
sizeof(l_value_expanded), home, l_value + 6);
102 l_value_final = l_value_expanded;
117 if (xdg_map !=
nullptr) {
133 const char *default_path,
138 const char *xdg_path =
static_cast<const char *
>(xdg_map ?
BLI_ghash_lookup(xdg_map, key) :
140 if (xdg_path ==
nullptr) {
141 BLI_path_join(xdg_path_buf,
sizeof(xdg_path_buf), home, default_path);
142 xdg_path = xdg_path_buf;
154 if (read_bookmarks && home) {
163 const char *default_path;
166 {
"XDG_DESKTOP_DIR",
"Desktop", ICON_DESKTOP},
167 {
"XDG_DOCUMENTS_DIR",
"Documents", ICON_DOCUMENTS},
168 {
"XDG_DOWNLOAD_DIR",
"Downloads", ICON_IMPORT},
169 {
"XDG_VIDEOS_DIR",
"Videos", ICON_FILE_MOVIE},
170 {
"XDG_PICTURES_DIR",
"Pictures", ICON_FILE_IMAGE},
171 {
"XDG_MUSIC_DIR",
"Music", ICON_FILE_SOUND},
174 for (
int i = 0; i <
ARRAY_SIZE(xdg_items); i++) {
176 xdg_map, fsmenu, xdg_items[i].key, xdg_items[i].default_path, xdg_items[i].icon, home);
189 fp = setmntent(MOUNTED,
"r");
191 CLOG_WARN(&
LOG,
"Could not get a list of mounted file-systems");
198 auto strncmp_dir_delimit = [](
const char *a,
const char *
b,
size_t b_len) ->
int {
199 const int result = strncmp(a,
b, b_len);
202# define STRPREFIX_DIR_DELIMIT(a, b) (strncmp_dir_delimit((a), (b), strlen(b)) == 0)
204 while ((mnt = getmntent(fp))) {
205 if (STRPREFIX_DIR_DELIMIT(mnt->mnt_dir,
"/boot") ||
208 STRPREFIX_DIR_DELIMIT(mnt->mnt_dir,
"/efi"))
213 if (!STRPREFIX_DIR_DELIMIT(mnt->mnt_fsname,
"/dev")) {
217 if (
STRPREFIX(mnt->mnt_fsname,
"/dev/loop")) {
228# undef STRPREFIX_DIR_DELIMIT
230 if (endmntent(fp) == 0) {
231 CLOG_WARN(&
LOG,
"Could not close the list of mounted file-systems");
235 const char *
const xdg_runtime_dir =
BLI_getenv(
"XDG_RUNTIME_DIR");
236 if (xdg_runtime_dir !=
nullptr) {
239 BLI_path_join(filepath,
sizeof(filepath), xdg_runtime_dir,
"gvfs/");
243 for (
uint i = 0; i < dirs_num; i++) {
244 if ((dirs[i].type & S_IFDIR) == 0) {
247 const char *
dirname = dirs[i].relname;
254 const char *label = strstr(
dirname,
"share=");
255 if (label !=
nullptr) {
257 const char *label_test = label + 6;
258 label = *label_test ? label_test :
dirname;
File and directory operations.
Some types for dealing with directories.
#define BLI_path_join(...)
#define SNPRINTF(dst, format,...)
const char * dirname(char *path)
#define CLOG_WARN(clg_ref,...)
Read Blender memory allocation and freeing.
unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void MEM_delete_void(void *vmemh)
static void fsmenu_xdg_insert_entry(GHash *xdg_map, FSMenu *fsmenu, const char *key, const char *default_path, int icon, const char *home)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
const char * BLI_dir_home()
void fsmenu_insert_entry(FSMenu *fsmenu, FSMenuCategory category, const char *path, const char *name, int icon, FSMenuInsert flag)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
static GHash * fsmenu_xdg_user_dirs_parse(const char *home)
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void BLI_str_rstrip(char *str) ATTR_NONNULL(1)
@ FS_CATEGORY_SYSTEM_BOOKMARKS
void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
static void fsmenu_xdg_user_dirs_free(GHash *xdg_map)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT