]> git.sesse.net Git - vlc/blob - src/win32/dirs.c
Remove useless vlc_object_detach() before vlc_object_release()
[vlc] / src / win32 / dirs.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 #include "config/configuration.h"
43
44 #include <assert.h>
45 #include <limits.h>
46
47 char *config_GetDataDirDefault( void )
48 {
49     return strdup (psz_vlcpath);
50 }
51
52 const char *config_GetConfDir (void)
53 {
54     static char appdir[PATH_MAX] = "";
55     wchar_t wdir[MAX_PATH];
56
57 #warning FIXME: thread-safety!
58     if (*appdir)
59         return appdir;
60
61 #if defined (UNDER_CE)
62     /*There are some errors in cegcc headers*/
63 #undef SHGetSpecialFolderPath
64     BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
65     if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
66 #else
67     /* Get the "Application Data" folder for all users */
68     if( S_OK == SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA
69               | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wdir ) )
70 #endif
71     {
72         WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
73                              appdir, PATH_MAX, NULL, NULL);
74         return appdir;
75     }
76     return NULL;
77 }
78
79 static char *config_GetShellDir (int csidl)
80 {
81     wchar_t wdir[MAX_PATH];
82
83 #if defined (UNDER_CE)
84     /*There are some errors in cegcc headers*/
85 #undef SHGetSpecialFolderPath
86     BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
87     if (SHGetSpecialFolderPath (NULL, wdir, CSIDL_APPDATA, 1))
88 #else
89     if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
90                           NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
91 #endif
92         return FromWide (wdir);
93     return NULL;
94 }
95
96 static char *config_GetAppDir (void)
97 {
98     char *psz_dir;
99     char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
100
101     if (psz_parent == NULL
102      ||  asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
103         psz_dir = NULL;
104     free (psz_parent);
105     return psz_dir;
106 }
107
108 #warning FIXME Use known folders on Vista and above
109 char *config_GetUserDir (vlc_userdir_t type)
110 {
111     switch (type)
112     {
113         case VLC_HOME_DIR:
114             return config_GetShellDir (CSIDL_PERSONAL);
115         case VLC_CONFIG_DIR:
116         case VLC_DATA_DIR:
117         case VLC_CACHE_DIR:
118             return config_GetAppDir ();
119
120         case VLC_DESKTOP_DIR:
121         case VLC_DOWNLOAD_DIR:
122         case VLC_TEMPLATES_DIR:
123         case VLC_PUBLICSHARE_DIR:
124         case VLC_DOCUMENTS_DIR:
125             return config_GetUserDir(VLC_HOME_DIR);
126         case VLC_MUSIC_DIR:
127             return config_GetShellDir (CSIDL_MYMUSIC);
128         case VLC_PICTURES_DIR:
129             return config_GetShellDir (CSIDL_MYPICTURES);
130         case VLC_VIDEOS_DIR:
131             return config_GetShellDir (CSIDL_MYVIDEO);
132     }
133     assert (0);
134 }