[SENDMAIL] Fix Send To -> Desktop (create shortcut) behavior (#4913)

Several fixes and improvements to the CDeskLinkDropHandler:
- Set default working directory for shortcuts (except folders and zip files)
- Copy existing shortcut to the desktop if the source file is a shortcut
- Prevent destination file name collision

Verified on Windows XP SP3 and Windows 7 SP1.
This commit is contained in:
Thamatip Chitpong 2022-12-04 00:06:45 +07:00 committed by GitHub
parent feff2b1e6c
commit 7c2b22c4de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,14 +86,49 @@ CDeskLinkDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState,
StringCbCopyW(szDest, sizeof(szDest), szDir);
if (SHGetPathFromIDListW(pidl, szSrc))
{
CStringW strTitle;
strTitle.Format(IDS_SHORTCUT, PathFindFileNameW(szSrc));
LPCWSTR pszSourceExt;
BOOL bIsLink;
PathAppendW(szDest, strTitle);
PathRemoveExtensionW(szDest);
StringCbCatW(szDest, sizeof(szDest), L".lnk");
pszSourceExt = PathFindExtensionW(szSrc);
bIsLink = ((_wcsicmp(pszSourceExt, L".lnk") == 0) ||
(_wcsicmp(pszSourceExt, L".url") == 0));
hr = CreateShellLink(szDest, szSrc, NULL, NULL, NULL, NULL, -1, NULL);
if (bIsLink)
{
PathAppendW(szDest, PathFindFileNameW(szSrc));
}
else
{
CStringW strTitle;
strTitle.Format(IDS_SHORTCUT, PathFindFileNameW(szSrc));
PathAppendW(szDest, strTitle);
PathRemoveExtensionW(szDest);
StringCbCatW(szDest, sizeof(szDest), L".lnk");
}
if (PathFileExistsW(szDest))
{
CStringW strName(PathFindFileNameW(szDest));
PathYetAnotherMakeUniqueName(szDest, szDir, NULL, strName);
}
if (bIsLink)
{
hr = (CopyFileW(szSrc, szDest, TRUE) ? S_OK : E_FAIL);
}
else if (PathIsDirectoryW(szSrc) || (_wcsicmp(pszSourceExt, L".zip") == 0))
{
hr = CreateShellLink(szDest, szSrc, NULL, NULL, NULL, NULL, -1, NULL);
}
else
{
/* Set default working directory for the shortcut */
CStringW strWorkingDir(szSrc);
PathRemoveFileSpecW(strWorkingDir.GetBuffer());
hr = CreateShellLink(szDest, szSrc, NULL, NULL, strWorkingDir, NULL, -1, NULL);
}
}
else
{