5
5
using Files . ViewModels ;
6
6
using Microsoft . Toolkit . Uwp . Extensions ;
7
7
using System ;
8
+ using System . Collections . Generic ;
8
9
using System . Collections . ObjectModel ;
9
10
using System . ComponentModel ;
10
11
using System . IO ;
@@ -317,31 +318,39 @@ private static async Task SetSelectedTabInfoAsync(TabItem selectedTabItem, strin
317
318
// If path is a drive's root
318
319
if ( NormalizePath ( Path . GetPathRoot ( currentPath ) ) == NormalizePath ( currentPath ) )
319
320
{
320
- if ( NormalizePath ( currentPath ) != NormalizePath ( "A:" ) && NormalizePath ( currentPath ) != NormalizePath ( "B:" ) )
321
+ try
321
322
{
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 ) ) ) ;
324
325
325
- if ( matchingDriveName = = null )
326
+ if ( matchingDrive ! = null )
326
327
{
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
+ }
329
338
}
330
339
else
331
340
{
332
- fontIconSource . Glyph = "\xec0a " ;
333
- tabLocationHeader = matchingDriveName ;
341
+ fontIconSource . Glyph = "\xeb4a " ; //Floppy icon
334
342
}
335
343
}
336
- else
344
+ catch ( Exception )
337
345
{
338
- fontIconSource . Glyph = "\xeb4a " ;
339
- tabLocationHeader = NormalizePath ( currentPath ) ;
346
+ fontIconSource . Glyph = "\xeb8b " ; //Fallback
340
347
}
348
+
349
+ tabLocationHeader = NormalizePath ( currentPath ) ;
341
350
}
342
351
else
343
352
{
344
- fontIconSource . Glyph = "\xea55 " ;
353
+ fontIconSource . Glyph = "\xea55 " ; //Folder icon
345
354
tabLocationHeader = currentPath . TrimEnd ( Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar ) . Split ( '\\ ' , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
346
355
}
347
356
}
@@ -492,5 +501,54 @@ private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs
492
501
{
493
502
MultitaskingControl = HorizontalMultitaskingControl ;
494
503
}
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
+ }
495
553
}
496
554
}
0 commit comments