2929using Windows . UI . Core ;
3030using Windows . Storage . Search ;
3131using Windows . UI . Xaml . Input ;
32+ using Windows . UI . Xaml . Controls . Primitives ;
3233
3334namespace Files
3435{
@@ -42,6 +43,7 @@ public App()
4243 {
4344 this . InitializeComponent ( ) ;
4445 exceptionDialog = new Dialogs . ExceptionDialog ( ) ;
46+ consentDialog = new Dialogs . ConsentDialog ( ) ;
4547 this . Suspending += OnSuspending ;
4648 this . UnhandledException += App_UnhandledException ;
4749
@@ -131,29 +133,39 @@ public void PopulateDrivesListWithLocalDisks()
131133 if ( ! ( await KnownFolders . RemovableDevices . GetFoldersAsync ( ) ) . Select ( x => x . Path ) . ToList ( ) . Contains ( roots . Name ) )
132134 {
133135 // TODO: Display Custom Names for Local Disks as well
134- content = $ "Local Disk ({ roots . Name . TrimEnd ( '\\ ' ) } )";
135- icon = "\uEDA2 " ;
136+ if ( InstanceTabsView . NormalizePath ( roots . Name ) != InstanceTabsView . NormalizePath ( "A:" )
137+ && InstanceTabsView . NormalizePath ( roots . Name ) != InstanceTabsView . NormalizePath ( "B:" ) )
138+ {
139+ content = $ "Local Disk ({ roots . Name . TrimEnd ( '\\ ' ) } )";
140+ icon = "\uEDA2 " ;
141+ }
142+ else
143+ {
144+ content = $ "Floppy Disk ({ roots . Name . TrimEnd ( '\\ ' ) } )";
145+ icon = "\uE74E " ;
146+ }
147+
136148
137149 await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
138150 async ( ) =>
139151 {
140- StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( roots . Name ) ;
141- var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
142-
152+ Visibility capacityBarVis = Visibility . Visible ;
143153 ulong totalSpaceProg = 0 ;
144154 ulong freeSpaceProg = 0 ;
145155 string free_space_text = "Unknown" ;
146156 string total_space_text = "Unknown" ;
147- Visibility capacityBarVis = Visibility . Visible ;
157+
148158 try
149159 {
160+ StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( roots . Name ) ;
161+ var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
162+
150163 var sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . GigaBytes ;
151164 freeSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
152165
153166 sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . GigaBytes ;
154167 totalSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
155168
156-
157169 free_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . ToString ( ) ;
158170 total_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . ToString ( ) ;
159171 }
@@ -193,8 +205,16 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
193205
194206 private async void Watcher_EnumerationCompleted ( DeviceWatcher sender , object args )
195207 {
196- PopulateDrivesListWithLocalDisks ( ) ;
208+ try
209+ {
210+ PopulateDrivesListWithLocalDisks ( ) ;
211+ }
212+ catch ( UnauthorizedAccessException )
213+ {
214+ await consentDialog . ShowAsync ( ) ;
215+ }
197216 DeviceAdded ( sender , null ) ;
217+
198218 await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
199219 ( ) =>
200220 {
@@ -241,14 +261,12 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
241261 {
242262 try
243263 {
244- //var device = StorageDevice.FromId(args.Id);
245264 var devices = ( await KnownFolders . RemovableDevices . GetFoldersAsync ( ) ) . OrderBy ( x => x . Path ) ;
246- foreach ( StorageFolder device in devices )
265+ foreach ( StorageFolder device in devices )
247266 {
248267 var letter = device . Path ;
249- if ( ! foundDrives . Any ( x => x . tag == letter ) )
268+ if ( ! foundDrives . Any ( x => x . tag == letter ) )
250269 {
251- //if (roots.Name == @"C:\") return;
252270 var content = device . DisplayName ;
253271 string icon = null ;
254272 await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
@@ -263,23 +281,22 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
263281 icon = "\uE88E " ;
264282 }
265283
266- StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( letter ) ;
267- var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
268-
269284 ulong totalSpaceProg = 0 ;
270285 ulong freeSpaceProg = 0 ;
271286 string free_space_text = "Unknown" ;
272287 string total_space_text = "Unknown" ;
273288 Visibility capacityBarVis = Visibility . Visible ;
274289 try
275290 {
291+ StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( letter ) ;
292+ var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
293+
276294 var sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . GigaBytes ;
277295 freeSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
278296
279297 sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . GigaBytes ;
280298 totalSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
281299
282-
283300 free_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . ToString ( ) ;
284301 total_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . ToString ( ) ;
285302 }
@@ -306,33 +323,25 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
306323 } ) ;
307324 }
308325 } ) ;
309-
326+
310327 }
311328 }
312329 }
313- catch ( UnauthorizedAccessException e )
330+ catch ( UnauthorizedAccessException )
314331 {
315- Debug . WriteLine ( e . Message ) ;
332+ await consentDialog . ShowAsync ( ) ;
316333 }
317334 }
318335
319336 public static List < string > LinesToRemoveFromFile = new List < string > ( ) ;
320337
321338 public async void PopulatePinnedSidebarItems ( )
322339 {
323-
324340 AddDefaultLocations ( ) ;
325341
326342 StorageFile ListFile ;
327343 StorageFolder cacheFolder = ApplicationData . Current . LocalCacheFolder ;
328- try
329- {
330- ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
331- }
332- catch ( FileNotFoundException )
333- {
334- ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" ) ;
335- }
344+ ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" , CreationCollisionOption . OpenIfExists ) ;
336345
337346 if ( ListFile != null )
338347 {
@@ -399,14 +408,7 @@ public static async void RemoveStaleSidebarItems()
399408 {
400409 StorageFile ListFile ;
401410 StorageFolder cacheFolder = ApplicationData . Current . LocalCacheFolder ;
402- try
403- {
404- ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
405- }
406- catch ( FileNotFoundException )
407- {
408- ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" ) ;
409- }
411+ ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" , CreationCollisionOption . OpenIfExists ) ;
410412
411413 if ( ListFile != null )
412414 {
@@ -464,17 +466,32 @@ public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
464466 public static Windows . UI . Xaml . UnhandledExceptionEventArgs exceptionInfo { get ; set ; }
465467 public static string exceptionStackTrace { get ; set ; }
466468 public Dialogs . ExceptionDialog exceptionDialog ;
469+ public static Dialogs . ConsentDialog consentDialog { get ; set ; }
467470
468471 private async void App_UnhandledException ( object sender , Windows . UI . Xaml . UnhandledExceptionEventArgs e )
469472 {
470473 e . Handled = true ;
471- if ( exceptionDialog . Visibility == Visibility . Visible )
472- exceptionDialog . Hide ( ) ;
473-
474474 exceptionInfo = e ;
475475 exceptionStackTrace = e . Exception . StackTrace ;
476- await exceptionDialog . ShowAsync ( ) ;
476+ await exceptionDialog . ShowAsync ( ) ;
477+ }
477478
479+ public static IReadOnlyList < ContentDialog > FindDisplayedContentDialogs < T > ( )
480+ {
481+ var popupElements = VisualTreeHelper . GetOpenPopupsForXamlRoot ( Window . Current . Content . XamlRoot ) ;
482+ List < ContentDialog > dialogs = new List < ContentDialog > ( ) ;
483+ List < ContentDialog > openDialogs = new List < ContentDialog > ( ) ;
484+ Interaction . FindChildren < ContentDialog > ( dialogs , Window . Current . Content . XamlRoot . Content as DependencyObject ) ;
485+ foreach ( var dialog in dialogs )
486+ {
487+ var popups = new List < Popup > ( ) ;
488+ Interaction . FindChildren < Popup > ( popups , dialog ) ;
489+ if ( popups . First ( ) . IsOpen && popups . First ( ) is T )
490+ {
491+ openDialogs . Add ( dialog ) ;
492+ }
493+ }
494+ return openDialogs ;
478495 }
479496
480497 public static PasteState PS { get ; set ; } = new PasteState ( ) ;
0 commit comments