@@ -364,7 +364,7 @@ private static Win32 ExeProgram(string path)
364
364
}
365
365
}
366
366
367
- private static IEnumerable < string > ProgramPaths ( string directory , string [ ] suffixes , bool recursive = true )
367
+ private static IEnumerable < string > EnmuerateProgramsInDir ( string directory , string [ ] suffixes , bool recursive = true )
368
368
{
369
369
if ( ! Directory . Exists ( directory ) )
370
370
return Enumerable . Empty < string > ( ) ;
@@ -389,13 +389,11 @@ private static string Extension(string path)
389
389
}
390
390
}
391
391
392
- private static IEnumerable < Win32 > UnregisteredPrograms ( List < ProgramSource > sources , string [ ] suffixes , string [ ] protocols )
392
+ private static IEnumerable < Win32 > UnregisteredPrograms ( List < string > directories , string [ ] suffixes , string [ ] protocols )
393
393
{
394
394
// Disabled custom sources are not in DisabledProgramSources
395
- var paths = sources . Where ( s => Directory . Exists ( s . Location ) && s . Enabled )
396
- . Distinct ( )
397
- . AsParallel ( )
398
- . SelectMany ( s => ProgramPaths ( s . Location , suffixes ) ) ;
395
+ var paths = directories . AsParallel ( )
396
+ . SelectMany ( s => EnmuerateProgramsInDir ( s , suffixes ) ) ;
399
397
400
398
// Remove disabled programs in DisabledProgramSources
401
399
var programs = ExceptDisabledSource ( paths ) . Select ( x => GetProgramFromPath ( x , protocols ) ) ;
@@ -406,8 +404,8 @@ private static IEnumerable<Win32> StartMenuPrograms(string[] suffixes, string[]
406
404
{
407
405
var directory1 = Environment . GetFolderPath ( Environment . SpecialFolder . Programs ) ;
408
406
var directory2 = Environment . GetFolderPath ( Environment . SpecialFolder . CommonPrograms ) ;
409
- var paths1 = ProgramPaths ( directory1 , suffixes ) ;
410
- var paths2 = ProgramPaths ( directory2 , suffixes ) ;
407
+ var paths1 = EnmuerateProgramsInDir ( directory1 , suffixes ) ;
408
+ var paths2 = EnmuerateProgramsInDir ( directory2 , suffixes ) ;
411
409
412
410
var toFilter = paths1 . Concat ( paths2 ) ;
413
411
@@ -426,7 +424,7 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
426
424
427
425
var paths = pathEnv . Split ( ";" , StringSplitOptions . RemoveEmptyEntries ) . DistinctBy ( p => p . ToLowerInvariant ( ) ) ;
428
426
429
- var toFilter = paths . AsParallel ( ) . SelectMany ( p => ProgramPaths ( p , suffixes , recursive : false ) ) ;
427
+ var toFilter = paths . AsParallel ( ) . SelectMany ( p => EnmuerateProgramsInDir ( p , suffixes , recursive : false ) ) ;
430
428
431
429
var programs = ExceptDisabledSource ( toFilter . Distinct ( ) )
432
430
. Select ( x => GetProgramFromPath ( x , protocols ) ) ;
@@ -570,7 +568,11 @@ public static Win32[] All(Settings settings)
570
568
var suffixes = settings . GetSuffixes ( ) ;
571
569
var protocols = settings . GetProtocols ( ) ;
572
570
573
- var unregistered = UnregisteredPrograms ( settings . ProgramSources , suffixes , protocols ) ;
571
+ // Disabled custom sources are not in DisabledProgramSources
572
+ var sources = settings . ProgramSources . Where ( s => Directory . Exists ( s . Location ) && s . Enabled ) . Distinct ( ) ;
573
+ var commonParents = GetCommonParents ( sources ) ;
574
+
575
+ var unregistered = UnregisteredPrograms ( commonParents , suffixes , protocols ) ;
574
576
575
577
programs = programs . Concat ( unregistered ) ;
576
578
@@ -705,7 +707,7 @@ public static void Dispose()
705
707
}
706
708
}
707
709
708
- private List < string > GetCommonParents ( IEnumerable < ProgramSource > programSources )
710
+ private static List < string > GetCommonParents ( IEnumerable < ProgramSource > programSources )
709
711
{
710
712
// To avoid unnecessary io
711
713
// like c:\windows and c:\windows\system32
0 commit comments