demux: adaptive: missing es_format_Init
[vlc.git] / src / win32 / dirs.c
blob23fef44baa140d2c04b7af72fb9c707bd06530a3
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #define COBJMACROS
29 #define INITGUID
31 #ifndef UNICODE
32 #define UNICODE
33 #endif
34 #include <vlc_common.h>
36 #ifdef __MINGW32__
37 # include <w32api.h>
38 #endif
39 #include <direct.h>
40 #include <shlobj.h>
42 #include "../libvlc.h"
43 #include <vlc_charset.h>
44 #include <vlc_configuration.h>
45 #include "config/configuration.h"
47 #include <assert.h>
48 #include <limits.h>
50 #if VLC_WINSTORE_APP
51 #include <winstring.h>
52 #include <windows.storage.h>
53 #include <roapi.h>
55 static HRESULT WinRTSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
57 VLC_UNUSED(hwnd);
58 VLC_UNUSED(hToken);
60 HRESULT hr;
61 IStorageFolder *folder;
63 if (dwFlags != SHGFP_TYPE_CURRENT)
64 return E_NOTIMPL;
66 folder = NULL;
67 csidl &= ~0xFF00; /* CSIDL_FLAG_MASK */
69 if (csidl == CSIDL_APPDATA) {
70 IApplicationDataStatics *appDataStatics = NULL;
71 IApplicationData *appData = NULL;
72 static const WCHAR *className = L"Windows.Storage.ApplicationData";
73 const UINT32 clen = wcslen(className);
75 HSTRING hClassName = NULL;
76 HSTRING_HEADER header;
77 hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
78 if (FAILED(hr))
79 goto end_appdata;
81 hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics);
83 if (FAILED(hr))
84 goto end_appdata;
86 if (!appDataStatics) {
87 hr = E_FAIL;
88 goto end_appdata;
91 hr = IApplicationDataStatics_get_Current(appDataStatics, &appData);
93 if (FAILED(hr))
94 goto end_appdata;
96 if (!appData) {
97 hr = E_FAIL;
98 goto end_appdata;
101 hr = IApplicationData_get_LocalFolder(appData, &folder);
103 end_appdata:
104 WindowsDeleteString(hClassName);
105 if (appDataStatics)
106 IApplicationDataStatics_Release(appDataStatics);
107 if (appData)
108 IApplicationData_Release(appData);
110 else
112 IKnownFoldersStatics *knownFoldersStatics = NULL;
113 static const WCHAR *className = L"Windows.Storage.KnownFolders";
114 const UINT32 clen = wcslen(className);
116 HSTRING hClassName = NULL;
117 HSTRING_HEADER header;
118 hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
119 if (FAILED(hr))
120 goto end_other;
122 hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, (void**)&knownFoldersStatics);
124 if (FAILED(hr))
125 goto end_other;
127 if (!knownFoldersStatics) {
128 hr = E_FAIL;
129 goto end_other;
132 switch (csidl) {
133 case CSIDL_PERSONAL:
134 hr = IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics, &folder);
135 break;
136 case CSIDL_MYMUSIC:
137 hr = IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics, &folder);
138 break;
139 case CSIDL_MYPICTURES:
140 hr = IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics, &folder);
141 break;
142 case CSIDL_MYVIDEO:
143 hr = IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics, &folder);
144 break;
145 default:
146 hr = E_NOTIMPL;
149 end_other:
150 WindowsDeleteString(hClassName);
151 if (knownFoldersStatics)
152 IKnownFoldersStatics_Release(knownFoldersStatics);
155 if( SUCCEEDED(hr) && folder != NULL )
157 HSTRING path = NULL;
158 IStorageItem *item = NULL;
159 PCWSTR pszPathTemp;
160 hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item);
161 if (FAILED(hr))
162 goto end_folder;
163 hr = IStorageItem_get_Path(item, &path);
164 if (FAILED(hr))
165 goto end_folder;
166 pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
167 wcscpy(pszPath, pszPathTemp);
168 end_folder:
169 WindowsDeleteString(path);
170 IStorageFolder_Release(folder);
171 if (item)
172 IStorageItem_Release(item);
175 return hr;
177 #define SHGetFolderPathW WinRTSHGetFolderPath
178 #endif
180 char *config_GetLibDir (void)
182 #if VLC_WINSTORE_APP
183 return NULL;
184 #else
185 /* Get our full path */
186 MEMORY_BASIC_INFORMATION mbi;
187 if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
188 goto error;
190 wchar_t wpath[MAX_PATH];
191 if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH))
192 goto error;
194 wchar_t *file = wcsrchr (wpath, L'\\');
195 if (file == NULL)
196 goto error;
197 *file = L'\0';
199 return FromWide (wpath);
200 error:
201 abort ();
202 #endif
205 char *config_GetDataDir (void)
207 const char *path = getenv ("VLC_DATA_PATH");
208 return (path != NULL) ? strdup (path) : config_GetLibDir ();
211 static char *config_GetShellDir (int csidl)
213 wchar_t wdir[MAX_PATH];
215 if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
216 NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
217 return FromWide (wdir);
218 return NULL;
221 static char *config_GetAppDir (void)
223 #if !VLC_WINSTORE_APP
224 /* if portable directory exists, use it */
225 TCHAR path[MAX_PATH];
226 if (GetModuleFileName (NULL, path, MAX_PATH))
228 TCHAR *lastDir = _tcsrchr (path, '\\');
229 if (lastDir)
231 _tcscpy (lastDir + 1, TEXT("portable"));
232 DWORD attrib = GetFileAttributes (path);
233 if (attrib != INVALID_FILE_ATTRIBUTES &&
234 (attrib & FILE_ATTRIBUTE_DIRECTORY))
235 return FromT (path);
238 #endif
240 char *psz_dir;
241 char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
243 if (psz_parent == NULL
244 || asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
245 psz_dir = NULL;
246 free (psz_parent);
247 return psz_dir;
250 #warning FIXME Use known folders on Vista and above
251 char *config_GetUserDir (vlc_userdir_t type)
253 switch (type)
255 case VLC_HOME_DIR:
256 return config_GetShellDir (CSIDL_PERSONAL);
257 case VLC_CONFIG_DIR:
258 case VLC_DATA_DIR:
259 case VLC_CACHE_DIR:
260 return config_GetAppDir ();
262 case VLC_DESKTOP_DIR:
263 case VLC_DOWNLOAD_DIR:
264 case VLC_TEMPLATES_DIR:
265 case VLC_PUBLICSHARE_DIR:
266 case VLC_DOCUMENTS_DIR:
267 return config_GetUserDir(VLC_HOME_DIR);
268 case VLC_MUSIC_DIR:
269 return config_GetShellDir (CSIDL_MYMUSIC);
270 case VLC_PICTURES_DIR:
271 return config_GetShellDir (CSIDL_MYPICTURES);
272 case VLC_VIDEOS_DIR:
273 return config_GetShellDir (CSIDL_MYVIDEO);
275 vlc_assert_unreachable ();