Skip to content

Commit 2110ed8

Browse files
committed
Only Show Fully-Supported Drives
1 parent 5d62ca9 commit 2110ed8

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

Files/Filesystem/Drives.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@ public class DrivesManager
2424

2525
public DrivesManager()
2626
{
27+
Task findDrivesTask = null;
2728
try
2829
{
29-
GetDrives(Drives);
30-
GetVirtualDrivesList(Drives);
30+
findDrivesTask = GetDrives(Drives);
3131
}
3232
catch (AggregateException e)
3333
{
3434
ShowUserConsentOnInit = true;
3535
}
3636

37-
_deviceWatcher = DeviceInformation.CreateWatcher(StorageDevice.GetDeviceSelector());
38-
_deviceWatcher.Added += DeviceAdded;
39-
_deviceWatcher.Removed += DeviceRemoved;
40-
_deviceWatcher.Updated += DeviceUpdated;
41-
_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
42-
_deviceWatcher.Start();
37+
findDrivesTask.ContinueWith((x) =>
38+
{
39+
GetVirtualDrivesList(Drives);
40+
41+
_deviceWatcher = DeviceInformation.CreateWatcher(StorageDevice.GetDeviceSelector());
42+
_deviceWatcher.Added += DeviceAdded;
43+
_deviceWatcher.Removed += DeviceRemoved;
44+
_deviceWatcher.Updated += DeviceUpdated;
45+
_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
46+
_deviceWatcher.Start();
47+
});
48+
4349
}
4450

4551
private async void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
@@ -87,7 +93,11 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
8793
// Update the collection on the ui-thread.
8894
try
8995
{
90-
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); });
96+
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
97+
{
98+
Drives.Add(driveItem);
99+
DeviceWatcher_EnumerationCompleted(null, null);
100+
});
91101
}
92102
catch (Exception e)
93103
{
@@ -110,7 +120,11 @@ private async void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate a
110120
// Update the collection on the ui-thread.
111121
try
112122
{
113-
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Remove(drive); });
123+
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
124+
{
125+
Drives.Remove(drive);
126+
DeviceWatcher_EnumerationCompleted(null, null);
127+
});
114128
}
115129
catch (Exception e)
116130
{
@@ -126,9 +140,20 @@ private void DeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate args)
126140
Debug.WriteLine("Devices updated");
127141
}
128142

129-
private void GetDrives(IList<DriveItem> list)
143+
private async Task GetDrives(IList<DriveItem> list)
130144
{
131-
var drives = DriveInfo.GetDrives();
145+
var drives = DriveInfo.GetDrives().ToList();
146+
147+
var remDevices = await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector());
148+
var supportedDevicesNames = remDevices.Select(x => StorageDevice.FromId(x.Id).Name);
149+
foreach (DriveInfo driveInfo in drives.ToList())
150+
{
151+
if (!supportedDevicesNames.Contains(driveInfo.Name) && driveInfo.DriveType == System.IO.DriveType.Removable)
152+
{
153+
drives.Remove(driveInfo);
154+
}
155+
}
156+
132157

133158
foreach (var drive in drives)
134159
{

Files/Filesystem/ItemViewModel.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -653,31 +653,30 @@ public async void RapidAddItemsToCollectionAsync(string path)
653653
App.CurrentInstance.NavigationControl.CanGoBack = App.CurrentInstance.ContentFrame.CanGoBack;
654654
App.CurrentInstance.NavigationControl.CanGoForward = App.CurrentInstance.ContentFrame.CanGoForward;
655655

656-
try
657-
{
658-
_rootFolder = await StorageFolder.GetFolderFromPathAsync(path);
659-
}
660-
catch (UnauthorizedAccessException)
661-
{
662-
await App.consentDialog.ShowAsync();
663-
return;
664-
}
665-
catch (COMException e)
666-
{
667-
Frame rootContentFrame = Window.Current.Content as Frame;
668-
MessageDialog driveGone = new MessageDialog(e.Message, "Did you unplug this drive?");
669-
await driveGone.ShowAsync();
670-
isLoadingItems = false;
671-
return;
672-
}
673-
catch (FileNotFoundException)
674-
{
675-
Frame rootContentFrame = Window.Current.Content as Frame;
676-
MessageDialog folderGone = new MessageDialog("The folder you've navigated to was not found.", "Did you delete this folder?");
677-
await folderGone.ShowAsync();
678-
isLoadingItems = false;
679-
return;
680-
}
656+
try
657+
{
658+
_rootFolder = await StorageFolder.GetFolderFromPathAsync(path);
659+
}
660+
catch (UnauthorizedAccessException)
661+
{
662+
await App.consentDialog.ShowAsync();
663+
return;
664+
}
665+
catch (FileNotFoundException)
666+
{
667+
MessageDialog folderGone = new MessageDialog("The folder you've navigated to was not found.", "Did you delete this folder?");
668+
await folderGone.ShowAsync();
669+
isLoadingItems = false;
670+
return;
671+
}
672+
catch (Exception e)
673+
{
674+
MessageDialog driveGone = new MessageDialog(e.Message, "Did you unplug this drive?");
675+
await driveGone.ShowAsync();
676+
isLoadingItems = false;
677+
return;
678+
}
679+
681680

682681
WIN32_FIND_DATA findData;
683682
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoStandard;

0 commit comments

Comments
 (0)