1 /*****************************************************************************
2 * dirs.c: directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
5 * Copyright © 2007-2008 Rémi Denis-Courmont
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <vlc_common.h>
36 #include "../libvlc.h"
37 #include <vlc_charset.h>
38 #include <vlc_configuration.h>
39 #include "config/configuration.h"
44 char *config_GetDataDirDefault( void )
46 return strdup (psz_vlcpath);
49 const char *config_GetLibDir (void)
54 const char *config_GetConfDir (void)
56 static char appdir[PATH_MAX] = "";
57 wchar_t wdir[MAX_PATH];
59 #warning FIXME: thread-safety!
63 #if defined (UNDER_CE)
64 /*There are some errors in cegcc headers*/
65 #undef SHGetSpecialFolderPath
66 BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
67 if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
69 /* Get the "Application Data" folder for all users */
70 if( S_OK == SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA
71 | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wdir ) )
74 WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
75 appdir, PATH_MAX, NULL, NULL);
81 static char *config_GetShellDir (int csidl)
83 wchar_t wdir[MAX_PATH];
85 #if defined (UNDER_CE)
86 /*There are some errors in cegcc headers*/
87 #undef SHGetSpecialFolderPath
88 BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
89 if (SHGetSpecialFolderPath (NULL, wdir, CSIDL_APPDATA, 1))
91 if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
92 NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
94 return FromWide (wdir);
98 static char *config_GetAppDir (void)
101 char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
103 if (psz_parent == NULL
104 || asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
110 #warning FIXME Use known folders on Vista and above
111 char *config_GetUserDir (vlc_userdir_t type)
116 return config_GetShellDir (CSIDL_PERSONAL);
120 return config_GetAppDir ();
122 case VLC_DESKTOP_DIR:
123 case VLC_DOWNLOAD_DIR:
124 case VLC_TEMPLATES_DIR:
125 case VLC_PUBLICSHARE_DIR:
126 case VLC_DOCUMENTS_DIR:
127 return config_GetUserDir(VLC_HOME_DIR);
129 return config_GetShellDir (CSIDL_MYMUSIC);
130 case VLC_PICTURES_DIR:
131 return config_GetShellDir (CSIDL_MYPICTURES);
133 return config_GetShellDir (CSIDL_MYVIDEO);