[SHELL32] Don't add folder verbs to non-folder RegItems (#6991)

RegItems that pretend to be files should not have Folder verbs
This commit is contained in:
Whindmar Saksit 2024-06-05 02:12:58 +02:00 committed by GitHub
parent ee92f4b28e
commit 82721de625
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 29 deletions

View file

@ -97,19 +97,22 @@ HRESULT CGuidItemContextMenu_CreateInstance(PCIDLIST_ABSOLUTE pidlFolder,
GUID *pGuid = _ILGetGUIDPointer(apidl[0]);
if (pGuid)
{
LPOLESTR pwszCLSID;
WCHAR key[60];
wcscpy(key, L"CLSID\\");
HRESULT hr = StringFromCLSID(*pGuid, &pwszCLSID);
if (hr == S_OK)
{
wcscpy(&key[6], pwszCLSID);
AddClassKeyToArray(key, hKeys, &cKeys);
CoTaskMemFree(pwszCLSID);
}
StringFromGUID2(*pGuid, &key[6], 39);
AddClassKeyToArray(key, hKeys, &cKeys);
}
AddClassKeyToArray(L"Folder", hKeys, &cKeys);
// FIXME: CRegFolder should be aggregated by its outer folder and should
// provide the attributes for all required non-registry folders.
// It currently does not so we have to ask the outer folder ourself so
// that we get the correct attributes for My Computer etc.
CComPtr<IShellFolder> pOuterSF;
SHBindToObject(NULL, pidlFolder, IID_PPV_ARG(IShellFolder, &pOuterSF));
SFGAOF att = (psf && cidl) ? SHGetAttributes(pOuterSF ? pOuterSF.p : psf, apidl[0], SFGAO_FOLDER) : 0;
if (att & SFGAO_FOLDER)
AddClassKeyToArray(L"Folder", hKeys, &cKeys);
return CDefFolderMenu_Create2(pidlFolder, hwnd, cidl, apidl, psf, RegFolderContextMenuCallback, cKeys, hKeys, ppcm);
}
@ -390,10 +393,7 @@ HRESULT CRegFolder::GetGuidItemAttributes (LPCITEMIDLIST pidl, LPDWORD pdwAttrib
}
/* In any case, links can be created */
if (*pdwAttributes == NULL)
{
*pdwAttributes |= (dwAttributes & SFGAO_CANLINK);
}
*pdwAttributes |= (dwAttributes & SFGAO_CANLINK);
return S_OK;
}

View file

@ -245,20 +245,16 @@ Shell_DisplayNameOf(
DWORD
SHGetAttributes(_In_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ DWORD dwAttributes)
{
LPCITEMIDLIST pidlLast;
if (psf)
{
psf->AddRef();
pidlLast = pidl;
}
else
{
SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast);
}
LPCITEMIDLIST pidlLast = pidl;
IShellFolder *release = NULL;
if (!psf)
return 0;
{
SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast);
if (!psf)
return 0;
release = psf;
}
DWORD oldAttrs = dwAttributes;
if (FAILED(psf->GetAttributesOf(1, &pidlLast, &dwAttributes)))
@ -276,9 +272,8 @@ SHGetAttributes(_In_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ DWORD dwAt
dwAttributes |= SFGAO_STORAGEANCESTOR;
}
if (psf)
psf->Release();
if (release)
release->Release();
return dwAttributes;
}