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 *****************************************************************************/
34 #include <vlc_common.h>
42 #include "../libvlc.h"
43 #include <vlc_charset.h>
44 #include <vlc_configuration.h>
45 #include "config/configuration.h"
51 #include <winstring.h>
52 #include <windows.storage.h>
55 static HRESULT
WinRTSHGetFolderPath(HWND hwnd
, int csidl
, HANDLE hToken
, DWORD dwFlags
, LPWSTR pszPath
)
61 IStorageFolder
*folder
;
63 if (dwFlags
!= SHGFP_TYPE_CURRENT
)
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
);
81 hr
= RoGetActivationFactory(hClassName
, &IID_IApplicationDataStatics
, (void**)&appDataStatics
);
86 if (!appDataStatics
) {
91 hr
= IApplicationDataStatics_get_Current(appDataStatics
, &appData
);
101 hr
= IApplicationData_get_LocalFolder(appData
, &folder
);
104 WindowsDeleteString(hClassName
);
106 IApplicationDataStatics_Release(appDataStatics
);
108 IApplicationData_Release(appData
);
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
);
122 hr
= RoGetActivationFactory(hClassName
, &IID_IKnownFoldersStatics
, (void**)&knownFoldersStatics
);
127 if (!knownFoldersStatics
) {
134 hr
= IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics
, &folder
);
137 hr
= IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics
, &folder
);
139 case CSIDL_MYPICTURES
:
140 hr
= IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics
, &folder
);
143 hr
= IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics
, &folder
);
150 WindowsDeleteString(hClassName
);
151 if (knownFoldersStatics
)
152 IKnownFoldersStatics_Release(knownFoldersStatics
);
155 if( SUCCEEDED(hr
) && folder
!= NULL
)
158 IStorageItem
*item
= NULL
;
160 hr
= IStorageFolder_QueryInterface(folder
, &IID_IStorageItem
, (void**)&item
);
163 hr
= IStorageItem_get_Path(item
, &path
);
166 pszPathTemp
= WindowsGetStringRawBuffer(path
, NULL
);
167 wcscpy(pszPath
, pszPathTemp
);
169 WindowsDeleteString(path
);
170 IStorageFolder_Release(folder
);
172 IStorageItem_Release(item
);
177 #define SHGetFolderPathW WinRTSHGetFolderPath
180 char *config_GetLibDir (void)
185 /* Get our full path */
186 MEMORY_BASIC_INFORMATION mbi
;
187 if (!VirtualQuery (config_GetLibDir
, &mbi
, sizeof(mbi
)))
190 wchar_t wpath
[MAX_PATH
];
191 if (!GetModuleFileName ((HMODULE
) mbi
.AllocationBase
, wpath
, MAX_PATH
))
194 wchar_t *file
= wcsrchr (wpath
, L
'\\');
199 return FromWide (wpath
);
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
);
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
, '\\');
231 _tcscpy (lastDir
+ 1, TEXT("portable"));
232 DWORD attrib
= GetFileAttributes (path
);
233 if (attrib
!= INVALID_FILE_ATTRIBUTES
&&
234 (attrib
& FILE_ATTRIBUTE_DIRECTORY
))
241 char *psz_parent
= config_GetShellDir (CSIDL_APPDATA
);
243 if (psz_parent
== NULL
244 || asprintf (&psz_dir
, "%s\\vlc", psz_parent
) == -1)
250 #warning FIXME Use known folders on Vista and above
251 char *config_GetUserDir (vlc_userdir_t type
)
256 return config_GetShellDir (CSIDL_PERSONAL
);
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
);
269 return config_GetShellDir (CSIDL_MYMUSIC
);
270 case VLC_PICTURES_DIR
:
271 return config_GetShellDir (CSIDL_MYPICTURES
);
273 return config_GetShellDir (CSIDL_MYVIDEO
);
275 vlc_assert_unreachable ();