Commit d6631760 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

shell32: Don't search Path or PIDL for an icon in IShellLink::GetIconLocation.

Try as I might, I couldn't get a path out of GetIconLocation that wasn't put there via SetIconLocation. As far as I can tell, the code here was based on nothing.
parent f324f3c3
...@@ -1593,78 +1593,19 @@ static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd ...@@ -1593,78 +1593,19 @@ static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd
return NOERROR; return NOERROR;
} }
static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPCITEMIDLIST pidl,
LPSTR pszIconPath, int cchIconPath, int* piIcon)
{
LPCITEMIDLIST pidlLast;
HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
if (SUCCEEDED(hr)) {
IExtractIconA* pei;
hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
if (SUCCEEDED(hr)) {
hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
IExtractIconA_Release(pei);
}
IShellFolder_Release(psf);
}
return hr;
}
static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon) static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
{ {
IShellLinkImpl *This = (IShellLinkImpl *)iface; IShellLinkImpl *This = (IShellLinkImpl *)iface;
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon); TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
pszIconPath[0] = 0;
*piIcon = This->iIcoNdx; *piIcon = This->iIcoNdx;
if (This->sIcoPath) if (This->sIcoPath)
{
WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
return S_OK; else
} pszIconPath[0] = 0;
if (This->pPidl || This->sPath)
{
IShellFolder* pdsk;
HRESULT hr = SHGetDesktopFolder(&pdsk);
if (SUCCEEDED(hr))
{
/* first look for an icon using the PIDL (if present) */
if (This->pPidl)
hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
else
hr = E_FAIL;
/* if we couldn't find an icon yet, look for it using the file system path */
if (FAILED(hr) && This->sPath)
{
LPITEMIDLIST pidl;
hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
if (SUCCEEDED(hr)) {
hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
SHFree(pidl);
}
}
IShellFolder_Release(pdsk);
}
return hr;
}
return S_OK; return S_OK;
} }
...@@ -1984,78 +1925,19 @@ static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd ...@@ -1984,78 +1925,19 @@ static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd
return S_OK; return S_OK;
} }
static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPCITEMIDLIST pidl,
LPWSTR pszIconPath, int cchIconPath, int* piIcon)
{
LPCITEMIDLIST pidlLast;
HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
if (SUCCEEDED(hr)) {
IExtractIconW* pei;
hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
if (SUCCEEDED(hr)) {
hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
IExtractIconW_Release(pei);
}
IShellFolder_Release(psf);
}
return hr;
}
static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon) static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
{ {
IShellLinkImpl *This = impl_from_IShellLinkW(iface); IShellLinkImpl *This = impl_from_IShellLinkW(iface);
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon); TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
pszIconPath[0] = 0;
*piIcon = This->iIcoNdx; *piIcon = This->iIcoNdx;
if (This->sIcoPath) if (This->sIcoPath)
{
lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath); lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
return S_OK; else
} pszIconPath[0] = 0;
if (This->pPidl || This->sPath)
{
IShellFolder* pdsk;
HRESULT hr = SHGetDesktopFolder(&pdsk);
if (SUCCEEDED(hr))
{
/* first look for an icon using the PIDL (if present) */
if (This->pPidl)
hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
else
hr = E_FAIL;
/* if we couldn't find an icon yet, look for it using the file system path */
if (FAILED(hr) && This->sPath)
{
LPITEMIDLIST pidl;
hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
if (SUCCEEDED(hr))
{
hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
SHFree(pidl);
}
}
IShellFolder_Release(pdsk);
}
return hr;
}
return S_OK; return S_OK;
} }
......
...@@ -325,8 +325,8 @@ static void test_get_set(void) ...@@ -325,8 +325,8 @@ static void test_get_set(void)
strcpy(buffer,"garbage"); strcpy(buffer,"garbage");
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i); r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r); ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
todo_wine ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer); ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
todo_wine ok(i==0, "GetIconLocation returned %d\n", i); ok(i==0, "GetIconLocation returned %d\n", i);
str="c:\\nonexistent\\file"; str="c:\\nonexistent\\file";
r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe); r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
...@@ -868,6 +868,65 @@ static void test_shdefextracticon(void) ...@@ -868,6 +868,65 @@ static void test_shdefextracticon(void)
ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res); ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
} }
static void test_GetIconLocation(void)
{
IShellLinkA *sl;
const char *str;
char buffer[INFOTIPSIZE], mypath[MAX_PATH];
int i;
HRESULT r;
LPITEMIDLIST pidl;
r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
&IID_IShellLinkA, (LPVOID*)&sl);
ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
if(r != S_OK)
return;
i = 0xdeadbeef;
strcpy(buffer, "garbage");
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
ok(i == 0, "GetIconLocation returned %d\n", i);
str = "c:\\some\\path";
r = IShellLinkA_SetPath(sl, str);
ok(r == S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
i = 0xdeadbeef;
strcpy(buffer, "garbage");
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
ok(i == 0, "GetIconLocation returned %d\n", i);
GetWindowsDirectoryA(mypath, sizeof(mypath) - 12);
strcat(mypath, "\\regedit.exe");
pidl = path_to_pidl(mypath);
r = IShellLinkA_SetIDList(sl, pidl);
ok(r == S_OK, "SetPath failed (0x%08x)\n", r);
i = 0xdeadbeef;
strcpy(buffer, "garbage");
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
ok(i == 0, "GetIconLocation returned %d\n", i);
str = "c:\\nonexistent\\file";
r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
i = 0xdeadbeef;
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(lstrcmpi(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
IShellLinkA_Release(sl);
}
START_TEST(shelllink) START_TEST(shelllink)
{ {
HRESULT r; HRESULT r;
...@@ -891,6 +950,7 @@ START_TEST(shelllink) ...@@ -891,6 +950,7 @@ START_TEST(shelllink)
test_load_save(); test_load_save();
test_datalink(); test_datalink();
test_shdefextracticon(); test_shdefextracticon();
test_GetIconLocation();
CoUninitialize(); CoUninitialize();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment