1 /*****************************************************************************
2 * dirs.c: directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2010 VLC authors and VideoLAN
5 * Copyright © 2007-2012 Rémi Denis-Courmont
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
37 #include "../libvlc.h"
38 #include <vlc_charset.h>
39 #include <vlc_configuration.h>
40 #include "config/configuration.h"
45 char *config_GetLibDir (void)
47 /* Get our full path */
48 MEMORY_BASIC_INFORMATION mbi;
49 if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
52 wchar_t wpath[MAX_PATH];
53 if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH))
56 wchar_t *file = wcsrchr (wpath, L'\\');
61 return FromWide (wpath);
66 char *config_GetDataDir (void)
68 const char *path = getenv ("VLC_DATA_PATH");
69 return (path != NULL) ? strdup (path) : config_GetLibDir ();
72 const char *config_GetConfDir (void)
74 static char appdir[PATH_MAX] = "";
75 wchar_t wdir[MAX_PATH];
77 #warning FIXME: thread-safety!
81 #if defined (UNDER_CE)
82 /*There are some errors in cegcc headers*/
83 #undef SHGetSpecialFolderPath
84 BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
85 if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
87 /* Get the "Application Data" folder for all users */
88 if( S_OK == SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA
89 | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wdir ) )
92 WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
93 appdir, PATH_MAX, NULL, NULL);
99 static char *config_GetShellDir (int csidl)
101 wchar_t wdir[MAX_PATH];
103 #if defined (UNDER_CE)
104 /*There are some errors in cegcc headers*/
105 #undef SHGetSpecialFolderPath
106 BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
107 if (SHGetSpecialFolderPath (NULL, wdir, CSIDL_APPDATA, 1))
109 if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
110 NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
112 return FromWide (wdir);
116 static char *config_GetAppDir (void)
119 char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
121 if (psz_parent == NULL
122 || asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
128 #warning FIXME Use known folders on Vista and above
129 char *config_GetUserDir (vlc_userdir_t type)
134 return config_GetShellDir (CSIDL_PERSONAL);
138 return config_GetAppDir ();
140 case VLC_DESKTOP_DIR:
141 case VLC_DOWNLOAD_DIR:
142 case VLC_TEMPLATES_DIR:
143 case VLC_PUBLICSHARE_DIR:
144 case VLC_DOCUMENTS_DIR:
145 return config_GetUserDir(VLC_HOME_DIR);
147 return config_GetShellDir (CSIDL_MYMUSIC);
148 case VLC_PICTURES_DIR:
149 return config_GetShellDir (CSIDL_MYPICTURES);
151 return config_GetShellDir (CSIDL_MYVIDEO);