55using Files . ViewModels ;
66using Microsoft . Toolkit . Uwp . Extensions ;
77using System ;
8+ using System . Collections . Generic ;
89using System . Collections . ObjectModel ;
910using System . ComponentModel ;
1011using System . IO ;
@@ -317,31 +318,39 @@ private static async Task SetSelectedTabInfoAsync(TabItem selectedTabItem, strin
317318 // If path is a drive's root
318319 if ( NormalizePath ( Path . GetPathRoot ( currentPath ) ) == NormalizePath ( currentPath ) )
319320 {
320- if ( NormalizePath ( currentPath ) != NormalizePath ( "A:" ) && NormalizePath ( currentPath ) != NormalizePath ( "B:" ) )
321+ try
321322 {
322- var remDriveNames = ( await KnownFolders . RemovableDevices . GetFoldersAsync ( ) ) . Select ( x => x . DisplayName ) ;
323- var matchingDriveName = remDriveNames . FirstOrDefault ( x => NormalizePath ( currentPath ) . Contains ( x . ToUpperInvariant ( ) ) ) ;
323+ List < DriveInfo > drives = DriveInfo . GetDrives ( ) . ToList ( ) ;
324+ DriveInfo matchingDrive = drives . FirstOrDefault ( x => NormalizePath ( currentPath ) . Contains ( NormalizePath ( x . Name ) ) ) ;
324325
325- if ( matchingDriveName = = null )
326+ if ( matchingDrive ! = null )
326327 {
327- fontIconSource . Glyph = "\xeb8b " ;
328- tabLocationHeader = NormalizePath ( currentPath ) ;
328+ //Go through types and set the icon according to type
329+ string type = GetDriveTypeIcon ( matchingDrive ) ;
330+ if ( ! string . IsNullOrWhiteSpace ( type ) )
331+ {
332+ fontIconSource . Glyph = type ;
333+ }
334+ else
335+ {
336+ fontIconSource . Glyph = "\xeb8b " ; //Drive icon
337+ }
329338 }
330339 else
331340 {
332- fontIconSource . Glyph = "\xec0a " ;
333- tabLocationHeader = matchingDriveName ;
341+ fontIconSource . Glyph = "\xeb4a " ; //Floppy icon
334342 }
335343 }
336- else
344+ catch ( Exception )
337345 {
338- fontIconSource . Glyph = "\xeb4a " ;
339- tabLocationHeader = NormalizePath ( currentPath ) ;
346+ fontIconSource . Glyph = "\xeb8b " ; //Fallback
340347 }
348+
349+ tabLocationHeader = NormalizePath ( currentPath ) ;
341350 }
342351 else
343352 {
344- fontIconSource . Glyph = "\xea55 " ;
353+ fontIconSource . Glyph = "\xea55 " ; //Folder icon
345354 tabLocationHeader = currentPath . TrimEnd ( Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar ) . Split ( '\\ ' , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
346355 }
347356 }
@@ -492,5 +501,54 @@ private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs
492501 {
493502 MultitaskingControl = HorizontalMultitaskingControl ;
494503 }
504+
505+ private static string GetDriveTypeIcon ( DriveInfo drive )
506+ {
507+ string type ;
508+
509+ switch ( drive . DriveType )
510+ {
511+ case System . IO . DriveType . CDRom :
512+ type = "\xec39 " ;
513+ break ;
514+
515+ case System . IO . DriveType . Fixed :
516+ type = "\xeb8b " ;
517+ break ;
518+
519+ case System . IO . DriveType . Network :
520+ type = "\xeac2 " ;
521+ break ;
522+
523+ case System . IO . DriveType . NoRootDirectory :
524+ type = "\xea5a " ;
525+ break ;
526+
527+ case System . IO . DriveType . Ram :
528+ type = "\xe9f2 " ;
529+ break ;
530+
531+ case System . IO . DriveType . Removable :
532+ type = "\xec0a " ;
533+ break ;
534+
535+ case System . IO . DriveType . Unknown :
536+ if ( NormalizePath ( drive . Name ) != NormalizePath ( "A:" ) && NormalizePath ( drive . Name ) != NormalizePath ( "B:" ) )
537+ {
538+ type = "\xeb8b " ;
539+ }
540+ else
541+ {
542+ type = "\xeb4a " ; //Floppy icon
543+ }
544+ break ;
545+
546+ default :
547+ type = "\xeb8b " ; //Drive icon
548+ break ;
549+ }
550+
551+ return type ;
552+ }
495553 }
496554}
0 commit comments