@@ -235,24 +235,22 @@ ex is UnauthorizedAccessException
235
235
}
236
236
237
237
using var thumbnail = ( StorageItemThumbnail ) await FilesystemTasks . Wrap ( ( ) => root . GetThumbnailAsync ( ThumbnailMode . SingleItem , 40 , ThumbnailOptions . UseCurrentScale ) . AsTask ( ) ) ;
238
+ var driveItem = await DriveItem . CreateFromPropertiesAsync ( root , deviceId , type , thumbnail ) ;
239
+
238
240
lock ( drivesList )
239
241
{
240
242
// If drive already in list, skip.
241
243
if ( drivesList . Any ( x => x . DeviceID == deviceId ||
242
- string . IsNullOrEmpty ( root . Path ) ? x . Path . Contains ( root . Name , StringComparison . Ordinal ) : x . Path == root . Path ) )
244
+ string . IsNullOrEmpty ( root . Path ) ? x . Path . Contains ( root . Name , StringComparison . OrdinalIgnoreCase ) : x . Path == root . Path ) )
243
245
{
244
246
return ;
245
247
}
246
- }
247
-
248
- var driveItem = await DriveItem . CreateFromPropertiesAsync ( root , deviceId , type , thumbnail ) ;
249
-
250
- lock ( drivesList )
251
- {
248
+
252
249
Logger . Info ( $ "Drive added: { driveItem . Path } , { driveItem . Type } ") ;
253
250
254
251
drivesList . Add ( driveItem ) ;
255
252
}
253
+
256
254
// Update the collection on the ui-thread.
257
255
DeviceWatcher_EnumerationCompleted ( null , null ) ;
258
256
}
@@ -291,20 +289,17 @@ private async Task<bool> GetDrivesAsync()
291
289
}
292
290
293
291
using var thumbnail = ( StorageItemThumbnail ) await FilesystemTasks . Wrap ( ( ) => res . Result . GetThumbnailAsync ( ThumbnailMode . SingleItem , 40 , ThumbnailOptions . UseCurrentScale ) . AsTask ( ) ) ;
292
+ var type = GetDriveType ( drive ) ;
293
+ var driveItem = await DriveItem . CreateFromPropertiesAsync ( res . Result , drive . Name . TrimEnd ( '\\ ' ) , type , thumbnail ) ;
294
+
294
295
lock ( drivesList )
295
296
{
296
297
// If drive already in list, skip.
297
298
if ( drivesList . Any ( x => x . Path == drive . Name ) )
298
299
{
299
300
continue ;
300
301
}
301
- }
302
-
303
- var type = GetDriveType ( drive ) ;
304
- var driveItem = await DriveItem . CreateFromPropertiesAsync ( res . Result , drive . Name . TrimEnd ( '\\ ' ) , type , thumbnail ) ;
305
302
306
- lock ( drivesList )
307
- {
308
303
Logger . Info ( $ "Drive added: { driveItem . Path } , { driveItem . Type } ") ;
309
304
drivesList . Add ( driveItem ) ;
310
305
}
@@ -448,29 +443,27 @@ public async Task HandleWin32DriveEvent(DeviceEvent eventType, string deviceId)
448
443
return ;
449
444
}
450
445
446
+ DriveItem driveItem ;
447
+
448
+ using ( var thumbnail = ( StorageItemThumbnail ) await FilesystemTasks . Wrap ( ( ) => rootAdded . Result . GetThumbnailAsync ( ThumbnailMode . SingleItem , 40 , ThumbnailOptions . UseCurrentScale ) . AsTask ( ) ) )
449
+ {
450
+ var type = GetDriveType ( driveAdded ) ;
451
+ driveItem = await DriveItem . CreateFromPropertiesAsync ( rootAdded , deviceId , type , thumbnail ) ;
452
+ }
453
+
451
454
lock ( drivesList )
452
455
{
453
456
// If drive already in list, skip.
454
457
var matchingDrive = drivesList . FirstOrDefault ( x => x . DeviceID == deviceId ||
455
- string . IsNullOrEmpty ( rootAdded . Result . Path ) ? x . Path . Contains ( rootAdded . Result . Name , StringComparison . Ordinal ) : x . Path == rootAdded . Result . Path ) ;
458
+ string . IsNullOrEmpty ( rootAdded . Result . Path ) ? x . Path . Contains ( rootAdded . Result . Name , StringComparison . OrdinalIgnoreCase ) : x . Path == rootAdded . Result . Path ) ;
456
459
if ( matchingDrive != null )
457
460
{
458
461
// Update device id to match drive letter
459
462
matchingDrive . DeviceID = deviceId ;
460
463
return ;
461
464
}
462
- }
463
-
464
- using ( var thumbnail = ( StorageItemThumbnail ) await FilesystemTasks . Wrap ( ( ) => rootAdded . Result . GetThumbnailAsync ( ThumbnailMode . SingleItem , 40 , ThumbnailOptions . UseCurrentScale ) . AsTask ( ) ) )
465
- {
466
- var type = GetDriveType ( driveAdded ) ;
467
- var driveItem = await DriveItem . CreateFromPropertiesAsync ( rootAdded , deviceId , type , thumbnail ) ;
468
-
469
- lock ( drivesList )
470
- {
471
- Logger . Info ( $ "Drive added from fulltrust process: { driveItem . Path } , { driveItem . Type } ") ;
472
- drivesList . Add ( driveItem ) ;
473
- }
465
+ Logger . Info ( $ "Drive added from fulltrust process: { driveItem . Path } , { driveItem . Type } ") ;
466
+ drivesList . Add ( driveItem ) ;
474
467
}
475
468
476
469
DeviceWatcher_EnumerationCompleted ( null , null ) ;
0 commit comments