From 084e596a95d9d1145a21e5cb0a4a6a6f9d817a50 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Wed, 16 Feb 2005 16:27:42 +0000 Subject: [PATCH] SetPath("") should return S_OK. SetPath("nonexistent_path") should return S_FALSE. --- dlls/shell32/shelllink.c | 18 ++++++++++++++---- dlls/shell32/tests/shelllink.c | 10 +++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index b7b379f81c5..f08a6421261 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -1336,11 +1336,16 @@ static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile) IShellLinkImpl *This = (IShellLinkImpl *)iface; char buffer[MAX_PATH]; LPSTR fname; + HRESULT hr = S_OK; TRACE("(%p)->(path=%s)\n",This, pszFile); - if (!GetFullPathNameA(pszFile, MAX_PATH, buffer, &fname)) + if(*pszFile == '\0') + *buffer = '\0'; + else if (!GetFullPathNameA(pszFile, MAX_PATH, buffer, &fname)) return E_FAIL; + else if(!PathFileExistsA(buffer)) + hr = S_FALSE; HeapFree(GetProcessHeap(), 0, This->sPath); This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, buffer); @@ -1349,7 +1354,7 @@ static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile) This->bDirty = TRUE; - return S_OK; + return hr; } /************************************************************************** @@ -1756,11 +1761,16 @@ static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface); WCHAR buffer[MAX_PATH]; LPWSTR fname; + HRESULT hr = S_OK; TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile)); - if (!GetFullPathNameW(pszFile, MAX_PATH, buffer, &fname)) + if (*pszFile == '\0') + *buffer = '\0'; + else if (!GetFullPathNameW(pszFile, MAX_PATH, buffer, &fname)) return E_FAIL; + else if(!PathFileExistsW(buffer)) + hr = S_FALSE; HeapFree(GetProcessHeap(), 0, This->sPath); This->sPath = HeapAlloc( GetProcessHeap(), 0, @@ -1771,7 +1781,7 @@ static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile lstrcpyW(This->sPath, buffer); This->bDirty = TRUE; - return S_OK; + return hr; } /************************************************************************** diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c index 8c88e8448f6..201a966e563 100644 --- a/dlls/shell32/tests/shelllink.c +++ b/dlls/shell32/tests/shelllink.c @@ -136,9 +136,17 @@ static void test_get_set() ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r); ok(*buffer=='\0', "GetPath returned '%s'\n", buffer); + r = IShellLinkA_SetPath(sl, ""); + ok(r==S_OK, "SetPath failed (0x%08lx)\n", r); + + strcpy(buffer,"garbage"); + r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH); + ok(SUCCEEDED(r), "GetPath failed (0x%08lx)\n", r); + ok(*buffer=='\0', "GetPath returned '%s'\n", buffer); + str="c:\\nonexistent\\file"; r = IShellLinkA_SetPath(sl, str); - ok(SUCCEEDED(r), "SetPath failed (0x%08lx)\n", r); + ok(r==S_FALSE, "SetPath failed (0x%08lx)\n", r); strcpy(buffer,"garbage"); r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);