@@ -231,7 +231,7 @@ private static Win32 Win32Program(string path)
231
231
"|An unexpected error occurred in the calling method Win32Program" , e ) ;
232
232
233
233
return Default ;
234
- }
234
+ }
235
235
#endif
236
236
}
237
237
@@ -394,7 +394,7 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<ProgramSource> sourc
394
394
// Disabled custom sources are not in DisabledProgramSources
395
395
var paths = sources . Where ( s => Directory . Exists ( s . Location ) && s . Enabled )
396
396
. Distinct ( )
397
- . AsParallel ( )
397
+ . AsParallel ( )
398
398
. SelectMany ( s => ProgramPaths ( s . Location , suffixes ) ) ;
399
399
400
400
// Remove disabled programs in DisabledProgramSources
@@ -504,9 +504,6 @@ private static Win32 GetProgramFromPath(string path, string[] protocols)
504
504
505
505
path = Environment . ExpandEnvironmentVariables ( path ) ;
506
506
507
- if ( ! File . Exists ( path ) )
508
- return Default ;
509
-
510
507
return Extension ( path ) switch
511
508
{
512
509
ShortcutExtension => LnkProgram ( path ) ,
@@ -707,5 +704,27 @@ public static void Dispose()
707
704
fileSystemWatcher . Dispose ( ) ;
708
705
}
709
706
}
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
+ }
710
729
}
711
730
}
0 commit comments