mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
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
|
|
{
|
|
public class RecentService : IRecent
|
|
{
|
|
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
|
|
|
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);
|
|
}
|
|
|
|
public async Task<IStorageItem> GetFileAsync(string token)
|
|
{
|
|
return await _mru.GetFileAsync(token);
|
|
}
|
|
}
|
|
}
|