[SHELL32] Don't add the file to the parameters if the registry command did not ask for a file (#7139)

Bugs fixed:
 - fDefault detection of default verb is flawed because it checks the ici struct after conversion instead of the source sei struct.
 - The command to execute should not have the filename appended just because %1 nor %L did not appear in the registry command template.
This commit is contained in:
Whindmar Saksit 2024-08-08 19:30:14 +02:00 committed by GitHub
parent 8f483a76a6
commit 724b20d414
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 26 deletions

View file

@ -1302,8 +1302,7 @@ CDefaultContextMenu::TryToBrowse(
HRESULT
CDefaultContextMenu::InvokePidl(LPCMINVOKECOMMANDINFOEX lpcmi, LPCITEMIDLIST pidl, PStaticShellEntry pEntry)
{
BOOL unicode = lpcmi->cbSize >= FIELD_OFFSET(CMINVOKECOMMANDINFOEX, ptInvoke) &&
(lpcmi->fMask & CMIC_MASK_UNICODE);
const BOOL unicode = IsUnicode(*lpcmi);
LPITEMIDLIST pidlFull = ILCombine(m_pidlFolder, pidl);
if (pidlFull == NULL)
@ -1315,7 +1314,23 @@ CDefaultContextMenu::InvokePidl(LPCMINVOKECOMMANDINFOEX lpcmi, LPCITEMIDLIST pid
BOOL bHasPath = SHGetPathFromIDListW(pidlFull, wszPath);
WCHAR wszDir[MAX_PATH];
if (bHasPath)
SHELLEXECUTEINFOW sei = { sizeof(sei) };
sei.fMask = SEE_MASK_CLASSKEY | SEE_MASK_IDLIST | (CmicFlagsToSeeFlags(lpcmi->fMask) & ~SEE_MASK_INVOKEIDLIST);
sei.hwnd = lpcmi->hwnd;
sei.nShow = lpcmi->nShow;
sei.lpVerb = pEntry->Verb;
sei.lpIDList = pidlFull;
sei.hkeyClass = pEntry->hkClass;
sei.dwHotKey = lpcmi->dwHotKey;
sei.hIcon = lpcmi->hIcon;
sei.lpDirectory = wszDir;
if (unicode && !StrIsNullOrEmpty(lpcmi->lpDirectoryW))
{
sei.lpDirectory = lpcmi->lpDirectoryW;
}
else if (bHasPath)
{
wcscpy(wszDir, wszPath);
PathRemoveFileSpec(wszDir);
@ -1326,25 +1341,16 @@ CDefaultContextMenu::InvokePidl(LPCMINVOKECOMMANDINFOEX lpcmi, LPCITEMIDLIST pid
*wszDir = UNICODE_NULL;
}
CComHeapPtr<WCHAR> pszParamsW;
SHELLEXECUTEINFOW sei = { sizeof(sei) };
sei.hwnd = lpcmi->hwnd;
sei.nShow = SW_SHOWNORMAL;
sei.lpVerb = pEntry->Verb;
sei.lpDirectory = wszDir;
sei.lpIDList = pidlFull;
sei.hkeyClass = pEntry->hkClass;
sei.fMask = SEE_MASK_CLASSKEY | SEE_MASK_IDLIST;
if (bHasPath)
sei.lpFile = wszPath;
CComHeapPtr<WCHAR> pszParamsW;
if (unicode && !StrIsNullOrEmpty(lpcmi->lpParametersW))
sei.lpParameters = lpcmi->lpParametersW;
else if (!StrIsNullOrEmpty(lpcmi->lpParameters) && __SHCloneStrAtoW(&pszParamsW, lpcmi->lpParameters))
sei.lpParameters = pszParamsW;
ShellExecuteExW(&sei);
ILFree(pidlFull);
return S_OK;