@@ -17,7 +17,7 @@ public static class EverythingApi
17
17
{
18
18
private const int BufferSize = 4096 ;
19
19
20
- private static SemaphoreSlim _semaphore = new ( 1 , 1 ) ;
20
+ private static readonly SemaphoreSlim _semaphore = new ( 1 , 1 ) ;
21
21
22
22
// cached buffer to remove redundant allocations.
23
23
private static readonly StringBuilder buffer = new ( BufferSize ) ;
@@ -34,6 +34,9 @@ public enum StateCode
34
34
InvalidCallError
35
35
}
36
36
37
+ const uint EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004u ;
38
+ const uint EVERYTHING_REQUEST_RUN_COUNT = 0x00000400u ;
39
+
37
40
/// <summary>
38
41
/// Checks whether the sort option is Fast Sort.
39
42
/// </summary>
@@ -78,7 +81,7 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
78
81
79
82
if ( option . MaxCount < 0 )
80
83
throw new ArgumentOutOfRangeException ( nameof ( option . MaxCount ) , option . MaxCount , "MaxCount must be greater than or equal to 0" ) ;
81
-
84
+
82
85
await _semaphore . WaitAsync ( token ) ;
83
86
84
87
@@ -112,6 +115,17 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
112
115
113
116
EverythingApiDllImport . Everything_SetSort ( option . SortOption ) ;
114
117
EverythingApiDllImport . Everything_SetMatchPath ( option . IsFullPathSearch ) ;
118
+
119
+ if ( option . SortOption == SortOption . RUN_COUNT_DESCENDING )
120
+ {
121
+ EverythingApiDllImport . Everything_SetRequestFlags ( EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME | EVERYTHING_REQUEST_RUN_COUNT ) ;
122
+ }
123
+ else
124
+ {
125
+ EverythingApiDllImport . Everything_SetRequestFlags ( EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME ) ;
126
+ }
127
+
128
+
115
129
116
130
if ( token . IsCancellationRequested ) yield break ;
117
131
@@ -132,10 +146,12 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
132
146
133
147
var result = new SearchResult
134
148
{
149
+ // todo the types are wrong. Everything expects uint everywhere, but we send int just above/below. how to fix? Is EverythingApiDllImport autogenerated or handmade?
135
150
FullPath = buffer . ToString ( ) ,
136
151
Type = EverythingApiDllImport . Everything_IsFolderResult ( idx ) ? ResultType . Folder :
137
152
EverythingApiDllImport . Everything_IsFileResult ( idx ) ? ResultType . File :
138
- ResultType . Volume
153
+ ResultType . Volume ,
154
+ Score = ( int ) EverythingApiDllImport . Everything_GetResultRunCount ( ( uint ) idx )
139
155
} ;
140
156
141
157
yield return result ;
@@ -172,5 +188,19 @@ private static void CheckAndThrowExceptionOnError()
172
188
throw new ArgumentOutOfRangeException ( ) ;
173
189
}
174
190
}
191
+
192
+ public static async Task IncrementRunCounterAsync ( string fileOrFolder )
193
+ {
194
+ await _semaphore . WaitAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
195
+ try
196
+ {
197
+ _ = EverythingApiDllImport . Everything_IncRunCountFromFileName ( fileOrFolder ) ;
198
+ }
199
+ catch ( Exception )
200
+ {
201
+ /*ignored*/
202
+ }
203
+ finally { _semaphore . Release ( ) ; }
204
+ }
175
205
}
176
206
}
0 commit comments