[vlc-devel] [PATCH 1/9] win32: separate the directory reading for winstore builds

Steve Lhomme robux4 at ycbcr.xyz
Mon Apr 6 13:34:59 CEST 2020


---
 src/Makefile.am      |   7 +-
 src/win32/dirs-uap.c | 265 +++++++++++++++++++++++++++++++++++++++++++
 src/win32/dirs.c     | 140 -----------------------
 3 files changed, 268 insertions(+), 144 deletions(-)
 create mode 100644 src/win32/dirs-uap.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 88c6d903ae1..98de4fa48fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -397,7 +397,6 @@ libvlccore_la_LIBADD = $(LIBS_libvlccore) \
 
 if HAVE_WIN32
 libvlccore_la_SOURCES += \
-	win32/dirs.c \
 	win32/error.c \
 	win32/filesystem.c \
 	win32/netconf.c \
@@ -407,9 +406,9 @@ libvlccore_la_SOURCES += \
 	win32/thread.c \
 	win32/winsock.c
 if HAVE_WINSTORE
-libvlccore_la_SOURCES += posix/timer.c
+libvlccore_la_SOURCES += posix/timer.c win32/dirs-uap.c
 else
-libvlccore_la_SOURCES += win32/timer.c
+libvlccore_la_SOURCES += win32/timer.c win32/dirs.c
 endif
 endif
 
@@ -612,7 +611,7 @@ test_mrl_helpers_SOURCES = test/mrl_helpers.c
 test_arrays_SOURCES = test/arrays.c
 test_vector_SOURCES = test/vector.c
 test_shared_data_ptr_SOURCES = test/shared_data_ptr.cpp
-test_extensions_SOURCES = test/extensions.c 
+test_extensions_SOURCES = test/extensions.c
 test_playlist_SOURCES = playlist/test.c \
 	playlist/content.c \
 	playlist/control.c \
diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
new file mode 100644
index 00000000000..46286fc6149
--- /dev/null
+++ b/src/win32/dirs-uap.c
@@ -0,0 +1,265 @@
+/*****************************************************************************
+ * dirs.c: directories configuration
+ *****************************************************************************
+ * Copyright (C) 2001-2010 VLC authors and VideoLAN
+ * Copyright © 2007-2012 Rémi Denis-Courmont
+ *
+ * Authors: Gildas Bazin <gbazin at videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#define COBJMACROS
+#define INITGUID
+
+#ifndef UNICODE
+#define UNICODE
+#endif
+#include <vlc_common.h>
+
+#ifdef __MINGW32__
+# include <w32api.h>
+#endif
+#include <direct.h>
+#include <shlobj.h>
+
+#include "../libvlc.h"
+#include <vlc_charset.h>
+#include <vlc_configuration.h>
+#include "config/configuration.h"
+
+#include <assert.h>
+#include <limits.h>
+
+#include <winstring.h>
+#include <windows.storage.h>
+#include <roapi.h>
+
+static HRESULT WinRTSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
+{
+    VLC_UNUSED(hwnd);
+    VLC_UNUSED(hToken);
+
+    HRESULT hr;
+    IStorageFolder *folder;
+
+    if (dwFlags != SHGFP_TYPE_CURRENT)
+        return E_NOTIMPL;
+
+    folder = NULL;
+    csidl &= ~CSIDL_FLAG_CREATE;
+
+    if (csidl == CSIDL_APPDATA) {
+        IApplicationDataStatics *appDataStatics = NULL;
+        IApplicationData *appData = NULL;
+        static const WCHAR *className = L"Windows.Storage.ApplicationData";
+        const UINT32 clen = wcslen(className);
+
+        HSTRING hClassName = NULL;
+        HSTRING_HEADER header;
+        hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
+        if (FAILED(hr))
+            goto end_appdata;
+
+        hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics);
+
+        if (FAILED(hr))
+            goto end_appdata;
+
+        if (!appDataStatics) {
+            hr = E_FAIL;
+            goto end_appdata;
+        }
+
+        hr = IApplicationDataStatics_get_Current(appDataStatics, &appData);
+
+        if (FAILED(hr))
+            goto end_appdata;
+
+        if (!appData) {
+            hr = E_FAIL;
+            goto end_appdata;
+        }
+
+        hr = IApplicationData_get_LocalFolder(appData, &folder);
+
+end_appdata:
+        WindowsDeleteString(hClassName);
+        if (appDataStatics)
+            IApplicationDataStatics_Release(appDataStatics);
+        if (appData)
+            IApplicationData_Release(appData);
+    }
+    else
+    {
+        IKnownFoldersStatics *knownFoldersStatics = NULL;
+        static const WCHAR *className = L"Windows.Storage.KnownFolders";
+        const UINT32 clen = wcslen(className);
+
+        HSTRING hClassName = NULL;
+        HSTRING_HEADER header;
+        hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
+        if (FAILED(hr))
+            goto end_other;
+
+        hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, (void**)&knownFoldersStatics);
+
+        if (FAILED(hr))
+            goto end_other;
+
+        if (!knownFoldersStatics) {
+            hr = E_FAIL;
+            goto end_other;
+        }
+
+        switch (csidl) {
+        case CSIDL_PERSONAL:
+            hr = IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics, &folder);
+            break;
+        case CSIDL_MYMUSIC:
+            hr = IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics, &folder);
+            break;
+        case CSIDL_MYPICTURES:
+            hr = IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics, &folder);
+            break;
+        case CSIDL_MYVIDEO:
+            hr = IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics, &folder);
+            break;
+        default:
+            hr = E_NOTIMPL;
+        }
+
+end_other:
+        WindowsDeleteString(hClassName);
+        if (knownFoldersStatics)
+            IKnownFoldersStatics_Release(knownFoldersStatics);
+    }
+
+    if( SUCCEEDED(hr) && folder != NULL )
+    {
+        HSTRING path = NULL;
+        IStorageItem *item = NULL;
+        PCWSTR pszPathTemp;
+        hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item);
+        if (FAILED(hr))
+            goto end_folder;
+        hr = IStorageItem_get_Path(item, &path);
+        if (FAILED(hr))
+            goto end_folder;
+        pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
+        wcscpy(pszPath, pszPathTemp);
+end_folder:
+        WindowsDeleteString(path);
+        IStorageFolder_Release(folder);
+        if (item)
+            IStorageItem_Release(item);
+    }
+
+    return hr;
+}
+#define SHGetFolderPathW WinRTSHGetFolderPath
+
+static char *config_GetDataDir(void)
+{
+    const char *path = getenv ("VLC_DATA_PATH");
+    return (path != NULL) ? strdup (path) : NULL;
+}
+
+char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
+{
+    char *dir = NULL;
+
+    switch (type)
+    {
+        case VLC_PKG_DATA_DIR:
+            dir = config_GetDataDir();
+            break;
+        case VLC_PKG_LIB_DIR:
+        case VLC_PKG_LIBEXEC_DIR:
+            dir = NULL;
+            break;
+        case VLC_SYSDATA_DIR:
+            break;
+        case VLC_LOCALE_DIR:
+            dir = config_GetSysPath(VLC_PKG_DATA_DIR, "locale");
+            break;
+        default:
+            vlc_assert_unreachable();
+    }
+
+    if (filename == NULL || unlikely(dir == NULL))
+        return dir;
+
+    char *path;
+    if (unlikely(asprintf(&path, "%s/%s", dir, filename) == -1))
+        path = NULL;
+    free(dir);
+    return path;
+}
+
+static char *config_GetShellDir (int csidl)
+{
+    wchar_t wdir[MAX_PATH];
+
+    if (SHGetFolderPathW (NULL, csidl | CSIDL_FLAG_CREATE,
+                          NULL, SHGFP_TYPE_CURRENT, wdir ) == S_OK)
+        return FromWide (wdir);
+    return NULL;
+}
+
+static char *config_GetAppDir (void)
+{
+    char *psz_dir;
+    char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
+
+    if (psz_parent == NULL
+     ||  asprintf (&psz_dir, "%s\\vlc", psz_parent) == -1)
+        psz_dir = NULL;
+    free (psz_parent);
+    return psz_dir;
+}
+
+#warning FIXME Use known folders on Vista and above
+char *config_GetUserDir (vlc_userdir_t type)
+{
+    switch (type)
+    {
+        case VLC_HOME_DIR:
+            return config_GetShellDir (CSIDL_PERSONAL);
+        case VLC_CONFIG_DIR:
+        case VLC_USERDATA_DIR:
+            return config_GetAppDir ();
+        case VLC_CACHE_DIR:
+            return config_GetShellDir (CSIDL_LOCAL_APPDATA);
+
+        case VLC_DESKTOP_DIR:
+        case VLC_DOWNLOAD_DIR:
+        case VLC_TEMPLATES_DIR:
+        case VLC_PUBLICSHARE_DIR:
+        case VLC_DOCUMENTS_DIR:
+            return config_GetUserDir(VLC_HOME_DIR);
+        case VLC_MUSIC_DIR:
+            return config_GetShellDir (CSIDL_MYMUSIC);
+        case VLC_PICTURES_DIR:
+            return config_GetShellDir (CSIDL_MYPICTURES);
+        case VLC_VIDEOS_DIR:
+            return config_GetShellDir (CSIDL_MYVIDEO);
+    }
+    vlc_assert_unreachable ();
+}
diff --git a/src/win32/dirs.c b/src/win32/dirs.c
index f50742c9a2b..beed4f25c66 100644
--- a/src/win32/dirs.c
+++ b/src/win32/dirs.c
@@ -47,141 +47,9 @@
 #include <assert.h>
 #include <limits.h>
 
-#if VLC_WINSTORE_APP
-#include <winstring.h>
-#include <windows.storage.h>
-#include <roapi.h>
-
-static HRESULT WinRTSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
-{
-    VLC_UNUSED(hwnd);
-    VLC_UNUSED(hToken);
-
-    HRESULT hr;
-    IStorageFolder *folder;
-
-    if (dwFlags != SHGFP_TYPE_CURRENT)
-        return E_NOTIMPL;
-
-    folder = NULL;
-    csidl &= ~CSIDL_FLAG_MASK;
-
-    if (csidl == CSIDL_APPDATA) {
-        IApplicationDataStatics *appDataStatics = NULL;
-        IApplicationData *appData = NULL;
-        static const WCHAR *className = L"Windows.Storage.ApplicationData";
-        const UINT32 clen = wcslen(className);
-
-        HSTRING hClassName = NULL;
-        HSTRING_HEADER header;
-        hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
-        if (FAILED(hr))
-            goto end_appdata;
-
-        hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics);
-
-        if (FAILED(hr))
-            goto end_appdata;
-
-        if (!appDataStatics) {
-            hr = E_FAIL;
-            goto end_appdata;
-        }
-
-        hr = IApplicationDataStatics_get_Current(appDataStatics, &appData);
-
-        if (FAILED(hr))
-            goto end_appdata;
-
-        if (!appData) {
-            hr = E_FAIL;
-            goto end_appdata;
-        }
-
-        hr = IApplicationData_get_LocalFolder(appData, &folder);
-
-end_appdata:
-        WindowsDeleteString(hClassName);
-        if (appDataStatics)
-            IApplicationDataStatics_Release(appDataStatics);
-        if (appData)
-            IApplicationData_Release(appData);
-    }
-    else
-    {
-        IKnownFoldersStatics *knownFoldersStatics = NULL;
-        static const WCHAR *className = L"Windows.Storage.KnownFolders";
-        const UINT32 clen = wcslen(className);
-
-        HSTRING hClassName = NULL;
-        HSTRING_HEADER header;
-        hr = WindowsCreateStringReference(className, clen, &header, &hClassName);
-        if (FAILED(hr))
-            goto end_other;
-
-        hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, (void**)&knownFoldersStatics);
-
-        if (FAILED(hr))
-            goto end_other;
-
-        if (!knownFoldersStatics) {
-            hr = E_FAIL;
-            goto end_other;
-        }
-
-        switch (csidl) {
-        case CSIDL_PERSONAL:
-            hr = IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics, &folder);
-            break;
-        case CSIDL_MYMUSIC:
-            hr = IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics, &folder);
-            break;
-        case CSIDL_MYPICTURES:
-            hr = IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics, &folder);
-            break;
-        case CSIDL_MYVIDEO:
-            hr = IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics, &folder);
-            break;
-        default:
-            hr = E_NOTIMPL;
-        }
-
-end_other:
-        WindowsDeleteString(hClassName);
-        if (knownFoldersStatics)
-            IKnownFoldersStatics_Release(knownFoldersStatics);
-    }
-
-    if( SUCCEEDED(hr) && folder != NULL )
-    {
-        HSTRING path = NULL;
-        IStorageItem *item = NULL;
-        PCWSTR pszPathTemp;
-        hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item);
-        if (FAILED(hr))
-            goto end_folder;
-        hr = IStorageItem_get_Path(item, &path);
-        if (FAILED(hr))
-            goto end_folder;
-        pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
-        wcscpy(pszPath, pszPathTemp);
-end_folder:
-        WindowsDeleteString(path);
-        IStorageFolder_Release(folder);
-        if (item)
-            IStorageItem_Release(item);
-    }
-
-    return hr;
-}
-#define SHGetFolderPathW WinRTSHGetFolderPath
-#endif
 
 char *config_GetLibDir (void)
 {
-#if VLC_WINSTORE_APP
-    return NULL;
-#else
     /* Get our full path */
     MEMORY_BASIC_INFORMATION mbi;
     if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
@@ -199,7 +67,6 @@ char *config_GetLibDir (void)
     return FromWide (wpath);
 error:
     abort ();
-#endif
 }
 
 static char *config_GetDataDir(void)
@@ -252,7 +119,6 @@ static char *config_GetShellDir (int csidl)
 
 static char *config_GetAppDir (void)
 {
-#if !VLC_WINSTORE_APP
     /* if portable directory exists, use it */
     WCHAR path[MAX_PATH];
     if (GetModuleFileName (NULL, path, MAX_PATH))
@@ -267,7 +133,6 @@ static char *config_GetAppDir (void)
                 return FromWide (path);
         }
     }
-#endif
 
     char *psz_dir;
     char *psz_parent = config_GetShellDir (CSIDL_APPDATA);
@@ -290,12 +155,7 @@ char *config_GetUserDir (vlc_userdir_t type)
         case VLC_USERDATA_DIR:
             return config_GetAppDir ();
         case VLC_CACHE_DIR:
-#if !VLC_WINSTORE_APP
             return config_GetAppDir ();
-#else
-            return config_GetShellDir (CSIDL_LOCAL_APPDATA);
-#endif
-
         case VLC_DESKTOP_DIR:
         case VLC_DOWNLOAD_DIR:
         case VLC_TEMPLATES_DIR:
-- 
2.17.1



More information about the vlc-devel mailing list