Gijs Vermeulen : wmp: Implement IWMPMedia::put/get_name.

Alexandre Julliard julliard at winehq.org
Thu Aug 1 17:16:47 CDT 2019


Module: wine
Branch: master
Commit: 3b0e8197613dcafbf67f8c1792a7456acdf73017
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3b0e8197613dcafbf67f8c1792a7456acdf73017

Author: Gijs Vermeulen <gijsvrm at codeweavers.com>
Date:   Thu Aug  1 15:07:55 2019 +0200

wmp: Implement IWMPMedia::put/get_name.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47029
Signed-off-by: Gijs Vermeulen <gijsvrm at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wmp/Makefile.in   |  2 +-
 dlls/wmp/player.c      | 61 ++++++++++++++++++++++++++++++++++++++++++++------
 dlls/wmp/tests/media.c |  5 -----
 dlls/wmp/wmp_private.h |  1 +
 4 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/dlls/wmp/Makefile.in b/dlls/wmp/Makefile.in
index 5ed3d42..333717c 100644
--- a/dlls/wmp/Makefile.in
+++ b/dlls/wmp/Makefile.in
@@ -1,5 +1,5 @@
 MODULE    = wmp.dll
-IMPORTS   = oleaut32 ole32 user32 gdi32
+IMPORTS   = oleaut32 ole32 urlmon shlwapi user32 gdi32
 
 EXTRADLLFLAGS = -mno-cygwin
 
diff --git a/dlls/wmp/player.c b/dlls/wmp/player.c
index 7a1befe..5673d0e 100644
--- a/dlls/wmp/player.c
+++ b/dlls/wmp/player.c
@@ -21,6 +21,7 @@
 #include "wine/debug.h"
 #include <nserror.h>
 #include "wmpids.h"
+#include "shlwapi.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(wmp);
 
@@ -1730,6 +1731,7 @@ static ULONG WINAPI WMPMedia_Release(IWMPMedia *iface)
 
     if(!ref) {
         heap_free(This->url);
+        heap_free(This->name);
         heap_free(This);
     }
 
@@ -1789,17 +1791,21 @@ static HRESULT WINAPI WMPMedia_get_name(IWMPMedia *iface, BSTR *name)
 {
     WMPMedia *This = impl_from_IWMPMedia(iface);
 
-    FIXME("(%p)->(%p)\n", This, name);
+    TRACE("(%p)->(%p)\n", This, name);
 
-    /* FIXME: this should be a display name */
-    return return_bstr(This->url, name);
+    return return_bstr(This->name, name);
 }
 
-static HRESULT WINAPI WMPMedia_put_name(IWMPMedia *iface, BSTR pbstrName)
+static HRESULT WINAPI WMPMedia_put_name(IWMPMedia *iface, BSTR name)
 {
     WMPMedia *This = impl_from_IWMPMedia(iface);
-    FIXME("(%p)->(%s)\n", This, debugstr_w(pbstrName));
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(name));
+
+    if (!name) return E_POINTER;
+
+    This->name = heap_strdupW(name);
+    return S_OK;
 }
 
 static HRESULT WINAPI WMPMedia_get_imageSourceWidth(IWMPMedia *iface, LONG *pWidth)
@@ -2022,13 +2028,54 @@ WMPMedia *unsafe_impl_from_IWMPMedia(IWMPMedia *iface)
 HRESULT create_media_from_url(BSTR url, double duration, IWMPMedia **ppMedia)
 {
     WMPMedia *media;
+    IUri *uri;
+    BSTR path;
+    HRESULT hr;
+    WCHAR *name_dup, slashW[] = {'/',0};
 
     media = heap_alloc_zero(sizeof(*media));
     if (!media)
         return E_OUTOFMEMORY;
 
     media->IWMPMedia_iface.lpVtbl = &WMPMediaVtbl;
-    media->url = url ? heap_strdupW(url) : heap_strdupW(emptyW);
+
+    if (url)
+    {
+        media->url = heap_strdupW(url);
+        name_dup = heap_strdupW(url);
+
+        hr = CreateUri(name_dup, Uri_CREATE_ALLOW_RELATIVE | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, &uri);
+        if (FAILED(hr))
+        {
+            heap_free(name_dup);
+            return hr;
+        }
+        hr = IUri_GetPath(uri, &path);
+        if (hr != S_OK)
+        {
+            heap_free(name_dup);
+            IUri_Release(uri);
+            return hr;
+        }
+
+        /* GetPath() will return "/" for invalid uri's
+         * only strip extension when uri is valid
+         */
+        if (wcscmp(path, slashW) != 0)
+            PathRemoveExtensionW(name_dup);
+        PathStripPathW(name_dup);
+
+        media->name = name_dup;
+
+        SysFreeString(path);
+        IUri_Release(uri);
+    }
+    else
+    {
+        media->url = heap_strdupW(emptyW);
+        media->name = heap_strdupW(emptyW);
+    }
+
     media->duration = duration;
     media->ref = 1;
 
diff --git a/dlls/wmp/tests/media.c b/dlls/wmp/tests/media.c
index c190eee..3d750e1 100644
--- a/dlls/wmp/tests/media.c
+++ b/dlls/wmp/tests/media.c
@@ -573,15 +573,12 @@ todo_wine
     SysFreeString(str);
     hr = IWMPMedia_get_name(media, &str);
     ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
-todo_wine
     ok(!lstrcmpW(str, testW), "Expected %s, got %s\n", wine_dbgstr_w(testW), wine_dbgstr_w(str));
     SysFreeString(str);
     hr = IWMPMedia_put_name(media, NULL);
-todo_wine
     ok(hr == E_POINTER, "Unexpected hr %#x.\n", hr);
     hr = IWMPMedia_get_name(media, &str);
     ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
-todo_wine
     ok(!lstrcmpW(str, testW), "Expected %s, got %s\n", wine_dbgstr_w(testW), wine_dbgstr_w(str));
     SysFreeString(str);
 
@@ -594,7 +591,6 @@ todo_wine
     ok(media2 != NULL, "Unexpected media instance.\n");
     hr = IWMPMedia_get_name(media2, &str);
     ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
-todo_wine
     ok(!lstrcmpW(str, testW), "Expected %s, got %s\n", wine_dbgstr_w(testW), wine_dbgstr_w(str));
     SysFreeString(str);
     IWMPMedia_Release(media2);
@@ -615,7 +611,6 @@ todo_wine
         SysFreeString(str);
         hr = IWMPMedia_get_name(media, &str);
         ok(hr == S_OK, "Failed to get item name, hr %#x.\n", hr);
-    todo_wine
         ok(!lstrcmpW(str, tests[i].expected), "Expected %s, got %s\n", wine_dbgstr_w(tests[i].expected), wine_dbgstr_w(str));
         SysFreeString(str);
         IWMPMedia_Release(media);
diff --git a/dlls/wmp/wmp_private.h b/dlls/wmp/wmp_private.h
index 27ec55e..5149d73 100644
--- a/dlls/wmp/wmp_private.h
+++ b/dlls/wmp/wmp_private.h
@@ -56,6 +56,7 @@ typedef struct {
     LONG ref;
 
     WCHAR *url;
+    WCHAR *name;
 
     DOUBLE duration;
 } WMPMedia;




More information about the wine-cvs mailing list