Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Win32>
{
public string Name { get; set; }
public string UniqueIdentifier { get; set; }
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -470,14 +485,15 @@ public static IEnumerable<T> DistinctBy<T, R>(IEnumerable<T> source, Func<T, R>
}
}

private static Win32[] ProgramsHasher(IEnumerable<Win32> programs)
private static IEnumerable<Win32> ProgramsHasher(IEnumerable<Win32> 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();
}

Expand All @@ -489,22 +505,26 @@ public static Win32[] All(Settings settings)
var programs = Enumerable.Empty<Win32>();

var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);

programs = programs.Concat(unregistered);

var autoIndexPrograms = Enumerable.Empty<Win32>();

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)
Expand All @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Program/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down