From 22922dec07c83d4d5ea354acce12ea17c4ce76a4 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Wed, 7 Jan 2004 23:34:08 +0000 Subject: [PATCH] SHELL_SHGetPathFromIDList() svn path=/trunk/; revision=7507 --- reactos/lib/shell32/clipboard.c | 4 +- reactos/lib/shell32/pidl.c | 162 +++++++++++++------------------- reactos/lib/shell32/pidl.h | 4 +- reactos/lib/shell32/shelllink.c | 4 +- reactos/lib/shell32/shlexec.c | 17 +--- 5 files changed, 74 insertions(+), 117 deletions(-) diff --git a/reactos/lib/shell32/clipboard.c b/reactos/lib/shell32/clipboard.c index 0114f1b3077..dea09ee2a26 100644 --- a/reactos/lib/shell32/clipboard.c +++ b/reactos/lib/shell32/clipboard.c @@ -222,7 +222,7 @@ HGLOBAL RenderFILENAMEA (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) if (!pidl) return 0; - hr = _SHGetPathFromIDListA(pidl, szTemp, MAX_PATH); + hr = SHELL_SHGetPathFromIDListA(pidl, szTemp, MAX_PATH); SHFree(pidl); if (FAILED(hr)) return 0; @@ -254,7 +254,7 @@ HGLOBAL RenderFILENAMEW (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) if (!pidl) return 0; - hr = _SHGetPathFromIDListW(pidl, szTemp, MAX_PATH); + hr = SHELL_SHGetPathFromIDListW(pidl, szTemp, MAX_PATH); SHFree(pidl); if (FAILED(hr)) return 0; diff --git a/reactos/lib/shell32/pidl.c b/reactos/lib/shell32/pidl.c index 38269b87277..90dad0b3886 100644 --- a/reactos/lib/shell32/pidl.c +++ b/reactos/lib/shell32/pidl.c @@ -1287,70 +1287,55 @@ HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int n } /************************************************************************* - * _SHGetPathFromIDListA + * SHELL_SHGetPathFromIDListA */ -HRESULT _SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize) +HRESULT SHELL_SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize) { - HRESULT hr; - STRRET str; - LPSHELLFOLDER desktop; - LPSTR pstr; + LPSTR pstr = pszPath; LPSTR end = pszPath + uOutSize; + HRESULT hr = S_OK; - /* If the item ID list begins at "My Computer", we can use - an optimized loop to retrieve file system paths. */ - if (_ILIsMyComputer(pidl)) { - LPCITEMIDLIST p = ILGetNext(pidl); + /* One case is a PIDL rooted at desktop level */ + if (_ILIsValue(pidl) || _ILIsFolder(pidl)) { + hr = SHGetSpecialFolderPathA(0, pstr, CSIDL_DESKTOP, FALSE); + + if (SUCCEEDED(hr)) + pstr = PathAddBackslashA(pstr); + } + /* The only other valid case is a item ID list beginning at "My Computer". */ + else if (_ILIsMyComputer(pidl)) + pidl = ILGetNext(pidl); + + if (SUCCEEDED(hr)) { LPSTR txt; - pstr = pszPath; + while(pidl && pidl->mkid.cb && pstrmkid.cb && pstrmkid.cb) - return TRUE; + if (!pidl->mkid.cb) { + /* We are at the end and successfully converted the complete PIDL. */ + break; + } pstr = PathAddBackslashA(pstr); if (!pstr) - break; - } - } - - pstr = pszPath; - - /* The only other valid case is a simple PIDL rooted at desktop level */ - if (_ILIsValue(pidl) && _ILIsPidlSimple(pidl)) { - hr = SHGetDesktopFolder(&desktop); - - if (SUCCEEDED(hr)) { - hr = SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOP, FALSE); - - if (SUCCEEDED(hr)) { - pstr = PathAddBackslashA(pszPath); - hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &str); - } - - IShellFolder_Release(desktop); + {hr = E_INVALIDARG; break;} } } else - return E_INVALIDARG; + hr = E_INVALIDARG; - if (SUCCEEDED(hr)) - hr = StrRetToStrNA(pstr, end-pstr, &str, pidl); - - TRACE_(shell)("-- %s, 0x%08lx\n",pszPath, hr); + TRACE_(shell)("-- %s, 0x%08lx\n", pszPath, S_OK); return hr; } @@ -1379,78 +1364,63 @@ BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath) if (!pidl) return FALSE; - hr = _SHGetPathFromIDListA(pidl, pszPath, MAX_PATH); + hr = SHELL_SHGetPathFromIDListA(pidl, pszPath, MAX_PATH); return SUCCEEDED(hr); } /************************************************************************* - * _SHGetPathFromIDListW + * SHELL_SHGetPathFromIDListW */ -HRESULT _SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize) +HRESULT SHELL_SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize) { - HRESULT hr; - STRRET str; - LPSHELLFOLDER desktop; - LPWSTR pstr; + LPWSTR pstr = pszPath; LPWSTR end = pszPath + uOutSize; + HRESULT hr = S_OK; - /* If the item ID list begins at "My Computer", we can use - an optimized loop to retrieve file system paths. */ - if (_ILIsMyComputer(pidl)) { - LPCITEMIDLIST p = ILGetNext(pidl); + /* One case is a PIDL rooted at desktop level */ + if (_ILIsValue(pidl) || _ILIsFolder(pidl)) { + hr = SHGetSpecialFolderPathW(0, pstr, CSIDL_DESKTOP, FALSE); + + if (SUCCEEDED(hr)) + pstr = PathAddBackslashW(pstr); + } + /* The only other valid case is a item ID list beginning at "My Computer". */ + else if (_ILIsMyComputer(pidl)) + pidl = ILGetNext(pidl); + + if (SUCCEEDED(hr)) { LPSTR txt; - pstr = pszPath; + while(pidl && pidl->mkid.cb && pstrmkid.cb && pstrmkid.cb) - return TRUE; + if (!pidl->mkid.cb) { + /* We are at the end and successfully converted the complete PIDL. */ + break; + } pstr = PathAddBackslashW(pstr); if (!pstr) - break; - } - } - - pstr = pszPath; - - /* The only other valid case is a simple PIDL rooted at desktop level */ - if (_ILIsValue(pidl) && _ILIsPidlSimple(pidl)) { - hr = SHGetDesktopFolder(&desktop); - - if (SUCCEEDED(hr)) { - hr = SHGetSpecialFolderPathW(0, pszPath, CSIDL_DESKTOP, FALSE); - - if (SUCCEEDED(hr)) { - pstr = PathAddBackslashW(pszPath); - hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &str); - } - - IShellFolder_Release(desktop); + {hr = E_INVALIDARG; break;} } } else - return E_INVALIDARG; + hr = E_INVALIDARG; - if (SUCCEEDED(hr)) - hr = StrRetToStrNW(pstr, end-pstr, &str, pidl); - - TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr); - return hr; + TRACE_(shell)("-- %s, 0x%08lx\n", debugstr_w(pszPath), hr); + return hr; } /************************************************************************* @@ -1466,7 +1436,7 @@ BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath) if (!pidl) return FALSE; - hr = _SHGetPathFromIDListW(pidl, pszPath, MAX_PATH); + hr = SHELL_SHGetPathFromIDListW(pidl, pszPath, MAX_PATH); TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr); return SUCCEEDED(hr); diff --git a/reactos/lib/shell32/pidl.h b/reactos/lib/shell32/pidl.h index 720761a7d4c..b09f8d93a50 100644 --- a/reactos/lib/shell32/pidl.h +++ b/reactos/lib/shell32/pidl.h @@ -223,7 +223,7 @@ LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida); BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type); BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type); -HRESULT _SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize); -HRESULT _SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize); +HRESULT SHELL_SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize); +HRESULT SHELL_SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize); #endif diff --git a/reactos/lib/shell32/shelllink.c b/reactos/lib/shell32/shelllink.c index ec485cb8e42..b5a54d05f06 100644 --- a/reactos/lib/shell32/shelllink.c +++ b/reactos/lib/shell32/shelllink.c @@ -1311,7 +1311,7 @@ static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWOR if (!This->sPath && This->pPidl) { WCHAR buffer[MAX_PATH]; - hr = _SHGetPathFromIDListW(This->pPidl, buffer, MAX_PATH); + hr = SHELL_SHGetPathFromIDListW(This->pPidl, buffer, MAX_PATH); if (SUCCEEDED(hr) && *buffer) { This->sPath = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer)+1)*sizeof(WCHAR)); @@ -1740,7 +1740,7 @@ static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWOR if (!This->sPath && This->pPidl) { WCHAR buffer[MAX_PATH]; - hr = _SHGetPathFromIDListW(This->pPidl, buffer, MAX_PATH); + hr = SHELL_SHGetPathFromIDListW(This->pPidl, buffer, MAX_PATH); if (SUCCEEDED(hr) && *buffer) { This->sPath = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer)+1)*sizeof(WCHAR)); diff --git a/reactos/lib/shell32/shlexec.c b/reactos/lib/shell32/shlexec.c index 645df90b7c3..8ff591fae70 100644 --- a/reactos/lib/shell32/shlexec.c +++ b/reactos/lib/shell32/shlexec.c @@ -922,21 +922,8 @@ BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execf if (SUCCEEDED(_ResolveShortCut(cmd, wdir, args, sei->hwnd, &sei->nShow, &tmpPidl))) { if (!*cmd && tmpPidl) { /* We got a PIDL instead of a file system path. */ - IShellFolder* desktop; - STRRET str; - - HRESULT hr = SHGetDesktopFolder(&desktop); - - if (SUCCEEDED(hr)) { - hr = IShellFolder_GetDisplayNameOf(desktop, tmpPidl, SHGDN_FORPARSING, &str); - - if (SUCCEEDED(hr)) { - hr = StrRetToStrNW(cmd, MAX_PATH, &str, tmpPidl); - tmpPidl = NULL; - } - - IShellFolder_Release(desktop); - } + if (SHGetPathFromIDListA(tmpPidl, cmd)) + tmpPidl = NULL; if (cmd[0]==':' && cmd[1]==':') { /* open shell folder for the specified class GUID */