2017-12-01 17:59:38 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using ModernKeePass.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Services
|
|
|
|
|
{
|
2018-02-23 18:09:21 +01:00
|
|
|
|
public class RecentService : SingletonServiceBase<RecentService>, IRecentService
|
2017-12-01 17:59:38 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
2018-02-23 18:09:21 +01:00
|
|
|
|
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public int EntryCount => _mru.Entries.Count;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<IRecentItem> GetAllFiles(bool removeIfNonExistant = true)
|
|
|
|
|
{
|
|
|
|
|
var result = new ObservableCollection<IRecentItem>();
|
|
|
|
|
foreach (var entry in _mru.Entries)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var file = _mru.GetFileAsync(entry.Token, AccessCacheOptions.SuppressAccessTimeUpdate).GetAwaiter().GetResult();
|
|
|
|
|
result.Add(new RecentItemVm(entry.Token, entry.Metadata, file));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
if (removeIfNonExistant) _mru.Remove(entry.Token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(IStorageItem file, string metadata)
|
|
|
|
|
{
|
|
|
|
|
_mru.Add(file, metadata);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 10:46:01 +01:00
|
|
|
|
public void ClearAll()
|
|
|
|
|
{
|
|
|
|
|
_mru.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public async Task<IStorageItem> GetFileAsync(string token)
|
|
|
|
|
{
|
|
|
|
|
return await _mru.GetFileAsync(token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|