]> git.sesse.net Git - vlc/blob - src/config/dirs_win.c
65d7aefa88cf3e92afc4ebfa8b7ae04474f3c6ed
[vlc] / src / config / dirs_win.c
1 /*****************************************************************************
2  * dirs.c: directories configuration
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * Copyright © 2007-2008 Rémi Denis-Courmont
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29
30 #ifndef _WIN32_IE
31 # define _WIN32_IE 0x0501
32 #endif
33 #include <w32api.h>
34 #ifndef UNDER_CE
35 # include <direct.h>
36 #endif
37 #include <shlobj.h>
38
39 #include "../libvlc.h"
40 #include <vlc_charset.h>
41 #include <vlc_configuration.h>
42
43 #include <assert.h>
44 #include <limits.h>
45
46 const char *config_GetDataDir( void )
47 {
48     static char path[PATH_MAX] = "";
49 #warning FIXME: thread-safety!
50
51     if( *path == '\0' )
52         strlcpy (path, psz_vlcpath, sizeof (path));
53     return path;
54 }
55
56 const char *config_GetConfDir (void)
57 {
58     static char appdir[PATH_MAX] = "";
59     wchar_t wdir[MAX_PATH];
60
61 #warning FIXME: thread-safety!
62     if (*appdir)
63         return appdir;
64
65 #if defined (UNDER_CE)
66     /*There are some errors in cegcc headers*/
67 #undef SHGetSpecialFolderPath
68     BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
69     if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
70 #else
71     /* Get the "Application Data" folder for the current user */
72     if( S_OK == SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA
73               | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wdir ) )
74 #endif
75     {
76         WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
77                              appdir, PATH_MAX, NULL, NULL);
78         return appdir;
79     }
80     return NULL;
81 }
82
83 static char *config_GetShellDir (int csidl)
84 {
85     wchar_t wdir[MAX_PATH];
86
87 #if defined (UNDER_CE)
88     /*There are some errors in cegcc headers*/
89 #undef SHGetSpecialFolderPath
90     BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
91     if (SHGetSpecialFolderPath (NULL, wdir, CSIDL_APPDATA, 1))
92 #else
93     if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
94                           NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
95 #endif
96         return FromWide (wdir);
97     return NULL;
98 }
99
100 static char *config_GetAppDir (void)
101 {
102     char *psz_dir;
103     char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
104
105     if (psz_parent == NULL
106      ||  asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
107         psz_dir = NULL;
108     free (psz_parent);
109     return psz_dir;
110 }
111
112 #warning FIXME Use known folders on Vista and above
113 char *config_GetUserDir (vlc_userdir_t type)
114 {
115     switch (type)
116     {
117         case VLC_HOME_DIR:
118             return config_GetShellDir (CSIDL_PERSONAL);
119         case VLC_CONFIG_DIR:
120         case VLC_DATA_DIR:
121         case VLC_CACHE_DIR:
122             return config_GetAppDir ();
123
124         case VLC_DESKTOP_DIR:
125         case VLC_DOWNLOAD_DIR:
126         case VLC_TEMPLATES_DIR:
127         case VLC_PUBLICSHARE_DIR:
128         case VLC_DOCUMENTS_DIR:
129             return config_GetUserDir(VLC_HOME_DIR);
130         case VLC_MUSIC_DIR:
131             return config_GetShellDir (CSIDL_MYMUSIC);
132         case VLC_PICTURES_DIR:
133             return config_GetShellDir (CSIDL_MYPICTURES);
134         case VLC_VIDEOS_DIR:
135             return config_GetShellDir (CSIDL_MYVIDEO);
136     }
137     assert (0);
138 }