mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Powertoys Run] Implemented "hidden files" flag in native Windows Search (#5500)
* Implemented "hidden files" flag in native Windows Search * add missing file * Change InitQueryHelper back to static * Fix Line Endings * Add files via github Co-authored-by: Roy <royvou@hotmailcom>
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
{
|
||||
while (!wDSResults.IsClosed && wDSResults.Read())
|
||||
{
|
||||
List<object> fieldData = new List<object>();
|
||||
List<object> fieldData = new List<object>(wDSResults.FieldCount);
|
||||
for (int i = 0; i < wDSResults.FieldCount; i++)
|
||||
{
|
||||
fieldData.Add(wDSResults.GetValue(i));
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Search.Interop;
|
||||
|
||||
@@ -54,25 +53,19 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
// Loop over all records from the database
|
||||
foreach (OleDBResult oleDBResult in oleDBResults)
|
||||
{
|
||||
if (oleDBResult.FieldData[0] == DBNull.Value || oleDBResult.FieldData[1] == DBNull.Value || oleDBResult.FieldData[2] == DBNull.Value)
|
||||
if (oleDBResult.FieldData[0] == DBNull.Value || oleDBResult.FieldData[1] == DBNull.Value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint fileAttributes = (uint)((long)oleDBResult.FieldData[2]);
|
||||
bool isFileHidden = (fileAttributes & _fileAttributeHidden) == _fileAttributeHidden;
|
||||
|
||||
if (DisplayHiddenFiles || !isFileHidden)
|
||||
var uri_path = new Uri((string)oleDBResult.FieldData[0]);
|
||||
var result = new SearchResult
|
||||
{
|
||||
var uri_path = new Uri((string)oleDBResult.FieldData[0]);
|
||||
var result = new SearchResult
|
||||
{
|
||||
Path = uri_path.LocalPath,
|
||||
Title = (string)oleDBResult.FieldData[1],
|
||||
};
|
||||
Path = uri_path.LocalPath,
|
||||
Title = (string)oleDBResult.FieldData[1],
|
||||
};
|
||||
|
||||
results.Add(result);
|
||||
}
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
return results;
|
||||
@@ -108,7 +101,7 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitQueryHelper(out ISearchQueryHelper queryHelper, int maxCount)
|
||||
public static void InitQueryHelper(out ISearchQueryHelper queryHelper, int maxCount, bool displayHiddenFiles)
|
||||
{
|
||||
// This uses the Microsoft.Search.Interop assembly
|
||||
CSearchManager manager = new CSearchManager();
|
||||
@@ -128,6 +121,12 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
// Set additional query restriction
|
||||
queryHelper.QueryWhereRestrictions = "AND scope='file:'";
|
||||
|
||||
if (!displayHiddenFiles)
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/windows/win32/search/all-bitwise
|
||||
queryHelper.QueryWhereRestrictions += " AND System.FileAttributes <> SOME BITWISE " + _fileAttributeHidden;
|
||||
}
|
||||
|
||||
// To filter based on title for now
|
||||
queryHelper.QueryContentProperties = "System.FileName";
|
||||
|
||||
@@ -138,7 +137,7 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
public IEnumerable<SearchResult> Search(string keyword, bool isFullQuery = false, string pattern = "*", int maxCount = 30)
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, maxCount);
|
||||
InitQueryHelper(out queryHelper, maxCount, DisplayHiddenFiles);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
return ExecuteQuery(queryHelper, keyword, isFullQuery);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user