Skip to content

Commit 43a50e0

Browse files
committed
Implement Removable Drive Access
1 parent e531ae5 commit 43a50e0

File tree

7 files changed

+86
-27
lines changed

7 files changed

+86
-27
lines changed

FileLoader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Windows.UI.Popups;
1313
using Interacts;
1414
using Windows.UI.Xaml.Controls;
15+
using Windows.UI.Xaml.Media.Animation;
1516

1617
namespace ItemListPresenter
1718
{
@@ -342,6 +343,13 @@ public async void GetItemsAsync(string path)
342343
{
343344
DisplayConsentDialog();
344345
}
346+
catch (System.Runtime.InteropServices.COMException e)
347+
{
348+
Frame rootFrame = Window.Current.Content as Frame;
349+
MessageDialog driveGone = new MessageDialog(e.Message, "Drive Not Found");
350+
await driveGone.ShowAsync();
351+
rootFrame.Navigate(typeof(MainPage), new SuppressNavigationTransitionInfo());
352+
}
345353
stopwatch.Stop();
346354
Debug.WriteLine("Loading of: " + path + " completed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
347355

GenericFileBrowser.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Navigation;
44
using System;
55
using System.ComponentModel;
6+
using System.Diagnostics;
67
using System.Linq;
78
using Windows.ApplicationModel.Core;
89
using Windows.ApplicationModel.DataTransfer;
@@ -68,6 +69,8 @@ public GenericFileBrowser()
6869
ReviewBox.SecondaryButtonClick += Interacts.Interaction.SkipChoiceClick;
6970
}
7071

72+
73+
7174
private async void AddItem_ClickAsync(object sender, RoutedEventArgs e)
7275
{
7376
var CurrentView = ApplicationView.GetForCurrentView();
@@ -109,10 +112,6 @@ private void Clipboard_ContentChanged(object sender, object e)
109112

110113
public static UniversalPath p = new UniversalPath();
111114
public static UniversalPath P { get { return GenericFileBrowser.p; } }
112-
113-
//private static GenericFileBrowser getGenericFileBrowser = new GenericFileBrowser();
114-
//public static GenericFileBrowser GetGenericFileBrowser { get { return getGenericFileBrowser; } }
115-
116115

117116
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
118117
{

ItemInteractions.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,18 @@ public static async void List_ItemClick(object sender, DoubleTappedRoutedEventAr
154154
}
155155
else
156156
{
157-
GenericFileBrowser.P.path = clickedOnItem.FilePath;
158-
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
157+
if (clickedOnItem.FilePath.Contains("C:"))
159158
{
160-
if (NavItemChoice is Microsoft.UI.Xaml.Controls.NavigationViewItem && NavItemChoice.Name.ToString() == "LocD_IC")
159+
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
161160
{
162-
MainPage.Select.itemSelected = NavItemChoice;
163-
break;
161+
if (NavItemChoice is Microsoft.UI.Xaml.Controls.NavigationViewItem && NavItemChoice.Name.ToString() == "LocD_IC")
162+
{
163+
MainPage.Select.itemSelected = NavItemChoice;
164+
break;
165+
}
164166
}
165167
}
168+
GenericFileBrowser.P.path = clickedOnItem.FilePath;
166169
ItemViewModel.ViewModel = new ItemViewModel(clickedOnItem.FilePath, GenericFileBrowser.GFBPageName);
167170
}
168171
}
@@ -319,6 +322,7 @@ public static async void List_ItemClick(object sender, DoubleTappedRoutedEventAr
319322
Interaction.message.Commands.Add(new UICommand("Continue...", new UICommandInvokedHandler(Interaction.CommandInvokedHandler)));
320323
Interaction.message.Commands.Add(new UICommand("Cancel"));
321324
await Interaction.message.ShowAsync();
325+
322326
}
323327
else
324328
{
@@ -492,11 +496,6 @@ private static void Manager_DataRequested(DataTransferManager sender, DataReques
492496

493497
}
494498

495-
public static void ScanItem_Click(object sender, RoutedEventArgs e)
496-
{
497-
498-
}
499-
500499
public static void DeleteItem_Click(object sender, RoutedEventArgs e)
501500
{
502501

MainPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423

424424
<UILib:NavigationViewItemHeader Content="Drives"/>
425425

426-
<UILib:NavigationViewItem Content="Local Disk" x:Name="LocD_IC" FontFamily="Segoe UI" Margin="0,0,0,0" Tag="LDPage">
426+
<UILib:NavigationViewItem Content="Local Disk (C:\)" x:Name="LocD_IC" FontFamily="Segoe UI" Margin="0,0,0,0" Tag="LDPage">
427427
<UILib:NavigationViewItem.Icon>
428428
<FontIcon Glyph="&#xEDA2;" FontFamily="Segoe MDL2 Assets"/>
429429
</UILib:NavigationViewItem.Icon>

MainPage.xaml.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
using ItemListPresenter;
22
using System;
3+
using System.Collections;
4+
using System.Collections.ObjectModel;
35
using System.ComponentModel;
46
using System.Diagnostics;
57
using Windows.ApplicationModel.Core;
8+
using Windows.Devices.Enumeration;
9+
using Windows.Devices.Usb;
10+
using Windows.Foundation;
11+
using Windows.Storage;
612
using Windows.UI;
13+
using Windows.UI.Popups;
714
using Windows.UI.ViewManagement;
815
using Windows.UI.Xaml;
916
using Windows.UI.Xaml.Controls;
17+
using Windows.UI.Xaml.Media.Animation;
1018

1119
namespace Files
1220
{
@@ -23,6 +31,7 @@ public sealed partial class MainPage : Page
2331
string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
2432
string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
2533
string VideosPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
34+
2635
public MainPage()
2736
{
2837
this.InitializeComponent();
@@ -36,8 +45,25 @@ public MainPage()
3645
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
3746
nv = navView;
3847
accessibleAutoSuggestBox = auto_suggest;
48+
PopulateNavViewWithExternalDrives();
49+
3950
}
4051

52+
public async void PopulateNavViewWithExternalDrives()
53+
{
54+
StorageFolder RemDevicesFolder = KnownFolders.RemovableDevices;
55+
foreach (StorageFolder fol in await RemDevicesFolder.GetFoldersAsync())
56+
{
57+
nv.MenuItems.Add(new Microsoft.UI.Xaml.Controls.NavigationViewItem()
58+
{
59+
Content = "Removable Drive (" + fol.Name + ")",
60+
Icon = new SymbolIcon((Symbol)0xE88E),
61+
Tag = fol.Name
62+
});
63+
64+
}
65+
}
66+
4167
private static SelectItem select = new SelectItem();
4268
public static SelectItem Select { get { return MainPage.select; } }
4369

@@ -52,17 +78,15 @@ private void navView_ItemSelected(Microsoft.UI.Xaml.Controls.NavigationView send
5278
}
5379
}
5480

55-
56-
57-
81+
5882
private void auto_suggest_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
5983
{
6084

6185
}
6286

6387
private void navView_Loaded(object sender, RoutedEventArgs e)
6488
{
65-
89+
6690
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItemBase NavItemChoice in nv.MenuItems)
6791
{
6892
if (NavItemChoice is Microsoft.UI.Xaml.Controls.NavigationViewItem && NavItemChoice.Name.ToString() == "homeIc")
@@ -80,7 +104,7 @@ private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
80104
{
81105

82106
var item = args.InvokedItem;
83-
107+
var itemContainer = args.InvokedItemContainer;
84108
//var item = Interaction.FindParent<NavigationViewItemBase>(args.InvokedItem as DependencyObject);
85109
if (args.IsSettingsInvoked == true)
86110
{
@@ -129,7 +153,7 @@ private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
129153
ContentFrame.Navigate(typeof(GenericFileBrowser), VideosPath);
130154
auto_suggest.PlaceholderText = "Search Videos";
131155
}
132-
else if (item.ToString() == "Local Disk")
156+
else if (item.ToString() == "Local Disk (C:\\)")
133157
{
134158
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
135159
ContentFrame.Navigate(typeof(GenericFileBrowser), @"C:\");
@@ -141,6 +165,22 @@ private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sende
141165
ContentFrame.Navigate(typeof(GenericFileBrowser), OneDrivePath);
142166
auto_suggest.PlaceholderText = "Search OneDrive";
143167
}
168+
else
169+
{
170+
var tagOfInvokedItem = (nv.MenuItems[nv.MenuItems.IndexOf(itemContainer)] as Microsoft.UI.Xaml.Controls.NavigationViewItem).Tag;
171+
172+
if (StorageFolder.GetFolderFromPathAsync(tagOfInvokedItem.ToString()) != null)
173+
{
174+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
175+
ContentFrame.Navigate(typeof(GenericFileBrowser), tagOfInvokedItem);
176+
auto_suggest.PlaceholderText = "Search " + tagOfInvokedItem;
177+
}
178+
else
179+
{
180+
181+
}
182+
183+
}
144184

145185
}
146186
}

NavigationSystem.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,21 @@ public static void Back_Click(object sender, RoutedEventArgs e)
263263
}
264264
else
265265
{
266-
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
267-
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
266+
267+
if((History.HistoryList[History.HistoryList.Count - 1]).Contains("C:"))
268268
{
269-
if (NavItemChoice is Microsoft.UI.Xaml.Controls.NavigationViewItem && NavItemChoice.Name.ToString() == "LocD_IC")
269+
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItemBase NavItemChoice in MainPage.nv.MenuItems)
270270
{
271-
MainPage.Select.itemSelected = NavItemChoice;
272-
break;
271+
if (NavItemChoice is Microsoft.UI.Xaml.Controls.NavigationViewItem && NavItemChoice.Name.ToString() == "LocD_IC")
272+
{
273+
MainPage.Select.itemSelected = NavItemChoice;
274+
break;
275+
}
273276
}
274277
}
278+
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
275279
ItemViewModel.ViewModel = new ItemViewModel(History.HistoryList[History.HistoryList.Count - 1], GenericFileBrowser.GFBPageName); // To take into account the correct index without interference from the folder being navigated to
280+
276281
}
277282

278283
if (History.ForwardList.Count == 0)

Package.appxmanifest

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" IgnorableNamespaces="uap mp rescap desktop4">
2+
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4" IgnorableNamespaces="uap mp rescap desktop4 desktop uap3 uap4">
33
<Identity Name="cd15f916-6036-4135-8201-430a5c5547dd" Publisher="CN=lukeb" Version="0.4.5.0" />
44
<mp:PhoneIdentity PhoneProductId="cd15f916-6036-4135-8201-430a5c5547dd" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
55
<Properties>
@@ -25,10 +25,18 @@
2525
</uap:DefaultTile>
2626
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="black" />
2727
</uap:VisualElements>
28+
<!--<Extensions>
29+
<desktop:Extension Category="windows.fullTrustProcess" Executable="LegacyLauncher.exe"/>
30+
<uap:Extension Category="windows.appService" EntryPoint="MyAppService.ExeNameProvider">
31+
<uap3:AppService Name="com.placeholder.here" uap4:SupportsMultipleInstances="true"/>
32+
</uap:Extension>
33+
</Extensions>-->
2834
</Application>
2935
</Applications>
3036
<Capabilities>
3137
<Capability Name="internetClient" />
38+
<uap:Capability Name="removableStorage" />
39+
<!--<rescap:Capability Name="runFullTrust"/>-->
3240
<rescap:Capability Name="broadFileSystemAccess" />
3341
</Capabilities>
3442
</Package>

0 commit comments

Comments
 (0)