2008-12-18 19:21:30 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** 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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* 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 *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
2008-12-18 19:21:30 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_linklist.h"
|
|
|
|
#include "BLI_dynstr.h"
|
2009-07-28 16:46:14 +00:00
|
|
|
#include "BLI_string.h"
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#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"
|
|
|
|
#endif
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-05-02 03:09:40 +00:00
|
|
|
#ifdef __APPLE__
|
2009-07-28 16:56:22 +00:00
|
|
|
/* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */
|
|
|
|
#define ID ID_
|
2009-05-02 03:09:40 +00:00
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
#endif
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
/* FSMenuEntry's without paths indicate seperators */
|
|
|
|
typedef struct _FSMenuEntry FSMenuEntry;
|
|
|
|
struct _FSMenuEntry {
|
|
|
|
FSMenuEntry *next;
|
|
|
|
|
|
|
|
char *path;
|
|
|
|
short save;
|
|
|
|
};
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
typedef struct FSMenu
|
|
|
|
{
|
|
|
|
FSMenuEntry *fsmenu_system;
|
|
|
|
FSMenuEntry *fsmenu_bookmarks;
|
|
|
|
FSMenuEntry *fsmenu_recent;
|
|
|
|
|
|
|
|
} FSMenu;
|
|
|
|
|
|
|
|
static FSMenu *g_fsmenu = NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
struct FSMenu* fsmenu_get(void)
|
|
|
|
{
|
|
|
|
if (!g_fsmenu) {
|
|
|
|
g_fsmenu=MEM_callocN(sizeof(struct FSMenu), "fsmenu");
|
|
|
|
}
|
|
|
|
return g_fsmenu;
|
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
static FSMenuEntry *fsmenu_get_category(struct FSMenu* fsmenu, FSMenuCategory category)
|
2009-03-10 23:14:41 +00:00
|
|
|
{
|
2009-03-12 19:36:59 +00:00
|
|
|
FSMenuEntry *fsms = NULL;
|
2009-03-10 23:14:41 +00:00
|
|
|
|
|
|
|
switch(category) {
|
|
|
|
case FS_CATEGORY_SYSTEM:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsms = fsmenu->fsmenu_system;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
case FS_CATEGORY_BOOKMARKS:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsms = fsmenu->fsmenu_bookmarks;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
case FS_CATEGORY_RECENT:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsms = fsmenu->fsmenu_recent;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-12 19:36:59 +00:00
|
|
|
return fsms;
|
2009-03-10 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
static void fsmenu_set_category(struct FSMenu* fsmenu, FSMenuCategory category, FSMenuEntry *fsms)
|
2009-03-10 23:14:41 +00:00
|
|
|
{
|
|
|
|
switch(category) {
|
|
|
|
case FS_CATEGORY_SYSTEM:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu->fsmenu_system = fsms;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
case FS_CATEGORY_BOOKMARKS:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu->fsmenu_bookmarks = fsms;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
case FS_CATEGORY_RECENT:
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu->fsmenu_recent = fsms;
|
2009-03-10 23:14:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
int fsmenu_get_nentries(struct FSMenu* fsmenu, FSMenuCategory category)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
FSMenuEntry *fsme;
|
|
|
|
int count= 0;
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
for (fsme= fsmenu_get_category(fsmenu, category); fsme; fsme= fsme->next)
|
2008-12-18 19:21:30 +00:00
|
|
|
count++;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
char *fsmenu_get_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
FSMenuEntry *fsme;
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
|
2008-12-18 19:21:30 +00:00
|
|
|
idx--;
|
|
|
|
|
2009-03-10 23:14:41 +00:00
|
|
|
return fsme?fsme->path:NULL;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-06-29 23:21:11 +00:00
|
|
|
short fsmenu_can_save (struct FSMenu* fsmenu, FSMenuCategory category, int idx)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
FSMenuEntry *fsme;
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
|
2008-12-18 19:21:30 +00:00
|
|
|
idx--;
|
|
|
|
|
2009-06-29 23:21:11 +00:00
|
|
|
return fsme?fsme->save:0;
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
void fsmenu_insert_entry(struct FSMenu* fsmenu, FSMenuCategory category, char *path, int sorted, short save)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
|
|
|
FSMenuEntry *prev;
|
|
|
|
FSMenuEntry *fsme;
|
2009-03-12 19:36:59 +00:00
|
|
|
FSMenuEntry *fsms;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
fsms = fsmenu_get_category(fsmenu, category);
|
|
|
|
prev= fsme= fsms;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
for (; fsme; prev= fsme, fsme= fsme->next) {
|
|
|
|
if (fsme->path) {
|
|
|
|
if (BLI_streq(path, fsme->path)) {
|
|
|
|
return;
|
|
|
|
} else if (sorted && strcmp(path, fsme->path)<0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if we're bookmarking this, file should come
|
|
|
|
// before the last separator, only automatically added
|
|
|
|
// current dir go after the last sep.
|
|
|
|
if (save) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fsme= MEM_mallocN(sizeof(*fsme), "fsme");
|
|
|
|
fsme->path= BLI_strdup(path);
|
|
|
|
fsme->save = save;
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
fsme->next= prev->next;
|
|
|
|
prev->next= fsme;
|
|
|
|
} else {
|
2009-03-12 19:36:59 +00:00
|
|
|
fsme->next= fsms;
|
|
|
|
fsmenu_set_category(fsmenu, category, fsme);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
void fsmenu_remove_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2009-03-10 23:14:41 +00:00
|
|
|
FSMenuEntry *prev= NULL, *fsme= NULL;
|
2009-03-12 19:36:59 +00:00
|
|
|
FSMenuEntry *fsms = fsmenu_get_category(fsmenu, category);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
for (fsme= fsms; fsme && idx; prev= fsme, fsme= fsme->next)
|
2008-12-18 19:21:30 +00:00
|
|
|
idx--;
|
|
|
|
|
|
|
|
if (fsme) {
|
|
|
|
/* you should only be able to remove entries that were
|
|
|
|
not added by default, like windows drives.
|
|
|
|
also separators (where path == NULL) shouldn't be removed */
|
|
|
|
if (fsme->save && fsme->path) {
|
|
|
|
|
|
|
|
/* remove fsme from list */
|
|
|
|
if (prev) {
|
|
|
|
prev->next= fsme->next;
|
|
|
|
} else {
|
2009-03-12 19:36:59 +00:00
|
|
|
fsms= fsme->next;
|
|
|
|
fsmenu_set_category(fsmenu, category, fsms);
|
2008-12-18 19:21:30 +00:00
|
|
|
}
|
|
|
|
/* free entry */
|
|
|
|
MEM_freeN(fsme->path);
|
|
|
|
MEM_freeN(fsme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
void fsmenu_write_file(struct FSMenu* fsmenu, const char *filename)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2009-03-10 23:14:41 +00:00
|
|
|
FSMenuEntry *fsme= NULL;
|
2009-03-12 19:36:59 +00:00
|
|
|
int count=FSMENU_RECENT_MAX;
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
FILE *fp = fopen(filename, "w");
|
|
|
|
if (!fp) return;
|
2009-03-12 19:36:59 +00:00
|
|
|
|
|
|
|
fprintf(fp, "[Bookmarks]\n");
|
|
|
|
for (fsme= fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsme; fsme= fsme->next) {
|
|
|
|
if (fsme->path && fsme->save) {
|
|
|
|
fprintf(fp, "%s\n", fsme->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp, "[Recent]\n");
|
|
|
|
for (fsme= fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsme && count; fsme= fsme->next, --count) {
|
2008-12-18 19:21:30 +00:00
|
|
|
if (fsme->path && fsme->save) {
|
|
|
|
fprintf(fp, "%s\n", fsme->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
|
|
|
char line[256];
|
2009-03-12 19:36:59 +00:00
|
|
|
FSMenuCategory category = FS_CATEGORY_BOOKMARKS;
|
2009-01-06 14:42:54 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
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 folder[256];
|
|
|
|
char tmps[4];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
tmp= GetLogicalDrives();
|
|
|
|
|
|
|
|
for (i=2; i < 26; i++) {
|
|
|
|
if ((tmp>>i) & 1) {
|
|
|
|
tmps[0]='a'+i;
|
|
|
|
tmps[1]=':';
|
|
|
|
tmps[2]='\\';
|
|
|
|
tmps[3]=0;
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, 1, 0);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adding Desktop and My Documents */
|
|
|
|
SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0);
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu_insert_entry(fsmenu,FS_CATEGORY_BOOKMARKS, folder, 1, 0);
|
2009-01-06 14:42:54 +00:00
|
|
|
SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0);
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, folder, 1, 0);
|
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)
|
2009-05-02 03:09:40 +00:00
|
|
|
OSErr err=noErr;
|
|
|
|
int i;
|
2009-12-17 09:23:47 +00:00
|
|
|
char *home;
|
2009-05-02 03:09:40 +00:00
|
|
|
|
|
|
|
/* loop through all the OS X Volumes, and add them to the SYSTEM section */
|
|
|
|
for (i=1; err!=nsvErr; i++)
|
|
|
|
{
|
|
|
|
FSRef dir;
|
|
|
|
unsigned char path[FILE_MAXDIR+FILE_MAXFILE];
|
|
|
|
|
|
|
|
err = FSGetVolumeInfo(kFSInvalidVolumeRefNum, i, NULL, kFSVolInfoNone, NULL, NULL, &dir);
|
|
|
|
if (err != noErr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FSRefMakePath(&dir, path, FILE_MAXDIR+FILE_MAXFILE);
|
2009-12-17 09:23:47 +00:00
|
|
|
if (strcmp((char*)path, "/home") && strcmp((char*)path, "/net"))
|
|
|
|
{ /* /net and /home are meaningless on OSX, home folders are stored in /Users */
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* As 10.4 doesn't provide proper API to retrieve the favorite places,
|
|
|
|
assume they are the standard ones
|
|
|
|
TODO : replace hardcoded paths with proper BLI_get_folder calls */
|
|
|
|
home = BLI_gethome();
|
|
|
|
if(home) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (i=0; i<pathesCount; i++)
|
|
|
|
{
|
|
|
|
itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
|
|
|
|
|
|
|
|
err = LSSharedFileListItemResolve(itemRef,
|
|
|
|
kLSSharedFileListNoUserInteraction
|
|
|
|
| kLSSharedFileListDoNotMountVolumes,
|
|
|
|
&cfURL, NULL);
|
|
|
|
if (err != noErr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
|
|
|
|
|
|
|
|
if (!CFStringGetCString(pathString,line,256,kCFStringEncodingASCII))
|
|
|
|
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;
|
|
|
|
for (i=1; err!=nsvErr; i++)
|
|
|
|
{
|
|
|
|
FSRef dir;
|
|
|
|
FSVolumeRefNum volRefNum;
|
|
|
|
struct GetVolParmsInfoBuffer volParmsBuffer;
|
|
|
|
unsigned char path[FILE_MAXDIR+FILE_MAXFILE];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
FSRefMakePath(&dir, path, FILE_MAXDIR+FILE_MAXFILE);
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally get user favorite places */
|
2009-12-17 09:23:47 +00:00
|
|
|
list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
|
|
|
|
pathesArray = LSSharedFileListCopySnapshot(list, &seed);
|
|
|
|
pathesCount = CFArrayGetCount(pathesArray);
|
|
|
|
|
|
|
|
for (i=0; i<pathesCount; i++)
|
|
|
|
{
|
|
|
|
itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
|
|
|
|
|
|
|
|
err = LSSharedFileListItemResolve(itemRef,
|
|
|
|
kLSSharedFileListNoUserInteraction
|
|
|
|
| kLSSharedFileListDoNotMountVolumes,
|
|
|
|
&cfURL, NULL);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(pathesArray);
|
|
|
|
CFRelease(list);
|
|
|
|
#endif /* OSX 10.5+ */
|
2009-05-02 03:09:40 +00:00
|
|
|
}
|
2009-07-28 16:46:14 +00:00
|
|
|
#else
|
|
|
|
/* unix */
|
|
|
|
{
|
|
|
|
char dir[FILE_MAXDIR];
|
|
|
|
char *home= BLI_gethome();
|
|
|
|
|
|
|
|
if(home) {
|
|
|
|
BLI_snprintf(dir, FILE_MAXDIR, "%s/", home);
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, dir, 1, 0);
|
|
|
|
BLI_snprintf(dir, FILE_MAXDIR, "%s/Desktop/", home);
|
2009-07-29 22:37:33 +00:00
|
|
|
if (BLI_exists(dir)) {
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, dir, 1, 0);
|
|
|
|
}
|
2009-07-28 16:46:14 +00:00
|
|
|
}
|
2009-07-28 22:44:50 +00:00
|
|
|
|
|
|
|
{
|
2009-07-29 21:35:03 +00:00
|
|
|
int found= 0;
|
|
|
|
#ifdef __linux__
|
2009-07-28 22:44:50 +00:00
|
|
|
/* loop over mount points */
|
|
|
|
struct mntent *mnt;
|
|
|
|
FILE *fp;
|
2009-07-29 21:35:03 +00:00
|
|
|
int len;
|
|
|
|
|
2009-07-28 22:44:50 +00:00
|
|
|
fp = setmntent (MOUNTED, "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
fprintf(stderr, "could not get a list of mounted filesystemts\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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 */
|
|
|
|
if(strncmp(mnt->mnt_fsname, "/dev", 4))
|
2009-07-28 22:44:50 +00:00
|
|
|
continue;
|
2009-07-29 21:35:03 +00:00
|
|
|
|
|
|
|
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);
|
2009-07-28 22:44:50 +00:00
|
|
|
}
|
2009-07-29 21:35:03 +00:00
|
|
|
else
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, 1, 0);
|
2009-07-28 22:44:50 +00:00
|
|
|
|
2009-07-29 21:35:03 +00:00
|
|
|
found= 1;
|
2009-07-28 22:44:50 +00:00
|
|
|
}
|
|
|
|
if (endmntent (fp) == 0) {
|
|
|
|
fprintf(stderr, "could not close the list of mounted filesystemts\n");
|
|
|
|
}
|
|
|
|
}
|
2009-07-29 21:35:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
if(!found)
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", 1, 0);
|
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-02-01 13:52:11 +00:00
|
|
|
fp = fopen(filename, "r");
|
2009-01-06 14:42:54 +00:00
|
|
|
if (!fp) return;
|
|
|
|
|
|
|
|
while ( fgets ( line, 256, fp ) != NULL ) /* read a line */
|
|
|
|
{
|
2009-03-12 19:36:59 +00:00
|
|
|
if (strncmp(line, "[Bookmarks]", 11)==0){
|
|
|
|
category = FS_CATEGORY_BOOKMARKS;
|
|
|
|
} else if (strncmp(line, "[Recent]", 8)==0){
|
|
|
|
category = FS_CATEGORY_RECENT;
|
|
|
|
} else {
|
|
|
|
int len = strlen(line);
|
|
|
|
if (len>0) {
|
|
|
|
if (line[len-1] == '\n') {
|
|
|
|
line[len-1] = '\0';
|
|
|
|
}
|
2009-07-27 19:06:33 +00:00
|
|
|
if (BLI_exist(line)) {
|
|
|
|
fsmenu_insert_entry(fsmenu, category, line, 0, 1);
|
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
static void fsmenu_free_category(struct FSMenu* fsmenu, FSMenuCategory category)
|
2008-12-18 19:21:30 +00:00
|
|
|
{
|
2009-03-12 19:36:59 +00:00
|
|
|
FSMenuEntry *fsme= fsmenu_get_category(fsmenu, category);
|
2008-12-18 19:21:30 +00:00
|
|
|
|
|
|
|
while (fsme) {
|
|
|
|
FSMenuEntry *n= fsme->next;
|
|
|
|
|
|
|
|
if (fsme->path) MEM_freeN(fsme->path);
|
|
|
|
MEM_freeN(fsme);
|
|
|
|
|
|
|
|
fsme= n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:36:59 +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
|
|
|
}
|
2008-12-18 19:21:30 +00:00
|
|
|
|