Skip to content

Commit 5f85694

Browse files
get common parents for program sources
1 parent 519702c commit 5f85694

File tree

1 file changed

+24
-5
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+24
-5
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private static Win32 Win32Program(string path)
231231
"|An unexpected error occurred in the calling method Win32Program", e);
232232

233233
return Default;
234-
}
234+
}
235235
#endif
236236
}
237237

@@ -394,7 +394,7 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<ProgramSource> sourc
394394
// Disabled custom sources are not in DisabledProgramSources
395395
var paths = sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
396396
.Distinct()
397-
.AsParallel()
397+
.AsParallel()
398398
.SelectMany(s => ProgramPaths(s.Location, suffixes));
399399

400400
// Remove disabled programs in DisabledProgramSources
@@ -504,9 +504,6 @@ private static Win32 GetProgramFromPath(string path, string[] protocols)
504504

505505
path = Environment.ExpandEnvironmentVariables(path);
506506

507-
if (!File.Exists(path))
508-
return Default;
509-
510507
return Extension(path) switch
511508
{
512509
ShortcutExtension => LnkProgram(path),
@@ -707,5 +704,27 @@ public static void Dispose()
707704
fileSystemWatcher.Dispose();
708705
}
709706
}
707+
708+
private List<string> GetCommonParents(IEnumerable<ProgramSource> programSources)
709+
{
710+
// To avoid unnecessary io
711+
// like c:\windows and c:\windows\system32
712+
var grouped = programSources.GroupBy(p => p.Location.ToLowerInvariant()[0]); // group by disk
713+
List<string> result = new();
714+
foreach (var group in grouped)
715+
{
716+
HashSet<ProgramSource> parents = group.ToHashSet();
717+
foreach (var source in group)
718+
{
719+
if (parents.Any(p => source.Location.StartsWith(p.Location, StringComparison.OrdinalIgnoreCase) &&
720+
source != p))
721+
{
722+
parents.Remove(source);
723+
}
724+
}
725+
result.AddRange(parents.Select(x => x.Location));
726+
}
727+
return result.DistinctBy(x => x.ToLowerInvariant()).ToList();
728+
}
710729
}
711730
}

0 commit comments

Comments
 (0)