@@ -88,11 +88,19 @@ public static string GetDownloadsFolderPath()
88
88
}
89
89
}
90
90
91
+ private static readonly List < string > ignoredDrives = [ "sys" , "proc" , "dev" , "run" , "snap" , "tmp" , "boot" , "System" ] ;
92
+
91
93
public static void ClearCache ( )
92
94
{
93
95
List < FileSystemItem > drives = new ( ) ;
94
96
foreach ( var drive in DriveInfo . GetDrives ( ) )
95
97
{
98
+ // shouldn't be a performance concern, but if it ever gets to the point use a trie.
99
+ if ( drive . Name . StartsWith ( '/' ) && ignoredDrives . Any ( x => drive . Name . AsSpan ( 1 ) . StartsWith ( x ) ) )
100
+ {
101
+ continue ;
102
+ }
103
+
96
104
try
97
105
{
98
106
if ( drive . IsReady && drive . RootDirectory != null )
@@ -135,7 +143,11 @@ public static void ClearCache()
135
143
name = "Local Disk" ;
136
144
}
137
145
138
- name += $ " ({ drive . Name } )";
146
+ if ( name != drive . Name )
147
+ {
148
+ name += $ " ({ drive . Name } )";
149
+ }
150
+
139
151
140
152
drives . Add ( new FileSystemItem ( drive . RootDirectory . FullName , driveIcon , name , FileSystemItemFlags . Folder ) ) ;
141
153
}
@@ -146,25 +158,39 @@ public static void ClearCache()
146
158
}
147
159
148
160
logicalDrives = [ .. drives ] ;
161
+
162
+ List < FileSystemItem > items = [ ] ;
163
+ AddSpecialDir ( items , Environment . SpecialFolder . Desktop , $ "{ MaterialIcons . DesktopWindows } ") ;
164
+ AddSpecialDir ( items , GetDownloadsFolderPath , $ "{ MaterialIcons . DesktopWindows } ") ;
165
+ AddSpecialDir ( items , Environment . SpecialFolder . MyDocuments , $ "{ MaterialIcons . DesktopWindows } ") ;
166
+ AddSpecialDir ( items , Environment . SpecialFolder . MyMusic , $ "{ MaterialIcons . DesktopWindows } ") ;
167
+ AddSpecialDir ( items , Environment . SpecialFolder . MyPictures , $ "{ MaterialIcons . DesktopWindows } ") ;
168
+ AddSpecialDir ( items , Environment . SpecialFolder . MyVideos , $ "{ MaterialIcons . DesktopWindows } ") ;
169
+ specialDirs = [ .. items ] ;
170
+
171
+ cache . Clear ( ) ;
172
+ }
173
+
174
+ private static void AddSpecialDir ( List < FileSystemItem > items , Environment . SpecialFolder folder , string icon )
175
+ {
149
176
try
150
177
{
151
- List < FileSystemItem > items =
152
- [
153
- new ( Environment . GetFolderPath ( Environment . SpecialFolder . Desktop ) , $ "{ MaterialIcons . DesktopWindows } ", FileSystemItemFlags . Folder ) ,
154
- new ( GetDownloadsFolderPath ( ) , $ "{ MaterialIcons . Download } ", FileSystemItemFlags . Folder ) ,
155
- new ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , $ "{ MaterialIcons . Description } ", FileSystemItemFlags . Folder ) ,
156
- new ( Environment . GetFolderPath ( Environment . SpecialFolder . MyMusic ) , $ "{ MaterialIcons . LibraryMusic } ", FileSystemItemFlags . Folder ) ,
157
- new ( Environment . GetFolderPath ( Environment . SpecialFolder . MyPictures ) , $ "{ MaterialIcons . Image } ", FileSystemItemFlags . Folder ) ,
158
- new ( Environment . GetFolderPath ( Environment . SpecialFolder . MyVideos ) , $ "{ MaterialIcons . VideoLibrary } ", FileSystemItemFlags . Folder ) ,
159
- ] ;
160
-
161
- specialDirs = [ .. items ] ;
178
+ items . Add ( new ( Environment . GetFolderPath ( folder ) , icon , FileSystemItemFlags . Folder ) ) ;
162
179
}
163
- catch
180
+ catch ( Exception )
181
+ {
182
+ }
183
+ }
184
+
185
+ private static void AddSpecialDir ( List < FileSystemItem > items , Func < string > getPath , string icon )
186
+ {
187
+ try
188
+ {
189
+ items . Add ( new ( getPath ( ) , icon , FileSystemItemFlags . Folder ) ) ;
190
+ }
191
+ catch ( Exception )
164
192
{
165
- specialDirs = [ ] ;
166
193
}
167
- cache . Clear ( ) ;
168
194
}
169
195
170
196
public static IEnumerable < FileSystemItem > Refresh ( string folder , RefreshFlags refreshFlags , List < string > ? allowedExtensions , SearchOptions searchOptions , Func < FileMetadata , string > fileDecorator , char ? folderDecorator )
0 commit comments