1
1
using System ;
2
+ using System . Collections ;
2
3
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
4
using System . IO ;
5
5
using System . Linq ;
6
6
using System . Windows ;
@@ -58,10 +58,12 @@ public List<Result> Query(Query query)
58
58
var results = GetUserFolderResults ( query ) ;
59
59
60
60
string search = query . Search . ToLower ( ) ;
61
- if ( ! IsDriveOrSharedFolder ( search ) )
61
+ if ( ! IsDriveOrSharedFolder ( search ) && ! IsEnvironmentVariableSearch ( search ) )
62
+ {
62
63
return results ;
64
+ }
63
65
64
- if ( search . StartsWith ( "%" ) )
66
+ if ( IsEnvironmentVariableSearch ( search ) )
65
67
{
66
68
results . AddRange ( GetEnvironmentStringPathResults ( search , query ) ) ;
67
69
}
@@ -79,18 +81,18 @@ public List<Result> Query(Query query)
79
81
return results ;
80
82
}
81
83
84
+ private static bool IsEnvironmentVariableSearch ( string search )
85
+ {
86
+ return _envStringPaths != null && search . StartsWith ( "%" ) ;
87
+ }
88
+
82
89
private static bool IsDriveOrSharedFolder ( string search )
83
90
{
84
91
if ( search . StartsWith ( @"\\" ) )
85
92
{ // shared folder
86
93
return true ;
87
94
}
88
95
89
- if ( _envStringPaths != null && search . StartsWith ( "%" ) )
90
- { // environment string formatted folder
91
- return true ;
92
- }
93
-
94
96
if ( _driverNames != null && _driverNames . Any ( search . StartsWith ) )
95
97
{ // normal drive letter
96
98
return true ;
@@ -164,25 +166,14 @@ private void InitialDriverList()
164
166
private void LoadEnvironmentStringPaths ( )
165
167
{
166
168
_envStringPaths = new Dictionary < string , string > ( ) ;
167
-
168
- var specialPaths =
169
- new Dictionary < string , Environment . SpecialFolder > {
170
- { "appdata" , Environment . SpecialFolder . ApplicationData } ,
171
- { "localappdata" , Environment . SpecialFolder . LocalApplicationData } ,
172
- { "programfiles" , Environment . SpecialFolder . ProgramFiles } ,
173
- { "programfiles(x86)" , Environment . SpecialFolder . ProgramFilesX86 } ,
174
- { "programdata" , Environment . SpecialFolder . CommonApplicationData } ,
175
- { "userprofile" , Environment . SpecialFolder . UserProfile }
176
- } ;
177
-
178
- foreach ( var special in specialPaths )
169
+
170
+ foreach ( DictionaryEntry special in Environment . GetEnvironmentVariables ( ) )
179
171
{
180
- _envStringPaths . Add ( special . Key , Environment . GetFolderPath ( special . Value ) ) ;
172
+ if ( Directory . Exists ( special . Value . ToString ( ) ) )
173
+ {
174
+ _envStringPaths . Add ( special . Key . ToString ( ) . ToLower ( ) , special . Value . ToString ( ) ) ;
175
+ }
181
176
}
182
-
183
- var tempDirectoryPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Temp" ) ;
184
-
185
- _envStringPaths . Add ( "temp" , tempDirectoryPath ) ;
186
177
}
187
178
188
179
private static readonly char [ ] _specialSearchChars = new char [ ]
0 commit comments