| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  |  * Contributor(s): Andrea Weikert (c) 2008 Blender Foundation. | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/space_file/fsmenu.c
 | 
					
						
							|  |  |  |  *  \ingroup spfile | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | #include <math.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | #include "DNA_space_types.h" /* FILE_MAX */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-18 14:08:54 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "BLI_linklist.h"
 | 
					
						
							|  |  |  | #include "BLI_dynstr.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | #ifdef WIN32
 | 
					
						
							| 
									
										
										
										
											2012-04-15 07:54:07 +00:00
										 |  |  | #  include <windows.h> /* need to include windows.h so _WIN32_IE is defined  */
 | 
					
						
							|  |  |  | #  ifndef _WIN32_IE
 | 
					
						
							|  |  |  | #    define _WIN32_IE 0x0400 /* minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already */
 | 
					
						
							|  |  |  | #  endif
 | 
					
						
							|  |  |  | #  include <shlobj.h>  /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff
 | 
					
						
							|  |  |  |                         * because 'near' is disabled through BLI_windstuff */ | 
					
						
							|  |  |  | #  include "BLI_winstuff.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | #ifdef __APPLE__
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | /* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */ | 
					
						
							| 
									
										
										
										
											2012-04-15 07:54:07 +00:00
										 |  |  | #  define ID ID_
 | 
					
						
							|  |  |  | #  include <CoreServices/CoreServices.h>
 | 
					
						
							|  |  |  | #endif /* __APPLE__ */
 | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | #ifdef __linux__
 | 
					
						
							|  |  |  | #include <mntent.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | #include "fsmenu.h"  /* include ourselves */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* FSMENU HANDLING */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | /* FSMenuEntry's without paths indicate seperators */ | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | typedef struct _FSMenuEntry FSMenuEntry; | 
					
						
							|  |  |  | struct _FSMenuEntry { | 
					
						
							|  |  |  | 	FSMenuEntry *next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *path; | 
					
						
							|  |  |  | 	short save; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | typedef struct FSMenu { | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | 	FSMenuEntry *fsmenu_system; | 
					
						
							|  |  |  | 	FSMenuEntry *fsmenu_bookmarks; | 
					
						
							|  |  |  | 	FSMenuEntry *fsmenu_recent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } FSMenu; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static FSMenu *g_fsmenu = NULL; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | FSMenu *fsmenu_get(void) | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!g_fsmenu) { | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		g_fsmenu = MEM_callocN(sizeof(struct FSMenu), "fsmenu"); | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return g_fsmenu; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | static FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category) | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_head = NULL; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	switch (category) { | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 		case FS_CATEGORY_SYSTEM: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsm_head = fsmenu->fsmenu_system; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case FS_CATEGORY_BOOKMARKS: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsm_head = fsmenu->fsmenu_bookmarks; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case FS_CATEGORY_RECENT: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsm_head = fsmenu->fsmenu_recent; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	return fsm_head; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | static void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head) | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	switch (category) { | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 		case FS_CATEGORY_SYSTEM: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsmenu->fsmenu_system = fsm_head; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case FS_CATEGORY_BOOKMARKS: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsmenu->fsmenu_bookmarks = fsm_head; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case FS_CATEGORY_RECENT: | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			fsmenu->fsmenu_recent = fsm_head; | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_iter; | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 	int count = 0; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter; fsm_iter = fsm_iter->next) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		count++; | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_iter; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		idx--; | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	return fsm_iter ? fsm_iter->path : NULL; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_iter; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		idx--; | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	return fsm_iter ? fsm_iter->save : 0; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, FSMenuInsert flag) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_prev; | 
					
						
							|  |  |  | 	FSMenuEntry *fsm_iter; | 
					
						
							|  |  |  | 	FSMenuEntry *fsm_head; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	fsm_head = fsmenu_get_category(fsmenu, category); | 
					
						
							|  |  |  | 	fsm_prev = fsm_head;  /* this is odd and not really correct? */ | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsm_head; fsm_iter; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) { | 
					
						
							|  |  |  | 		if (fsm_iter->path) { | 
					
						
							|  |  |  | 			const int cmp_ret = BLI_path_cmp(path, fsm_iter->path); | 
					
						
							| 
									
										
										
										
											2011-04-06 06:03:48 +00:00
										 |  |  | 			if (cmp_ret == 0) { | 
					
						
							| 
									
										
										
										
											2012-09-17 02:19:41 +00:00
										 |  |  | 				if (FS_INSERT_FIRST) { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 					if (fsm_iter != fsm_head) { | 
					
						
							|  |  |  | 						fsm_prev->next = fsm_iter->next; | 
					
						
							|  |  |  | 						fsm_iter->next = fsm_head; | 
					
						
							|  |  |  | 						fsmenu_set_category(fsmenu, category, fsm_iter); | 
					
						
							| 
									
										
										
										
											2012-09-17 02:19:41 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2011-04-06 06:03:48 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 			else if ((flag & FS_INSERT_SORTED) && cmp_ret < 0) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 			/* if we're bookmarking this, file should come
 | 
					
						
							|  |  |  | 			 * before the last separator, only automatically added | 
					
						
							|  |  |  | 			 * current dir go after the last sep. */ | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 			if (flag & FS_INSERT_SAVE) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme"); | 
					
						
							|  |  |  | 	fsm_iter->path = BLI_strdup(path); | 
					
						
							|  |  |  | 	fsm_iter->save = (flag & FS_INSERT_SAVE) != 0; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	if (fsm_prev) { | 
					
						
							|  |  |  | 		fsm_iter->next = fsm_prev->next; | 
					
						
							|  |  |  | 		fsm_prev->next = fsm_iter; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 		fsm_iter->next = fsm_head; | 
					
						
							|  |  |  | 		fsmenu_set_category(fsmenu, category, fsm_iter); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_prev = NULL; | 
					
						
							|  |  |  | 	FSMenuEntry *fsm_iter; | 
					
						
							|  |  |  | 	FSMenuEntry *fsm_head; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	fsm_head = fsmenu_get_category(fsmenu, category); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (fsm_iter = fsm_head; fsm_iter && idx; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		idx--; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	if (fsm_iter) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		/* you should only be able to remove entries that were 
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 		 * not added by default, like windows drives. | 
					
						
							|  |  |  | 		 * also separators (where path == NULL) shouldn't be removed */ | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 		if (fsm_iter->save && fsm_iter->path) { | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* remove fsme from list */ | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			if (fsm_prev) { | 
					
						
							|  |  |  | 				fsm_prev->next = fsm_iter->next; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 				fsm_head = fsm_iter->next; | 
					
						
							|  |  |  | 				fsmenu_set_category(fsmenu, category, fsm_head); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			/* free entry */ | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 			MEM_freeN(fsm_iter->path); | 
					
						
							|  |  |  | 			MEM_freeN(fsm_iter); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_iter = NULL; | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 	int nskip = 0; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-20 02:17:37 +00:00
										 |  |  | 	FILE *fp = BLI_fopen(filename, "w"); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 	if (!fp) return; | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	fprintf(fp, "[Bookmarks]\n"); | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsm_iter; fsm_iter = fsm_iter->next) { | 
					
						
							|  |  |  | 		if (fsm_iter->path && fsm_iter->save) { | 
					
						
							|  |  |  | 			fprintf(fp, "%s\n", fsm_iter->path); | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fprintf(fp, "[Recent]\n"); | 
					
						
							| 
									
										
										
										
											2011-04-04 20:32:39 +00:00
										 |  |  | 	nskip = fsmenu_get_nentries(fsmenu, FS_CATEGORY_RECENT) - FSMENU_RECENT_MAX; | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 	/* skip first entries if list too long */ | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsm_iter && (nskip > 0); fsm_iter = fsm_iter->next, --nskip) { | 
					
						
							| 
									
										
										
										
											2012-02-27 10:35:39 +00:00
										 |  |  | 		/* pass */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	for (; fsm_iter; fsm_iter = fsm_iter->next) { | 
					
						
							|  |  |  | 		if (fsm_iter->path && fsm_iter->save) { | 
					
						
							|  |  |  | 			fprintf(fp, "%s\n", fsm_iter->path); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fclose(fp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename) | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char line[256]; | 
					
						
							|  |  |  | 	FSMenuCategory category = FS_CATEGORY_BOOKMARKS; | 
					
						
							|  |  |  | 	FILE *fp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-20 02:17:37 +00:00
										 |  |  | 	fp = BLI_fopen(filename, "r"); | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 	if (!fp) return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 	while (fgets(line, 256, fp) != NULL) {       /* read a line */ | 
					
						
							|  |  |  | 		if (strncmp(line, "[Bookmarks]", 11) == 0) { | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 			category = FS_CATEGORY_BOOKMARKS; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		else if (strncmp(line, "[Recent]", 8) == 0) { | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 			category = FS_CATEGORY_RECENT; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 			int len = strlen(line); | 
					
						
							| 
									
										
										
										
											2012-05-11 17:41:38 +00:00
										 |  |  | 			if (len > 0) { | 
					
						
							|  |  |  | 				if (line[len - 1] == '\n') { | 
					
						
							|  |  |  | 					line[len - 1] = '\0'; | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-05-11 17:41:38 +00:00
										 |  |  | 				/* don't do this because it can be slow on network drives,
 | 
					
						
							|  |  |  | 				 * having a bookmark from a drive thats ejected or so isn't | 
					
						
							|  |  |  | 				 * all _that_ bad */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 				if (BLI_exists(line)) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 					fsmenu_insert_entry(fsmenu, category, line, FS_INSERT_SAVE); | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fclose(fp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char line[256]; | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | #ifdef WIN32
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | 	/* Add the drive names to the listing */ | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		__int64 tmp; | 
					
						
							|  |  |  | 		char tmps[4]; | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		tmp = GetLogicalDrives(); | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		for (i = 0; i < 26; i++) { | 
					
						
							|  |  |  | 			if ((tmp >> i) & 1) { | 
					
						
							|  |  |  | 				tmps[0] = 'A' + i; | 
					
						
							|  |  |  | 				tmps[1] = ':'; | 
					
						
							|  |  |  | 				tmps[2] = '\\'; | 
					
						
							|  |  |  | 				tmps[3] = 0; | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2012-09-17 08:36:47 +00:00
										 |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Adding Desktop and My Documents */ | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 		if (read_bookmarks) { | 
					
						
							|  |  |  | 			SHGetSpecialFolderPath(0, line, CSIDL_PERSONAL, 0); | 
					
						
							| 
									
										
										
										
											2012-09-17 08:36:47 +00:00
										 |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 			SHGetSpecialFolderPath(0, line, CSIDL_DESKTOPDIRECTORY, 0); | 
					
						
							| 
									
										
										
										
											2012-09-17 08:36:47 +00:00
										 |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | #ifdef __APPLE__
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | #if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		OSErr err = noErr; | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 		int i; | 
					
						
							| 
									
										
										
										
											2011-02-26 15:28:56 +00:00
										 |  |  | 		const char *home; | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* loop through all the OS X Volumes, and add them to the SYSTEM section */ | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 		for (i = 1; err != nsvErr; i++) { | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 			FSRef dir; | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 			unsigned char path[FILE_MAX]; | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			err = FSGetVolumeInfo(kFSInvalidVolumeRefNum, i, NULL, kFSVolInfoNone, NULL, NULL, &dir); | 
					
						
							|  |  |  | 			if (err != noErr) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 			FSRefMakePath(&dir, path, FILE_MAX); | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 			if (strcmp((char *)path, "/home") && strcmp((char *)path, "/net")) { | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 				/* /net and /home are meaningless on OSX, home folders are stored in /Users */ | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* As 10.4 doesn't provide proper API to retrieve the favorite places,
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 		 * assume they are the standard ones  | 
					
						
							|  |  |  | 		 * TODO : replace hardcoded paths with proper BLI_get_folder calls */ | 
					
						
							| 
									
										
										
										
											2010-07-16 16:02:07 +00:00
										 |  |  | 		home = getenv("HOME"); | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 		if (read_bookmarks && home) { | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 			BLI_snprintf(line, 256, "%s/", home); | 
					
						
							|  |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			BLI_snprintf(line, 256, "%s/Desktop/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			BLI_snprintf(line, 256, "%s/Documents/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			BLI_snprintf(line, 256, "%s/Pictures/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			BLI_snprintf(line, 256, "%s/Music/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			BLI_snprintf(line, 256, "%s/Movies/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 		/* 10.5 provides ability to retrieve Finder favorite places */ | 
					
						
							|  |  |  | 		UInt32 seed; | 
					
						
							|  |  |  | 		OSErr err = noErr; | 
					
						
							|  |  |  | 		CFArrayRef pathesArray; | 
					
						
							|  |  |  | 		LSSharedFileListRef list; | 
					
						
							|  |  |  | 		LSSharedFileListItemRef itemRef; | 
					
						
							|  |  |  | 		CFIndex i, pathesCount; | 
					
						
							|  |  |  | 		CFURLRef cfURL = NULL; | 
					
						
							|  |  |  | 		CFStringRef pathString = NULL; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-12-18 16:35:41 +00:00
										 |  |  | 		/* First get local mounted volumes */ | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 		list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteVolumes, NULL); | 
					
						
							|  |  |  | 		pathesArray = LSSharedFileListCopySnapshot(list, &seed); | 
					
						
							|  |  |  | 		pathesCount = CFArrayGetCount(pathesArray); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		for (i = 0; i < pathesCount; i++) { | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 			itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			err = LSSharedFileListItemResolve(itemRef,  | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 			                                  kLSSharedFileListNoUserInteraction | | 
					
						
							| 
									
										
										
										
											2012-05-09 09:24:15 +00:00
										 |  |  | 			                                  kLSSharedFileListDoNotMountVolumes, | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 			                                  &cfURL, NULL); | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 			if (err != noErr) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-04-29 15:47:02 +00:00
										 |  |  | 			if (!CFStringGetCString(pathString, line, 256, kCFStringEncodingASCII)) | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, 1, 0); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			CFRelease(pathString); | 
					
						
							|  |  |  | 			CFRelease(cfURL); | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		CFRelease(pathesArray); | 
					
						
							|  |  |  | 		CFRelease(list); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-12-18 16:35:41 +00:00
										 |  |  | 		/* Then get network volumes */ | 
					
						
							|  |  |  | 		err = noErr; | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		for (i = 1; err != nsvErr; i++) { | 
					
						
							| 
									
										
										
										
											2009-12-18 16:35:41 +00:00
										 |  |  | 			FSRef dir; | 
					
						
							|  |  |  | 			FSVolumeRefNum volRefNum; | 
					
						
							|  |  |  | 			struct GetVolParmsInfoBuffer volParmsBuffer; | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 			unsigned char path[FILE_MAX]; | 
					
						
							| 
									
										
										
										
											2009-12-18 16:35:41 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			err = FSGetVolumeInfo(kFSInvalidVolumeRefNum, i, &volRefNum, kFSVolInfoNone, NULL, NULL, &dir); | 
					
						
							|  |  |  | 			if (err != noErr) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			err = FSGetVolumeParms(volRefNum, &volParmsBuffer, sizeof(volParmsBuffer)); | 
					
						
							|  |  |  | 			if ((err != noErr) || (volParmsBuffer.vMServerAdr == 0)) /* Exclude local devices */ | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 			FSRefMakePath(&dir, path, FILE_MAX); | 
					
						
							| 
									
										
										
										
											2009-12-18 16:35:41 +00:00
										 |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* Finally get user favorite places */ | 
					
						
							| 
									
										
										
										
											2012-05-22 16:24:09 +00:00
										 |  |  | 		if (read_bookmarks) { | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 			list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); | 
					
						
							|  |  |  | 			pathesArray = LSSharedFileListCopySnapshot(list, &seed); | 
					
						
							|  |  |  | 			pathesCount = CFArrayGetCount(pathesArray); | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 			for (i = 0; i < pathesCount; i++) { | 
					
						
							|  |  |  | 				itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				err = LSSharedFileListItemResolve(itemRef,  | 
					
						
							| 
									
										
										
										
											2012-06-18 13:01:24 +00:00
										 |  |  | 				                                  kLSSharedFileListNoUserInteraction | | 
					
						
							|  |  |  | 				                                  kLSSharedFileListDoNotMountVolumes, | 
					
						
							|  |  |  | 				                                  &cfURL, NULL); | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 				if (err != noErr) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				if (!CFStringGetCString(pathString, line, 256, kCFStringEncodingASCII)) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				CFRelease(pathString); | 
					
						
							|  |  |  | 				CFRelease(cfURL); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 			CFRelease(pathesArray); | 
					
						
							|  |  |  | 			CFRelease(list); | 
					
						
							| 
									
										
										
										
											2009-12-17 09:23:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | #endif /* OSX 10.5+ */
 | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	/* unix */ | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 		const char *home = getenv("HOME"); | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | 		if (read_bookmarks && home) { | 
					
						
							| 
									
										
										
										
											2010-07-04 15:52:32 +00:00
										 |  |  | 			BLI_snprintf(line, FILE_MAXDIR, "%s/", home); | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2010-07-04 15:52:32 +00:00
										 |  |  | 			BLI_snprintf(line, FILE_MAXDIR, "%s/Desktop/", home); | 
					
						
							|  |  |  | 			if (BLI_exists(line)) { | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2009-07-29 22:37:33 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 			int found = 0; | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | #ifdef __linux__
 | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 			/* loop over mount points */ | 
					
						
							|  |  |  | 			struct mntent *mnt; | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | 			int len; | 
					
						
							| 
									
										
										
										
											2010-09-15 16:13:32 +00:00
										 |  |  | 			FILE *fp; | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 			fp = setmntent(MOUNTED, "r"); | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 			if (fp == NULL) { | 
					
						
							|  |  |  | 				fprintf(stderr, "could not get a list of mounted filesystemts\n"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 				while ((mnt = getmntent(fp))) { | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | 					/* not sure if this is right, but seems to give the relevant mnts */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 					if (strncmp(mnt->mnt_fsname, "/dev", 4)) | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 						continue; | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 					len = strlen(mnt->mnt_dir); | 
					
						
							|  |  |  | 					if (len && mnt->mnt_dir[len - 1] != '/') { | 
					
						
							| 
									
										
										
										
											2010-07-04 15:52:32 +00:00
										 |  |  | 						BLI_snprintf(line, FILE_MAXDIR, "%s/", mnt->mnt_dir); | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 						fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, FS_INSERT_SORTED); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else { | 
					
						
							|  |  |  | 						fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 					found = 1; | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | 				if (endmntent(fp) == 0) { | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 					fprintf(stderr, "could not close the list of mounted filesystemts\n"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-07-29 21:35:03 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* fallback */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 			if (!found) | 
					
						
							| 
									
										
										
										
											2012-09-17 02:01:09 +00:00
										 |  |  | 				fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", FS_INSERT_SORTED); | 
					
						
							| 
									
										
										
										
											2009-07-28 22:44:50 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-07-28 16:46:14 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-05-02 03:09:40 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:42:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-04 15:35:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | static void fsmenu_free_category(struct FSMenu *fsmenu, FSMenuCategory category) | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	FSMenuEntry *fsm_iter = fsmenu_get_category(fsmenu, category); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 	while (fsm_iter) { | 
					
						
							|  |  |  | 		FSMenuEntry *fsm_next = fsm_iter->next; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 		if (fsm_iter->path) { | 
					
						
							|  |  |  | 			MEM_freeN(fsm_iter->path); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		MEM_freeN(fsm_iter); | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 04:29:43 +00:00
										 |  |  | 		fsm_iter = fsm_next; | 
					
						
							| 
									
										
										
										
											2008-12-18 19:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-18 12:49:25 +00:00
										 |  |  | void fsmenu_refresh_system_category(struct FSMenu *fsmenu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM); | 
					
						
							|  |  |  | 	fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Add all entries to system category */ | 
					
						
							|  |  |  | 	fsmenu_read_system(fsmenu, FALSE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 11:01:29 +00:00
										 |  |  | void fsmenu_free(struct FSMenu *fsmenu) | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-12 19:36:59 +00:00
										 |  |  | 	fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM); | 
					
						
							|  |  |  | 	fsmenu_free_category(fsmenu, FS_CATEGORY_BOOKMARKS); | 
					
						
							|  |  |  | 	fsmenu_free_category(fsmenu, FS_CATEGORY_RECENT); | 
					
						
							|  |  |  | 	MEM_freeN(fsmenu); | 
					
						
							| 
									
										
										
										
											2009-03-10 23:14:41 +00:00
										 |  |  | } |