]> git.sesse.net Git - vlc/blob - src/win32/dirs.c
Add port range to LUA telnet
[vlc] / src / win32 / dirs.c
1 /*****************************************************************************
2  * dirs.c: directories configuration
3  *****************************************************************************
4  * Copyright (C) 2001-2010 VLC authors and VideoLAN
5  * Copyright © 2007-2012 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 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.
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 Lesser General Public License for more details.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #define UNICODE
29 #include <vlc_common.h>
30
31 #include <w32api.h>
32 #ifndef UNDER_CE
33 # include <direct.h>
34 #endif
35 #include <shlobj.h>
36
37 #include "../libvlc.h"
38 #include <vlc_charset.h>
39 #include <vlc_configuration.h>
40 #include "config/configuration.h"
41
42 #include <assert.h>
43 #include <limits.h>
44
45 char *config_GetLibDir (void)
46 {
47     /* Get our full path */
48     MEMORY_BASIC_INFORMATION mbi;
49     if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
50         goto error;
51
52     wchar_t wpath[MAX_PATH];
53     if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH))
54         goto error;
55
56     wchar_t *file = wcsrchr (wpath, L'\\');
57     if (file == NULL)
58         goto error;
59     *file = L'\0';
60
61     return FromWide (wpath);
62 error:
63     abort ();
64 }
65
66 char *config_GetDataDir (void)
67 {
68     const char *path = getenv ("VLC_DATA_PATH");
69     return (path != NULL) ? strdup (path) : config_GetLibDir ();
70 }
71
72 const char *config_GetConfDir (void)
73 {
74     static char appdir[PATH_MAX] = "";
75     wchar_t wdir[MAX_PATH];
76
77 #warning FIXME: thread-safety!
78     if (*appdir)
79         return appdir;
80
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 ) )
86 #else
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 ) )
90 #endif
91     {
92         WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
93                              appdir, PATH_MAX, NULL, NULL);
94         return appdir;
95     }
96     return NULL;
97 }
98
99 static char *config_GetShellDir (int csidl)
100 {
101     wchar_t wdir[MAX_PATH];
102
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))
108 #else
109     if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
110                           NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
111 #endif
112         return FromWide (wdir);
113     return NULL;
114 }
115
116 static char *config_GetAppDir (void)
117 {
118     char *psz_dir;
119     char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
120
121     if (psz_parent == NULL
122      ||  asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
123         psz_dir = NULL;
124     free (psz_parent);
125     return psz_dir;
126 }
127
128 #warning FIXME Use known folders on Vista and above
129 char *config_GetUserDir (vlc_userdir_t type)
130 {
131     switch (type)
132     {
133         case VLC_HOME_DIR:
134             return config_GetShellDir (CSIDL_PERSONAL);
135         case VLC_CONFIG_DIR:
136         case VLC_DATA_DIR:
137         case VLC_CACHE_DIR:
138             return config_GetAppDir ();
139
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);
146         case VLC_MUSIC_DIR:
147             return config_GetShellDir (CSIDL_MYMUSIC);
148         case VLC_PICTURES_DIR:
149             return config_GetShellDir (CSIDL_MYPICTURES);
150         case VLC_VIDEOS_DIR:
151             return config_GetShellDir (CSIDL_MYVIDEO);
152     }
153     assert (0);
154 }