@@ -23,7 +23,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
23
23
public class Win32 : IProgram , IEquatable < Win32 >
24
24
{
25
25
public string Name { get ; set ; }
26
- public string UniqueIdentifier { get => _uid ; set => _uid = value == null ? string . Empty : value . ToLowerInvariant ( ) ; } // For path comparison
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
/// <summary>
29
29
/// Path of the file. It's the path of .lnk and .url for .lnk and .url files.
@@ -69,28 +69,15 @@ public class Win32 : IProgram, IEquatable<Win32>
69
69
Enabled = false
70
70
} ;
71
71
72
- private static MatchResult Match ( string query , List < string > candidates )
72
+ private static MatchResult Match ( string query , IReadOnlyCollection < string > candidates )
73
73
{
74
74
if ( candidates . Count == 0 )
75
75
return null ;
76
76
77
- List < MatchResult > matches = new List < MatchResult > ( ) ;
78
- foreach ( var candidate in candidates )
79
- {
80
- var match = StringMatcher . FuzzySearch ( query , candidate ) ;
81
- if ( match . IsSearchPrecisionScoreMet ( ) )
82
- {
83
- matches . Add ( match ) ;
84
- }
85
- }
86
- if ( matches . Count == 0 )
87
- {
88
- return null ;
89
- }
90
- else
91
- {
92
- return matches . MaxBy ( match => match . Score ) ;
93
- }
77
+ var match = candidates . Select ( candidate => StringMatcher . FuzzySearch ( query , candidate ) )
78
+ . MaxBy ( match => match . Score ) ;
79
+
80
+ return match ? . IsSearchPrecisionScoreMet ( ) ?? false ? match : null ;
94
81
}
95
82
96
83
public Result Result ( string query , IPublicAPI api )
@@ -334,7 +321,7 @@ private static Win32 LnkProgram(string path)
334
321
program . ExecutableName = Path . GetFileName ( target ) ;
335
322
336
323
var args = _helper . arguments ;
337
- if ( ! string . IsNullOrEmpty ( args ) )
324
+ if ( ! string . IsNullOrEmpty ( args ) )
338
325
{
339
326
program . LnkResolvedPath += " " + args ;
340
327
}
@@ -361,7 +348,7 @@ private static Win32 LnkProgram(string path)
361
348
catch ( FileNotFoundException e )
362
349
{
363
350
ProgramLogger . LogException ( $ "|Win32|LnkProgram|{ path } " +
364
- "|An unexpected error occurred in the calling method LnkProgram" , e ) ;
351
+ "|An unexpected error occurred in the calling method LnkProgram" , e ) ;
365
352
366
353
return Default ;
367
354
}
@@ -428,7 +415,7 @@ private static Win32 ExeProgram(string path)
428
415
catch ( FileNotFoundException e )
429
416
{
430
417
ProgramLogger . LogException ( $ "|Win32|ExeProgram|{ path } " +
431
- $ "|File not found when trying to load the program from { path } ", e ) ;
418
+ $ "|File not found when trying to load the program from { path } ", e ) ;
432
419
433
420
return Default ;
434
421
}
@@ -448,8 +435,7 @@ private static IEnumerable<string> EnumerateProgramsInDir(string directory, stri
448
435
449
436
return Directory . EnumerateFiles ( directory , "*" , new EnumerationOptions
450
437
{
451
- IgnoreInaccessible = true ,
452
- RecurseSubdirectories = recursive
438
+ IgnoreInaccessible = true , RecurseSubdirectories = recursive
453
439
} ) . Where ( x => suffixes . Contains ( Extension ( x ) ) ) ;
454
440
}
455
441
@@ -458,7 +444,7 @@ private static string Extension(string path)
458
444
var extension = Path . GetExtension ( path ) ? . ToLowerInvariant ( ) ;
459
445
if ( ! string . IsNullOrEmpty ( extension ) )
460
446
{
461
- return extension . Substring ( 1 ) ; // remove dot
447
+ return extension . Substring ( 1 ) ; // remove dot
462
448
}
463
449
else
464
450
{
@@ -470,7 +456,7 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<string> directories,
470
456
{
471
457
// Disabled custom sources are not in DisabledProgramSources
472
458
var paths = directories . AsParallel ( )
473
- . SelectMany ( s => EnumerateProgramsInDir ( s , suffixes ) ) ;
459
+ . SelectMany ( s => EnumerateProgramsInDir ( s , suffixes ) ) ;
474
460
475
461
// Remove disabled programs in DisabledProgramSources
476
462
var programs = ExceptDisabledSource ( paths ) . Select ( x => GetProgramFromPath ( x , protocols ) ) ;
@@ -502,8 +488,8 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
502
488
var paths = pathEnv . Split ( ";" , StringSplitOptions . RemoveEmptyEntries ) . DistinctBy ( p => p . ToLowerInvariant ( ) ) ;
503
489
504
490
var toFilter = paths . Where ( x => commonParents . All ( parent => ! IsSubPathOf ( x , parent ) ) )
505
- . AsParallel ( )
506
- . SelectMany ( p => EnumerateProgramsInDir ( p , suffixes , recursive : false ) ) ;
491
+ . AsParallel ( )
492
+ . SelectMany ( p => EnumerateProgramsInDir ( p , suffixes , recursive : false ) ) ;
507
493
508
494
var programs = ExceptDisabledSource ( toFilter . Distinct ( ) )
509
495
. Select ( x => GetProgramFromPath ( x , protocols ) ) ;
@@ -533,7 +519,7 @@ private static IEnumerable<Win32> AppPathsPrograms(string[] suffixes, string[] p
533
519
toFilter = toFilter . Distinct ( ) . Where ( p => suffixes . Contains ( Extension ( p ) ) ) ;
534
520
535
521
var programs = ExceptDisabledSource ( toFilter )
536
- . Select ( x => GetProgramFromPath ( x , protocols ) ) . Where ( x => x . Valid ) . ToList ( ) ; // ToList due to disposing issue
522
+ . Select ( x => GetProgramFromPath ( x , protocols ) ) . Where ( x => x . Valid ) . ToList ( ) ; // ToList due to disposing issue
537
523
return programs ;
538
524
}
539
525
@@ -587,7 +573,8 @@ private static Win32 GetProgramFromPath(string path, string[] protocols)
587
573
ExeExtension => ExeProgram ( path ) ,
588
574
UrlExtension => UrlProgram ( path , protocols ) ,
589
575
_ => Win32Program ( path )
590
- } ; ;
576
+ } ;
577
+ ;
591
578
}
592
579
593
580
public static IEnumerable < string > ExceptDisabledSource ( IEnumerable < string > paths )
@@ -797,10 +784,10 @@ private static bool IsSubPathOf(string subPath, string basePath)
797
784
{
798
785
var rel = Path . GetRelativePath ( basePath , subPath ) ;
799
786
return rel != "."
800
- && rel != ".."
801
- && ! rel . StartsWith ( "../" )
802
- && ! rel . StartsWith ( @"..\" )
803
- && ! Path . IsPathRooted ( rel ) ;
787
+ && rel != ".."
788
+ && ! rel . StartsWith ( "../" )
789
+ && ! rel . StartsWith ( @"..\" )
790
+ && ! Path . IsPathRooted ( rel ) ;
804
791
}
805
792
806
793
private static List < string > GetCommonParents ( IEnumerable < ProgramSource > programSources )
@@ -815,7 +802,7 @@ private static List<string> GetCommonParents(IEnumerable<ProgramSource> programS
815
802
foreach ( var source in group )
816
803
{
817
804
if ( parents . Any ( p => IsSubPathOf ( source . Location , p . Location ) &&
818
- source != p ) )
805
+ source != p ) )
819
806
{
820
807
parents . Remove ( source ) ;
821
808
}
0 commit comments