diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index f54135beb..610da2915 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -231,7 +231,7 @@ namespace Flow.Launcher.Plugin.Program.Programs "|An unexpected error occurred in the calling method Win32Program", e); return Default; - } + } #endif } @@ -394,7 +394,7 @@ namespace Flow.Launcher.Plugin.Program.Programs // Disabled custom sources are not in DisabledProgramSources var paths = sources.Where(s => Directory.Exists(s.Location) && s.Enabled) .Distinct() - .AsParallel() + .AsParallel() .SelectMany(s => ProgramPaths(s.Location, suffixes)); // Remove disabled programs in DisabledProgramSources @@ -504,9 +504,6 @@ namespace Flow.Launcher.Plugin.Program.Programs path = Environment.ExpandEnvironmentVariables(path); - if (!File.Exists(path)) - return Default; - return Extension(path) switch { ShortcutExtension => LnkProgram(path), @@ -707,5 +704,27 @@ namespace Flow.Launcher.Plugin.Program.Programs fileSystemWatcher.Dispose(); } } + + private List GetCommonParents(IEnumerable programSources) + { + // To avoid unnecessary io + // like c:\windows and c:\windows\system32 + var grouped = programSources.GroupBy(p => p.Location.ToLowerInvariant()[0]); // group by disk + List result = new(); + foreach (var group in grouped) + { + HashSet parents = group.ToHashSet(); + foreach (var source in group) + { + if (parents.Any(p => source.Location.StartsWith(p.Location, StringComparison.OrdinalIgnoreCase) && + source != p)) + { + parents.Remove(source); + } + } + result.AddRange(parents.Select(x => x.Location)); + } + return result.DistinctBy(x => x.ToLowerInvariant()).ToList(); + } } }