[vlc-devel] [PATCH 3/9] win32: dirs-uap: create a function to get the name of a IStorageFolder

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


It also released the IStorageFolder once it's done.
---
 src/win32/dirs-uap.c | 46 ++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
index 25ad4d427d8..9c12fb87dde 100644
--- a/src/win32/dirs-uap.c
+++ b/src/win32/dirs-uap.c
@@ -49,6 +49,28 @@
 #include <windows.storage.h>
 #include <roapi.h>
 
+static char * GetFolderName(IStorageFolder *folder)
+{
+    HRESULT hr;
+    IStorageItem *item;
+    hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item);
+    if (FAILED(hr))
+        return NULL;
+
+    char *result = NULL;
+    HSTRING path;
+    hr = IStorageItem_get_Path(item, &path);
+    if (SUCCEEDED(hr))
+    {
+        PCWSTR pszPathTemp = WindowsGetStringRawBuffer(path, NULL);
+        result = FromWide(pszPathTemp);
+        WindowsDeleteString(path);
+    }
+    IStorageItem_Release(item);
+    IStorageFolder_Release(folder);
+    return result;
+}
+
 static char *config_GetShellDir(vlc_userdir_t csidl)
 {
     HRESULT hr;
@@ -140,28 +162,10 @@ end_other:
             IKnownFoldersStatics_Release(knownFoldersStatics);
     }
 
-    char *result = NULL;
-    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);
-        result = FromWide(pszPathTemp);
-end_folder:
-        WindowsDeleteString(path);
-        IStorageFolder_Release(folder);
-        if (item)
-            IStorageItem_Release(item);
-    }
+    if( FAILED(hr) || folder == NULL )
+        return NULL;
 
-    return result;
+    return GetFolderName(folder);
 }
 
 static char *config_GetDataDir(void)
-- 
2.17.1



More information about the vlc-devel mailing list