@@ -88,11 +88,19 @@ public static string GetDownloadsFolderPath()
8888 }
8989 }
9090
91+ private static readonly List < string > ignoredDrives = [ "sys" , "proc" , "dev" , "run" , "snap" , "tmp" , "boot" , "System" ] ;
92+
9193 public static void ClearCache ( )
9294 {
9395 List < FileSystemItem > drives = new ( ) ;
9496 foreach ( var drive in DriveInfo . GetDrives ( ) )
9597 {
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+
96104 try
97105 {
98106 if ( drive . IsReady && drive . RootDirectory != null )
@@ -135,7 +143,11 @@ public static void ClearCache()
135143 name = "Local Disk" ;
136144 }
137145
138- name += $ " ({ drive . Name } )";
146+ if ( name != drive . Name )
147+ {
148+ name += $ " ({ drive . Name } )";
149+ }
150+
139151
140152 drives . Add ( new FileSystemItem ( drive . RootDirectory . FullName , driveIcon , name , FileSystemItemFlags . Folder ) ) ;
141153 }
@@ -146,25 +158,39 @@ public static void ClearCache()
146158 }
147159
148160 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+ {
149176 try
150177 {
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 ) ) ;
162179 }
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 )
164192 {
165- specialDirs = [ ] ;
166193 }
167- cache . Clear ( ) ;
168194 }
169195
170196 public static IEnumerable < FileSystemItem > Refresh ( string folder , RefreshFlags refreshFlags , List < string > ? allowedExtensions , SearchOptions searchOptions , Func < FileMetadata , string > fileDecorator , char ? folderDecorator )
0 commit comments