From 80015c886791c3a89dba8b37a0fc6a97cbd3f87c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 29 Jul 2009 21:35:03 +0000 Subject: [PATCH] 2.5: File Browser on Unix * Attempt to better filter file systems, it displayed all kinds of devices which are not interesting to the user. The trick used is now to use mounts starting with "/dev". * Add / at the end to properly highlight directories in the list. * Fix for non-linux unixes, this now falls back to showing / again. --- source/blender/editors/space_file/fsmenu.c | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 41d97e1e0ae..73233431fd8 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -307,8 +307,6 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename) char dir[FILE_MAXDIR]; char *home= BLI_gethome(); - // fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", 1, 0); - if(home) { BLI_snprintf(dir, FILE_MAXDIR, "%s/", home); fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, dir, 1, 0); @@ -317,30 +315,42 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename) } { + int found= 0; +#ifdef __linux__ /* loop over mount points */ struct mntent *mnt; FILE *fp; + int len; + fp = setmntent (MOUNTED, "r"); if (fp == NULL) { fprintf(stderr, "could not get a list of mounted filesystemts\n"); } else { while ((mnt = getmntent (fp))) { - /* printf("%s %s %s %s %s %s\n", mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno); */ - - /* probably need to add more here */ - if( (strcmp (mnt->mnt_fsname, "none")==0) || /* /sys, /dev/pts */ - (strcmp (mnt->mnt_type, "ramfs")==0) /* /dev */ - ) { + /* not sure if this is right, but seems to give the relevant mnts */ + if(strncmp(mnt->mnt_fsname, "/dev", 4)) continue; - } - fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, 1, 0); + len= strlen(mnt->mnt_dir); + if(len && mnt->mnt_dir[len-1] != '/') { + BLI_snprintf(dir, FILE_MAXDIR, "%s/", mnt->mnt_dir); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, dir, 1, 0); + } + else + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, 1, 0); + + found= 1; } if (endmntent (fp) == 0) { fprintf(stderr, "could not close the list of mounted filesystemts\n"); } } +#endif + + /* fallback */ + if(!found) + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", 1, 0); } } #endif