29
29
using Windows . UI . Core ;
30
30
using Windows . Storage . Search ;
31
31
using Windows . UI . Xaml . Input ;
32
+ using Windows . UI . Xaml . Controls . Primitives ;
32
33
33
34
namespace Files
34
35
{
@@ -42,6 +43,7 @@ public App()
42
43
{
43
44
this . InitializeComponent ( ) ;
44
45
exceptionDialog = new Dialogs . ExceptionDialog ( ) ;
46
+ consentDialog = new Dialogs . ConsentDialog ( ) ;
45
47
this . Suspending += OnSuspending ;
46
48
this . UnhandledException += App_UnhandledException ;
47
49
@@ -131,29 +133,39 @@ public void PopulateDrivesListWithLocalDisks()
131
133
if ( ! ( await KnownFolders . RemovableDevices . GetFoldersAsync ( ) ) . Select ( x => x . Path ) . ToList ( ) . Contains ( roots . Name ) )
132
134
{
133
135
// 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
+
136
148
137
149
await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
138
150
async ( ) =>
139
151
{
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 ;
143
153
ulong totalSpaceProg = 0 ;
144
154
ulong freeSpaceProg = 0 ;
145
155
string free_space_text = "Unknown" ;
146
156
string total_space_text = "Unknown" ;
147
- Visibility capacityBarVis = Visibility . Visible ;
157
+
148
158
try
149
159
{
160
+ StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( roots . Name ) ;
161
+ var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
162
+
150
163
var sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . GigaBytes ;
151
164
freeSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
152
165
153
166
sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . GigaBytes ;
154
167
totalSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
155
168
156
-
157
169
free_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . ToString ( ) ;
158
170
total_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . ToString ( ) ;
159
171
}
@@ -193,8 +205,16 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
193
205
194
206
private async void Watcher_EnumerationCompleted ( DeviceWatcher sender , object args )
195
207
{
196
- PopulateDrivesListWithLocalDisks ( ) ;
208
+ try
209
+ {
210
+ PopulateDrivesListWithLocalDisks ( ) ;
211
+ }
212
+ catch ( UnauthorizedAccessException )
213
+ {
214
+ await consentDialog . ShowAsync ( ) ;
215
+ }
197
216
DeviceAdded ( sender , null ) ;
217
+
198
218
await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
199
219
( ) =>
200
220
{
@@ -241,14 +261,12 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
241
261
{
242
262
try
243
263
{
244
- //var device = StorageDevice.FromId(args.Id);
245
264
var devices = ( await KnownFolders . RemovableDevices . GetFoldersAsync ( ) ) . OrderBy ( x => x . Path ) ;
246
- foreach ( StorageFolder device in devices )
265
+ foreach ( StorageFolder device in devices )
247
266
{
248
267
var letter = device . Path ;
249
- if ( ! foundDrives . Any ( x => x . tag == letter ) )
268
+ if ( ! foundDrives . Any ( x => x . tag == letter ) )
250
269
{
251
- //if (roots.Name == @"C:\") return;
252
270
var content = device . DisplayName ;
253
271
string icon = null ;
254
272
await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Low ,
@@ -263,23 +281,22 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
263
281
icon = "\uE88E " ;
264
282
}
265
283
266
- StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( letter ) ;
267
- var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
268
-
269
284
ulong totalSpaceProg = 0 ;
270
285
ulong freeSpaceProg = 0 ;
271
286
string free_space_text = "Unknown" ;
272
287
string total_space_text = "Unknown" ;
273
288
Visibility capacityBarVis = Visibility . Visible ;
274
289
try
275
290
{
291
+ StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( letter ) ;
292
+ var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
293
+
276
294
var sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . GigaBytes ;
277
295
freeSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
278
296
279
297
sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . GigaBytes ;
280
298
totalSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
281
299
282
-
283
300
free_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . ToString ( ) ;
284
301
total_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . ToString ( ) ;
285
302
}
@@ -306,33 +323,25 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
306
323
} ) ;
307
324
}
308
325
} ) ;
309
-
326
+
310
327
}
311
328
}
312
329
}
313
- catch ( UnauthorizedAccessException e )
330
+ catch ( UnauthorizedAccessException )
314
331
{
315
- Debug . WriteLine ( e . Message ) ;
332
+ await consentDialog . ShowAsync ( ) ;
316
333
}
317
334
}
318
335
319
336
public static List < string > LinesToRemoveFromFile = new List < string > ( ) ;
320
337
321
338
public async void PopulatePinnedSidebarItems ( )
322
339
{
323
-
324
340
AddDefaultLocations ( ) ;
325
341
326
342
StorageFile ListFile ;
327
343
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 ) ;
336
345
337
346
if ( ListFile != null )
338
347
{
@@ -399,14 +408,7 @@ public static async void RemoveStaleSidebarItems()
399
408
{
400
409
StorageFile ListFile ;
401
410
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 ) ;
410
412
411
413
if ( ListFile != null )
412
414
{
@@ -464,17 +466,32 @@ public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
464
466
public static Windows . UI . Xaml . UnhandledExceptionEventArgs exceptionInfo { get ; set ; }
465
467
public static string exceptionStackTrace { get ; set ; }
466
468
public Dialogs . ExceptionDialog exceptionDialog ;
469
+ public static Dialogs . ConsentDialog consentDialog { get ; set ; }
467
470
468
471
private async void App_UnhandledException ( object sender , Windows . UI . Xaml . UnhandledExceptionEventArgs e )
469
472
{
470
473
e . Handled = true ;
471
- if ( exceptionDialog . Visibility == Visibility . Visible )
472
- exceptionDialog . Hide ( ) ;
473
-
474
474
exceptionInfo = e ;
475
475
exceptionStackTrace = e . Exception . StackTrace ;
476
- await exceptionDialog . ShowAsync ( ) ;
476
+ await exceptionDialog . ShowAsync ( ) ;
477
+ }
477
478
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 ;
478
495
}
479
496
480
497
public static PasteState PS { get ; set ; } = new PasteState ( ) ;
0 commit comments