4
4
using System . Collections . Generic ;
5
5
using System . IO ;
6
6
using System . Linq ;
7
+ using System . Threading ;
7
8
8
9
namespace Flow . Launcher . Plugin . Explorer . Search . DirectoryInfo
9
10
{
@@ -16,14 +17,18 @@ public DirectoryInfoSearch(PluginInitContext context)
16
17
resultManager = new ResultManager ( context ) ;
17
18
}
18
19
19
- internal List < Result > TopLevelDirectorySearch ( Query query , string search )
20
+ internal List < Result > TopLevelDirectorySearch ( Query query , string search , CancellationToken token )
20
21
{
21
22
var criteria = ConstructSearchCriteria ( search ) ;
22
23
23
- if ( search . LastIndexOf ( Constants . AllFilesFolderSearchWildcard ) > search . LastIndexOf ( Constants . DirectorySeperator ) )
24
- return DirectorySearch ( SearchOption . AllDirectories , query , search , criteria ) ;
24
+ if ( search . LastIndexOf ( Constants . AllFilesFolderSearchWildcard ) >
25
+ search . LastIndexOf ( Constants . DirectorySeperator ) )
26
+ return DirectorySearch ( new EnumerationOptions
27
+ {
28
+ RecurseSubdirectories = true
29
+ } , query , search , criteria , token ) ;
25
30
26
- return DirectorySearch ( SearchOption . TopDirectoryOnly , query , search , criteria ) ;
31
+ return DirectorySearch ( null , query , search , criteria , token ) ; // null will be passed as default
27
32
}
28
33
29
34
public string ConstructSearchCriteria ( string search )
@@ -45,7 +50,8 @@ public string ConstructSearchCriteria(string search)
45
50
return incompleteName ;
46
51
}
47
52
48
- private List < Result > DirectorySearch ( SearchOption searchOption , Query query , string search , string searchCriteria )
53
+ private List < Result > DirectorySearch ( EnumerationOptions enumerationOption , Query query , string search ,
54
+ string searchCriteria , CancellationToken token )
49
55
{
50
56
var results = new List < Result > ( ) ;
51
57
@@ -58,38 +64,38 @@ private List<Result> DirectorySearch(SearchOption searchOption, Query query, str
58
64
{
59
65
var directoryInfo = new System . IO . DirectoryInfo ( path ) ;
60
66
61
- foreach ( var fileSystemInfo in directoryInfo . EnumerateFileSystemInfos ( searchCriteria , searchOption ) )
67
+ foreach ( var fileSystemInfo in directoryInfo . EnumerateFileSystemInfos ( searchCriteria , enumerationOption ) )
62
68
{
63
- if ( ( fileSystemInfo . Attributes & FileAttributes . Hidden ) == FileAttributes . Hidden ) continue ;
64
-
65
69
if ( fileSystemInfo is System . IO . DirectoryInfo )
66
70
{
67
- folderList . Add ( resultManager . CreateFolderResult ( fileSystemInfo . Name , fileSystemInfo . FullName , fileSystemInfo . FullName , query , true , false ) ) ;
71
+ folderList . Add ( resultManager . CreateFolderResult ( fileSystemInfo . Name , fileSystemInfo . FullName ,
72
+ fileSystemInfo . FullName , query , true , false ) ) ;
68
73
}
69
74
else
70
75
{
71
76
fileList . Add ( resultManager . CreateFileResult ( fileSystemInfo . FullName , query , true , false ) ) ;
72
77
}
78
+
79
+ if ( token . IsCancellationRequested )
80
+ return null ;
73
81
}
74
82
}
75
83
catch ( Exception e )
76
84
{
77
- if ( e is UnauthorizedAccessException || e is ArgumentException )
78
- {
79
- results . Add ( new Result { Title = e . Message , Score = 501 } ) ;
85
+ if ( ! ( e is ArgumentException ) ) throw e ;
86
+
87
+ results . Add ( new Result { Title = e . Message , Score = 501 } ) ;
80
88
81
- return results ;
82
- }
89
+ return results ;
83
90
84
91
#if DEBUG // Please investigate and handle error from DirectoryInfo search
85
- throw e ;
86
92
#else
87
93
Log . Exception ( $ "|Flow.Launcher.Plugin.Explorer.DirectoryInfoSearch|Error from performing DirectoryInfoSearch", e ) ;
88
- #endif
94
+ #endif
89
95
}
90
96
91
- // Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
97
+ // Initial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
92
98
return results . Concat ( folderList . OrderBy ( x => x . Title ) ) . Concat ( fileList . OrderBy ( x => x . Title ) ) . ToList ( ) ;
93
99
}
94
100
}
95
- }
101
+ }
0 commit comments