Skip to content

Commit 2817842

Browse files
authored
Fixed an issue loading recent items on the home page (#1745)
1 parent aa101b7 commit 2817842

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Files/UserControls/Widgets/RecentFiles.xaml.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,16 @@ public async void PopulateRecentsList()
7777
IStorageItem item = await mostRecentlyUsed.GetItemAsync(mruToken);
7878
await AddItemToRecentList(item, entry);
7979
}
80-
catch (FileNotFoundException)
81-
{
82-
mostRecentlyUsed.Remove(mruToken);
83-
}
84-
catch (ArgumentException)
85-
{
86-
mostRecentlyUsed.Remove(mruToken);
87-
}
8880
catch (UnauthorizedAccessException)
8981
{
9082
// Skip item until consent is provided
9183
}
92-
catch (COMException ex)
84+
catch (Exception ex) when (
85+
ex is COMException
86+
|| ex is FileNotFoundException
87+
|| ex is ArgumentException
88+
|| (uint)ex.HResult == 0x8007016A // The cloud file provider is not running
89+
|| (uint)ex.HResult == 0x8000000A) // The data necessary to complete this operation is not yet available
9390
{
9491
mostRecentlyUsed.Remove(mruToken);
9592
System.Diagnostics.Debug.WriteLine(ex);
@@ -113,12 +110,17 @@ private async Task AddItemToRecentList(IStorageItem item, Windows.Storage.Access
113110
Visibility ItemFileIconVis;
114111
if (item.IsOfType(StorageItemTypes.File))
115112
{
116-
using (var inputStream = await ((StorageFile)item).OpenReadAsync())
117-
using (var classicStream = inputStream.AsStreamForRead())
118-
using (var streamReader = new StreamReader(classicStream))
113+
// Try to read the file to check if still exists
114+
// This is only needed to remove files opened from a disconnected android/MTP phone
115+
if (string.IsNullOrEmpty(item.Path)) // This indicates that the file was open from an MTP device
119116
{
120-
// Try to read the file to check if still exists
121-
streamReader.Peek();
117+
using (var inputStream = await ((StorageFile)item).OpenReadAsync())
118+
using (var classicStream = inputStream.AsStreamForRead())
119+
using (var streamReader = new StreamReader(classicStream))
120+
{
121+
// NB: this might trigger the download of the file from OneDrive
122+
streamReader.Peek();
123+
}
122124
}
123125

124126
ItemName = item.Name;

0 commit comments

Comments
 (0)