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 *****************************************************************************/
31 #include <vlc_common.h>
39 #include "../libvlc.h"
40 #include <vlc_charset.h>
41 #include <vlc_configuration.h>
42 #include "config/configuration.h"
47 char *config_GetLibDir (void)
52 /* Get our full path */
53 MEMORY_BASIC_INFORMATION mbi;
54 if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
57 wchar_t wpath[MAX_PATH];
58 if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH))
61 wchar_t *file = wcsrchr (wpath, L'\\');
66 return FromWide (wpath);
72 char *config_GetDataDir (void)
74 const char *path = getenv ("VLC_DATA_PATH");
75 return (path != NULL) ? strdup (path) : config_GetLibDir ();
78 static char *config_GetShellDir (int csidl)
80 wchar_t wdir[MAX_PATH];
82 if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
83 NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
84 return FromWide (wdir);
88 static char *config_GetAppDir (void)
91 char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
93 if (psz_parent == NULL
94 || asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
100 #warning FIXME Use known folders on Vista and above
101 char *config_GetUserDir (vlc_userdir_t type)
106 return config_GetShellDir (CSIDL_PERSONAL);
110 return config_GetAppDir ();
112 case VLC_DESKTOP_DIR:
113 case VLC_DOWNLOAD_DIR:
114 case VLC_TEMPLATES_DIR:
115 case VLC_PUBLICSHARE_DIR:
116 case VLC_DOCUMENTS_DIR:
117 return config_GetUserDir(VLC_HOME_DIR);
119 return config_GetShellDir (CSIDL_MYMUSIC);
120 case VLC_PICTURES_DIR:
121 return config_GetShellDir (CSIDL_MYPICTURES);
123 return config_GetShellDir (CSIDL_MYVIDEO);
125 vlc_assert_unreachable ();