Skip to content

Commit b6b7bda

Browse files
Doug-Lyonslearn-more
authored andcommitted
Shell Find Improvements to make Search Item general and Show Sub-directories (reactos#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
1 parent 36d9e80 commit b6b7bda

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

dll/win32/browseui/shellfind/CFindFolder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ static UINT RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
260260
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
261261
{
262262
CStringW status;
263+
if ((pSearchData->szFileName.IsEmpty() || PathMatchSpecW(FindData.cFileName, pSearchData->szFileName))
264+
&& (pSearchData->szQueryA.IsEmpty() || SearchFile(szPath, pSearchData)))
265+
{
266+
PostMessageW(pSearchData->hwnd, WM_SEARCH_ADD_RESULT, 0, (LPARAM) StrDupW(szPath));
267+
uTotalFound++;
268+
}
263269
status.Format(IDS_SEARCH_FOLDER, FindData.cFileName);
264270
PostMessageW(pSearchData->hwnd, WM_SEARCH_UPDATE_STATUS, 0, (LPARAM) StrDupW(status.GetBuffer()));
265271

dll/win32/browseui/shellfind/CSearchBar.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ HRESULT CSearchBar::GetSearchResultsFolder(IShellBrowser **ppShellBrowser, HWND
122122

123123
LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
124124
{
125+
size_t len = 0;
126+
WCHAR endchar;
127+
WCHAR startchar;
128+
125129
CComHeapPtr<SearchStart> pSearchStart(static_cast<SearchStart *>(CoTaskMemAlloc(sizeof(SearchStart))));
126130
GetDlgItemText(IDC_SEARCH_FILENAME, pSearchStart->szFileName, _countof(pSearchStart->szFileName));
127131
GetDlgItemText(IDC_SEARCH_QUERY, pSearchStart->szQuery, _countof(pSearchStart->szQuery));
@@ -131,6 +135,30 @@ LRESULT CSearchBar::OnSearchButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndC
131135
return 0;
132136
}
133137

138+
// See if we have an szFileName by testing for its entry lenth > 0 and our searched FileName does not contain
139+
// an asterisk or a question mark. If so, then prepend and append an asterisk to the searched FileName.
140+
// (i.e. it's equivalent to searching for *<the_file_name>* )
141+
if (FAILED (StringCchLengthW (pSearchStart->szFileName, MAX_PATH, &len))) return 0;
142+
if ((len > 0) && !wcspbrk(pSearchStart->szFileName, L"*?"))
143+
{
144+
endchar = pSearchStart->szFileName[len - 1];
145+
startchar = pSearchStart->szFileName[0];
146+
if ((len < MAX_PATH - 1) && (startchar != L'*'))
147+
{
148+
memmove(&pSearchStart->szFileName[1], &pSearchStart->szFileName[0],
149+
len * sizeof(WCHAR) + sizeof(WCHAR));
150+
len = len + 1;
151+
pSearchStart->szFileName[0] = L'*';
152+
}
153+
154+
// See if our last character is an asterisk and if not and we have room then add one
155+
if ((len < MAX_PATH - 1) && (endchar != L'*'))
156+
StringCchCatW(pSearchStart->szFileName, MAX_PATH, L"*");
157+
}
158+
159+
// Print our final search string for szFileName
160+
TRACE("Searched szFileName is '%S'.\n", pSearchStart->szFileName);
161+
134162
CComPtr<IShellBrowser> pShellBrowser;
135163
HRESULT hr = IUnknown_QueryService(m_pSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pShellBrowser));
136164
if (FAILED_UNEXPECTEDLY(hr))

0 commit comments

Comments
 (0)