1 /*****************************************************************************
2 * darwin_dirs.c: Mac OS X directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2014 VLC authors and VideoLAN
5 * Copyright (C) 2007-2012 Rémi Denis-Courmont
7 * Authors: Rémi Denis-Courmont
8 * Felix Paul Kühne <fkuehne at videolan dot org>
9 * Pierre d'Herbemont <pdherbemont # videolan org>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #include <CoreFoundation/CoreFoundation.h>
32 #include <vlc_common.h>
34 #include "../libvlc.h"
35 #include <vlc_configuration.h>
36 #include "config/configuration.h"
40 #include <mach-o/dyld.h>
43 # define MAXPATHLEN 1024
46 char *config_GetLibDir (void)
48 /* Get the full program path and name */
49 /* First try to see if we are linked to the framework */
50 for (unsigned i = 0; i < _dyld_image_count(); i++)
52 const char *psz_img_name = _dyld_get_image_name(i);
53 const char *p = strstr( psz_img_name, "VLCKit.framework/Versions/" );
55 /* Check for "VLCKit.framework/Versions/Current/VLCKit",
56 * as well as "VLCKit.framework/Versions/A/VLCKit" and
57 * "VLC.framework/Versions/B/VLCKit" */
59 /* Look for the next forward slash */
60 p += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
61 p += strcspn( p, "/" );
63 /* If the string ends with VLCKit then we've found a winner */
64 if (!strcmp( p, "/VLCKit"))
65 return strdup( dirname(psz_img_name) );
68 /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
70 size_t len = strlen(psz_img_name);
71 if (len >= 3 && !strcmp( psz_img_name + len - 3, "VLC"))
72 return strdup( dirname(psz_img_name) );
74 /* Do we end by "VLC-Plugin"? oh, we must be the NPAPI plugin */
75 if (len >= 10 && !strcmp( psz_img_name + len - 10, "VLC-Plugin"))
76 return strdup( dirname(psz_img_name) );
79 /* we are not part of any Mac-style package but were installed
80 * the UNIX way. let's trick-around a bit */
82 if (dladdr(system_Init, &info)) {
83 char *incompletepath = strdup(dirname( (char *)info.dli_fname ));
85 asprintf(&path, "%s/"PACKAGE, incompletepath);
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";
135 vlc_assert_unreachable();
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)