2020-03-24 13:01:14 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-04-09 19:43:06 +02:00
|
|
|
|
using System.Linq;
|
2020-04-24 13:58:30 +02:00
|
|
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
2020-03-24 13:01:14 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
2020-04-24 13:58:30 +02:00
|
|
|
|
using Windows.Storage;
|
2020-03-24 13:01:14 +01:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Infrastructure.UWP
|
|
|
|
|
{
|
|
|
|
|
public class UwpRecentFilesClient: IRecentProxy
|
|
|
|
|
{
|
|
|
|
|
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
|
|
|
|
|
|
|
|
|
public int EntryCount => _mru.Entries.Count;
|
|
|
|
|
|
2020-04-24 13:58:30 +02:00
|
|
|
|
public async Task<byte[]> Get(string token, bool updateAccessTime = true)
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
try
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
var file = await _mru.GetFileAsync(token,
|
|
|
|
|
updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate).AsTask().ConfigureAwait(false);
|
2020-04-24 13:58:30 +02:00
|
|
|
|
|
|
|
|
|
var result = await FileIO.ReadBufferAsync(file).AsTask();
|
|
|
|
|
return result.ToArray();
|
2020-04-09 19:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_mru.Remove(token);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public IEnumerable<FileInfo> GetAll()
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
return _mru.Entries.Select(e => new FileInfo
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
Id = e.Token,
|
|
|
|
|
Name = e.Metadata?.Substring(e.Metadata.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1),
|
|
|
|
|
Path = e.Metadata
|
|
|
|
|
});
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
2020-04-24 13:58:30 +02:00
|
|
|
|
|
2020-03-24 13:01:14 +01:00
|
|
|
|
public void ClearAll()
|
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
foreach (var entry in _mru.Entries)
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
|
|
|
|
_mru.Remove(entry.Token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|