From 94b841d341462ada653305b3b5a32b59da8d6d4b Mon Sep 17 00:00:00 2001 From: TheBestPessimist Date: Fri, 3 Mar 2023 14:36:36 +0200 Subject: [PATCH] Should be working --- .../Search/Everything/EverythingAPI.cs | 16 +++++++++++ .../Search/ResultManager.cs | 27 ++++++++++--------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs index 2a007cd73..ade6d1a66 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs @@ -172,5 +172,21 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything throw new ArgumentOutOfRangeException(); } } + + public static async Task IncrementRunCounterAsync(string fileOrFolder) + { + try + { + await _semaphore.WaitAsync(TimeSpan.FromSeconds(1)); + + if (await IsEverythingRunningAsync()) + _ = EverythingApiDllImport.Everything_IncRunCountFromFileName(fileOrFolder); + } + catch (Exception) + { + /*ignored*/ + } + finally { _semaphore.Release(); } + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 6110c0433..bee7cb1bc 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -78,10 +78,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search CopyText = path, Action = c => { + // open folder if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled)) { try { + IncrementRunCounterIfNeeded(path); Context.API.OpenDirectory(path); return true; } @@ -91,7 +93,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search return false; } } - + // or make this folder the current query Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword)); return false; @@ -224,16 +226,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search // TODO Why do we check if file exists here, but not in the other if conditions? if (File.Exists(filePath) && c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed) { - RunExplorerAsAdminAtPath(filePath); + IncrementRunCounterIfNeeded(filePath); + OpenFileAsAdmin(filePath); } else if (c.SpecialKeyState.CtrlPressed) { - RunExplorerAtPath(filePath); - } + IncrementRunCounterIfNeeded(filePath); + FilesFolders.OpenContainingFolder(filePath); + } + else { - FilesFolders.OpenPath(filePath); - EverythingApiDllImport.Everything_IncRunCountFromFileName(filePath); + IncrementRunCounterIfNeeded(filePath); + FilesFolders.OpenPath(filePath); } } catch (Exception ex) @@ -250,7 +255,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search return result; } - private static void RunExplorerAsAdminAtPath(string filePath) + private static void OpenFileAsAdmin(string filePath) { _ = Task.Run(() => { @@ -263,7 +268,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search WorkingDirectory = Settings.UseLocationAsWorkingDir ? Path.GetDirectoryName(filePath) : string.Empty, Verb = "runas", }); - EverythingApiDllImport.Everything_IncRunCountFromFileName(filePath); } catch (Exception e) { @@ -272,13 +276,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search }); } - private static void RunExplorerAtPath(string filePath) + private static void IncrementRunCounterIfNeeded(string fileOrFolder) { - Context.API.OpenDirectory(Path.GetDirectoryName(filePath), filePath); - EverythingApiDllImport.Everything_IncRunCountFromFileName(filePath); + if (Settings.EverythingEnabled) + _ = Task.Run(() => EverythingApi.IncrementRunCounterAsync(fileOrFolder)); } - public static bool IsMedia(string extension) { if (string.IsNullOrEmpty(extension))