]> git.sesse.net Git - vlc/blob - src/config/dirs_macos.c
Add --data-path option. Access the src share directory now works from build tree.
[vlc] / src / config / dirs_macos.c
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
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Felix Paul Kühne <fkuehne at videolan dot org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30
31 #include "../libvlc.h"
32 #include <vlc_charset.h>
33 #include <vlc_configuration.h>
34
35 static char *configdir = NULL;
36 static char *datadir = NULL;
37
38 static pthread_once_t once = PTHREAD_ONCE_INIT;
39
40 static void init_dirs( void )
41 {
42     configdir = config_GetUserDir(VLC_CONFIG_DIR);
43     datadir = config_GetUserDir(VLC_DATA_DIR);
44 }
45
46 const char *config_GetConfDir( void )
47 {
48     pthread_once(&once, init_dirs);
49     return configdir;
50 }
51
52 const char *config_GetDataDirDefault (void)
53 {
54     pthread_once(&once, init_dirs);
55     return datadir;
56 }
57
58 static char *config_GetHomeDir (void)
59 {
60     const char *home = getenv ("HOME");
61
62     if (home == NULL)
63         home = "/tmp";
64
65     return FromLocaleDup (home);
66 }
67
68 char *config_GetUserDir (vlc_userdir_t type)
69 {
70     char *psz_dir;
71     char *psz_parent = config_GetHomeDir ();
72     const char *psz_path;
73
74     switch (type)
75     {
76         case VLC_CONFIG_DIR:
77             psz_path = "%s/Library/Preferences/VLC";
78             break;
79         case VLC_TEMPLATES_DIR:
80         case VLC_DATA_DIR:
81             psz_path = "%s/Library/Application Support/VLC";
82             break;
83         case VLC_DESKTOP_DIR:
84             psz_path = "%s/Desktop";
85             break;
86         case VLC_DOWNLOAD_DIR:
87             psz_path = "%s/Downloads";
88             break;
89         case VLC_DOCUMENTS_DIR:
90             psz_path = "%s/Documents";
91             break;
92         case VLC_MUSIC_DIR:
93             psz_path = "%s/Music";
94             break;
95         case VLC_PICTURES_DIR:
96             psz_path = "%s/Pictures";
97             break;
98         case VLC_VIDEOS_DIR:
99             psz_path = "%s/Movies";
100             break;
101         case VLC_PUBLICSHARE_DIR:
102             psz_path = "%s/Public";
103             break;
104         case VLC_CACHE_DIR:
105             psz_path = "%s/Library/Caches/org.videolan.vlc";
106             break;
107         case VLC_HOME_DIR:
108         default:
109             psz_path = "%s";
110     }
111     if( asprintf( &psz_dir, psz_path, psz_parent ) == -1 )
112         psz_dir = NULL;
113     free(psz_parent);
114     return psz_dir;
115 }