Skip to content

Commit 42d3c3e

Browse files
committed
Handle Exceptions During WinRT Extended Property Load
1 parent 4191f45 commit 42d3c3e

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

Files/Filesystem/ItemViewModel.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -545,29 +545,57 @@ public async void LoadExtendedItemProperties(ListedItem item)
545545
{
546546
BitmapImage icon = new BitmapImage();
547547
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
548-
var matchingStorageItem = await StorageFile.GetFileFromPathAsync(item.FilePath);
549-
if (matchingItem != null && matchingStorageItem != null)
548+
try
550549
{
551-
matchingItem.FileType = matchingStorageItem.DisplayType;
552-
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
553-
var Thumbnail = await matchingStorageItem.GetThumbnailAsync(ThumbnailMode.ListView, 20, ThumbnailOptions.UseCurrentScale);
554-
if (Thumbnail != null)
550+
var matchingStorageItem = await StorageFile.GetFileFromPathAsync(item.FilePath);
551+
if (matchingItem != null && matchingStorageItem != null)
555552
{
556-
matchingItem.FileImg = icon;
557-
await icon.SetSourceAsync(Thumbnail);
558-
matchingItem.EmptyImgVis = Visibility.Collapsed;
559-
matchingItem.FileIconVis = Visibility.Visible;
553+
matchingItem.FileType = matchingStorageItem.DisplayType;
554+
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
555+
var Thumbnail = await matchingStorageItem.GetThumbnailAsync(ThumbnailMode.ListView, 20, ThumbnailOptions.UseCurrentScale);
556+
if (Thumbnail != null)
557+
{
558+
matchingItem.FileImg = icon;
559+
await icon.SetSourceAsync(Thumbnail);
560+
matchingItem.EmptyImgVis = Visibility.Collapsed;
561+
matchingItem.FileIconVis = Visibility.Visible;
562+
}
560563
}
561564
}
565+
catch (UnauthorizedAccessException)
566+
{
567+
await App.consentDialog.ShowAsync();
568+
return;
569+
}
570+
catch (FileNotFoundException)
571+
{
572+
item.ItemPropertiesInitialized = true;
573+
return;
574+
}
575+
562576
}
563577
else
564578
{
565579
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
566-
var matchingStorageItem = await StorageFolder.GetFolderFromPathAsync(item.FilePath);
567-
if (matchingItem != null && matchingStorageItem != null)
580+
try
568581
{
569-
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
582+
var matchingStorageItem = await StorageFolder.GetFolderFromPathAsync(item.FilePath);
583+
if (matchingItem != null && matchingStorageItem != null)
584+
{
585+
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
586+
}
570587
}
588+
catch (UnauthorizedAccessException)
589+
{
590+
await App.consentDialog.ShowAsync();
591+
return;
592+
}
593+
catch (FileNotFoundException)
594+
{
595+
item.ItemPropertiesInitialized = true;
596+
return;
597+
}
598+
571599
}
572600

573601
item.ItemPropertiesInitialized = true;
@@ -630,6 +658,7 @@ public async void RapidAddItemsToCollectionAsync(string path)
630658
catch (UnauthorizedAccessException)
631659
{
632660
await App.consentDialog.ShowAsync();
661+
return;
633662
}
634663
catch (COMException e)
635664
{

Files/Views/Pages/ProHome.xaml.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,6 @@ private async void ProHomeInstance_KeyUp(object sender, KeyRoutedEventArgs e)
313313
case (false, false, false, true, VirtualKey.Delete): //delete, delete item
314314
App.CurrentInstance.InteractionOperations.DeleteItem_Click(null, null);
315315
break;
316-
case (false, false, false, true, VirtualKey.Enter): //enter, open item
317-
App.CurrentInstance.InteractionOperations.List_ItemClick(null, null);
318-
break;
319316
case (false, false, false, true, VirtualKey.Space): //space, quick look
320317
if ((App.CurrentInstance.ContentPage).IsQuickLookEnabled)
321318
{

0 commit comments

Comments
 (0)