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
This commit is contained in:
Doug Lyons 2019-10-05 09:32:49 -05:00 committed by Mark Jansen
parent 36d9e80add
commit b6b7bda443
2 changed files with 34 additions and 0 deletions

View file

@ -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()));

View file

@ -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))