[SHELL32] Watch for common desktop and SHCNE_CREATE for IShellLink::Save (#2515)

- On desktop view, we have to watch both the common desktop and the private desktop.
- In Windows, IShellLink::Save (shortcut creation) sends SHCNE_CREATE or SHCNE_UPDATEITEM notification.
- Simplify CChangeNotify::ShouldNotify.
CORE-10391
This commit is contained in:
Katayama Hirofumi MZ 2020-04-09 16:56:54 +09:00 committed by GitHub
parent 0d187f7d56
commit 1c706d7483
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 45 deletions

View file

@ -1157,11 +1157,36 @@ LRESULT CDefView::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandl
SetShellWindowEx(hwndSB, m_ListView);
}
SHChangeNotifyEntry ntreg;
ntreg.fRecursive = TRUE;
ntreg.pidl = m_pidlParent;
INT nRegCount;
SHChangeNotifyEntry ntreg[3];
PIDLIST_ABSOLUTE pidls[3];
if (_ILIsDesktop(m_pidlParent))
{
nRegCount = 3;
SHGetSpecialFolderLocation(m_hWnd, CSIDL_DESKTOPDIRECTORY, &pidls[0]);
SHGetSpecialFolderLocation(m_hWnd, CSIDL_COMMON_DESKTOPDIRECTORY, &pidls[1]);
SHGetSpecialFolderLocation(m_hWnd, CSIDL_BITBUCKET, &pidls[2]);
ntreg[0].fRecursive = FALSE;
ntreg[0].pidl = pidls[0];
ntreg[1].fRecursive = FALSE;
ntreg[1].pidl = pidls[1];
ntreg[2].fRecursive = FALSE;
ntreg[2].pidl = pidls[2];
}
else
{
nRegCount = 1;
ntreg[0].fRecursive = FALSE;
ntreg[0].pidl = m_pidlParent;
}
m_hNotify = SHChangeNotifyRegister(m_hWnd, SHCNRF_NewDelivery | SHCNRF_ShellLevel,
SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, 1, &ntreg);
SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, nRegCount, ntreg);
if (nRegCount == 3)
{
ILFree(pidls[0]);
ILFree(pidls[1]);
ILFree(pidls[2]);
}
/* _DoFolderViewCB(SFVM_GETNOTIFY, ?? ??) */

View file

@ -344,11 +344,16 @@ HRESULT STDMETHODCALLTYPE CShellLink::Load(LPCOLESTR pszFileName, DWORD dwMode)
HRESULT STDMETHODCALLTYPE CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember)
{
BOOL bAlreadyExists;
WCHAR szFullPath[MAX_PATH];
TRACE("(%p)->(%s)\n", this, debugstr_w(pszFileName));
if (!pszFileName)
return E_FAIL;
bAlreadyExists = PathFileExistsW(pszFileName);
CComPtr<IStream> stm;
HRESULT hr = SHCreateStreamOnFileW(pszFileName, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &stm);
if (SUCCEEDED(hr))
@ -357,6 +362,12 @@ HRESULT STDMETHODCALLTYPE CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember
if (SUCCEEDED(hr))
{
GetFullPathNameW(pszFileName, _countof(szFullPath), szFullPath, NULL);
if (bAlreadyExists)
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATHW, szFullPath, NULL);
else
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, szFullPath, NULL);
if (m_sLinkPath)
HeapFree(GetProcessHeap(), 0, m_sLinkPath);

View file

@ -536,58 +536,27 @@ BOOL CChangeNotify::DoDelivery(HANDLE hTicket, DWORD dwOwnerPID)
BOOL CChangeNotify::ShouldNotify(LPDELITICKET pTicket, LPNOTIFSHARE pShared)
{
BOOL ret = FALSE;
LPITEMIDLIST pidl = NULL, pidl1 = NULL, pidl2 = NULL;
WCHAR szPath[MAX_PATH], szPath1[MAX_PATH], szPath2[MAX_PATH];
INT cch, cch1, cch2;
BOOL ret;
LPITEMIDLIST pidl, pidl1, pidl2;
szPath[0] = szPath1[0] = szPath2[0] = 0;
if (!pShared->ibPidl)
return TRUE;
if (pShared->ibPidl)
{
pidl = (LPITEMIDLIST)((LPBYTE)pShared + pShared->ibPidl);
SHGetPathFromIDListW(pidl, szPath);
PathAddBackslashW(szPath);
}
ret = FALSE;
pidl = (LPITEMIDLIST)((LPBYTE)pShared + pShared->ibPidl);
if (pTicket->ibOffset1)
if (!ret && pTicket->ibOffset1)
{
pidl1 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset1);
if (ILIsEqual(pidl, pidl1))
if (ILIsEqual(pidl, pidl1) || ILIsParent(pidl, pidl1, !pShared->fRecursive))
ret = TRUE;
SHGetPathFromIDListW(pidl1, szPath1);
PathAddBackslashW(szPath1);
}
if (pTicket->ibOffset2)
if (!ret && pTicket->ibOffset2)
{
pidl2 = (LPITEMIDLIST)((LPBYTE)pTicket + pTicket->ibOffset2);
if (ILIsEqual(pidl, pidl2))
if (ILIsEqual(pidl, pidl2) || ILIsParent(pidl, pidl2, !pShared->fRecursive))
ret = TRUE;
SHGetPathFromIDListW(pidl2, szPath2);
PathAddBackslashW(szPath2);
}
if (pShared->fRecursive)
{
if (szPath1[0] == 0)
ret = TRUE;
cch = lstrlenW(szPath);
cch1 = lstrlenW(szPath1);
cch2 = lstrlenW(szPath2);
if (cch < cch1)
{
szPath1[cch] = 0;
if (lstrcmpiW(szPath, szPath1) == 0)
ret = TRUE;
}
if (cch < cch2)
{
szPath2[cch] = 0;
if (lstrcmpiW(szPath, szPath2) == 0)
ret = TRUE;
}
}
return ret;