Skip to content

Commit 9ea0354

Browse files
committed
Added user-consent dialog for broadFileSystemAccess
1 parent 6e55b50 commit 9ea0354

File tree

6 files changed

+116
-15
lines changed

6 files changed

+116
-15
lines changed

App.xaml.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Windows.ApplicationModel;
33
using Windows.ApplicationModel.Activation;
4+
using Windows.Storage;
45
using Windows.UI.Xaml;
56
using Windows.UI.Xaml.Controls;
67
using Windows.UI.Xaml.Navigation;
@@ -53,10 +54,13 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
5354
{
5455
if (rootFrame.Content == null)
5556
{
56-
// When the navigation stack isn't restored navigate to the first page,
57-
// configuring the new page by passing required information as a navigation
58-
// parameter
59-
rootFrame.Navigate(typeof(MainPage), e.Arguments);
57+
58+
// When the navigation stack isn't restored navigate to the first page,
59+
// configuring the new page by passing required information as a navigation
60+
// parameter
61+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
62+
63+
6064
}
6165
// Ensure the current window is active
6266
Window.Current.Activate();

ClassicMode.xaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Page
2+
x:Class="Files.ClassicMode"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Files"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
10+
11+
<Grid>
12+
<SplitView IsPaneOpen="True">
13+
<SplitView.Pane>
14+
<Grid>
15+
<TreeView Name="DirectoryView">
16+
17+
18+
19+
</TreeView>
20+
</Grid>
21+
</SplitView.Pane>
22+
<Grid/>
23+
</SplitView>
24+
25+
26+
</Grid>
27+
</Page>

ClassicMode.xaml.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel.Core;
7+
using Windows.Foundation;
8+
using Windows.Foundation.Collections;
9+
using Windows.UI;
10+
using Windows.UI.ViewManagement;
11+
using Windows.UI.Xaml;
12+
using Windows.UI.Xaml.Controls;
13+
using Windows.UI.Xaml.Controls.Primitives;
14+
using Windows.UI.Xaml.Data;
15+
using Windows.UI.Xaml.Input;
16+
using Windows.UI.Xaml.Media;
17+
using Windows.UI.Xaml.Navigation;
18+
19+
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
20+
21+
namespace Files
22+
{
23+
/// <summary>
24+
/// An empty page that can be used on its own or navigated to within a Frame.
25+
/// </summary>
26+
public sealed partial class ClassicMode : Page
27+
{
28+
public ClassicMode()
29+
{
30+
this.InitializeComponent();
31+
var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar;
32+
CoreTitleBar.ExtendViewIntoTitleBar = true;
33+
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
34+
titleBar.ButtonBackgroundColor = Color.FromArgb(100, 255, 255, 255);
35+
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
36+
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
37+
}
38+
}
39+
}

FileLoader.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using Windows.Storage.Search;
2525
using System.Data.SqlClient;
2626
using System.Threading.Tasks;
27+
using Windows.UI.Popups;
28+
using Interact;
2729

2830
namespace ItemListPresenter
2931
{
@@ -115,8 +117,10 @@ public ItemViewModel(string ViewPath, bool isInPhotoMode)
115117
{
116118
isPhotoAlbumMode = isInPhotoMode;
117119
GenericFileBrowser.P.path = ViewPath;
118-
FilesAndFolders.Clear();
119-
GetItemsAsync(ViewPath);
120+
FilesAndFolders.Clear();
121+
122+
GetItemsAsync(ViewPath);
123+
120124
History.AddToHistory(ViewPath);
121125

122126

@@ -136,7 +140,13 @@ public ItemViewModel(string ViewPath, bool isInPhotoMode)
136140

137141
}
138142

139-
143+
private async void DisplayConsentDialog()
144+
{
145+
MessageDialog message = new MessageDialog("This app is not able to access your files. You need to allow it to by granting permission in Settings.");
146+
message.Title = "Permission Denied";
147+
message.Commands.Add(new UICommand("Allow...", new UICommandInvokedHandler(Interaction.GrantAccessPermissionHandler)));
148+
await message.ShowAsync();
149+
}
140150

141151
private ListedItem li = new ListedItem();
142152
public ListedItem LI { get { return this.li; } }
@@ -156,7 +166,11 @@ public async void GetItemsAsync(string path)
156166
{
157167
IsTerminated = false;
158168
PUIP.Path = path;
159-
folder = await StorageFolder.GetFolderFromPathAsync(path); // Set location to the current directory specified in path
169+
try
170+
{
171+
folder = await StorageFolder.GetFolderFromPathAsync(path); // Set location to the current directory specified in path
172+
173+
160174
QueryOptions options = new QueryOptions()
161175
{
162176
FolderDepth = FolderDepth.Shallow,
@@ -285,6 +299,11 @@ public async void GetItemsAsync(string path)
285299
PVIS.isVisible = Visibility.Collapsed;
286300
//}
287301
IsTerminated = true;
302+
}
303+
catch (UnauthorizedAccessException e)
304+
{
305+
DisplayConsentDialog();
306+
}
288307
}
289308

290309

Files.csproj

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
<Compile Include="App.xaml.cs">
104104
<DependentUpon>App.xaml</DependentUpon>
105105
</Compile>
106+
<Compile Include="ClassicMode.xaml.cs">
107+
<DependentUpon>ClassicMode.xaml</DependentUpon>
108+
</Compile>
106109
<Compile Include="FileLoader.cs" />
107110
<Compile Include="GenericFileBrowser.xaml.cs">
108111
<DependentUpon>GenericFileBrowser.xaml</DependentUpon>
@@ -197,6 +200,10 @@
197200
<Generator>MSBuild:Compile</Generator>
198201
<SubType>Designer</SubType>
199202
</ApplicationDefinition>
203+
<Page Include="ClassicMode.xaml">
204+
<SubType>Designer</SubType>
205+
<Generator>MSBuild:Compile</Generator>
206+
</Page>
200207
<Page Include="GenericFileBrowser.xaml">
201208
<SubType>Designer</SubType>
202209
<Generator>MSBuild:Compile</Generator>
@@ -224,25 +231,25 @@
224231
</ItemGroup>
225232
<ItemGroup>
226233
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
227-
<Version>6.1.7</Version>
234+
<Version>6.2.0-preview1-26926-04</Version>
228235
</PackageReference>
229236
<PackageReference Include="Microsoft.Toolkit.Uwp">
230-
<Version>4.0.0</Version>
237+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
231238
</PackageReference>
232239
<PackageReference Include="Microsoft.Toolkit.Uwp.DeveloperTools">
233-
<Version>4.0.0</Version>
240+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
234241
</PackageReference>
235242
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
236-
<Version>4.0.0</Version>
243+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
237244
</PackageReference>
238245
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
239-
<Version>4.0.0</Version>
246+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
240247
</PackageReference>
241248
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
242-
<Version>4.0.0</Version>
249+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
243250
</PackageReference>
244251
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.DataGrid">
245-
<Version>4.0.0</Version>
252+
<Version>5.0.0-preview.gb86cb1c4cb</Version>
246253
</PackageReference>
247254
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
248255
<Version>2.0.0</Version>

ItemInteractions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ private static async void CommandInvokedHandler(IUICommand command)
108108
await Launcher.LaunchUriAsync(new Uri("ms-windows-store://home"));
109109
}
110110

111+
public static async void GrantAccessPermissionHandler(IUICommand command)
112+
{
113+
await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess"));
114+
}
115+
111116
public static async void PhotoAlbumItemList_ClickAsync(object sender, ItemClickEventArgs e)
112117
{
113118
GridView grid = sender as GridView;

0 commit comments

Comments
 (0)