https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a17b6e9369568dbbfc67e…
commit a17b6e9369568dbbfc67edc0dd7bbe454127eb87
Author: Whindmar Saksit <whindsaks(a)proton.me>
AuthorDate: Fri Nov 8 23:27:26 2024 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 8 23:27:26 2024 +0100
[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
---
dll/win32/browseui/shellfind/CFindFolder.cpp | 16 ++++++++++++++++
dll/win32/shell32/CShellLink.cpp | 11 ++++++++++-
dll/win32/shell32/folders/CDesktopFolder.cpp | 7 +++++++
dll/win32/shell32/folders/CFSFolder.cpp | 4 ++++
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/dll/win32/browseui/shellfind/CFindFolder.cpp
b/dll/win32/browseui/shellfind/CFindFolder.cpp
index 6e01db9c44a..1c254e75ab5 100644
--- a/dll/win32/browseui/shellfind/CFindFolder.cpp
+++ b/dll/win32/browseui/shellfind/CFindFolder.cpp
@@ -937,6 +937,22 @@ STDMETHODIMP CFindFolder::MessageSFVCB(UINT uMsg, WPARAM wParam,
LPARAM lParam)
CComVariant searchBar(pwszGuid);
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;
}
diff --git a/dll/win32/shell32/CShellLink.cpp b/dll/win32/shell32/CShellLink.cpp
index 685391a9262..582a605ba54 100644
--- a/dll/win32/shell32/CShellLink.cpp
+++ b/dll/win32/shell32/CShellLink.cpp
@@ -2623,6 +2623,7 @@ HRESULT STDMETHODCALLTYPE
CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
{
+ LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici;
const BOOL unicode = IsUnicode(*lpici);
CStringW args;
@@ -2631,7 +2632,6 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
if (unicode)
{
- LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici;
if (!StrIsNullOrEmpty(iciex->lpParametersW))
{
args += L' ';
@@ -2674,6 +2674,15 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
if (lpici->nShow != SW_SHOWNORMAL && lpici->nShow != SW_SHOW)
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);
}
diff --git a/dll/win32/shell32/folders/CDesktopFolder.cpp
b/dll/win32/shell32/folders/CDesktopFolder.cpp
index ee1c10834dc..945f3450ede 100644
--- a/dll/win32/shell32/folders/CDesktopFolder.cpp
+++ b/dll/win32/shell32/folders/CDesktopFolder.cpp
@@ -1069,6 +1069,13 @@ HRESULT WINAPI CDesktopFolderViewCB::MessageSFVCB(UINT uMsg, WPARAM
wParam, LPAR
case SFVM_VIEWRELEASE:
m_pShellView = NULL;
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;
}
diff --git a/dll/win32/shell32/folders/CFSFolder.cpp
b/dll/win32/shell32/folders/CFSFolder.cpp
index 4943eeba0f1..0a209ade806 100644
--- a/dll/win32/shell32/folders/CFSFolder.cpp
+++ b/dll/win32/shell32/folders/CFSFolder.cpp
@@ -2076,6 +2076,10 @@ HRESULT WINAPI CFSFolder::MessageSFVCB(UINT uMsg, WPARAM wParam,
LPARAM lParam)
case SFVM_GET_CUSTOMVIEWINFO:
hr = GetCustomViewInfo((ULONG)wParam, (SFVM_CUSTOMVIEWINFO_DATA *)lParam);
break;
+ case SFVM_GETCOMMANDDIR:
+ if (m_sPathTarget)
+ hr = StringCchCopyW((PWSTR)lParam, wParam, m_sPathTarget);
+ break;
}
return hr;
}