@@ -25,23 +25,29 @@ public class Win32 : IProgram, IEquatable<Win32>
25
25
public string Name { get ; set ; }
26
26
public string UniqueIdentifier { get => _uid ; set => _uid = value == null ? string . Empty : value . ToLowerInvariant ( ) ; } // For path comparison
27
27
public string IcoPath { get ; set ; }
28
+
28
29
/// <summary>
29
30
/// Path of the file. It's the path of .lnk and .url for .lnk and .url files.
30
31
/// </summary>
31
32
public string FullPath { get ; set ; }
33
+
32
34
/// <summary>
33
35
/// Path of the executable for .lnk, or the URL for .url. Arguments are included if any.
34
36
/// </summary>
35
37
public string LnkResolvedPath { get ; set ; }
38
+
36
39
/// <summary>
37
40
/// Path of the actual executable file. Args are included.
38
41
/// </summary>
39
42
public string ExecutablePath => LnkResolvedPath ?? FullPath ;
43
+
40
44
public string ParentDirectory { get ; set ; }
45
+
41
46
/// <summary>
42
47
/// Name of the executable for .lnk files
43
48
/// </summary>
44
49
public string ExecutableName { get ; set ; }
50
+
45
51
public string Description { get ; set ; }
46
52
public bool Valid { get ; set ; }
47
53
public bool Enabled { get ; set ; }
@@ -199,8 +205,8 @@ public List<Result> ContextMenus(IPublicAPI api)
199
205
{
200
206
var info = new ProcessStartInfo
201
207
{
202
- FileName = FullPath ,
203
- WorkingDirectory = ParentDirectory ,
208
+ FileName = FullPath ,
209
+ WorkingDirectory = ParentDirectory ,
204
210
UseShellExecute = true
205
211
} ;
206
212
@@ -363,6 +369,7 @@ private static Win32 UrlProgram(string path, string[] protocols)
363
369
{
364
370
return program ;
365
371
}
372
+
366
373
foreach ( var protocol in protocols )
367
374
{
368
375
if ( url . StartsWith ( protocol ) )
@@ -418,10 +425,10 @@ private static IEnumerable<string> EnumerateProgramsInDir(string directory, stri
418
425
if ( ! Directory . Exists ( directory ) )
419
426
return Enumerable . Empty < string > ( ) ;
420
427
421
- return Directory . EnumerateFiles ( directory , "*" , new EnumerationOptions
422
- {
423
- IgnoreInaccessible = true , RecurseSubdirectories = recursive
424
- } ) . Where ( x => suffixes . Contains ( Extension ( x ) ) ) ;
428
+ return Directory . EnumerateFiles (
429
+ directory , "*" ,
430
+ new EnumerationOptions { IgnoreInaccessible = true , RecurseSubdirectories = recursive } )
431
+ . Where ( x => suffixes . Contains ( Extension ( x ) ) ) ;
425
432
}
426
433
427
434
private static string Extension ( string path )
@@ -450,14 +457,11 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<string> directories,
450
457
451
458
private static IEnumerable < Win32 > StartMenuPrograms ( string [ ] suffixes , string [ ] protocols )
452
459
{
453
- var directory1 = Environment . GetFolderPath ( Environment . SpecialFolder . Programs ) ;
454
- var directory2 = Environment . GetFolderPath ( Environment . SpecialFolder . CommonPrograms ) ;
455
- var paths1 = EnumerateProgramsInDir ( directory1 , suffixes ) ;
456
- var paths2 = EnumerateProgramsInDir ( directory2 , suffixes ) ;
457
-
458
- var toFilter = paths1 . Concat ( paths2 ) ;
460
+ var allPrograms = GetStartMenuPaths ( )
461
+ . SelectMany ( p => EnumerateProgramsInDir ( p , suffixes ) )
462
+ . Distinct ( ) ;
459
463
460
- var programs = ExceptDisabledSource ( toFilter . Distinct ( ) )
464
+ var programs = ExceptDisabledSource ( allPrograms )
461
465
. Select ( x => GetProgramFromPath ( x , protocols ) ) ;
462
466
return programs ;
463
467
}
@@ -471,7 +475,7 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
471
475
}
472
476
473
477
var paths = pathEnv . Split ( ";" , StringSplitOptions . RemoveEmptyEntries ) . DistinctBy ( p => p . ToLowerInvariant ( ) ) ;
474
-
478
+
475
479
var toFilter = paths . Where ( x => commonParents . All ( parent => ! FilesFolders . PathContains ( parent , x ) ) )
476
480
. AsParallel ( )
477
481
. SelectMany ( p => EnumerateProgramsInDir ( p , suffixes , recursive : false ) ) ;
@@ -695,12 +699,10 @@ public override bool Equals(object obj)
695
699
696
700
private static IEnumerable < string > GetStartMenuPaths ( )
697
701
{
698
- var directory1 = Environment . GetFolderPath ( Environment . SpecialFolder . Programs ) ;
699
- var directory2 = Environment . GetFolderPath ( Environment . SpecialFolder . CommonPrograms ) ;
700
- return new [ ]
701
- {
702
- directory1 , directory2
703
- } ;
702
+ var userStartMenu = Environment . GetFolderPath ( Environment . SpecialFolder . StartMenu ) ;
703
+ var commonStartMenu = Environment . GetFolderPath ( Environment . SpecialFolder . CommonStartMenu ) ;
704
+
705
+ return new [ ] { userStartMenu , commonStartMenu } ;
704
706
}
705
707
706
708
public static void WatchProgramUpdate ( Settings settings )
0 commit comments