[vlc-devel] [PATCH 8/9] win32: dirs-uap: handle the VLC_CACHE_DIR in a separate function

Steve Lhomme robux4 at ycbcr.xyz
Mon Apr 6 13:35:06 CEST 2020


It's the only one using IApplicationData2
---
 src/win32/dirs-uap.c | 64 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
index 5cdc379e524..eb871445e9d 100644
--- a/src/win32/dirs-uap.c
+++ b/src/win32/dirs-uap.c
@@ -221,6 +221,68 @@ end_appdata:
     return psz_dir;
 }
 
+static char *config_GetCacheDir (void)
+{
+#ifndef HAVE_IAPPLICATIONDATA2
+    return NULL;
+#else // HAVE_IAPPLICATIONDATA2
+    IStorageFolder *folder = NULL;
+    IApplicationDataStatics *appDataStatics = NULL;
+    IApplicationData *appData = NULL;
+    IApplicationData2 *appData2 = 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;
+    }
+
+    IApplicationData_QueryInterface(appData, &IID_IApplicationData2, (void**)&appData2);
+    if (!appData2) {
+        hr = E_FAIL;
+        goto end_appdata;
+    }
+
+    hr = IApplicationData2_get_LocalCacheFolder(appData2, &folder);
+
+end_appdata:
+    WindowsDeleteString(hClassName);
+    if (appDataStatics)
+        IApplicationDataStatics_Release(appDataStatics);
+    if (appData2)
+        IApplicationData2_Release(appData2);
+    if (appData)
+        IApplicationData_Release(appData);
+
+    if( FAILED(hr) || folder == NULL )
+        return NULL;
+
+    return GetFolderName(folder);
+#endif // HAVE_IAPPLICATIONDATA2
+}
+
 char *config_GetUserDir (vlc_userdir_t type)
 {
     switch (type)
@@ -236,7 +298,7 @@ char *config_GetUserDir (vlc_userdir_t type)
         case VLC_USERDATA_DIR:
             return config_GetAppDir ();
         case VLC_CACHE_DIR:
-            return config_GetShellDir (VLC_CACHE_DIR);
+            return config_GetCacheDir ();
         case VLC_MUSIC_DIR:
             return config_GetShellDir (VLC_MUSIC_DIR);
         case VLC_PICTURES_DIR:
-- 
2.17.1



More information about the vlc-devel mailing list