Skip to content

Commit 6fdff29

Browse files
committed
Merge Explorer & Everything Plugins (Step 1)
1. Shared Interface for Windows Index and Everything Index 2. Settings Merge (Part 1) 3. Include Everything dll
1 parent b0f9b48 commit 6fdff29

19 files changed

+642
-126
lines changed
Binary file not shown.
Binary file not shown.

Plugins/Flow.Launcher.Plugin.Explorer/Flow.Launcher.Plugin.Explorer.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<SubType>Designer</SubType>
3636
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3737
</Content>
38+
<Content Include="EverythingSDK\*.dll">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
3841
</ItemGroup>
3942

4043
<ItemGroup>

Plugins/Flow.Launcher.Plugin.Explorer/Main.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using Flow.Launcher.Infrastructure.Storage;
22
using Flow.Launcher.Plugin.Explorer.Search;
3+
using Flow.Launcher.Plugin.Explorer.Search.Everything;
34
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
45
using Flow.Launcher.Plugin.Explorer.ViewModels;
56
using Flow.Launcher.Plugin.Explorer.Views;
7+
using System;
68
using System.Collections.Generic;
9+
using System.IO;
710
using System.Linq;
811
using System.Threading;
912
using System.Threading.Tasks;
@@ -47,7 +50,8 @@ public Task InitAsync(PluginInitContext context)
4750
contextMenu = new ContextMenu(Context, Settings, viewModel);
4851
searchManager = new SearchManager(Settings, Context);
4952
ResultManager.Init(Context, Settings);
50-
53+
EverythingApiDllImport.Load(Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "EverythingSDK",
54+
Environment.Is64BitProcess ? "Everything64.dll" : "Everything86.dll"));
5155
return Task.CompletedTask;
5256
}
5357

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
using Flow.Launcher.Plugin.Everything.Everything;
2+
using Flow.Launcher.Plugin.Everything.Everything.Exceptions;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Runtime.InteropServices;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
11+
{
12+
13+
public static class EverythingApi
14+
{
15+
16+
private const int BufferSize = 4096;
17+
18+
private static readonly object syncObject = new object();
19+
// cached buffer to remove redundant allocations.
20+
private static readonly StringBuilder buffer = new StringBuilder(BufferSize);
21+
22+
public enum StateCode
23+
{
24+
OK,
25+
MemoryError,
26+
IPCError,
27+
RegisterClassExError,
28+
CreateWindowError,
29+
CreateThreadError,
30+
InvalidIndexError,
31+
InvalidCallError
32+
}
33+
34+
/// <summary>
35+
/// Gets or sets a value indicating whether [match path].
36+
/// </summary>
37+
/// <value><c>true</c> if [match path]; otherwise, <c>false</c>.</value>
38+
public static bool MatchPath
39+
{
40+
get => EverythingApiDllImport.Everything_GetMatchPath();
41+
set => EverythingApiDllImport.Everything_SetMatchPath(value);
42+
}
43+
44+
/// <summary>
45+
/// Gets or sets a value indicating whether [match case].
46+
/// </summary>
47+
/// <value><c>true</c> if [match case]; otherwise, <c>false</c>.</value>
48+
public static bool MatchCase
49+
{
50+
get => EverythingApiDllImport.Everything_GetMatchCase();
51+
set => EverythingApiDllImport.Everything_SetMatchCase(value);
52+
}
53+
54+
/// <summary>
55+
/// Gets or sets a value indicating whether [match whole word].
56+
/// </summary>
57+
/// <value><c>true</c> if [match whole word]; otherwise, <c>false</c>.</value>
58+
public static bool MatchWholeWord
59+
{
60+
get => EverythingApiDllImport.Everything_GetMatchWholeWord();
61+
set => EverythingApiDllImport.Everything_SetMatchWholeWord(value);
62+
}
63+
64+
/// <summary>
65+
/// Gets or sets a value indicating whether [enable regex].
66+
/// </summary>
67+
/// <value><c>true</c> if [enable regex]; otherwise, <c>false</c>.</value>
68+
public static bool EnableRegex
69+
{
70+
get => EverythingApiDllImport.Everything_GetRegex();
71+
set => EverythingApiDllImport.Everything_SetRegex(value);
72+
}
73+
74+
/// <summary>
75+
/// Resets this instance.
76+
/// </summary>
77+
private static void Reset()
78+
{
79+
lock (syncObject)
80+
{
81+
EverythingApiDllImport.Everything_Reset();
82+
}
83+
}
84+
85+
/// <summary>
86+
/// Checks whether the sort option is Fast Sort.
87+
/// </summary>
88+
public static bool IsFastSortOption(SortOption sortOption)
89+
{
90+
var fastSortOptionEnabled = EverythingApiDllImport.Everything_IsFastSort(sortOption);
91+
92+
// If the Everything service is not running, then this call will incorrectly report
93+
// the state as false. This checks for errors thrown by the api and up to the caller to handle.
94+
CheckAndThrowExceptionOnError();
95+
96+
return fastSortOptionEnabled;
97+
}
98+
99+
/// <summary>
100+
/// Searches the specified key word and reset the everything API afterwards
101+
/// </summary>
102+
/// <param name="keyword">The key word.</param>
103+
/// <param name="token">when cancelled the current search will stop and exit (and would not reset)</param>
104+
/// <param name="sortOption">Sort By</param>
105+
/// <param name="offset">The offset.</param>
106+
/// <param name="maxCount">The max count.</param>
107+
/// <returns></returns>
108+
public static IEnumerable<SearchResult> SearchAsync(string keyword, CancellationToken token, SortOption sortOption = SortOption.NAME_ASCENDING, int offset = 0, int maxCount = 100)
109+
{
110+
if (string.IsNullOrEmpty(keyword))
111+
throw new ArgumentNullException(nameof(keyword));
112+
113+
if (offset < 0)
114+
throw new ArgumentOutOfRangeException(nameof(offset));
115+
116+
if (maxCount < 0)
117+
throw new ArgumentOutOfRangeException(nameof(maxCount));
118+
119+
lock (syncObject)
120+
{
121+
if (keyword.StartsWith("@"))
122+
{
123+
EverythingApiDllImport.Everything_SetRegex(true);
124+
keyword = keyword[1..];
125+
}
126+
127+
EverythingApiDllImport.Everything_SetSearchW(keyword);
128+
EverythingApiDllImport.Everything_SetOffset(offset);
129+
EverythingApiDllImport.Everything_SetMax(maxCount);
130+
131+
EverythingApiDllImport.Everything_SetSort(sortOption);
132+
133+
if (token.IsCancellationRequested)
134+
{
135+
return null;
136+
}
137+
138+
139+
if (!EverythingApiDllImport.Everything_QueryW(true))
140+
{
141+
CheckAndThrowExceptionOnError();
142+
return null;
143+
}
144+
145+
var results = new List<SearchResult>();
146+
for (var idx = 0; idx < EverythingApiDllImport.Everything_GetNumResults(); ++idx)
147+
{
148+
if (token.IsCancellationRequested)
149+
{
150+
return null;
151+
}
152+
153+
EverythingApiDllImport.Everything_GetResultFullPathNameW(idx, buffer, BufferSize);
154+
155+
var result = new SearchResult
156+
{
157+
FullPath = buffer.ToString(),
158+
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :
159+
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
160+
ResultType.Volume
161+
};
162+
163+
results.Add(result);
164+
}
165+
166+
Reset();
167+
168+
return results;
169+
}
170+
}
171+
172+
private static void CheckAndThrowExceptionOnError()
173+
{
174+
switch (EverythingApiDllImport.Everything_GetLastError())
175+
{
176+
case StateCode.CreateThreadError:
177+
throw new CreateThreadException();
178+
case StateCode.CreateWindowError:
179+
throw new CreateWindowException();
180+
case StateCode.InvalidCallError:
181+
throw new InvalidCallException();
182+
case StateCode.InvalidIndexError:
183+
throw new InvalidIndexException();
184+
case StateCode.IPCError:
185+
throw new IPCErrorException();
186+
case StateCode.MemoryError:
187+
throw new MemoryErrorException();
188+
case StateCode.RegisterClassExError:
189+
throw new RegisterClassExException();
190+
}
191+
}
192+
}
193+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using Flow.Launcher.Plugin.Everything.Everything;
2+
using System;
3+
using System.Runtime.InteropServices;
4+
using System.Text;
5+
6+
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
7+
{
8+
public static class EverythingApiDllImport
9+
{
10+
public static void Load(string path)
11+
{
12+
LoadLibrary(path);
13+
}
14+
15+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
16+
private static extern int LoadLibrary(string name);
17+
18+
private const string DLL = "Everything.dll";
19+
20+
[DllImport(DLL, CharSet = CharSet.Unicode)]
21+
internal static extern int Everything_SetSearchW(string lpSearchString);
22+
23+
[DllImport(DLL)]
24+
internal static extern void Everything_SetMatchPath(bool bEnable);
25+
26+
[DllImport(DLL)]
27+
internal static extern void Everything_SetMatchCase(bool bEnable);
28+
29+
[DllImport(DLL)]
30+
internal static extern void Everything_SetMatchWholeWord(bool bEnable);
31+
32+
[DllImport(DLL)]
33+
internal static extern void Everything_SetRegex(bool bEnable);
34+
35+
[DllImport(DLL)]
36+
internal static extern void Everything_SetMax(int dwMax);
37+
38+
[DllImport(DLL)]
39+
internal static extern void Everything_SetOffset(int dwOffset);
40+
41+
[DllImport(DLL)]
42+
internal static extern bool Everything_GetMatchPath();
43+
44+
[DllImport(DLL)]
45+
internal static extern bool Everything_GetMatchCase();
46+
47+
[DllImport(DLL)]
48+
internal static extern bool Everything_GetMatchWholeWord();
49+
50+
[DllImport(DLL)]
51+
internal static extern bool Everything_GetRegex();
52+
53+
[DllImport(DLL)]
54+
internal static extern uint Everything_GetMax();
55+
56+
[DllImport(DLL)]
57+
internal static extern uint Everything_GetOffset();
58+
59+
[DllImport(DLL, CharSet = CharSet.Unicode)]
60+
internal static extern string Everything_GetSearchW();
61+
62+
[DllImport(DLL)]
63+
internal static extern EverythingApi.StateCode Everything_GetLastError();
64+
65+
[DllImport(DLL, CharSet = CharSet.Unicode)]
66+
internal static extern bool Everything_QueryW(bool bWait);
67+
68+
[DllImport(DLL)]
69+
internal static extern void Everything_SortResultsByPath();
70+
71+
[DllImport(DLL)]
72+
internal static extern int Everything_GetNumFileResults();
73+
74+
[DllImport(DLL)]
75+
internal static extern int Everything_GetNumFolderResults();
76+
77+
[DllImport(DLL)]
78+
internal static extern int Everything_GetNumResults();
79+
80+
[DllImport(DLL)]
81+
internal static extern int Everything_GetTotFileResults();
82+
83+
[DllImport(DLL)]
84+
internal static extern int Everything_GetTotFolderResults();
85+
86+
[DllImport(DLL)]
87+
internal static extern int Everything_GetTotResults();
88+
89+
[DllImport(DLL)]
90+
internal static extern bool Everything_IsVolumeResult(int nIndex);
91+
92+
[DllImport(DLL)]
93+
internal static extern bool Everything_IsFolderResult(int nIndex);
94+
95+
[DllImport(DLL)]
96+
internal static extern bool Everything_IsFileResult(int nIndex);
97+
98+
[DllImport(DLL, CharSet = CharSet.Unicode)]
99+
internal static extern void Everything_GetResultFullPathNameW(int nIndex, StringBuilder lpString, int nMaxCount);
100+
101+
[DllImport(DLL)]
102+
internal static extern void Everything_Reset();
103+
104+
// Everything 1.4
105+
106+
[DllImport(DLL)]
107+
public static extern void Everything_SetSort(SortOption dwSortType);
108+
[DllImport(DLL)]
109+
public static extern bool Everything_IsFastSort(SortOption dwSortType);
110+
[DllImport(DLL)]
111+
public static extern SortOption Everything_GetSort();
112+
[DllImport(DLL)]
113+
public static extern uint Everything_GetResultListSort();
114+
[DllImport(DLL)]
115+
public static extern void Everything_SetRequestFlags(uint dwRequestFlags);
116+
[DllImport(DLL)]
117+
public static extern uint Everything_GetRequestFlags();
118+
[DllImport(DLL)]
119+
public static extern uint Everything_GetResultListRequestFlags();
120+
[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
121+
public static extern IntPtr Everything_GetResultExtension(uint nIndex);
122+
[DllImport(DLL)]
123+
public static extern bool Everything_GetResultSize(uint nIndex, out long lpFileSize);
124+
[DllImport(DLL)]
125+
public static extern bool Everything_GetResultDateCreated(uint nIndex, out long lpFileTime);
126+
[DllImport(DLL)]
127+
public static extern bool Everything_GetResultDateModified(uint nIndex, out long lpFileTime);
128+
[DllImport(DLL)]
129+
public static extern bool Everything_GetResultDateAccessed(uint nIndex, out long lpFileTime);
130+
[DllImport(DLL)]
131+
public static extern uint Everything_GetResultAttributes(uint nIndex);
132+
[DllImport(DLL, CharSet = CharSet.Unicode)]
133+
public static extern IntPtr Everything_GetResultFileListFileName(uint nIndex);
134+
[DllImport(DLL)]
135+
public static extern uint Everything_GetResultRunCount(uint nIndex);
136+
[DllImport(DLL)]
137+
public static extern bool Everything_GetResultDateRun(uint nIndex, out long lpFileTime);
138+
[DllImport(DLL)]
139+
public static extern bool Everything_GetResultDateRecentlyChanged(uint nIndex, out long lpFileTime);
140+
[DllImport(DLL, CharSet = CharSet.Unicode)]
141+
public static extern IntPtr Everything_GetResultHighlightedFileName(uint nIndex);
142+
[DllImport(DLL, CharSet = CharSet.Unicode)]
143+
public static extern IntPtr Everything_GetResultHighlightedPath(uint nIndex);
144+
[DllImport(DLL, CharSet = CharSet.Unicode)]
145+
public static extern IntPtr Everything_GetResultHighlightedFullPathAndFileName(uint nIndex);
146+
[DllImport(DLL)]
147+
public static extern uint Everything_GetRunCountFromFileName(string lpFileName);
148+
[DllImport(DLL)]
149+
public static extern bool Everything_SetRunCountFromFileName(string lpFileName, uint dwRunCount);
150+
[DllImport(DLL)]
151+
public static extern uint Everything_IncRunCountFromFileName(string lpFileName);
152+
}
153+
}

0 commit comments

Comments
 (0)