1 /*****************************************************************************
2 * dirs_macos.c: Mac OS X directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2009 the VideoLAN team
5 * Copyright © 2007-2009 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
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 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 General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, 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_charset.h>
35 #include <vlc_configuration.h>
36 #include "configuration.h"
38 static char *configdir = NULL;
40 static pthread_once_t once = PTHREAD_ONCE_INIT;
42 static void init_dirs( void )
44 configdir = config_GetUserDir(VLC_CONFIG_DIR);
47 const char *config_GetConfDir( void )
49 pthread_once(&once, init_dirs);
53 char *config_GetDataDirDefault (void)
57 if (asprintf (&datadir, "%s/share", psz_vlcpath) == -1)
62 const char *config_GetLibDir (void)
67 static char *config_GetHomeDir (void)
69 const char *home = getenv ("HOME");
74 return FromLocaleDup (home);
77 static char *getAppDependentDir(vlc_userdir_t type)
83 psz_path = "%s/Library/Preferences/%s";
85 case VLC_TEMPLATES_DIR:
87 psz_path = "%s/Library/Application Support/%s";
90 psz_path = "%s/Library/Caches/%s";
98 const char *name = "org.videolan.vlc";
100 CFBundleRef mainBundle = CFBundleGetMainBundle();
103 CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle);
106 char identifier[256];
107 Boolean ret = CFStringGetCString(identifierAsNS, identifier, sizeof(identifier), kCFStringEncodingUTF8);
113 char *psz_parent = config_GetHomeDir ();
115 if( asprintf( &psz_dir, psz_path, psz_parent, name) == -1 )
122 char *config_GetUserDir (vlc_userdir_t type)
124 const char *psz_path;
128 case VLC_TEMPLATES_DIR:
131 return getAppDependentDir(type);
133 case VLC_DESKTOP_DIR:
134 psz_path = "%s/Desktop";
136 case VLC_DOWNLOAD_DIR:
137 psz_path = "%s/Downloads";
139 case VLC_DOCUMENTS_DIR:
140 psz_path = "%s/Documents";
143 psz_path = "%s/Music";
145 case VLC_PICTURES_DIR:
146 psz_path = "%s/Pictures";
149 psz_path = "%s/Movies";
151 case VLC_PUBLICSHARE_DIR:
152 psz_path = "%s/Public";
158 char *psz_parent = config_GetHomeDir ();
160 if( asprintf( &psz_dir, psz_path, psz_parent ) == -1 )