From 033ce3051b4abd06318d9b8234775c29ff325695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 16 Feb 2021 01:41:02 +0800 Subject: [PATCH 1/5] filter desctiption existance before passing it to distinct --- Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 372d365245f..8657f0ec035 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -475,9 +475,10 @@ private static Win32[] 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(); } From f14a5b92296f2d7cba3cf55cfb69c1e217725d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 16 Feb 2021 15:54:11 +0800 Subject: [PATCH 2/5] add default win32, so we should not contain null --- .../Programs/Win32.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 8657f0ec035..aeb35ea3992 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -35,6 +35,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 +437,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); @@ -504,7 +518,6 @@ public static Win32[] All(Settings settings) programs = programs.Concat(startMenu); } - return ProgramsHasher(programs.Where(p => p != null)); } #if DEBUG //This is to make developer aware of any unhandled exception and add in handling. From 5fe833f7f2dff74edd65b900c400979f7b2e7856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 16 Feb 2021 15:55:44 +0800 Subject: [PATCH 3/5] Take user added program outside the hasher --- .../Flow.Launcher.Plugin.Program/Programs/Win32.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index aeb35ea3992..a186b6613a7 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -484,7 +484,7 @@ 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 => @@ -503,8 +503,6 @@ public static Win32[] All(Settings settings) { var programs = Enumerable.Empty(); - var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes); - programs = programs.Concat(unregistered); if (settings.EnableRegistrySource) { @@ -518,7 +516,13 @@ public static Win32[] All(Settings settings) programs = programs.Concat(startMenu); } - return ProgramsHasher(programs.Where(p => p != null)); + programs = ProgramsHasher(programs.Where(p => p != null)); + + var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes); + + programs = programs.Concat(unregistered); + + return programs.ToArray(); } #if DEBUG //This is to make developer aware of any unhandled exception and add in handling. catch (Exception e) From df2be9b82836c46545bb8639b9ab97178a9d4038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 16 Feb 2021 16:09:55 +0800 Subject: [PATCH 4/5] seperate user program sources and autoindex program source and distinct prior to user one --- .../Programs/Win32.cs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index a186b6613a7..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; } @@ -503,26 +504,27 @@ 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); } - programs = ProgramsHasher(programs.Where(p => p != null)); - - var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes); - - programs = programs.Concat(unregistered); + autoIndexPrograms = ProgramsHasher(autoIndexPrograms); - return programs.ToArray(); + 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) @@ -540,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 From 99193a42d87d0c04efea6524530281e0c9c862a2 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 22 Feb 2021 20:58:21 +1100 Subject: [PATCH 5/5] version bump Program plugin --- Plugins/Flow.Launcher.Plugin.Program/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",