1 /*****************************************************************************
2 * darwin_dirs.c: Mac OS X directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2009 VLC authors and VideoLAN
5 * Copyright © 2007-2012 Rémi Denis-Courmont
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include <CoreFoundation/CoreFoundation.h>
31 #include <vlc_common.h>
33 #include "../libvlc.h"
34 #include <vlc_configuration.h>
35 #include "config/configuration.h"
39 #include <mach-o/dyld.h>
42 # define MAXPATHLEN 1024
45 char *config_GetLibDir (void)
47 /* Get the full program path and name */
48 /* First try to see if we are linked to the framework */
49 for (unsigned i = 0; i < _dyld_image_count(); i++)
51 const char *psz_img_name = _dyld_get_image_name(i);
52 const char *p = strstr( psz_img_name, "VLCKit.framework/Versions/" );
54 /* Check for "VLCKit.framework/Versions/Current/VLCKit",
55 * as well as "VLCKit.framework/Versions/A/VLCKit" and
56 * "VLC.framework/Versions/B/VLCKit" */
58 /* Look for the next forward slash */
59 p += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
60 p += strcspn( p, "/" );
62 /* If the string ends with VLCKit then we've found a winner */
63 if (!strcmp( p, "/VLCKit"))
64 return strdup( dirname(psz_img_name) );
67 /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
69 size_t len = strlen(psz_img_name);
70 if (len >= 3 && !strcmp( psz_img_name + len - 3, "VLC"))
71 return strdup( dirname(psz_img_name) );
73 /* Do we end by "VLC-Plugin"? oh, we must be the NPAPI plugin */
74 if (len >= 10 && !strcmp( psz_img_name + len - 10, "VLC-Plugin"))
75 return strdup( dirname(psz_img_name) );
78 /* we are not part of any Mac-style package but were installed
79 * the UNIX way. let's trick-around a bit */
81 if (dladdr(system_Init, &info)) {
82 char *incompletepath = strdup(dirname( (char *)info.dli_fname ));
84 asprintf(&path, "%s/"PACKAGE, incompletepath);
86 printf("final path %s\n", path);
90 /* should never happen */
94 char *config_GetDataDir (void)
96 const char *path = getenv ("VLC_DATA_PATH");
100 char *vlcpath = config_GetLibDir ();
103 if (asprintf (&datadir, "%s/share", vlcpath) == -1)
110 static char *config_GetHomeDir (void)
112 const char *home = getenv ("HOME");
117 return strdup (home);
120 static char *getAppDependentDir(vlc_userdir_t type)
122 const char *psz_path;
125 psz_path = "%s/Library/Preferences/%s";
127 case VLC_TEMPLATES_DIR:
129 psz_path = "%s/Library/Application Support/%s";
132 psz_path = "%s/Library/Caches/%s";
140 const char *name = "org.videolan.vlc";
142 CFBundleRef mainBundle = CFBundleGetMainBundle();
144 CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle);
145 if (identifierAsNS) {
146 char identifier[256];
147 Boolean ret = CFStringGetCString(identifierAsNS, identifier, sizeof(identifier), kCFStringEncodingUTF8);
153 char *psz_parent = config_GetHomeDir ();
155 if ( asprintf( &psz_dir, psz_path, psz_parent, name) == -1 )
162 char *config_GetUserDir (vlc_userdir_t type)
164 const char *psz_path;
167 case VLC_TEMPLATES_DIR:
170 return getAppDependentDir(type);
172 case VLC_DESKTOP_DIR:
173 psz_path = "%s/Desktop";
175 case VLC_DOWNLOAD_DIR:
176 psz_path = "%s/Downloads";
178 case VLC_DOCUMENTS_DIR:
179 psz_path = "%s/Documents";
182 psz_path = "%s/Music";
184 case VLC_PICTURES_DIR:
185 psz_path = "%s/Pictures";
188 psz_path = "%s/Movies";
190 case VLC_PUBLICSHARE_DIR:
191 psz_path = "%s/Public";
197 char *psz_parent = config_GetHomeDir();
199 if (asprintf( &psz_dir, psz_path, psz_parent ) == -1)