[CmdPal][AOT] Make fileSearch ext become AOT compatible (#39732)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
* Use source generation to replace some csWin32 function call.
* Clean up some AOT compatible issues.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] **Closes:** #39889
- [x] **Communication:** I've discussed this with core contributors
already. If work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end user facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

If you want to try it out, please see
https://github.com/microsoft/PowerToys/pull/39605

---------

Co-authored-by: Yu Leng <yuleng@microsoft.com>
This commit is contained in:
Yu Leng
2025-06-04 17:15:55 +08:00
committed by GitHub
parent 78c7c8e88f
commit ddbb6161e3
33 changed files with 603 additions and 913 deletions

View File

@@ -1996,3 +1996,14 @@ Evercoder
LCh LCh
CIELCh CIELCh
CLSCTXINPROCALL CLSCTXINPROCALL
IIDI
irow
lcid
OTHERUNZOOM
OTHERZOOM
PARENTCLOSING
PARENTOPENING
ppwsz
rguid
SCROLLCHILDREN
VARTYPE

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ManagedCommon; using ManagedCommon;
using Microsoft.CmdPal.Ext.Indexer.Data; using Microsoft.CmdPal.Ext.Indexer.Data;
@@ -13,6 +14,7 @@ using Windows.Win32;
using Windows.Win32.Foundation; using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell; using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging; using Windows.Win32.UI.WindowsAndMessaging;
using static Microsoft.CmdPal.Ext.Indexer.Native.NativeMethods;
namespace Microsoft.CmdPal.Ext.Indexer.Commands; namespace Microsoft.CmdPal.Ext.Indexer.Commands;
@@ -27,19 +29,16 @@ internal sealed partial class OpenPropertiesCommand : InvokableCommand
try try
{ {
var filenamePCWSTR = new PCWSTR((char*)filenamePtr);
var propertiesPCWSTR = new PCWSTR((char*)propertiesPtr);
var info = new SHELLEXECUTEINFOW var info = new SHELLEXECUTEINFOW
{ {
cbSize = (uint)Marshal.SizeOf<SHELLEXECUTEINFOW>(), cbSize = (uint)sizeof(SHELLEXECUTEINFOW),
lpVerb = propertiesPCWSTR, lpVerb = propertiesPtr,
lpFile = filenamePCWSTR, lpFile = filenamePtr,
nShow = (int)SHOW_WINDOW_CMD.SW_SHOW, nShow = (int)SHOW_WINDOW_CMD.SW_SHOW,
fMask = NativeHelpers.SEEMASKINVOKEIDLIST, fMask = NativeHelpers.SEEMASKINVOKEIDLIST,
}; };
return PInvoke.ShellExecuteEx(ref info); return ShellExecuteEx(ref info);
} }
finally finally
{ {

View File

@@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.CmdPal.Ext.Indexer.Data; using Microsoft.CmdPal.Ext.Indexer.Data;
using Microsoft.CmdPal.Ext.Indexer.Native; using Microsoft.CmdPal.Ext.Indexer.Native;
@@ -11,6 +13,7 @@ using Windows.Win32;
using Windows.Win32.Foundation; using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell; using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging; using Windows.Win32.UI.WindowsAndMessaging;
using static Microsoft.CmdPal.Ext.Indexer.Native.NativeMethods;
namespace Microsoft.CmdPal.Ext.Indexer.Commands; namespace Microsoft.CmdPal.Ext.Indexer.Commands;
@@ -25,19 +28,16 @@ internal sealed partial class OpenWithCommand : InvokableCommand
try try
{ {
var filenamePCWSTR = new PCWSTR((char*)filenamePtr);
var verbPCWSTR = new PCWSTR((char*)verbPtr);
var info = new SHELLEXECUTEINFOW var info = new SHELLEXECUTEINFOW
{ {
cbSize = (uint)Marshal.SizeOf<SHELLEXECUTEINFOW>(), cbSize = (uint)sizeof(SHELLEXECUTEINFOW),
lpVerb = verbPCWSTR, lpVerb = verbPtr,
lpFile = filenamePCWSTR, lpFile = filenamePtr,
nShow = (int)SHOW_WINDOW_CMD.SW_SHOWNORMAL, nShow = (int)SHOW_WINDOW_CMD.SW_SHOWNORMAL,
fMask = NativeHelpers.SEEMASKINVOKEIDLIST, fMask = NativeHelpers.SEEMASKINVOKEIDLIST,
}; };
return PInvoke.ShellExecuteEx(ref info); return ShellExecuteEx(ref info);
} }
finally finally
{ {

View File

@@ -3,17 +3,17 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using ManagedCommon; using ManagedCommon;
using Windows.Win32; using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
using Windows.Win32.System.Com; using Microsoft.CmdPal.Ext.Indexer.Native;
using Windows.Win32.System.Search;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer; namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
internal static class DataSourceManager internal static class DataSourceManager
{ {
private static readonly Guid CLSIDCollatorDataSource = new("9E175B8B-F52A-11D8-B9A5-505054503030");
private static IDBInitialize _dataSource; private static IDBInitialize _dataSource;
public static IDBInitialize GetDataSource() public static IDBInitialize GetDataSource()
@@ -28,20 +28,29 @@ internal static class DataSourceManager
private static bool InitializeDataSource() private static bool InitializeDataSource()
{ {
var hr = PInvoke.CoCreateInstance(CLSIDCollatorDataSource, null, CLSCTX.CLSCTX_INPROC_SERVER, typeof(IDBInitialize).GUID, out var dataSourceObj); var riid = typeof(IDBInitialize).GUID;
var hr = NativeMethods.CoCreateInstance(ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.CLSIDCollatorDataSource), IntPtr.Zero, NativeHelpers.CLSCTXINPROCALL, ref riid, out var dataSourceObjPtr);
if (hr != 0) if (hr != 0)
{ {
Logger.LogError("CoCreateInstance failed: " + hr); Logger.LogError("CoCreateInstance failed: " + hr);
return false; return false;
} }
if (dataSourceObj == null) if (dataSourceObjPtr == IntPtr.Zero)
{
Logger.LogError("CoCreateInstance failed: dataSourceObjPtr is null");
return false;
}
var comWrappers = new StrategyBasedComWrappers();
_dataSource = (IDBInitialize)comWrappers.GetOrCreateObjectForComInstance(dataSourceObjPtr, CreateObjectFlags.None);
if (_dataSource == null)
{ {
Logger.LogError("CoCreateInstance failed: dataSourceObj is null"); Logger.LogError("CoCreateInstance failed: dataSourceObj is null");
return false; return false;
} }
_dataSource = (IDBInitialize)dataSourceObj;
_dataSource.Initialize(); _dataSource.Initialize();
return true; return true;

View File

@@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
using Microsoft.CmdPal.Ext.Indexer.Native;
using Windows.Win32.Storage.IndexServer; using Windows.Win32.Storage.IndexServer;
using Windows.Win32.System.Com.StructuredStorage; using Windows.Win32.System.Com.StructuredStorage;
@@ -16,6 +18,6 @@ internal struct DBPROP
public uint dwOptions; public uint dwOptions;
public uint dwStatus; public uint dwStatus;
public DBID colid; public DBID colid;
public PROPVARIANT vValue; public PropVariant vValue;
#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter #pragma warning restore SA1307 // Accessible fields should begin with upper-case letter
} }

View File

@@ -4,40 +4,38 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
[ComImport]
[Guid("0c733a7c-2a1c-11ce-ade5-00aa0044773d")] [Guid("0c733a7c-2a1c-11ce-ade5-00aa0044773d")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [GeneratedComInterface]
public interface IRowset public partial interface IRowset
{ {
[PreserveSig] void AddRefRows(
int AddRefRows(
uint cRows, uint cRows,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] rghRows, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] rghRows,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] uint[] rgRefCounts, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] uint[] rgRefCounts,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] rgRowStatus); [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] rgRowStatus);
[PreserveSig] void GetData(
int GetData(
IntPtr hRow, IntPtr hRow,
IntPtr hAccessor, IntPtr hAccessor,
IntPtr pData); IntPtr pData);
[PreserveSig] void GetNextRows(
int GetNextRows(
IntPtr hReserved, IntPtr hReserved,
long lRowsOffset, long lRowsOffset,
long cRows, long cRows,
out uint pcRowsObtained, out uint pcRowsObtained,
out IntPtr prghRows); out IntPtr prghRows);
[PreserveSig] void ReleaseRows(
int ReleaseRows(
uint cRows, uint cRows,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] rghRows, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] rghRows,
IntPtr rgRowOptions, IntPtr rgRowOptions,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] uint[] rgRefCounts, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] uint[] rgRefCounts,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] rgRowStatus); [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] rgRowStatus);
void RestartPosition(nuint hReserved);
} }

View File

@@ -4,29 +4,29 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
[ComImport]
[Guid("0C733A55-2A1C-11CE-ADE5-00AA0044773D")] [Guid("0C733A55-2A1C-11CE-ADE5-00AA0044773D")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [GeneratedComInterface]
public interface IRowsetInfo public partial interface IRowsetInfo
{ {
[PreserveSig] [PreserveSig]
int GetProperties( int GetProperties(
uint cPropertyIDSets, uint cPropertyIDSets,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] DBPROPIDSET[] rgPropertyIDSets, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] DBPROPIDSET[] rgPropertyIDSets,
out ulong pcPropertySets, out ulong pcPropertySets,
out IntPtr prgPropertySets); out IntPtr prgPropertySets);
[PreserveSig] [PreserveSig]
int GetReferencedRowset( int GetReferencedRowset(
uint iOrdinal, uint iOrdinal,
[In] ref Guid riid, ref Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppReferencedRowset); [MarshalAs(UnmanagedType.Interface)] out object ppReferencedRowset);
[PreserveSig] [PreserveSig]
int GetSpecification( int GetSpecification(
[In] ref Guid riid, ref Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppSpecification); [MarshalAs(UnmanagedType.Interface)] out object ppSpecification);
} }

View File

@@ -8,12 +8,10 @@ using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using ManagedCommon; using ManagedCommon;
using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB; using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils; using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
using Microsoft.CmdPal.Ext.Indexer.Native; using Microsoft.CmdPal.Ext.Indexer.Native;
using Windows.Win32; using static Microsoft.CmdPal.Ext.Indexer.Native.NativeHelpers;
using Windows.Win32.System.Com;
using Windows.Win32.System.Search;
using Windows.Win32.UI.Shell.PropertiesSystem;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer; namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
@@ -120,11 +118,6 @@ internal sealed partial class SearchQuery : IDisposable
// We need to generate a search query string with the search text the user entered above // We need to generate a search query string with the search text the user entered above
if (currentRowset != null) if (currentRowset != null)
{ {
if (reuseRowset != null)
{
Marshal.ReleaseComObject(reuseRowset);
}
// We have a previous rowset, this means the user is typing and we should store this // We have a previous rowset, this means the user is typing and we should store this
// recapture the where ID from this so the next ExecuteSync call will be faster // recapture the where ID from this so the next ExecuteSync call will be faster
reuseRowset = currentRowset; reuseRowset = currentRowset;
@@ -148,13 +141,12 @@ internal sealed partial class SearchQuery : IDisposable
private bool HandleRow(IGetRow getRow, nuint rowHandle) private bool HandleRow(IGetRow getRow, nuint rowHandle)
{ {
object propertyStorePtr = null;
try try
{ {
getRow.GetRowFromHROW(null, rowHandle, typeof(IPropertyStore).GUID, out propertyStorePtr); var riid = CsWin32GUID.PropertyStore;
getRow.GetRowFromHROW(null, rowHandle, ref riid, out var propertyStore);
var propertyStore = (IPropertyStore)propertyStorePtr;
if (propertyStore == null) if (propertyStore == null)
{ {
Logger.LogError("Failed to get IPropertyStore interface"); Logger.LogError("Failed to get IPropertyStore interface");
@@ -176,14 +168,6 @@ internal sealed partial class SearchQuery : IDisposable
Logger.LogError("Error handling row", ex); Logger.LogError("Error handling row", ex);
return false; return false;
} }
finally
{
// Ensure the COM object is released if not returned
if (propertyStorePtr != null)
{
Marshal.ReleaseComObject(propertyStorePtr);
}
}
} }
public bool FetchRows(int offset, int limit) public bool FetchRows(int offset, int limit)
@@ -194,16 +178,17 @@ internal sealed partial class SearchQuery : IDisposable
return false; return false;
} }
if (currentRowset is not IGetRow) IGetRow getRow = null;
try
{
getRow = (IGetRow)currentRowset;
}
catch (Exception)
{ {
Logger.LogInfo("Reset the current rowset"); Logger.LogInfo("Reset the current rowset");
ExecuteSyncInternal(); ExecuteSyncInternal();
} getRow = (IGetRow)currentRowset;
if (currentRowset is not IGetRow getRow)
{
Logger.LogError("Rowset does not support IGetRow interface");
return false;
} }
uint rowCountReturned; uint rowCountReturned;
@@ -211,12 +196,7 @@ internal sealed partial class SearchQuery : IDisposable
try try
{ {
var res = currentRowset.GetNextRows(IntPtr.Zero, offset, limit, out rowCountReturned, out prghRows); currentRowset.GetNextRows(IntPtr.Zero, offset, limit, out rowCountReturned, out prghRows);
if (res < 0)
{
Logger.LogError($"Error fetching rows: {res}");
return false;
}
if (rowCountReturned == 0) if (rowCountReturned == 0)
{ {
@@ -237,11 +217,7 @@ internal sealed partial class SearchQuery : IDisposable
} }
} }
res = currentRowset.ReleaseRows(rowCountReturned, rowHandles, IntPtr.Zero, null, null); currentRowset.ReleaseRows(rowCountReturned, rowHandles, IntPtr.Zero, null, null);
if (res != 0)
{
Logger.LogError($"Error releasing rows: {res}");
}
Marshal.FreeCoTaskMem(prghRows); Marshal.FreeCoTaskMem(prghRows);
prghRows = IntPtr.Zero; prghRows = IntPtr.Zero;
@@ -268,11 +244,6 @@ internal sealed partial class SearchQuery : IDisposable
var rowset = ExecuteCommand(queryStr); var rowset = ExecuteCommand(queryStr);
if (rowset != null) if (rowset != null)
{ {
if (reuseRowset != null)
{
Marshal.ReleaseComObject(reuseRowset);
}
reuseRowset = rowset; reuseRowset = rowset;
reuseWhereID = GetReuseWhereId(reuseRowset); reuseWhereID = GetReuseWhereId(reuseRowset);
} }
@@ -280,110 +251,50 @@ internal sealed partial class SearchQuery : IDisposable
private unsafe IRowset ExecuteCommand(string queryStr) private unsafe IRowset ExecuteCommand(string queryStr)
{ {
object sessionPtr = null; if (string.IsNullOrEmpty(queryStr))
object commandPtr = null; {
return null;
}
try try
{ {
var session = (IDBCreateSession)DataSourceManager.GetDataSource(); var session = (IDBCreateSession)DataSourceManager.GetDataSource();
session.CreateSession(null, typeof(IDBCreateCommand).GUID, out sessionPtr); var guid = typeof(IDBCreateCommand).GUID;
if (sessionPtr == null) session.CreateSession(IntPtr.Zero, ref guid, out var ppDBSession);
if (ppDBSession == null)
{ {
Logger.LogError("CreateSession failed"); Logger.LogError("CreateSession failed");
return null; return null;
} }
var createCommand = (IDBCreateCommand)sessionPtr; var createCommand = (IDBCreateCommand)ppDBSession;
createCommand.CreateCommand(null, typeof(ICommandText).GUID, out commandPtr); guid = typeof(ICommandText).GUID;
if (commandPtr == null) createCommand.CreateCommand(IntPtr.Zero, ref guid, out ICommandText commandText);
{
Logger.LogError("CreateCommand failed");
return null;
}
var commandText = (ICommandText)commandPtr;
if (commandText == null) if (commandText == null)
{ {
Logger.LogError("Failed to get ICommandText interface"); Logger.LogError("Failed to get ICommandText interface");
return null; return null;
} }
commandText.SetCommandText(in NativeHelpers.OleDb.DbGuidDefault, queryStr); var riid = NativeHelpers.OleDb.DbGuidDefault;
commandText.Execute(null, typeof(IRowset).GUID, null, null, out var rowsetPointer);
return rowsetPointer as IRowset; var irowSetRiid = typeof(IRowset).GUID;
commandText.SetCommandText(ref riid, queryStr);
commandText.Execute(null, ref irowSetRiid, null, out var pcRowsAffected, out var rowsetPointer);
return rowsetPointer;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError("Unexpected error.", ex); Logger.LogError("Unexpected error.", ex);
return null; return null;
} }
finally
{
// Release the command pointer
if (commandPtr != null)
{
Marshal.ReleaseComObject(commandPtr);
} }
// Release the session pointer private unsafe DBPROP? GetPropset(IRowsetInfo rowsetInfo)
if (sessionPtr != null)
{
Marshal.ReleaseComObject(sessionPtr);
}
}
}
private IRowsetInfo GetRowsetInfo(IRowset rowset)
{
if (rowset == null)
{
return null;
}
var rowsetPtr = IntPtr.Zero;
var rowsetInfoPtr = IntPtr.Zero;
try
{
// Get the IUnknown pointer for the IRowset object
rowsetPtr = Marshal.GetIUnknownForObject(rowset);
// Query for IRowsetInfo interface
var rowsetInfoGuid = typeof(IRowsetInfo).GUID;
var res = Marshal.QueryInterface(rowsetPtr, in rowsetInfoGuid, out rowsetInfoPtr);
if (res != 0)
{
Logger.LogError($"Error getting IRowsetInfo interface: {res}");
return null;
}
// Marshal the interface pointer to the actual IRowsetInfo object
var rowsetInfo = (IRowsetInfo)Marshal.GetObjectForIUnknown(rowsetInfoPtr);
return rowsetInfo;
}
catch (Exception ex)
{
Logger.LogError($"Exception occurred while getting IRowsetInfo. ", ex);
return null;
}
finally
{
// Release the IRowsetInfo pointer if it was obtained
if (rowsetInfoPtr != IntPtr.Zero)
{
Marshal.Release(rowsetInfoPtr); // Release the IRowsetInfo pointer
}
// Release the IUnknown pointer for the IRowset object
if (rowsetPtr != IntPtr.Zero)
{
Marshal.Release(rowsetPtr);
}
}
}
private DBPROP? GetPropset(IRowsetInfo rowsetInfo)
{ {
var prgPropSetsPtr = IntPtr.Zero; var prgPropSetsPtr = IntPtr.Zero;
@@ -403,16 +314,15 @@ internal sealed partial class SearchQuery : IDisposable
return null; return null;
} }
var firstPropSetPtr = new IntPtr(prgPropSetsPtr.ToInt64()); var firstPropSetPtr = (DBPROPSET*)prgPropSetsPtr.ToInt64();
var propSet = Marshal.PtrToStructure<DBPROPSET>(firstPropSetPtr); var propSet = *firstPropSetPtr;
if (propSet.cProperties == 0 || propSet.rgProperties == IntPtr.Zero) if (propSet.cProperties == 0 || propSet.rgProperties == IntPtr.Zero)
{ {
return null; return null;
} }
var propPtr = new IntPtr(propSet.rgProperties.ToInt64()); var propPtr = (DBPROP*)propSet.rgProperties.ToInt64();
var prop = Marshal.PtrToStructure<DBPROP>(propPtr); return *propPtr;
return prop;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -431,7 +341,8 @@ internal sealed partial class SearchQuery : IDisposable
private uint GetReuseWhereId(IRowset rowset) private uint GetReuseWhereId(IRowset rowset)
{ {
var rowsetInfo = GetRowsetInfo(rowset); var rowsetInfo = (IRowsetInfo)rowset;
if (rowsetInfo == null) if (rowsetInfo == null)
{ {
return 0; return 0;
@@ -443,9 +354,9 @@ internal sealed partial class SearchQuery : IDisposable
return 0; return 0;
} }
if (prop?.vValue.Anonymous.Anonymous.vt == VARENUM.VT_UI4) if (prop?.vValue.VarType == VarEnum.VT_UI4)
{ {
var value = prop?.vValue.Anonymous.Anonymous.Anonymous.ulVal; var value = prop?.vValue._ulong;
return (uint)value; return (uint)value;
} }
@@ -462,18 +373,6 @@ internal sealed partial class SearchQuery : IDisposable
Marshal.FreeCoTaskMem(dbPropIdSet.rgPropertyIDs); Marshal.FreeCoTaskMem(dbPropIdSet.rgPropertyIDs);
} }
if (reuseRowset != null)
{
Marshal.ReleaseComObject(reuseRowset);
reuseRowset = null;
}
if (currentRowset != null)
{
Marshal.ReleaseComObject(currentRowset);
currentRowset = null;
}
queryCompletedEvent?.Dispose(); queryCompletedEvent?.Dispose();
} }
} }

View File

@@ -3,12 +3,11 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.InteropServices;
using ManagedCommon; using ManagedCommon;
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils; using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
using Microsoft.CmdPal.Ext.Indexer.Native; using Microsoft.CmdPal.Ext.Indexer.Native;
using Windows.Win32.System.Com;
using Windows.Win32.System.Com.StructuredStorage;
using Windows.Win32.UI.Shell.PropertiesSystem;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer; namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
@@ -39,14 +38,9 @@ internal sealed class SearchResult
{ {
try try
{ {
var key = NativeHelpers.PropertyKeys.PKEYItemNameDisplay; propStore.GetValue(NativeHelpers.PropertyKeys.PKEYItemNameDisplay, out var itemNameDisplay);
propStore.GetValue(&key, out var itemNameDisplay); propStore.GetValue(NativeHelpers.PropertyKeys.PKEYItemUrl, out var itemUrl);
propStore.GetValue(NativeHelpers.PropertyKeys.PKEYKindText, out var kindText);
key = NativeHelpers.PropertyKeys.PKEYItemUrl;
propStore.GetValue(&key, out var itemUrl);
key = NativeHelpers.PropertyKeys.PKEYKindText;
propStore.GetValue(&key, out var kindText);
var filePath = GetFilePath(ref itemUrl); var filePath = GetFilePath(ref itemUrl);
var isFolder = IsFoder(ref kindText); var isFolder = IsFoder(ref kindText);
@@ -67,28 +61,34 @@ internal sealed class SearchResult
} }
} }
private static bool IsFoder(ref PROPVARIANT kindText) private static bool IsFoder(ref PropVariant kindText)
{ {
var kindString = GetStringFromPropVariant(ref kindText); var kindString = GetStringFromPropVariant(ref kindText);
return string.Equals(kindString, "Folder", StringComparison.OrdinalIgnoreCase); return string.Equals(kindString, "Folder", StringComparison.OrdinalIgnoreCase);
} }
private static string GetFilePath(ref PROPVARIANT itemUrl) private static string GetFilePath(ref PropVariant itemUrl)
{ {
var filePath = GetStringFromPropVariant(ref itemUrl); var filePath = GetStringFromPropVariant(ref itemUrl);
filePath = UrlToFilePathConverter.Convert(filePath); filePath = UrlToFilePathConverter.Convert(filePath);
return filePath; return filePath;
} }
private static string GetStringFromPropVariant(ref PROPVARIANT propVariant) private static string GetStringFromPropVariant(ref PropVariant propVariant)
{ {
if (propVariant.Anonymous.Anonymous.vt == VARENUM.VT_LPWSTR) if (propVariant.VarType == System.Runtime.InteropServices.VarEnum.VT_LPWSTR)
{ {
var pwszVal = propVariant.Anonymous.Anonymous.Anonymous.pwszVal; var pwszVal = propVariant._ptr;
if (pwszVal != null)
if (pwszVal == IntPtr.Zero)
{ {
return pwszVal.ToString(); return string.Empty;
} }
// convert to string
var str = Marshal.PtrToStringUni(pwszVal);
return str;
} }
return string.Empty; return string.Empty;

View File

@@ -1,18 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[CoClass(typeof(CSearchCatalogManagerClass))]
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF50")]
[ComImport]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1715:Identifiers should have correct prefix", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:Interface names should begin with I", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Using original name from type lib")]
public interface CSearchCatalogManager : ISearchCatalogManager
{
}

View File

@@ -1,131 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[ComConversionLoss]
[Guid("AAB49DD5-AD0B-40AE-B654-AE8976BF6BD2")]
[ClassInterface((short)0)]
[ComImport]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1212:Property accessors should follow order", Justification = "The order of the property accessors must match the order in which the methods were defined in the vtable")]
public class CSearchCatalogManagerClass : ISearchCatalogManager, CSearchCatalogManager
{
[DispId(1610678272)]
public virtual extern string Name
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern IntPtr GetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void SetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName, [In] ref object pValue);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void GetCatalogStatus(
out object pStatus,
out object pPausedReason);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void Reset();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void Reindex();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void ReindexMatchingURLs([MarshalAs(UnmanagedType.LPWStr), In] string pszPattern);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void ReindexSearchRoot([MarshalAs(UnmanagedType.LPWStr), In] string pszRoot);
[DispId(1610678280)]
public virtual extern uint ConnectTimeout
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678282)]
public virtual extern uint DataTimeout
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern int NumberOfItems();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void NumberOfItemsToIndex(
out int plIncrementalCount,
out int plNotificationQueue,
out int plHighPriorityQueue);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public virtual extern string URLBeingIndexed();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern uint GetURLIndexingState([MarshalAs(UnmanagedType.LPWStr), In] string psz);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
public virtual extern object GetPersistentItemsChangedSink();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void RegisterViewForNotification(
[MarshalAs(UnmanagedType.LPWStr), In] string pszView,
[MarshalAs(UnmanagedType.Interface), In] object pViewChangedSink,
out uint pdwCookie);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void GetItemsChangedSink(
[MarshalAs(UnmanagedType.Interface), In] object pISearchNotifyInlineSite,
[In] ref Guid riid,
out IntPtr ppv,
out Guid pGUIDCatalogResetSignature,
out Guid pGUIDCheckPointSignature,
out uint pdwLastCheckPointNumber);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void UnregisterViewForNotification([In] uint dwCookie);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void SetExtensionClusion([MarshalAs(UnmanagedType.LPWStr), In] string pszExtension, [In] int fExclude);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
public virtual extern object EnumerateExcludedExtensions();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
public virtual extern CSearchQueryHelper GetQueryHelper();
[DispId(1610678295)]
public virtual extern int DiacriticSensitivity
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
public virtual extern object GetCrawlScopeManager();
}

View File

@@ -1,18 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[CoClass(typeof(CSearchManagerClass))]
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69")]
[ComImport]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1715:Identifiers should have correct prefix", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:Interface names should begin with I", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Using original name from type lib")]
public interface CSearchManager : ISearchManager
{
}

View File

@@ -1,90 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("7D096C5F-AC08-4F1F-BEB7-5C22C517CE39")]
[TypeLibType(2)]
[ClassInterface((short)0)]
[ComConversionLoss]
[ComImport]
public class CSearchManagerClass : ISearchManager, CSearchManager
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void GetIndexerVersionStr([MarshalAs(UnmanagedType.LPWStr)] out string ppszVersionString);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void GetIndexerVersion(out uint pdwMajor, out uint pdwMinor);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern IntPtr GetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void SetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName, [In] ref object pValue);
[DispId(1610678276)]
public virtual extern string ProxyName
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678277)]
public virtual extern string BypassList
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void SetProxy(
[In] object sUseProxy,
[In] int fLocalByPassProxy,
[In] uint dwPortNumber,
[MarshalAs(UnmanagedType.LPWStr), In] string pszProxyName,
[MarshalAs(UnmanagedType.LPWStr), In] string pszByPassList);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
public virtual extern CSearchCatalogManager GetCatalog([MarshalAs(UnmanagedType.LPWStr), In] string pszCatalog);
[DispId(1610678280)]
public virtual extern string UserAgent
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
}
[DispId(1610678282)]
public virtual extern object UseProxy
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678283)]
public virtual extern int LocalBypass
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678284)]
public virtual extern uint PortNumber
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
}

View File

@@ -1,18 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF63")]
[CoClass(typeof(CSearchQueryHelperClass))]
[ComImport]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1715:Identifiers should have correct prefix", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:Interface names should begin with I", Justification = "Using original name from type lib")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Using original name from type lib")]
public interface CSearchQueryHelper : ISearchQueryHelper
{
}

View File

@@ -1,134 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[ClassInterface((short)0)]
[Guid("B271E955-09E1-42E1-9B95-5994A534B613")]
[ComImport]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1212:Property accessors should follow order", Justification = "The order of the property accessors must match the order in which the methods were defined in the vtable")]
public class CSearchQueryHelperClass : ISearchQueryHelper, CSearchQueryHelper
{
[DispId(1610678272)]
public virtual extern string ConnectionString
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678273)]
public virtual extern uint QueryContentLocale
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678275)]
public virtual extern uint QueryKeywordLocale
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678277)]
public virtual extern object QueryTermExpansion
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678279)]
public virtual extern object QuerySyntax
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678281)]
public virtual extern string QueryContentProperties
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678283)]
public virtual extern string QuerySelectColumns
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678285)]
public virtual extern string QueryWhereRestrictions
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678287)]
public virtual extern string QuerySorting
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public virtual extern string GenerateSQLFromUserQuery([MarshalAs(UnmanagedType.LPWStr), In] string pszQuery);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public virtual extern void WriteProperties(
[In] int itemID,
[In] uint dwNumberOfColumns,
[In] ref object pColumns,
[In] ref object pValues,
[In] ref object pftGatherModifiedTime);
[DispId(1610678291)]
public virtual extern int QueryMaxResults
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
}

View File

@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733A63-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface ICommand
{
void Cancel();
void Execute([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, ref Guid riid, [Optional][MarshalAs(UnmanagedType.Interface)] object pParams, [Optional]out int pcRowsAffected, out IRowset ppRowset);
void GetDBSession(ref Guid riid, out IntPtr ppSession);
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733A27-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface ICommandText : ICommand
{
void GetCommandText([Optional] ref Guid pguidDialect, out IntPtr ppwszCommand);
void SetCommandText(ref Guid rguidDialect, string pwszCommand);
}

View File

@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733A1D-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface IDBCreateCommand
{
void CreateCommand(IntPtr pUnkOuter, ref Guid riid, out ICommandText ppCommand);
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733A5D-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface IDBCreateSession
{
void CreateSession(IntPtr pUnkOuter, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppDBSession);
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733A8B-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface IDBInitialize
{
void Initialize();
void Uninitialize();
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.Indexer.Native;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("0C733AAF-2A1C-11CE-ADE5-00AA0044773D")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface IGetRow
{
unsafe void GetRowFromHROW([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, nuint hRow, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out IPropertyStore ppUnk);
unsafe string GetURLFromHROW(nuint hRow);
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
[assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling]
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")]
[GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
public partial interface IPropertyStore
{
uint GetCount();
PropertyKey GetAt(uint iProp);
void GetValue(in PropertyKey pkey, out PropVariant pv);
void SetValue(in PropertyKey pkey, in PropVariant pv);
void Commit();
}

View File

@@ -5,125 +5,68 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF50")] [Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF50")]
[ComConversionLoss] [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
[InterfaceType(1)] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Please do not change the function name")]
[ComImport] public partial interface ISearchCatalogManager
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1212:Property accessors should follow order", Justification = "The order of the property accessors must match the order in which the methods were defined in the vtable")]
public interface ISearchCatalogManager
{ {
[DispId(1610678272)] string get_Name();
string Name
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void GetParameter(string pszName, out IntPtr pValue);
IntPtr GetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void SetParameter(string pszName, ref IntPtr pValue);
void SetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName, [In] ref object pValue);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void GetCatalogStatus(out uint pdwStatus, out uint pdwPausedReason);
void GetCatalogStatus(out object pStatus, out object pPausedReason);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void Reset(); void Reset();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void Reindex(); void Reindex();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void ReindexMatchingURLs(string pszPattern);
void ReindexMatchingURLs([MarshalAs(UnmanagedType.LPWStr), In] string pszPattern);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void ReindexSearchRoot(string pszRoot);
void ReindexSearchRoot([MarshalAs(UnmanagedType.LPWStr), In] string pszRoot);
[DispId(1610678280)] uint get_ConnectTimeout();
uint ConnectTimeout
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678282)] void put_ConnectTimeout(uint dwTimeout);
uint DataTimeout
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] uint get_DataTimeout();
int NumberOfItems();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void put_DataTimeout(uint dwTimeout);
void NumberOfItemsToIndex(
out int plIncrementalCount, uint NumberOfItems();
out int plNotificationQueue,
out int plHighPriorityQueue); uint NumberOfItemsToIndex();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)] [return: MarshalAs(UnmanagedType.LPWStr)]
string URLBeingIndexed(); string URLBeingIndexed();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void GetURLIndexingState(string pszURL, out uint pdwState);
uint GetURLIndexingState([MarshalAs(UnmanagedType.LPWStr), In] string psz);
IntPtr GetPersistentItemsChangedSink();
void RegisterViewForNotification(string pszView, IntPtr pViewNotify, out uint pdwCookie);
IntPtr GetItemsChangedSink();
void UnregisterViewForNotification(uint dwCookie);
void SetExtensionClusion(string pszExtension, [MarshalAs(UnmanagedType.Bool)] bool fExclude);
void EnumerateExcludedExtensions();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)] [return: MarshalAs(UnmanagedType.Interface)]
object GetPersistentItemsChangedSink(); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
ISearchQueryHelper GetQueryHelper();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [return: MarshalAs(UnmanagedType.Bool)]
void RegisterViewForNotification( bool get_DiacriticSensitivity();
[MarshalAs(UnmanagedType.LPWStr), In] string pszView,
[MarshalAs(UnmanagedType.Interface), In] object pViewChangedSink,
out uint pdwCookie);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void put_DiacriticSensitivity([MarshalAs(UnmanagedType.Bool)] bool fDiacriticSensitive);
void GetItemsChangedSink(
[MarshalAs(UnmanagedType.Interface), In] object pISearchNotifyInlineSite,
[In] ref Guid riid,
out IntPtr ppv,
out Guid pGUIDCatalogResetSignature,
out Guid pGUIDCheckPointSignature,
out uint pdwLastCheckPointNumber);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] IntPtr GetCrawlScopeManager();
void UnregisterViewForNotification([In] uint dwCookie);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void SetExtensionClusion([MarshalAs(UnmanagedType.LPWStr), In] string pszExtension, [In] int fExclude);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
object EnumerateExcludedExtensions();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
CSearchQueryHelper GetQueryHelper();
[DispId(1610678295)]
int DiacriticSensitivity
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)]
object GetCrawlScopeManager();
} }

View File

@@ -3,87 +3,46 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[ComConversionLoss]
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69")] [Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69")]
[InterfaceType(1)] [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
[ComImport] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Please do not change the function name")]
public interface ISearchManager public partial interface ISearchManager
{ {
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] string GetIndexerVersionStr();
void GetIndexerVersionStr([MarshalAs(UnmanagedType.LPWStr)] out string ppszVersionString);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void GetIndexerVersion(out uint pdwMajor, out uint pdwMinor); void GetIndexerVersion(out uint pdwMajor, out uint pdwMinor);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void GetParameter(string pszName, [MarshalAs(UnmanagedType.Interface)] out object pValue);
IntPtr GetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void SetParameter(string pszName, [MarshalAs(UnmanagedType.Interface)] ref object pValue);
void SetParameter([MarshalAs(UnmanagedType.LPWStr), In] string pszName, [In] ref object pValue);
[DispId(1610678276)] [return: MarshalAs(UnmanagedType.Bool)]
string ProxyName bool get_UseProxy();
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678277)] string get_BypassList();
string BypassList
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void SetProxy( void SetProxy(
[In] object sUseProxy, string pszProxyName,
[In] int fLocalByPassProxy, [MarshalAs(UnmanagedType.Bool)] bool fLocalBypass,
[In] uint dwPortNumber, string pszBypassList,
[MarshalAs(UnmanagedType.LPWStr), In] string pszProxyName, uint dwPortNumber);
[MarshalAs(UnmanagedType.LPWStr), In] string pszByPassList);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.Interface)] [return: MarshalAs(UnmanagedType.Interface)]
CSearchCatalogManager GetCatalog([MarshalAs(UnmanagedType.LPWStr), In] string pszCatalog); ISearchCatalogManager GetCatalog(string pszCatalog);
[DispId(1610678280)] string get_UserAgent();
string UserAgent
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
}
[DispId(1610678282)] void put_UserAgent(string pszUserAgent);
object UseProxy
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678283)] string get_ProxyName();
int LocalBypass
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678284)] [return: MarshalAs(UnmanagedType.Bool)]
uint PortNumber bool get_LocalBypass();
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] uint get_PortNumber();
get;
}
} }

View File

@@ -5,130 +5,74 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF63")] [Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF63")]
[InterfaceType(1)] [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)]
[ComImport] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "I don't want to change the name")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1212:Property accessors should follow order", Justification = "The order of the property accessors must match the order in which the methods were defined in the vtable")] public partial interface ISearchQueryHelper
public interface ISearchQueryHelper
{ {
[DispId(1610678272)] string GetConnectionString();
string ConnectionString
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678273)] void SetQueryContentLocale(int lcid);
uint QueryContentLocale
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678275)] uint GetQueryContentLocale();
uint QueryKeywordLocale
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678277)] void SetQueryKeywordLocale(int lcid);
object QueryTermExpansion
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678279)] uint GetQueryKeywordLocale();
object QuerySyntax
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
}
[DispId(1610678281)] void SetQueryTermExpansion(SEARCH_TERM_EXPANSION expandTerms);
string QueryContentProperties
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678283)] void GetQueryTermExpansion(out SEARCH_TERM_EXPANSION pExpandTerms);
string QuerySelectColumns
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678285)] void SetQuerySyntax(SEARCH_QUERY_SYNTAX querySyntax);
string QueryWhereRestrictions
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[DispId(1610678287)] [return: MarshalAs(UnmanagedType.Interface)]
string QuerySorting object GetQuerySyntax();
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[param: MarshalAs(UnmanagedType.LPWStr)]
[param: In]
set;
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[return: MarshalAs(UnmanagedType.LPWStr)]
get;
}
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void SetQueryContentProperties(string pszContentProperties);
[return: MarshalAs(UnmanagedType.LPWStr)]
string GenerateSQLFromUserQuery([MarshalAs(UnmanagedType.LPWStr), In] string pszQuery); string GetQueryContentProperties();
void SetQuerySelectColumns(string pszColumns);
string GetQuerySelectColumns();
void SetQueryWhereRestrictions(string pszRestrictions);
string GetQueryWhereRestrictions();
void SetQuerySorting(string pszSorting);
string GetQuerySorting();
string GenerateSQLFromUserQuery(string pszQuery);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void WriteProperties( void WriteProperties(
[In] int itemID, int itemID,
[In] uint dwNumberOfColumns, uint dwNumberOfColumns,
[In] ref object pColumns, [MarshalAs(UnmanagedType.Interface)] ref object pColumns,
[In] ref object pValues, [MarshalAs(UnmanagedType.Interface)] ref object pValues,
[In] ref object pftGatherModifiedTime); [MarshalAs(UnmanagedType.Interface)] ref object pftGatherModifiedTime);
[DispId(1610678291)] void SetQueryMaxResults(int lMaxResults);
int QueryMaxResults
int GetQueryMaxResults();
}
public enum SEARCH_TERM_EXPANSION
{ {
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] SEARCH_TERM_NO_EXPANSION,
[param: In] SEARCH_TERM_PREFIX_ALL,
set; SEARCH_TERM_STEM_ALL,
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
get;
} }
public enum SEARCH_QUERY_SYNTAX
{
SEARCH_NO_QUERY_SYNTAX,
SEARCH_ADVANCED_QUERY_SYNTAX,
SEARCH_NATURAL_QUERY_SYNTAX,
} }

View File

@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using VARTYPE = System.Runtime.InteropServices.VarEnum;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct PropVariant
{
/// <summary>Value type tag.</summary>
[FieldOffset(0)]
public ushort vt;
[FieldOffset(2)]
public ushort wReserved1;
/// <summary>Reserved for future use.</summary>
[FieldOffset(4)]
public ushort wReserved2;
/// <summary>Reserved for future use.</summary>
[FieldOffset(6)]
public ushort wReserved3;
/// <summary>The decimal value when VT_DECIMAL.</summary>
[FieldOffset(0)]
internal decimal _decimal;
/// <summary>The raw data pointer.</summary>
[FieldOffset(8)]
internal IntPtr _ptr;
/// <summary>The FILETIME when VT_FILETIME.</summary>
[FieldOffset(8)]
internal System.Runtime.InteropServices.ComTypes.FILETIME _ft;
[FieldOffset(8)]
internal BLOB _blob;
/// <summary>The value when a numeric value less than 8 bytes.</summary>
[FieldOffset(8)]
internal ulong _ulong;
public PropVariant(string value)
{
ArgumentNullException.ThrowIfNull(value);
vt = (ushort)VarEnum.VT_LPWSTR;
_ptr = Marshal.StringToCoTaskMemUni(value);
}
public VarEnum VarType { get => (VarEnum)vt; set => vt = (ushort)(VARTYPE)value; }
}
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct BLOB
{
/// <summary>The count of bytes</summary>
public uint cbSize;
/// <summary>A pointer to the allocated array of bytes.</summary>
public IntPtr pBlobData;
}
#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter

View File

@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
[StructLayout(LayoutKind.Sequential)]
public struct PropertyKey
{
public Guid FmtID;
public uint PID;
public PropertyKey(Guid fmtid, uint pid)
{
this.FmtID = fmtid;
this.PID = pid;
}
}

View File

@@ -2,12 +2,17 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Globalization; using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch; using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
using Microsoft.CmdPal.Ext.Indexer.Native;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.Utils; namespace Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
internal sealed class QueryStringBuilder internal sealed partial class QueryStringBuilder
{ {
private const string Properties = "System.ItemUrl, System.ItemNameDisplay, path, System.Search.EntryID, System.Kind, System.KindText"; private const string Properties = "System.ItemUrl, System.ItemNameDisplay, path, System.Search.EntryID, System.Kind, System.KindText";
private const string SystemIndex = "SystemIndex"; private const string SystemIndex = "SystemIndex";
@@ -24,16 +29,40 @@ internal sealed class QueryStringBuilder
{ {
if (queryHelper == null) if (queryHelper == null)
{ {
var searchManager = new CSearchManager(); ComWrappers cw = new StrategyBasedComWrappers();
ISearchCatalogManager catalogManager = searchManager.GetCatalog(SystemIndex);
queryHelper = catalogManager.GetQueryHelper();
queryHelper.QuerySelectColumns = Properties; var hr = NativeMethods.CoCreateInstance(ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.CLSIDSearchManager), IntPtr.Zero, NativeHelpers.CLSCTXINPROCALL, ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.IIDISearchManager), out var searchManagerPtr);
queryHelper.QueryContentProperties = "System.FileName"; if (hr != 0)
queryHelper.QuerySorting = OrderConditions; {
throw new ArgumentException($"Failed to create SearchManager instance. HR: 0x{hr:X}");
} }
queryHelper.QueryWhereRestrictions = "AND " + ScopeFileConditions + "AND ReuseWhere(" + whereId.ToString(CultureInfo.InvariantCulture) + ")"; var searchManager = (ISearchManager)cw.GetOrCreateObjectForComInstance(
searchManagerPtr, CreateObjectFlags.None);
if (searchManager == null)
{
throw new ArgumentException("Failed to get ISearchManager interface");
}
ISearchCatalogManager catalogManager = searchManager.GetCatalog(SystemIndex);
if (catalogManager == null)
{
throw new ArgumentException($"Failed to get catalog manager for {SystemIndex}");
}
queryHelper = catalogManager.GetQueryHelper();
if (queryHelper == null)
{
throw new ArgumentException("Failed to get query helper from catalog manager");
}
queryHelper.SetQuerySelectColumns(Properties);
queryHelper.SetQueryContentProperties("System.FileName");
queryHelper.SetQuerySorting(OrderConditions);
}
queryHelper.SetQueryWhereRestrictions("AND " + ScopeFileConditions + "AND ReuseWhere(" + whereId.ToString(CultureInfo.InvariantCulture) + ")");
return queryHelper.GenerateSQLFromUserQuery(searchText); return queryHelper.GenerateSQLFromUserQuery(searchText);
} }
} }

View File

@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" /> <Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
<Import Project="..\..\..\..\Common.Dotnet.AotCompatibility.props" />
<PropertyGroup> <PropertyGroup>
<RootNamespace>Microsoft.CmdPal.Ext.Indexer</RootNamespace> <RootNamespace>Microsoft.CmdPal.Ext.Indexer</RootNamespace>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal</OutputPath> <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -46,4 +46,9 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<AdditionalFiles Include="NativeMethods.txt" />
<AdditionalFiles Include="NativeMethods.json" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,25 +1,34 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using Windows.Win32.UI.Shell.PropertiesSystem; using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
namespace Microsoft.CmdPal.Ext.Indexer.Native; namespace Microsoft.CmdPal.Ext.Indexer.Native;
internal sealed class NativeHelpers public sealed partial class NativeHelpers
{ {
public const uint SEEMASKINVOKEIDLIST = 12; public const uint SEEMASKINVOKEIDLIST = 12;
internal static class PropertyKeys public const uint CLSCTXINPROCALL = 0x17;
public struct PropertyKeys
{ {
public static readonly PROPERTYKEY PKEYItemNameDisplay = new() { fmtid = new System.Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), pid = 10 }; public static readonly PropertyKey PKEYItemNameDisplay = new() { FmtID = new System.Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), PID = 10 };
public static readonly PROPERTYKEY PKEYItemUrl = new() { fmtid = new System.Guid("49691C90-7E17-101A-A91C-08002B2ECDA9"), pid = 9 }; public static readonly PropertyKey PKEYItemUrl = new() { FmtID = new System.Guid("49691C90-7E17-101A-A91C-08002B2ECDA9"), PID = 9 };
public static readonly PROPERTYKEY PKEYKindText = new() { fmtid = new System.Guid("F04BEF95-C585-4197-A2B7-DF46FDC9EE6D"), pid = 100 }; public static readonly PropertyKey PKEYKindText = new() { FmtID = new System.Guid("F04BEF95-C585-4197-A2B7-DF46FDC9EE6D"), PID = 100 };
} }
internal static class OleDb public static class OleDb
{ {
public static readonly Guid DbGuidDefault = new("C8B521FB-5CF3-11CE-ADE5-00AA0044773D"); public static readonly Guid DbGuidDefault = new("C8B521FB-5CF3-11CE-ADE5-00AA0044773D");
} }
public static class CsWin32GUID
{
public static readonly Guid CLSIDSearchManager = new Guid("7D096C5F-AC08-4F1F-BEB7-5C22C517CE39");
public static readonly Guid IIDISearchManager = new Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69");
public static readonly Guid CLSIDCollatorDataSource = new Guid("9E175B8B-F52A-11D8-B9A5-505054503030");
public static readonly Guid PropertyStore = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");
}
} }

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Windows.Win32.UI.Shell;
namespace Microsoft.CmdPal.Ext.Indexer.Native;
public sealed partial class NativeMethods
{
[LibraryImport("ole32.dll")]
[return: MarshalAs(UnmanagedType.U4)]
public static partial uint CoCreateInstance(
ref Guid rclsid,
IntPtr pUnkOuter,
uint dwClsContext,
ref Guid riid,
out IntPtr rReturnedComObject);
[LibraryImport("SHELL32.dll", EntryPoint = "ShellExecuteExW", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool ShellExecuteEx(ref SHELLEXECUTEINFOW lpExecInfo);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SHELLEXECUTEINFOW
{
public uint cbSize;
public uint fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
public IntPtr lpFile;
public IntPtr lpParameters;
public IntPtr lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
public IntPtr lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIconOrMonitor;
public IntPtr hProcess;
}
}

View File

@@ -0,0 +1,6 @@
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"allowMarshaling": false,
"emitSingleFile": false,
"public": true
}

View File

@@ -1,11 +1,2 @@
DBID DBID
SHOW_WINDOW_CMD SHOW_WINDOW_CMD
CoCreateInstance
GetErrorInfo
ICommandText
IDBCreateCommand
IDBCreateSession
IDBInitialize
IGetRow
IPropertyStore
ShellExecuteEx