[SHELL32][BROWSEUI] Set DefView InvokeCommand directory (#7495)

If a .lnk shortcut does not specify a working directory, it should use the directory provided by the InvokeCommand caller when it's launced.

CORE-19855
This commit is contained in:
Whindmar Saksit 2024-11-08 23:27:26 +01:00 committed by GitHub
parent 3ecd2363a6
commit a17b6e9369
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 1 deletions

View file

@ -937,6 +937,22 @@ STDMETHODIMP CFindFolder::MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
CComVariant searchBar(pwszGuid); CComVariant searchBar(pwszGuid);
return pWebBrowser2->ShowBrowserBar(&searchBar, NULL, NULL); return pWebBrowser2->ShowBrowserBar(&searchBar, NULL, NULL);
} }
case SFVM_GETCOMMANDDIR:
{
HRESULT hr = E_FAIL;
if (m_shellFolderView)
{
PCUITEMID_CHILD *apidl;
UINT cidl = 0;
if (SUCCEEDED(hr = m_shellFolderView->GetSelectedObjects(&apidl, &cidl)))
{
if (cidl)
hr = StringCchCopyW((PWSTR)lParam, wParam, _ILGetPath(apidl[0]));
LocalFree(apidl);
}
}
return hr;
}
} }
return E_NOTIMPL; return E_NOTIMPL;
} }

View file

@ -2623,6 +2623,7 @@ HRESULT STDMETHODCALLTYPE CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici) HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
{ {
LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici;
const BOOL unicode = IsUnicode(*lpici); const BOOL unicode = IsUnicode(*lpici);
CStringW args; CStringW args;
@ -2631,7 +2632,6 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
if (unicode) if (unicode)
{ {
LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici;
if (!StrIsNullOrEmpty(iciex->lpParametersW)) if (!StrIsNullOrEmpty(iciex->lpParametersW))
{ {
args += L' '; args += L' ';
@ -2674,6 +2674,15 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
if (lpici->nShow != SW_SHOWNORMAL && lpici->nShow != SW_SHOW) if (lpici->nShow != SW_SHOWNORMAL && lpici->nShow != SW_SHOW)
sei.nShow = lpici->nShow; // Allow invoker to override .lnk show mode sei.nShow = lpici->nShow; // Allow invoker to override .lnk show mode
// Use the invoker specified working directory if the link did not specify one
if (StrIsNullOrEmpty(sei.lpDirectory) || !PathIsDirectoryW(sei.lpDirectory))
{
LPCSTR pszDirA = lpici->lpDirectory;
if (unicode && !StrIsNullOrEmpty(iciex->lpDirectoryW))
sei.lpDirectory = iciex->lpDirectoryW;
else if (pszDirA && SHAnsiToUnicode(pszDirA, dir, _countof(dir)))
sei.lpDirectory = dir;
}
return (ShellExecuteExW(&sei) ? S_OK : E_FAIL); return (ShellExecuteExW(&sei) ? S_OK : E_FAIL);
} }

View file

@ -1069,6 +1069,13 @@ HRESULT WINAPI CDesktopFolderViewCB::MessageSFVCB(UINT uMsg, WPARAM wParam, LPAR
case SFVM_VIEWRELEASE: case SFVM_VIEWRELEASE:
m_pShellView = NULL; m_pShellView = NULL;
return S_OK; return S_OK;
case SFVM_GETCOMMANDDIR:
{
WCHAR buf[MAX_PATH];
if (SHGetSpecialFolderPathW(NULL, buf, CSIDL_DESKTOPDIRECTORY, TRUE))
return StringCchCopyW((PWSTR)lParam, wParam, buf);
break;
}
} }
return E_NOTIMPL; return E_NOTIMPL;
} }

View file

@ -2076,6 +2076,10 @@ HRESULT WINAPI CFSFolder::MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
case SFVM_GET_CUSTOMVIEWINFO: case SFVM_GET_CUSTOMVIEWINFO:
hr = GetCustomViewInfo((ULONG)wParam, (SFVM_CUSTOMVIEWINFO_DATA *)lParam); hr = GetCustomViewInfo((ULONG)wParam, (SFVM_CUSTOMVIEWINFO_DATA *)lParam);
break; break;
case SFVM_GETCOMMANDDIR:
if (m_sPathTarget)
hr = StringCchCopyW((PWSTR)lParam, wParam, m_sPathTarget);
break;
} }
return hr; return hr;
} }