@@ -77,19 +77,16 @@ public async void PopulateRecentsList()
77
77
IStorageItem item = await mostRecentlyUsed . GetItemAsync ( mruToken ) ;
78
78
await AddItemToRecentList ( item , entry ) ;
79
79
}
80
- catch ( FileNotFoundException )
81
- {
82
- mostRecentlyUsed . Remove ( mruToken ) ;
83
- }
84
- catch ( ArgumentException )
85
- {
86
- mostRecentlyUsed . Remove ( mruToken ) ;
87
- }
88
80
catch ( UnauthorizedAccessException )
89
81
{
90
82
// Skip item until consent is provided
91
83
}
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
93
90
{
94
91
mostRecentlyUsed . Remove ( mruToken ) ;
95
92
System . Diagnostics . Debug . WriteLine ( ex ) ;
@@ -113,12 +110,17 @@ private async Task AddItemToRecentList(IStorageItem item, Windows.Storage.Access
113
110
Visibility ItemFileIconVis ;
114
111
if ( item . IsOfType ( StorageItemTypes . File ) )
115
112
{
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
119
116
{
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
+ }
122
124
}
123
125
124
126
ItemName = item . Name ;
0 commit comments