@@ -140,8 +140,6 @@ public List<Result> ContextMenus(IPublicAPI api)
140
140
Title = api . GetTranslation ( "flowlauncher_plugin_program_open_containing_folder" ) ,
141
141
Action = _ =>
142
142
{
143
-
144
-
145
143
Main . StartProcess ( Process . Start , new ProcessStartInfo ( "explorer" , ParentDirectory ) ) ;
146
144
147
145
return true ;
@@ -254,10 +252,7 @@ private static Win32 ExeProgram(string path)
254
252
{
255
253
var program = Win32Program ( path ) ;
256
254
var info = FileVersionInfo . GetVersionInfo ( path ) ;
257
- if ( ! string . IsNullOrEmpty ( info . FileDescription ) )
258
- {
259
- program . Description = info . FileDescription ;
260
- }
255
+ program . Description = info . FileDescription ;
261
256
return program ;
262
257
}
263
258
catch ( Exception e ) when ( e is SecurityException || e is UnauthorizedAccessException )
@@ -273,47 +268,23 @@ private static IEnumerable<string> ProgramPaths(string directory, string[] suffi
273
268
{
274
269
if ( ! Directory . Exists ( directory ) )
275
270
return new string [ ] { } ;
276
- var files = new List < string > ( ) ;
277
- var folderQueue = new Queue < string > ( ) ;
278
- folderQueue . Enqueue ( directory ) ;
279
- do
271
+ try
280
272
{
281
- var currentDirectory = folderQueue . Dequeue ( ) ;
282
- try
283
- {
284
- foreach ( var suffix in suffixes )
285
- {
286
- try
287
- {
288
- files . AddRange ( Directory . EnumerateFiles ( currentDirectory , $ "*.{ suffix } ", SearchOption . TopDirectoryOnly ) ) ;
289
- }
290
- catch ( DirectoryNotFoundException e )
291
- {
292
- ProgramLogger . LogException ( $ "|Win32|ProgramPaths|{ currentDirectory } " +
293
- "|The directory trying to load the program from does not exist" , e ) ;
294
- }
295
- }
296
- }
297
- catch ( Exception e ) when ( e is SecurityException || e is UnauthorizedAccessException )
298
- {
299
- ProgramLogger . LogException ( $ "|Win32|ProgramPaths|{ currentDirectory } " +
300
- $ "|Permission denied when trying to load programs from { currentDirectory } ", e ) ;
301
- }
273
+ var paths = Directory . EnumerateFiles ( directory , "*" , SearchOption . AllDirectories )
274
+ . Where ( x => suffixes . Contains ( Extension ( x ) ) ) ;
275
+ return paths ;
302
276
303
- try
304
- {
305
- foreach ( var childDirectory in Directory . EnumerateDirectories ( currentDirectory , "*" , SearchOption . TopDirectoryOnly ) )
306
- {
307
- folderQueue . Enqueue ( childDirectory ) ;
308
- }
309
- }
310
- catch ( Exception e ) when ( e is SecurityException || e is UnauthorizedAccessException )
311
- {
312
- ProgramLogger . LogException ( $ "|Win32|ProgramPaths|{ currentDirectory } " +
313
- $ "|Permission denied when trying to load programs from { currentDirectory } ", e ) ;
314
- }
315
- } while ( folderQueue . Any ( ) ) ;
316
- return files ;
277
+ }
278
+ catch ( DirectoryNotFoundException e )
279
+ {
280
+ ProgramLogger . LogException ( $ "Directory not found { directory } ", e ) ;
281
+ return new string [ ] { } ;
282
+ }
283
+ catch ( Exception e ) when ( e is SecurityException || e is UnauthorizedAccessException )
284
+ {
285
+ ProgramLogger . LogException ( $ "Permission denied { directory } ", e ) ;
286
+ return new string [ ] { } ;
287
+ }
317
288
}
318
289
319
290
private static string Extension ( string path )
@@ -331,23 +302,20 @@ private static string Extension(string path)
331
302
332
303
private static ParallelQuery < Win32 > UnregisteredPrograms ( List < Settings . ProgramSource > sources , string [ ] suffixes )
333
304
{
334
- var listToAdd = new List < string > ( ) ;
335
- sources . Where ( s => Directory . Exists ( s . Location ) && s . Enabled )
305
+ var paths = sources . Where ( s => Directory . Exists ( s . Location ) && s . Enabled )
336
306
. SelectMany ( s => ProgramPaths ( s . Location , suffixes ) )
337
- . ToList ( )
338
307
. Where ( t1 => ! Main . _settings . DisabledProgramSources . Any ( x => t1 == x . UniqueIdentifier ) )
339
- . ToList ( )
340
- . ForEach ( x => listToAdd . Add ( x ) ) ;
341
-
342
- var paths = listToAdd . Distinct ( ) . ToArray ( ) ;
343
-
344
- var programs1 = paths . AsParallel ( ) . Where ( p => Extension ( p ) == ExeExtension ) . Select ( ExeProgram ) ;
345
- var programs2 = paths . AsParallel ( ) . Where ( p => Extension ( p ) == ShortcutExtension ) . Select ( LnkProgram ) ;
346
- var programs3 = from p in paths . AsParallel ( )
347
- let e = Extension ( p )
348
- where e != ShortcutExtension && e != ExeExtension
349
- select Win32Program ( p ) ;
350
- return programs1 . Concat ( programs2 ) . Concat ( programs3 ) ;
308
+ . Distinct ( ) ;
309
+
310
+ var programs = paths . AsParallel ( ) . Select ( x => Extension ( x ) switch
311
+ {
312
+ ExeExtension => ExeProgram ( x ) ,
313
+ ShortcutExtension => LnkProgram ( x ) ,
314
+ _ => Win32Program ( x )
315
+ } ) ;
316
+
317
+
318
+ return programs ;
351
319
}
352
320
353
321
private static ParallelQuery < Win32 > StartMenuPrograms ( string [ ] suffixes )
@@ -360,15 +328,16 @@ private static ParallelQuery<Win32> StartMenuPrograms(string[] suffixes)
360
328
var paths2 = ProgramPaths ( directory2 , suffixes ) ;
361
329
362
330
var toFilter = paths1 . Concat ( paths2 ) ;
363
- var paths = toFilter
331
+
332
+ var programs = toFilter
333
+ . AsParallel ( )
364
334
. Where ( t1 => ! disabledProgramsList . Any ( x => x . UniqueIdentifier == t1 ) )
365
- . Select ( t1 => t1 )
366
335
. Distinct ( )
367
- . ToArray ( ) ;
368
-
369
- var programs1 = paths . AsParallel ( ) . Where ( p => Extension ( p ) == ShortcutExtension ) . Select ( LnkProgram ) ;
370
- var programs2 = paths . AsParallel ( ) . Where ( p => Extension ( p ) == ApplicationReferenceExtension ) . Select ( Win32Program ) ;
371
- var programs = programs1 . Concat ( programs2 ) . Where ( p => p . Valid ) ;
336
+ . Select ( x => Extension ( x ) switch
337
+ {
338
+ ShortcutExtension => LnkProgram ( x ) ,
339
+ _ => Win32Program ( x )
340
+ } ) . Where ( x => x . Valid ) ;
372
341
return programs ;
373
342
}
374
343
0 commit comments