2020-03-24 13:01:14 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Infrastructure.UWP
|
|
|
|
|
{
|
|
|
|
|
public class UwpRecentFilesClient: IRecentProxy
|
|
|
|
|
{
|
|
|
|
|
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
|
|
|
|
|
|
|
|
|
public int EntryCount => _mru.Entries.Count;
|
|
|
|
|
|
2020-04-07 17:29:03 +02:00
|
|
|
|
public async Task<FileInfo> Get(string token, bool updateAccessTime = false)
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-04-07 17:29:03 +02:00
|
|
|
|
var file = await _mru.GetFileAsync(token, updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate);
|
2020-04-07 12:48:18 +02:00
|
|
|
|
StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file);
|
2020-03-24 13:01:14 +01:00
|
|
|
|
return new FileInfo
|
|
|
|
|
{
|
2020-04-07 12:48:18 +02:00
|
|
|
|
Id = token,
|
2020-03-24 13:01:14 +01:00
|
|
|
|
Name = file.DisplayName,
|
2020-04-07 12:48:18 +02:00
|
|
|
|
Path = file.Path
|
2020-03-24 13:01:14 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<FileInfo>> GetAll()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<FileInfo>();
|
|
|
|
|
foreach (var entry in _mru.Entries)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var recentItem = await Get(entry.Token);
|
|
|
|
|
result.Add(recentItem);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_mru.Remove(entry.Token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Add(FileInfo recentItem)
|
|
|
|
|
{
|
2020-04-07 12:48:18 +02:00
|
|
|
|
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(recentItem.Id);
|
|
|
|
|
_mru.Add(file);
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearAll()
|
|
|
|
|
{
|
|
|
|
|
for (var i = _mru.Entries.Count; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
var entry = _mru.Entries[i];
|
2020-04-07 12:48:18 +02:00
|
|
|
|
StorageApplicationPermissions.FutureAccessList.Remove(entry.Token);
|
2020-03-24 13:01:14 +01:00
|
|
|
|
_mru.Remove(entry.Token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|