Skip to content

Commit 83a44b1

Browse files
authored
Merge pull request #1950 from TheBestPessimist/everything_update_runcount
Everything: update RunCount on file action
2 parents 0c68225 + 1ed1c99 commit 83a44b1

File tree

9 files changed

+134
-108
lines changed

9 files changed

+134
-108
lines changed

.github/actions/spelling/allow.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ github
22
https
33
ssh
44
ubuntu
5+
runcount

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public interface IPublicAPI
233233
/// Open directory in an explorer configured by user via Flow's Settings. The default is Windows Explorer
234234
/// </summary>
235235
/// <param name="DirectoryPath">Directory Path to open</param>
236-
/// <param name="FileName">Extra FileName Info</param>
237-
public void OpenDirectory(string DirectoryPath, string FileName = null);
236+
/// <param name="FileNameOrFilePath">Extra FileName Info</param>
237+
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null);
238238

239239
/// <summary>
240240
/// Opens the URL with the given Uri object.

Flow.Launcher.Plugin/Result.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public override int GetHashCode()
178178
/// <inheritdoc />
179179
public override string ToString()
180180
{
181-
return Title + SubTitle;
181+
return Title + SubTitle + Score;
182182
}
183183

184184
/// <summary>

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public static class FilesFolders
1414
{
1515
private const string FileExplorerProgramName = "explorer";
1616

17-
private const string FileExplorerProgramEXE = "explorer.exe";
18-
1917
/// <summary>
2018
/// Copies the folder and all of its files and folders
2119
/// including subfolders to the target location
@@ -151,7 +149,12 @@ public static bool FileExists(this string filePath)
151149
/// <param name="fileOrFolderPath"></param>
152150
public static void OpenPath(string fileOrFolderPath)
153151
{
154-
var psi = new ProcessStartInfo { FileName = FileExplorerProgramName, UseShellExecute = true, Arguments = '"' + fileOrFolderPath + '"' };
152+
var psi = new ProcessStartInfo
153+
{
154+
FileName = FileExplorerProgramName,
155+
UseShellExecute = true,
156+
Arguments = '"' + fileOrFolderPath + '"'
157+
};
155158
try
156159
{
157160
if (LocationExists(fileOrFolderPath) || FileExists(fileOrFolderPath))
@@ -167,15 +170,6 @@ public static void OpenPath(string fileOrFolderPath)
167170
}
168171
}
169172

170-
/// <summary>
171-
/// Open the folder that contains <paramref name="path"/>
172-
/// </summary>
173-
/// <param name="path"></param>
174-
public static void OpenContainingFolder(string path)
175-
{
176-
Process.Start(FileExplorerProgramEXE, $" /select,\"{path}\"");
177-
}
178-
179173
///<summary>
180174
/// This checks whether a given string is a directory path or network location string.
181175
/// It does not check if location actually exists.

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
 using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net;
@@ -195,17 +195,20 @@ public void SavePluginSettings()
195195
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
196196
}
197197

198-
public void OpenDirectory(string DirectoryPath, string FileName = null)
198+
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
199199
{
200200
using var explorer = new Process();
201201
var explorerInfo = _settingsVM.Settings.CustomExplorer;
202202
explorer.StartInfo = new ProcessStartInfo
203203
{
204204
FileName = explorerInfo.Path,
205-
Arguments = FileName is null ?
206-
explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) :
207-
explorerInfo.FileArgument.Replace("%d", DirectoryPath).Replace("%f",
208-
Path.IsPathRooted(FileName) ? FileName : Path.Combine(DirectoryPath, FileName))
205+
Arguments = FileNameOrFilePath is null
206+
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
207+
: explorerInfo.FileArgument
208+
.Replace("%d", DirectoryPath)
209+
.Replace("%f",
210+
Path.IsPathRooted(FileNameOrFilePath) ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath)
211+
)
209212
};
210213
explorer.Start();
211214
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class EverythingApi
1717
{
1818
private const int BufferSize = 4096;
1919

20-
private static SemaphoreSlim _semaphore = new(1, 1);
20+
private static readonly SemaphoreSlim _semaphore = new(1, 1);
2121

2222
// cached buffer to remove redundant allocations.
2323
private static readonly StringBuilder buffer = new(BufferSize);
@@ -34,6 +34,9 @@ public enum StateCode
3434
InvalidCallError
3535
}
3636

37+
const uint EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004u;
38+
const uint EVERYTHING_REQUEST_RUN_COUNT = 0x00000400u;
39+
3740
/// <summary>
3841
/// Checks whether the sort option is Fast Sort.
3942
/// </summary>
@@ -78,7 +81,7 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
7881

7982
if (option.MaxCount < 0)
8083
throw new ArgumentOutOfRangeException(nameof(option.MaxCount), option.MaxCount, "MaxCount must be greater than or equal to 0");
81-
84+
8285
await _semaphore.WaitAsync(token);
8386

8487

@@ -112,6 +115,17 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
112115

113116
EverythingApiDllImport.Everything_SetSort(option.SortOption);
114117
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+
115129

116130
if (token.IsCancellationRequested) yield break;
117131

@@ -132,10 +146,12 @@ public static async IAsyncEnumerable<SearchResult> SearchAsync(EverythingSearchO
132146

133147
var result = new SearchResult
134148
{
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?
135150
FullPath = buffer.ToString(),
136151
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :
137152
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
138-
ResultType.Volume
153+
ResultType.Volume,
154+
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx)
139155
};
140156

141157
yield return result;
@@ -172,5 +188,19 @@ private static void CheckAndThrowExceptionOnError()
172188
throw new ArgumentOutOfRangeException();
173189
}
174190
}
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+
}
175205
}
176206
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingSearchManager.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private async ValueTask ThrowIfEverythingNotAvailableAsync(CancellationToken tok
3939
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue"));
4040
}
4141
}
42+
4243
private async ValueTask<bool> ClickToInstallEverythingAsync(ActionContext _)
4344
{
4445
var installedPath = await EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, Main.Context.API);
@@ -68,8 +69,8 @@ public async IAsyncEnumerable<SearchResult> SearchAsync(string search, [Enumerat
6869
await foreach (var result in EverythingApi.SearchAsync(option, token))
6970
yield return result;
7071
}
71-
public async IAsyncEnumerable<SearchResult> ContentSearchAsync(string plainSearch,
72-
string contentSearch,
72+
73+
public async IAsyncEnumerable<SearchResult> ContentSearchAsync(string plainSearch, string contentSearch,
7374
[EnumeratorCancellation] CancellationToken token)
7475
{
7576
await ThrowIfEverythingNotAvailableAsync(token);
@@ -102,6 +103,7 @@ public async IAsyncEnumerable<SearchResult> ContentSearchAsync(string plainSearc
102103
yield return result;
103104
}
104105
}
106+
105107
public async IAsyncEnumerable<SearchResult> EnumerateAsync(string path, string search, bool recursive, [EnumeratorCancellation] CancellationToken token)
106108
{
107109
await ThrowIfEverythingNotAvailableAsync(token);

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/SortOption.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public enum SortOption : uint
2727
ATTRIBUTES_DESCENDING = 16u,
2828
FILE_LIST_FILENAME_ASCENDING = 17u,
2929
FILE_LIST_FILENAME_DESCENDING = 18u,
30-
RUN_COUNT_ASCENDING = 19u,
3130
RUN_COUNT_DESCENDING = 20u,
3231
DATE_RECENTLY_CHANGED_ASCENDING = 21u,
3332
DATE_RECENTLY_CHANGED_DESCENDING = 22u,

0 commit comments

Comments
 (0)