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

commit b6b7bda44328c9fd5d9c1e94a9042723209b80c2
Author:     Doug Lyons <[email protected]>
AuthorDate: Sat Oct 5 09:32:49 2019 -0500
Commit:     Mark Jansen <[email protected]>
CommitDate: Sat Oct 5 16:32:49 2019 +0200

    Shell Find Improvements to make Search Item general and Show 
Sub-directories (#1927)
    
    * Shell Find Improvement to make Search Item general by adding asterisks 
before and after before search and show sub-directories in find listing. 
CORE-16152
---
 dll/win32/browseui/shellfind/CFindFolder.cpp |  6 ++++++
 dll/win32/browseui/shellfind/CSearchBar.cpp  | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/dll/win32/browseui/shellfind/CFindFolder.cpp 
b/dll/win32/browseui/shellfind/CFindFolder.cpp
index 0a2aec890ac..4db35f633b3 100644
--- a/dll/win32/browseui/shellfind/CFindFolder.cpp
+++ b/dll/win32/browseui/shellfind/CFindFolder.cpp
@@ -260,6 +260,12 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData 
*pSearchData)
         if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         {
             CStringW status;
+            if ((pSearchData->szFileName.IsEmpty() || 
PathMatchSpecW(FindData.cFileName, pSearchData->szFileName))
+                && (pSearchData->szQueryA.IsEmpty() || SearchFile(szPath, 
pSearchData)))
+            {
+                PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, 
(LPARAM) StrDupW(szPath));
+                uTotalFound++;
+            }
             status.Format(IDS_SEARCH_FOLDER, FindData.cFileName);
             PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, 
(LPARAM) StrDupW(status.GetBuffer()));
 
diff --git a/dll/win32/browseui/shellfind/CSearchBar.cpp 
b/dll/win32/browseui/shellfind/CSearchBar.cpp
index 6d486cec370..5e7117193d4 100644
--- a/dll/win32/browseui/shellfind/CSearchBar.cpp
+++ b/dll/win32/browseui/shellfind/CSearchBar.cpp
@@ -122,6 +122,10 @@ HRESULT CSearchBar::GetSearchResultsFolder(IShellBrowser 
**ppShellBrowser, HWND
 
 LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND 
hWndCtl, BOOL& bHandled)
 {
+    size_t len = 0;
+    WCHAR endchar;
+    WCHAR startchar;
+
     CComHeapPtr<SearchStart> pSearchStart(static_cast<SearchStart 
*>(CoTaskMemAlloc(sizeof(SearchStart))));
     GetDlgItemText(IDC_SEARCH_FILENAME, pSearchStart->szFileName, 
_countof(pSearchStart->szFileName));
     GetDlgItemText(IDC_SEARCH_QUERY, pSearchStart->szQuery, 
_countof(pSearchStart->szQuery));
@@ -131,6 +135,30 @@ LRESULT CSearchBar::OnSearchButtonClicked(WORD 
wNotifyCode, WORD wID, HWND hWndC
         return 0;
     }
 
+    // See if we have an szFileName by testing for its entry lenth > 0 and our 
searched FileName does not contain
+    // an asterisk or a question mark. If so, then prepend and append an 
asterisk to the searched FileName.
+    // (i.e. it's equivalent to searching for *<the_file_name>* )
+    if (FAILED (StringCchLengthW (pSearchStart->szFileName, MAX_PATH, &len))) 
return 0;
+    if ((len > 0) && !wcspbrk(pSearchStart->szFileName, L"*?"))
+    {
+        endchar = pSearchStart->szFileName[len - 1];
+        startchar = pSearchStart->szFileName[0];
+        if ((len < MAX_PATH - 1) && (startchar != L'*'))
+        {
+            memmove(&pSearchStart->szFileName[1], &pSearchStart->szFileName[0],
+                   len * sizeof(WCHAR) + sizeof(WCHAR));
+            len = len + 1;
+            pSearchStart->szFileName[0] = L'*';
+        }
+
+        // See if our last character is an asterisk and if not and we have 
room then add one
+        if ((len < MAX_PATH - 1) && (endchar != L'*'))
+            StringCchCatW(pSearchStart->szFileName, MAX_PATH, L"*");
+    }
+
+    // Print our final search string for szFileName
+    TRACE("Searched szFileName is '%S'.\n", pSearchStart->szFileName);
+
     CComPtr<IShellBrowser> pShellBrowser;
     HRESULT hr = IUnknown_QueryService(m_pSite, SID_SShellBrowser, 
IID_PPV_ARG(IShellBrowser, &pShellBrowser));
     if (FAILED_UNEXPECTEDLY(hr))

Reply via email to