@@ -166,196 +166,64 @@ private void Button_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEven
166
166
167
167
public async void PopulateRecentsList ( )
168
168
{
169
- recentItemsCollection . Clear ( ) ;
170
- dataFolder = Windows . Storage . ApplicationData . Current . LocalCacheFolder ;
171
- RecentsFile = await dataFolder . CreateFileAsync ( "recents.txt" , CreationCollisionOption . OpenIfExists ) ;
169
+ var mostRecentlyUsed = Windows . Storage . AccessCache . StorageApplicationPermissions . MostRecentlyUsedList ;
172
170
BitmapImage ItemImage = new BitmapImage ( ) ;
173
171
string ItemPath = null ;
174
172
string ItemName ;
175
173
Visibility ItemFolderImgVis ;
176
174
Visibility ItemEmptyImgVis ;
177
175
Visibility ItemFileIconVis ;
178
- IList < string > lines = new List < string > ( ) ;
179
- lines = await FileIO . ReadLinesAsync ( RecentsFile ) ;
180
- if ( lines . Count == 0 )
176
+ if ( mostRecentlyUsed . Entries . Count == 0 )
181
177
{
182
178
Empty . Visibility = Visibility . Visible ;
183
179
}
184
- else if ( lines . Count > 10 )
180
+ else
181
+ {
182
+ Empty . Visibility = Visibility . Collapsed ;
183
+ }
184
+ foreach ( Windows . Storage . AccessCache . AccessListEntry entry in mostRecentlyUsed . Entries )
185
185
{
186
+ string mruToken = entry . Token ;
186
187
try
187
188
{
188
- for ( int LineNum = 0 ; LineNum < 10 ; LineNum ++ )
189
+ Windows . Storage . IStorageItem item = await mostRecentlyUsed . GetItemAsync ( mruToken ) ;
190
+ if ( item . IsOfType ( StorageItemTypes . Folder ) )
189
191
{
190
- lines . RemoveAt ( 0 ) ;
192
+ ItemName = item . Name ;
193
+ ItemPath = item . Path ;
194
+ ItemFolderImgVis = Visibility . Visible ;
195
+ ItemEmptyImgVis = Visibility . Collapsed ;
196
+ ItemFileIconVis = Visibility . Collapsed ;
197
+ recentItemsCollection . Add ( new RecentItem ( ) { name = ItemName , path = ItemPath , EmptyImgVis = ItemEmptyImgVis , FolderImg = ItemFolderImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
191
198
}
192
-
193
- await FileIO . WriteLinesAsync ( RecentsFile , lines ) ;
194
- Empty . Visibility = Visibility . Collapsed ;
195
- lines = await FileIO . ReadLinesAsync ( RecentsFile ) ;
196
- foreach ( string s in lines )
199
+ else if ( item . IsOfType ( StorageItemTypes . File ) )
197
200
{
198
- try
201
+ ItemName = item . Name ;
202
+ ItemPath = item . Path ;
203
+ ItemImage = new BitmapImage ( ) ;
204
+ StorageFile file = await StorageFile . GetFileFromPathAsync ( ItemPath ) ;
205
+ var thumbnail = await file . GetThumbnailAsync ( Windows . Storage . FileProperties . ThumbnailMode . ListView , 30 , Windows . Storage . FileProperties . ThumbnailOptions . ResizeThumbnail ) ;
206
+ if ( thumbnail == null )
199
207
{
200
- var item = await StorageFolder . GetFolderFromPathAsync ( s ) ;
201
- ItemName = item . DisplayName ;
202
- ItemPath = item . Path ;
203
- ItemFolderImgVis = Visibility . Visible ;
204
- ItemEmptyImgVis = Visibility . Collapsed ;
205
- ItemFileIconVis = Visibility . Collapsed ;
206
- if ( ! recentItemsCollection . Contains ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) )
207
- {
208
- recentItemsCollection . Add ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
209
- }
210
-
208
+ ItemEmptyImgVis = Visibility . Visible ;
211
209
}
212
- catch ( System . IO . FileNotFoundException )
213
- {
214
- IList < string > modifyLines = new List < string > ( ) ;
215
- modifyLines = lines ;
216
- modifyLines . Remove ( s ) ;
217
- await FileIO . WriteLinesAsync ( RecentsFile , modifyLines ) ;
218
- PopulateRecentsList ( ) ;
219
- }
220
- catch ( UnauthorizedAccessException )
221
- {
222
- Empty . Visibility = Visibility . Visible ;
223
- }
224
- catch ( System . ArgumentException )
225
- {
226
- var item = await StorageFile . GetFileFromPathAsync ( s ) ;
227
- ItemName = item . DisplayName ;
228
- ItemPath = item . Path ;
229
- ItemImage = new BitmapImage ( ) ;
230
- var thumbnail = await item . GetThumbnailAsync ( Windows . Storage . FileProperties . ThumbnailMode . ListView , 30 , Windows . Storage . FileProperties . ThumbnailOptions . ResizeThumbnail ) ;
231
- if ( thumbnail == null )
232
- {
233
- ItemEmptyImgVis = Visibility . Visible ;
234
- }
235
- else
236
- {
237
- await ItemImage . SetSourceAsync ( thumbnail . CloneStream ( ) ) ;
238
- ItemEmptyImgVis = Visibility . Collapsed ;
239
- }
240
- ItemFolderImgVis = Visibility . Collapsed ;
241
- ItemFileIconVis = Visibility . Visible ;
242
- if ( ! recentItemsCollection . Contains ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) )
243
- {
244
- recentItemsCollection . Add ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
245
- }
246
- }
247
- }
248
- }
249
- catch ( System . IO . FileNotFoundException )
250
- {
251
- if ( ItemPath != null )
252
- {
253
- RemoveDeletedItemFromList ( ItemPath , lines ) ;
254
- }
255
- else
256
- {
257
- Debug . WriteLine ( "Attempted to delete redundant RecentItem from file when ItemPath was never set." ) ;
258
- }
259
- }
260
- catch ( COMException )
261
- {
262
- if ( ItemPath != null )
263
- {
264
- RemoveDeletedItemFromList ( ItemPath , lines ) ;
265
- }
266
- else
267
- {
268
- Debug . WriteLine ( "Attempted to delete redundant RecentItem from file when ItemPath was never set." ) ;
269
- }
270
- }
271
- }
272
- else
273
- {
274
- try
275
- {
276
- Empty . Visibility = Visibility . Collapsed ;
277
-
278
- foreach ( string s in lines )
279
- {
280
- try
210
+ else
281
211
{
282
- ItemPath = s ;
283
- var item = await StorageFolder . GetFolderFromPathAsync ( s ) ;
284
- ItemName = item . DisplayName ;
285
- ItemPath = item . Path ;
286
- ItemFolderImgVis = Visibility . Visible ;
212
+ await ItemImage . SetSourceAsync ( thumbnail . CloneStream ( ) ) ;
287
213
ItemEmptyImgVis = Visibility . Collapsed ;
288
- ItemFileIconVis = Visibility . Collapsed ;
289
- if ( ! recentItemsCollection . Contains ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) )
290
- {
291
- recentItemsCollection . Add ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
292
- }
293
-
294
- }
295
- catch ( UnauthorizedAccessException )
296
- {
297
- Empty . Visibility = Visibility . Visible ;
298
- }
299
- catch ( System . ArgumentException )
300
- {
301
- var item = await StorageFile . GetFileFromPathAsync ( s ) ;
302
- ItemName = item . DisplayName ;
303
- ItemPath = item . Path ;
304
- ItemImage = new BitmapImage ( ) ;
305
- var thumbnail = await item . GetThumbnailAsync ( Windows . Storage . FileProperties . ThumbnailMode . ListView , 30 , Windows . Storage . FileProperties . ThumbnailOptions . ResizeThumbnail ) ;
306
- if ( thumbnail == null )
307
- {
308
- ItemEmptyImgVis = Visibility . Visible ;
309
- }
310
- else
311
- {
312
- await ItemImage . SetSourceAsync ( thumbnail . CloneStream ( ) ) ;
313
- ItemEmptyImgVis = Visibility . Collapsed ;
314
- }
315
- ItemFolderImgVis = Visibility . Collapsed ;
316
- ItemFileIconVis = Visibility . Visible ;
317
- if ( ! recentItemsCollection . Contains ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) )
318
- {
319
- recentItemsCollection . Add ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
320
- }
321
214
}
215
+ ItemFolderImgVis = Visibility . Collapsed ;
216
+ ItemFileIconVis = Visibility . Visible ;
217
+ recentItemsCollection . Add ( new RecentItem ( ) { path = ItemPath , name = ItemName , FolderImg = ItemFolderImgVis , EmptyImgVis = ItemEmptyImgVis , FileImg = ItemImage , FileIconVis = ItemFileIconVis } ) ;
322
218
}
323
219
}
324
220
catch ( System . IO . FileNotFoundException )
325
221
{
326
- if ( ItemPath != null )
327
- {
328
- RemoveDeletedItemFromList ( ItemPath , lines ) ;
329
- }
330
- else
331
- {
332
- Debug . WriteLine ( "Attempted to delete redundant RecentItem from file when ItemPath was never set." ) ;
333
- }
222
+ mostRecentlyUsed . Remove ( mruToken ) ;
334
223
}
335
- catch ( COMException )
336
- {
337
- if ( ItemPath != null )
338
- {
339
- RemoveDeletedItemFromList ( ItemPath , lines ) ;
340
- }
341
- else
342
- {
343
- Debug . WriteLine ( "Attempted to delete redundant RecentItem from file when ItemPath was never set." ) ;
344
- }
345
- }
346
-
347
224
}
348
225
}
349
226
350
- private async void RemoveDeletedItemFromList ( string s , IList < string > lines )
351
- {
352
- IList < string > modifyLines = new List < string > ( ) ;
353
- modifyLines = lines ;
354
- modifyLines . Remove ( s ) ;
355
- await FileIO . WriteLinesAsync ( RecentsFile , modifyLines ) ;
356
- PopulateRecentsList ( ) ;
357
- }
358
-
359
227
private async void RecentsView_ItemClick ( object sender , ItemClickEventArgs e )
360
228
{
361
229
var path = ( e . ClickedItem as RecentItem ) . path ;
@@ -376,6 +244,10 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
376
244
await Launcher . LaunchFileAsync ( file , options ) ;
377
245
}
378
246
}
247
+ catch ( UnauthorizedAccessException )
248
+ {
249
+ await GetCurrentSelectedTabInstance < ProHome > ( ) . permissionBox . ShowAsync ( ) ;
250
+ }
379
251
catch ( System . ArgumentException )
380
252
{
381
253
GetCurrentSelectedTabInstance < ProHome > ( ) . accessibleContentFrame . Navigate ( typeof ( GenericFileBrowser ) , path ) ;
@@ -387,13 +259,13 @@ private void RecentsView_RightTapped(object sender, Windows.UI.Xaml.Input.RightT
387
259
388
260
}
389
261
390
- private async void MenuFlyoutItem_Click ( object sender , RoutedEventArgs e )
262
+ private void MenuFlyoutItem_Click ( object sender , RoutedEventArgs e )
391
263
{
392
264
recentItemsCollection . Clear ( ) ;
393
265
RecentsView . ItemsSource = null ;
394
- await RecentsFile . DeleteAsync ( ) ;
395
- GetCurrentSelectedTabInstance < ProHome > ( ) . accessibleContentFrame . Navigate ( typeof ( YourHome ) , null , new Windows . UI . Xaml . Media . Animation . SuppressNavigationTransitionInfo ( ) ) ;
396
-
266
+ var mru = Windows . Storage . AccessCache . StorageApplicationPermissions . MostRecentlyUsedList ;
267
+ mru . Clear ( ) ;
268
+ Empty . Visibility = Visibility . Visible ;
397
269
}
398
270
399
271
private void DropShadowPanel_PointerPressed ( object sender , Windows . UI . Xaml . Input . PointerRoutedEventArgs e )
0 commit comments