[vlc-commits] win32: dirs-uap: handle the VLC_CACHE_DIR in a separate function

Steve Lhomme git at videolan.org
Thu Apr 9 07:52:06 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Apr  6 12:53:10 2020 +0200| [e5c831002878a60de754a990230863f04dd4e41c] | committer: Steve Lhomme

win32: dirs-uap: handle the VLC_CACHE_DIR in a separate function

It's the only one using IApplicationData2

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e5c831002878a60de754a990230863f04dd4e41c
---

 src/win32/dirs-uap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
index c3869f3f57..120fdc39c2 100644
--- a/src/win32/dirs-uap.c
+++ b/src/win32/dirs-uap.c
@@ -213,6 +213,69 @@ end_appdata:
     return psz_dir;
 }
 
+static char *config_GetCacheDir (void)
+{
+#ifndef HAVE_IAPPLICATIONDATA2
+    return NULL;
+#else // HAVE_IAPPLICATIONDATA2
+    HRESULT hr;
+    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)
@@ -228,7 +291,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:



More information about the vlc-commits mailing list