https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1c706d7483b321bde3e1e43476eb92b6e2e4ca40

commit 1c706d7483b321bde3e1e43476eb92b6e2e4ca40
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Thu Apr 9 16:56:54 2020 +0900
Commit:     GitHub <[email protected]>
CommitDate: Thu Apr 9 16:56:54 2020 +0900

    [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
---
 dll/win32/shell32/CDefView.cpp                   | 33 +++++++++++++--
 dll/win32/shell32/CShellLink.cpp                 | 11 +++++
 dll/win32/shell32/shelldesktop/CChangeNotify.cpp | 51 +++++-------------------
 3 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/dll/win32/shell32/CDefView.cpp b/dll/win32/shell32/CDefView.cpp
index ff3ce600c38..48591cc3c71 100644
--- a/dll/win32/shell32/CDefView.cpp
+++ b/dll/win32/shell32/CDefView.cpp
@@ -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, ??  ??) */
 
diff --git a/dll/win32/shell32/CShellLink.cpp b/dll/win32/shell32/CShellLink.cpp
index 047813cfaab..2800510990a 100644
--- a/dll/win32/shell32/CShellLink.cpp
+++ b/dll/win32/shell32/CShellLink.cpp
@@ -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);
 
diff --git a/dll/win32/shell32/shelldesktop/CChangeNotify.cpp 
b/dll/win32/shell32/shelldesktop/CChangeNotify.cpp
index 8048a847ad6..32d00cb1e6f 100644
--- a/dll/win32/shell32/shelldesktop/CChangeNotify.cpp
+++ b/dll/win32/shell32/shelldesktop/CChangeNotify.cpp
@@ -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;

Reply via email to