1 /*****************************************************************************
2 * darwin_dirs.c: Darwin directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2016 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 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_charset.h>
32 #include "../libvlc.h"
37 #include <Foundation/Foundation.h>
39 static bool config_isBundle()
41 NSBundle *bundle = [NSBundle mainBundle];
42 NSString *bundlePath = bundle.bundlePath;
43 return [bundlePath hasSuffix:@".app"] || [bundlePath hasSuffix:@".framework"];
46 static char *config_getLibraryDirReal(const char *fallback)
48 const char *dir = getenv("VLC_LIB_PATH");
53 if (config_isBundle()) {
54 NSBundle *bundle = [NSBundle mainBundle];
55 NSString *path = bundle.privateFrameworksPath;
59 return strdup(path.UTF8String);
63 return strdup(fallback);
68 static char *config_getDataDirReal(const char *fallback)
70 const char *dir = getenv("VLC_DATA_PATH");
75 if (config_isBundle()) {
76 NSBundle *bundle = [NSBundle mainBundle];
77 NSString *path = bundle.resourcePath;
81 path = [path stringByAppendingPathComponent:@"share"];
82 return strdup(path.UTF8String);
86 return strdup(fallback);
91 char *config_GetLibDir(void)
93 return config_getLibraryDirReal(LIBDIR);
96 char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
101 case VLC_PKG_DATA_DIR:
102 dir = config_getDataDirReal(PKGDATADIR);
105 case VLC_PKG_LIB_DIR:
106 dir = config_getLibraryDirReal(PKGLIBDIR);
109 dir = config_getLibraryDirReal(LIBDIR);
113 case VLC_PKG_LIBEXEC_DIR:
114 dir = config_getLibraryDirReal(PKGLIBEXECDIR);
116 case VLC_LIBEXEC_DIR:
117 dir = config_getLibraryDirReal(LIBEXECDIR);
121 dir = config_getDataDirReal(NULL);
123 NSString *result = [NSString stringWithFormat:@"%s/locale", dir];
125 dir = strdup(result.UTF8String);
129 dir = strdup(LOCALEDIR);
132 case VLC_SYSDATA_DIR:
135 vlc_assert_unreachable();
138 if (filename == NULL || unlikely(dir == NULL))
142 asprintf(&path, "%s/%s", dir, filename);
147 static char *config_GetHomeDir (void)
149 const char *home = getenv ("HOME");
154 return strdup (home);
157 static char *getAppDependentDir(vlc_userdir_t type)
159 NSString *formatString;
162 formatString = @"%s/Library/Preferences/%@";
164 case VLC_TEMPLATES_DIR:
165 case VLC_USERDATA_DIR:
166 formatString = @"%s/Library/Application Support/%@";
169 formatString = @"%s/Library/Caches/%@";
172 vlc_assert_unreachable();
177 NSString *identifier = @"org.videolan.vlc";
178 NSBundle *mainBundle = [NSBundle mainBundle];
180 NSString *bundleId = mainBundle.bundleIdentifier;
182 identifier = bundleId;
185 char *homeDir = config_GetHomeDir();
186 NSString *result = [NSString stringWithFormat:formatString, homeDir, identifier];
188 return strdup(result.UTF8String);
191 char *config_GetUserDir (vlc_userdir_t type)
193 const char *psz_path;
196 case VLC_TEMPLATES_DIR:
197 case VLC_USERDATA_DIR:
199 return getAppDependentDir(type);
201 case VLC_DESKTOP_DIR:
202 psz_path = "%s/Desktop";
204 case VLC_DOWNLOAD_DIR:
205 psz_path = "%s/Downloads";
207 case VLC_DOCUMENTS_DIR:
208 psz_path = "%s/Documents";
211 psz_path = "%s/Music";
213 case VLC_PICTURES_DIR:
214 psz_path = "%s/Pictures";
217 psz_path = "%s/Movies";
219 case VLC_PUBLICSHARE_DIR:
220 psz_path = "%s/Public";
226 char *psz_parent = config_GetHomeDir();
228 if (asprintf( &psz_dir, psz_path, psz_parent ) == -1)