diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 372d365245f..773d0c6b69b 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -14,11 +14,12 @@ using Flow.Launcher.Infrastructure.Logger; using System.Diagnostics; using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; +using System.Diagnostics.CodeAnalysis; namespace Flow.Launcher.Plugin.Program.Programs { [Serializable] - public class Win32 : IProgram + public class Win32 : IProgram, IEquatable { public string Name { get; set; } public string UniqueIdentifier { get; set; } @@ -35,6 +36,20 @@ public class Win32 : IProgram private const string ShortcutExtension = "lnk"; private const string ExeExtension = "exe"; + private static readonly Win32 Default = new Win32() + { + Name = string.Empty, + Description = string.Empty, + IcoPath = string.Empty, + FullPath = string.Empty, + LnkResolvedPath = null, + ParentDirectory = string.Empty, + ExecutableName = null, + UniqueIdentifier = string.Empty, + Valid = false, + Enabled = false + }; + public Result Result(string query, IPublicAPI api) { @@ -423,12 +438,12 @@ private static string GetProgramPathFromRegistrySubKeys(RegistryKey root, string private static Win32 GetProgramFromPath(string path) { if (string.IsNullOrEmpty(path)) - return null; + return Default; path = Environment.ExpandEnvironmentVariables(path); if (!File.Exists(path)) - return null; + return Default; var entry = Win32Program(path); @@ -470,14 +485,15 @@ public static IEnumerable DistinctBy(IEnumerable source, Func } } - private static Win32[] ProgramsHasher(IEnumerable programs) + private static IEnumerable ProgramsHasher(IEnumerable programs) { return programs.GroupBy(p => p.FullPath.ToLower()) .SelectMany(g => { - if (g.Count() > 1) - return DistinctBy(g.Where(p => !string.IsNullOrEmpty(p.Description)), x => x.Description); - return g; + var temp = g.Where(g => !string.IsNullOrEmpty(g.Description)).ToList(); + if (temp.Any()) + return DistinctBy(temp, x => x.Description); + return g.Take(1); }).ToArray(); } @@ -489,22 +505,26 @@ public static Win32[] All(Settings settings) var programs = Enumerable.Empty(); var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes); + programs = programs.Concat(unregistered); + var autoIndexPrograms = Enumerable.Empty(); + if (settings.EnableRegistrySource) { var appPaths = AppPathsPrograms(settings.ProgramSuffixes); - programs = programs.Concat(appPaths); + autoIndexPrograms = autoIndexPrograms.Concat(appPaths); } if (settings.EnableStartMenuSource) { var startMenu = StartMenuPrograms(settings.ProgramSuffixes); - programs = programs.Concat(startMenu); + autoIndexPrograms = autoIndexPrograms.Concat(startMenu); } + autoIndexPrograms = ProgramsHasher(autoIndexPrograms); - return ProgramsHasher(programs.Where(p => p != null)); + return programs.Concat(autoIndexPrograms).Distinct().ToArray(); } #if DEBUG //This is to make developer aware of any unhandled exception and add in handling. catch (Exception e) @@ -522,5 +542,18 @@ public static Win32[] All(Settings settings) } #endif } + + public override int GetHashCode() + { + return UniqueIdentifier.GetHashCode(); + } + + public bool Equals([AllowNull] Win32 other) + { + if (other == null) + return false; + + return UniqueIdentifier == other.UniqueIdentifier; + } } } \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Program/plugin.json b/Plugins/Flow.Launcher.Plugin.Program/plugin.json index d110124ff42..082f0d85370 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Program/plugin.json @@ -4,7 +4,7 @@ "Name": "Program", "Description": "Search programs in Flow.Launcher", "Author": "qianlifeng", - "Version": "1.4.2", + "Version": "1.4.3", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Program.dll",